Skip to content

Commit d424488

Browse files
initial commit
0 parents  commit d424488

File tree

11 files changed

+258
-0
lines changed

11 files changed

+258
-0
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": [ "michaelcontento" ]
3+
}

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[package.json]
12+
indent_size = 2
13+
14+
[Makefile]
15+
indent_style = tab

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# build artefacts
2+
/build/
3+
4+
# npm
5+
/node_modules/
6+
/npm-debug.log
7+
/redux-storage-*.tgz
8+

.jshintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"esnext": true
3+
}

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: node_js
2+
node_js:
3+
- "5.5"
4+
- "5.4"
5+
- "5.3"
6+
- "5.2"
7+
- "5.1"
8+
- "5.0"
9+
- "4.2"
10+
- "4.1"
11+
- "0.12"
12+
- "0.10"

LICENSE.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Michael Contento
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Makefile

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
BIN = ./node_modules/.bin
2+
NPM = npm --loglevel=error
3+
4+
#
5+
# INSTALL
6+
#
7+
8+
install: node_modules/
9+
10+
node_modules/: package.json
11+
echo "> Installing ..."
12+
$(NPM) --ignore-scripts install > /dev/null
13+
touch node_modules/
14+
15+
#
16+
# CLEAN
17+
#
18+
19+
clean:
20+
echo "> Cleaning ..."
21+
rm -rf build/
22+
23+
mrproper: clean
24+
echo "> Cleaning deep ..."
25+
rm -rf node_modules/
26+
27+
#
28+
# BUILD
29+
#
30+
31+
build: clean install
32+
echo "> Building ..."
33+
$(BIN)/babel src/ --out-dir build/
34+
35+
build-watch: clean install
36+
echo "> Building forever ..."
37+
$(BIN)/babel src/ --out-dir build/ --watch
38+
39+
#
40+
# TEST
41+
#
42+
43+
lint: install
44+
echo "> Linting ..."
45+
$(BIN)/eslint src/
46+
47+
test: install
48+
echo "> Testing ..."
49+
$(BIN)/mocca
50+
51+
test-watch: install
52+
echo "> Testing forever ..."
53+
$(BIN)/mocca --watch
54+
55+
#
56+
# PUBLISH
57+
#
58+
59+
_publish : NODE_ENV ?= production
60+
_publish: lint test build
61+
62+
publish-fix: _publish
63+
$(BIN)/release-it --increment patch
64+
65+
publish-feature: _publish
66+
$(BIN)/release-it --increment minor
67+
68+
publish-breaking: _publish
69+
$(BIN)/release-it --increment major
70+
71+
#
72+
# MAKEFILE
73+
#
74+
75+
.PHONY: \
76+
install \
77+
clean mrproper \
78+
build build-watch \
79+
lint test test-watch \
80+
publish-fix publish-feature publish-breaking
81+
82+
.SILENT:

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# [redux-storage-engine-localStorage][]
2+
3+
[![build](https://travis-ci.org/michaelcontento/redux-storage-engine-localStorage.svg)](https://travis-ci.org/michaelcontento/redux-storage-engine-localStorage)
4+
[![dependencies](https://david-dm.org/michaelcontento/redux-storage-engine-localStorage.svg)](https://david-dm.org/michaelcontento/redux-storage-engine-localStorage)
5+
[![devDependencies](https://david-dm.org/michaelcontento/redux-storage-engine-localStorage/dev-status.svg)](https://david-dm.org/michaelcontento/redux-storage-engine-localStorage#info=devDependencies)
6+
7+
[![license](https://img.shields.io/npm/l/redux-storage-engine-localStorage.svg?style=flat-square)](https://www.npmjs.com/package/redux-storage-engine-localStorage)
8+
[![npm version](https://img.shields.io/npm/v/redux-storage-engine-localStorage.svg?style=flat-square)](https://www.npmjs.com/package/redux-storage-engine-localStorage)
9+
[![npm downloads](https://img.shields.io/npm/dm/redux-storage-engine-localStorage.svg?style=flat-square)](https://www.npmjs.com/package/redux-storage-engine-localStorage)
10+
[![Code Climate](https://codeclimate.com/github/michaelcontento/redux-storage-engine-localStorage/badges/gpa.svg)](https://codeclimate.com/github/michaelcontento/redux-storage-engine-localStorage)
11+
12+
`window.localStorage` based engine for [redux-storage][].
13+
14+
## Installation
15+
16+
npm install --save redux-storage-engine-localStorage
17+
18+
## Usage
19+
20+
Stores everything inside `window.localStorage`.
21+
22+
```js
23+
import createEngine from 'redux-storage-engine-localStorage';
24+
const engine = createEngine('my-save-key');
25+
```
26+
27+
**Warning**: `localStorage` does not expose a async API and every save/load
28+
operation will block the JS thread!
29+
30+
**Warning**: Some browsers like IE<=11 does not support Promises! If you don't
31+
want to polyfill the whole Promise API, [redux-storage-engine-localStorageFakePromise][]
32+
might be a possible solution for you.
33+
34+
## License
35+
36+
The MIT License (MIT)
37+
38+
Copyright (c) 2015 Michael Contento
39+
40+
Permission is hereby granted, free of charge, to any person obtaining a copy of
41+
this software and associated documentation files (the "Software"), to deal in
42+
the Software without restriction, including without limitation the rights to
43+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
44+
the Software, and to permit persons to whom the Software is furnished to do so,
45+
subject to the following conditions:
46+
47+
The above copyright notice and this permission notice shall be included in all
48+
copies or substantial portions of the Software.
49+
50+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
51+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
52+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
53+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
54+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
55+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
56+
57+
[redux-storage]: https://github.com/michaelcontento/redux-storage
58+
[redux-storage-engine-localStorage]: https://github.com/michaelcontento/redux-storage-engine-localStorage
59+
[redux-storage-engine-localStorageFakePromise]: https://github.com/michaelcontento/redux-storage-engine-localStorageFakePromise

package.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "redux-storage-engine-localStorage",
3+
"version": "1.0.0",
4+
"description": "window.localStorage engine for redux-storage",
5+
"main": "build/index.js",
6+
"jsnext:main": "src/index.js",
7+
"scripts": {
8+
"test": "make lint test build"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/michaelcontento/redux-storage-engine-localStorage.git"
13+
},
14+
"homepage": "https://github.com/michaelcontento/redux-storage-engine-localStorage",
15+
"keywords": [
16+
"redux",
17+
"redux-storage",
18+
"redux-storage-engine",
19+
"localStorage"
20+
],
21+
"author": "Michael Contento <[email protected]>",
22+
"files": [
23+
"build/",
24+
"src",
25+
"!**/__tests__/**"
26+
],
27+
"eslintConfig": {
28+
"extends": "michaelcontento"
29+
},
30+
"license": "MIT",
31+
"devDependencies": {
32+
"babel-cli": "^6.4.0",
33+
"babel-core": "^6.4.0",
34+
"babel-polyfill": "^6.3.14",
35+
"babel-preset-michaelcontento": "^1.3.0",
36+
"eslint": "^1.10.3",
37+
"eslint-config-michaelcontento": "^1.1.1",
38+
"eslint-plugin-mocha-only": "0.0.3",
39+
"mocca": "^0.3.0",
40+
"release-it": "^2.3.1"
41+
}
42+
}

src/__tests__/index-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
describe('engine', () => {
2+
});

src/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default (key) => ({
2+
load() {
3+
const jsonState = localStorage.getItem(key);
4+
return Promise.resolve(JSON.parse(jsonState) || {});
5+
},
6+
7+
save(state) {
8+
const jsonState = JSON.stringify(state);
9+
localStorage.setItem(key, jsonState);
10+
return Promise.resolve();
11+
}
12+
});

0 commit comments

Comments
 (0)