Skip to content

Commit

Permalink
Initial commit with version that probably does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Feb 23, 2016
0 parents commit ef187de
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"plugins": [ "add-module-exports" ],
"presets": [ "es2015" ]
}
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Commenting this out is preferred by some people, see
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules

# Users Environment Variables
.lock-wscript

# The compiled/babelified modules
lib/
31 changes: 31 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"node": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": "nofunc",
"newcap": false,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
"strict": false,
"trailing": true,
"smarttabs": true,
"white": false,
"node": true,
"browser": true,
"globals": {
"it": true,
"describe": true,
"before": true,
"beforeEach": true,
"after": true,
"afterEach": true
}
}
8 changes: 8 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.editorconfig
.jshintrc
.travis.yml
.babelrc
.idea/
src/
test/
!lib/
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: node_js
node_js:
- 'node'
- 'iojs'
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 Feathers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# feathers-localstorage

[![Build Status](https://travis-ci.org/feathersjs/feathers-localstorage.png?branch=master)](https://travis-ci.org/feathersjs/feathers-localstorage)

> A client side service based on feathers-memory that persists to LocalStorage
## About


## Changelog

__0.1.0__

- Initial release

## License

Copyright (c) 2015

Licensed under the [MIT license](LICENSE).
57 changes: 57 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "feathers-localstorage",
"description": "A client side service based on feathers-memory that persists to LocalStorage",
"version": "0.0.0",
"homepage": "https://github.com/feathersjs/feathers-localstorage",
"main": "lib/",
"keywords": [
"feathers",
"feathers-plugin"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/feathersjs/feathers-localstorage.git"
},
"author": {
"name": "Feathers contributors",
"email": "hello@feathersjs.com",
"url": "https://feathersjs.com"
},
"contributors": [],
"bugs": {
"url": "https://github.com/feathersjs/feathers-localstorage/issues"
},
"engines": {
"node": ">= 0.12.0"
},
"scripts": {
"prepublish": "npm run compile",
"publish": "git push origin && git push origin --tags",
"release:patch": "npm version patch && npm publish",
"release:minor": "npm version minor && npm publish",
"release:major": "npm version major && npm publish",
"compile": "rm -rf lib/ && babel -d lib/ src/",
"watch": "babel --watch -d lib/ src/",
"jshint": "jshint src/. test/. --config",
"mocha": "mocha test/ --compilers js:babel-core/register",
"test": "npm run compile && npm run jshint && npm run mocha"
},
"directories": {
"lib": "lib"
},
"dependencies": {
"debug": "^2.2.0",
"feathers-memory": "^0.6.1",
"lodash": "^4.5.1"
},
"devDependencies": {
"babel-cli": "^6.5.1",
"babel-core": "^6.5.2",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-preset-es2015": "^6.5.0",
"feathers": "^2.0.0",
"jshint": "^2.9.1",
"mocha": "^2.4.5"
}
}
42 changes: 42 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Service } from 'feathers-memory';
import debounce from 'lodash/debounce';

class LocalStorage extends Service {
constructor(options = {}) {
super(options);
this.storageKey = options.name || 'feathers';
this.storage = options.storage || window.LocalStorage;
this.store = JSON.parse(this.storage.getItem(this.storageKey) || '{}');
this.write = debounce(() =>
this.storage.setItem(this.storageKey, JSON.stringify(this.store)),
options.throttle || 100
);
}

flush(data) {
this.write();
return data;
}

create(... args) {
return super.create(... args).then(this.flush);
}

patch(... args) {
return super.patch(... args).then(this.flush);
}

update(... args) {
return super.update(... args).then(this.flush);
}

remove(... args) {
return super.remove(... args).then(this.flush);
}
}

export default function init(options) {
return new LocalStorage(options);
}

init.Service = Service;
13 changes: 13 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import assert from 'assert';
import plugin from '../src';

describe('feathers-localstorage', () => {
it('is CommonJS compatible', () => {
assert.equal(typeof require('../lib'), 'function');
});

it('basic functionality', done => {
assert.equal(typeof plugin, 'function', 'It worked');
done();
});
});

0 comments on commit ef187de

Please sign in to comment.