Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add working example #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Is identical to a plain Javascript [ES6 Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) but with a cap on it's size. Once `x` amount of items have been added to the set it will start dropping the first item in the set.

## Test on RunKit
[trasherdk/fixedset](https://runkit.com/trasherdk/fixedset)

## Usage

### Syntax
Expand All @@ -10,8 +13,32 @@ Is identical to a plain Javascript [ES6 Set](https://developer.mozilla.org/en-US
new Set(setSize: number, ...items: T[])`
```

### Example
## Examples

### Plain Javascript/Node
```javascript
const FixedSet = require("@magic8bot/fixedset").FixedSet;

var data = [
{ "o": 10.0, "h":15.0, "l":9.5, "c":11.0 },
{ "o": 11.0, "h":12.5, "l":9.8, "c":12.0 },
{ "o": 12.0, "h":15.5, "l":10.5, "c":13.0 },
{ "o": 13.0, "h":16.0, "l":10.5, "c":14.0 }
];

var fixedset = new FixedSet(5, data);

for (let item of fixedset.values())
console.log(item);

console.log("Add one object");

fixedset.add({"o": 14.0, "h": 14.5, "l": 12.0, "c":13.5});

for (let item of fixedset.values())
console.log(item);
```
### Typescript
```typescript
import { FixedSet } from '@magic8bot/fixedset'

Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ js-tokens@^3.0.2:
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"

js-yaml@^3.7.0:
version "3.12.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.12.0.tgz#eaed656ec8344f10f527c6bfa1b6e2244de167d1"
version "3.14.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.14.0.tgz#a7a34170f26a21bb162424d8adacb4113a69e482"
dependencies:
argparse "^1.0.7"
esprima "^4.0.0"
Expand Down