Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

data-store

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

data-store - npm Package Compare versions

Comparing version 0.8.1 to 0.8.2

71

index.js

@@ -9,7 +9,4 @@ 'use strict';

var util = require('util');
var typeOf = require('kind-of');
var omit = require('object.omit');
var extend = require('extend-shallow');
var Emitter = require('component-emitter');
var visit = require('collection-visit');
var lazy = require('lazy-cache')(require);

@@ -24,11 +21,14 @@ /**

var lazy = require('lazy-cache')(require);
var lazyFs = lazy('graceful-fs');
var lazyDel = lazy('rimraf');
var lazyMkdir = lazy('mkdirp');
var lazyGet = lazy('get-value');
var lazySet = lazy('set-value');
var lazyHas = lazy('has-value');
var lazyUnion = lazy('union-value');
var lazyHasOwn = lazy('has-own-deep');
lazy('collection-visit', 'visit');
lazy('extend-shallow', 'extend');
lazy('get-value', 'get');
lazy('graceful-fs', 'fs');
lazy('has-own-deep', 'hasOwn');
lazy('has-value', 'has');
lazy('kind-of', 'typeOf');
lazy('mkdirp', 'mkdirp');
lazy('object.omit', 'omit');
lazy('rimraf', 'del');
lazy('set-value', 'set');
lazy('union-value', 'union');

@@ -56,2 +56,3 @@ /**

* @option {String} [options] `cwd` Current working directory for storage. If not defined, the user home directory is used, based on OS. This is the only option currently, other may be added in the future.
* @option {Number} [options] `indent` Number passed to `JSON.stringify` when saving the data. Defaults to `2` if `null` or `undefined`
* @api public

@@ -69,2 +70,3 @@ */

this.indent = options.indent;
this.name = name;

@@ -114,8 +116,8 @@ this.path = path.join(cwd, name + '.json');

} else if (typeOf(val) === 'object') {
} else if (lazy.typeOf(val) === 'object') {
var existing = this.get(key);
val = extend({}, existing, val);
val = lazy.extend({}, existing, val);
}
lazySet()(this.data, key, val);
lazy.set(this.data, key, val);
this.emit('set', key, val);

@@ -144,4 +146,6 @@

Store.prototype.union = function (key, val) {
lazyUnion()(this.data, key, val);
lazy.union(this.data, key, val);
this.emit('union', key, val);
this.save();
return this;

@@ -169,3 +173,3 @@ };

Store.prototype.get = function (key) {
return key ? lazyGet()(this.data, key) : {
return key ? lazy.get(this.data, key) : {
name: this.name,

@@ -193,3 +197,3 @@ data: this.data

Store.prototype.has = function(key) {
return lazyHas()(this.data, key);
return lazy.has(this.data, key);
};

@@ -222,3 +226,3 @@

}
return lazyHasOwn()(this.data, key);
return lazy.hasOwn(this.data, key);
};

@@ -237,3 +241,3 @@

Store.prototype.save = function(dest) {
writeJson(dest || this.path, this.data);
writeJson(dest || this.path, this.data, this.indent);
};

@@ -268,3 +272,4 @@

if (keys.length) {
this.data = omit(this.data, keys);
this.data = lazy.omit(this.data, keys);
this.save();
return this;

@@ -274,6 +279,5 @@ }

options = options || {};
var del = lazyDel();
// if no keys are passed, delete the entire store
del(this.path, options, function (err) {
lazy.del(this.path, options, function (err) {
if (err) return console.error(err);

@@ -294,3 +298,3 @@ this.data = {};

Store.prototype.visit = function(method, object) {
visit(this, method, object);
lazy.visit(this, method, object);
return this;

@@ -322,4 +326,3 @@ };

try {
var fs = lazyFs();
var str = fs.readFileSync(path.resolve(fp), 'utf8');
var str = lazy.fs.readFileSync(path.resolve(fp), 'utf8');
return JSON.parse(str);

@@ -336,13 +339,15 @@ } catch(err) {}

* @param {String} `str`
* @param {Number} `indent` Indent passed to JSON.stringify (default 2)
*/
function writeJson(dest, str) {
function writeJson(dest, str, indent) {
if (typeof indent === 'undefined' || indent === null) {
indent = 2;
}
var dir = path.dirname(dest);
var fs = lazyFs();
try {
var mkdir = lazyMkdir();
if (!fs.existsSync(dir)) {
mkdir.sync(dir);
if (!lazy.fs.existsSync(dir)) {
lazy.mkdirp.sync(dir);
}
fs.writeFileSync(dest, JSON.stringify(str, null, 2));
lazy.fs.writeFileSync(dest, JSON.stringify(str, null, indent));
} catch (err) {

@@ -349,0 +354,0 @@ err.origin = __filename;

{
"name": "data-store",
"description": "Easily get, set and persist config data.",
"version": "0.8.1",
"version": "0.8.2",
"homepage": "https://github.com/jonschlinkert/data-store",

@@ -23,3 +23,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

"dependencies": {
"collection-visit": "^0.1.0",
"collection-visit": "^0.1.1",
"component-emitter": "^1.2.0",

@@ -32,3 +32,3 @@ "extend-shallow": "^2.0.1",

"kind-of": "^2.0.0",
"lazy-cache": "^0.1.0",
"lazy-cache": "^0.2.2",
"mkdirp": "^0.5.1",

@@ -35,0 +35,0 @@ "object.omit": "^2.0.0",

@@ -37,3 +37,3 @@ # data-store [![Build Status](https://travis-ci.org/jonschlinkert/data-store.svg)](https://travis-ci.org/jonschlinkert/data-store) [![NPM version](https://badge.fury.io/js/data-store.svg)](http://badge.fury.io/js/data-store)

### [Store](index.js#L57)
### [Store](index.js#L58)

@@ -48,2 +48,3 @@ Initialize a new `Store` with the given `name` and `options`.

- `cwd` **{String}**: Current working directory for storage. If not defined, the user home directory is used, based on OS. This is the only option currently, other may be added in the future.
- `indent` **{Number}**: Number passed to `JSON.stringify` when saving the data. Defaults to `2` if `null` or `undefined`

@@ -60,3 +61,3 @@ **Example**

### [.set](index.js#L102)
### [.set](index.js#L104)

@@ -93,3 +94,3 @@ Assign `value` to `key` and save to disk. Can be a key-value pair or an object.

### [.union](index.js#L138)
### [.union](index.js#L140)

@@ -113,3 +114,3 @@ Add or append an array of unique values to the given `key`.

### [.get](index.js#L162)
### [.get](index.js#L166)

@@ -134,3 +135,3 @@ Get the stored `value` of `key`, or return the entire store if no `key` is defined.

### [.has](index.js#L185)
### [.has](index.js#L189)

@@ -154,3 +155,3 @@ Returns `true` if the specified `key` has truthy value.

### [.hasOwn](index.js#L210)
### [.hasOwn](index.js#L214)

@@ -179,3 +180,3 @@ Returns `true` if the specified `key` exists.

### [.save](index.js#L227)
### [.save](index.js#L231)

@@ -194,3 +195,3 @@ Persist the store to disk.

### [.del](index.js#L249)
### [.del](index.js#L253)

@@ -250,2 +251,2 @@ Delete `keys` from the store, or delete the entire store if no keys are passed.

_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on August 01, 2015._
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on August 19, 2015._
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc