|
1 |
| -# Welcome to simple-data-storage |
| 1 | +# SData.js |
2 | 2 | 
|
3 | 3 | [](https://github.com/artmakarov/simple-data-storage/graphs/commit-activity)
|
4 | 4 | [](https://github.com/artmakarov/simple-data-storage/blob/master/LICENSE)
|
5 | 5 |
|
6 |
| -> Simple key-value storage |
| 6 | +> Simple key-value storage in the browser or node |
| 7 | +
|
| 8 | + |
| 9 | +## Install |
| 10 | + |
| 11 | +```shell script |
| 12 | +npm i simple-data-storage |
| 13 | +``` |
| 14 | + |
| 15 | +in browser: |
| 16 | + |
| 17 | +``` |
| 18 | +<script src="//unpkg.com/[email protected]/dist/sdata.min.js"></script> |
| 19 | +``` |
| 20 | + |
| 21 | + |
| 22 | +## Usage example |
| 23 | + |
| 24 | +```js |
| 25 | +const sdata = require('simple-data-storage'); |
| 26 | + |
| 27 | +sdata('one_key', 'one_value'); |
| 28 | +console.log(sdata('one_key')); //=> one_value |
| 29 | + |
| 30 | +sdata(321, 963); |
| 31 | +sdata('other key', { abc: 'boom!' }); |
| 32 | +console.log(sdata(321)); //=> 963 |
| 33 | +console.log(sdata('321')); //=> 963 |
| 34 | +console.log(sdata('other key')); //=> { abc: 'boom!' } |
| 35 | +console.log(sdata('other key').abc); //=> boom! |
| 36 | + |
| 37 | +// clear one item |
| 38 | +sdata.clear('other key'); |
| 39 | +console.log(sdata('other key')); //=> undefined |
| 40 | +console.log(sdata('one_key')); //=> one_value |
| 41 | + |
| 42 | +// clear all items |
| 43 | +sdata(123, ['test', 4]); |
| 44 | +sdata.clear(); |
| 45 | +console.log(sdata(123)); //=> undefined |
| 46 | +console.log(sdata('one_key')); //=> undefined |
| 47 | +``` |
| 48 | + |
| 49 | +In the browser, use the global function **SData()** |
| 50 | + |
| 51 | +```html |
| 52 | +<script> |
| 53 | + SData('key', { data: [1, 'two', { other: 3 }] }); |
| 54 | + alert(SData('key').data[2].other); //=> 3 |
| 55 | +</script> |
| 56 | +``` |
| 57 | + |
| 58 | +## Development |
| 59 | + |
| 60 | +```shell script |
| 61 | +git clone [email protected]:artmakarov/simple-data-storage.git |
| 62 | +cd simple-data-storage |
| 63 | +npm install |
| 64 | +npm run build |
| 65 | +``` |
| 66 | + |
| 67 | +#### Tests |
| 68 | + |
| 69 | +```shell script |
| 70 | +npm run test |
| 71 | +``` |
| 72 | + |
7 | 73 |
|
8 | 74 | ## Contributing
|
9 | 75 |
|
10 | 76 | Contributions, issues and feature requests are welcome!
|
11 | 77 |
|
12 | 78 | Feel free to check [issues page](https://github.com/artmakarov/simple-data-storage/issues).
|
13 | 79 |
|
14 |
| -## Show your support |
15 |
| - |
16 |
| -Give a ⭐️ if this project helped you! |
17 | 80 |
|
18 | 81 | ## License
|
19 | 82 |
|
|
0 commit comments