https://github.com/anzerr/storage.ts
Util to store data used in a service
https://github.com/anzerr/storage.ts
data nodejs storage typescript util
Last synced: about 1 month ago
JSON representation
Util to store data used in a service
- Host: GitHub
- URL: https://github.com/anzerr/storage.ts
- Owner: anzerr
- License: mit
- Created: 2020-01-17T15:26:40.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-01-21T16:45:18.000Z (over 4 years ago)
- Last Synced: 2025-05-25T11:07:14.041Z (about 1 year ago)
- Topics: data, nodejs, storage, typescript, util
- Language: TypeScript
- Homepage:
- Size: 376 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
### `Intro`

// explain
#### `Install`
``` bash
npm install --save git+https://git@github.com/anzerr/storage.ts.git
npm install --save @anzerr/storage.ts
```
### `Example`
``` javascript
import {Counter, Ref, PoolCounter, Cache, NetworkMap} from 'storage.ts';
const count = new Counter();
count.duration('test', 200);
for (let i = 0; i < runs; i++) {
count.add('test', 1);
}
console.log(count.get('test'), count.reduce('test'));
const ref = new Ref();
console.log(ref.get('cat'), ref.get('dog'), ref.get('cat'), ref.getRef(2)) // 1, 2, 1, 'dog'
const pool = new PoolCounter({
timeout: 2000, // how long added data exists
interval: 100 // how long the pool be drained
});
for (let i = 0; i < 1000; i++) {
pool.add('test', 'cat', 1);
pool.add('test', 'dog', 1);
}
console.log(pool.get());
setTimeout(() => {
console.log(pool.get());
}, 1000);
const cache = new Cache();
console.log(cache.get('test')); // null
cache.set('test', 'tests', 1000);
console.log(cache.get('test')); // tests
cache.clear('test');
console.log(cache.get('test')); // null
const map = new NetworkMap({
timeout: 2000, // when the data added should time out and be dropped
interval: 100 // at what interval should the pooled data be drained and added to it's map
});
map.add('cat', 'dog', 100);
map.add('cat', 'dog', 1000);
map.add('cat', 'egg', 100);
console.log(map.get());
```