Comparing version 0.14.3 to 0.15.0
@@ -1,2 +0,1 @@ | ||
module.exports=function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){function r(t){this._path=[],this._root=this,this._state=t}var i=n(4),o=n(5),u=n(2);r.prototype={getPath:function(t){return this._path.concat(t).filter(function(t){return void 0!==t})},getRoot:function(){return this._root},getState:function(){return this.getRoot()._state},commit:function(t){this.getRoot()._state=t},get:function(t,e){var n=u(this.getState(),this.getPath(t));return void 0===n?e:n},set:function(t,e){1===arguments.length&&(e=arguments[0],t=void 0),this.commit(i(this.getState(),this.getPath(t),e))},remove:function(t){this.commit(o(this.getState(),this.getPath(t)))},refine:function(t){return Object.create(this,{_path:{value:this.getPath(t)}})},keys:function(){return Object.keys(this.valueOf()||{})},values:function(){var t=this;return this.keys().map(function(e){return t.get(e)})},valueOf:function(){return u(this.getState(),this.getPath())},toJSON:function(){return this.valueOf()},is:function(t){return t.valueOf()==this.valueOf()},find:function(){return this.filter.apply(this,arguments)[0]},first:function(){return this.values().shift()},last:function(){return this.values().pop()},size:function(){return this.values().length}};var s=["sort","map","reduce","filter","forEach","some","every","join"];s.forEach(function(t){r.prototype[t]=function(){var e;return(e=this.values())[t].apply(e,arguments)}}),t.exports=r},function(t,e,n){t.exports=function(t){if(Array.isArray(t))return t.slice();var e={};for(var n in t)e[n]=t[n];return e}},function(t,e,n){var r=n(3);t.exports=function(t,e){for(var n=!0;n;){u=s=void 0,n=!1;var i=t,o=e,u=o[0],s=o.slice(1);if(!u)return i;if(r(i,o)===!1)return void 0;if(!s.length)return i[u];t=i[u],e=s,n=!0}}},function(t,e,n){t.exports=function(t,e){var n=!0;t:for(;n;){o=u=s=a=void 0,n=!1;var r=t,i=e,o=i[0],u=i.slice(1),s=void 0!==r,a=s&&o in r;if(u.length){if(a){t=r[o],e=u,n=!0;continue t}return!1}return a}}},function(t,e,n){var r=n(1),i=n(2);t.exports=function o(t,e,n){if(i(t,e)===n)return t;var u=e[0],s=e.slice(1),a=r(t);return s.length?a[u]=o(u in a?a[u]:{},s,n):u?a[u]=n:a=n,a}},function(t,e,n){var r=n(1),i=n(3);t.exports=function o(t,e){if(i(t,e)===!1)return t;var n=e[0],u=e.slice(1),s=r(t);return u.length?s[n]=o(t[n],u):delete s[n],s}}]); | ||
//# sourceMappingURL=Foliage.js.map | ||
module.exports=function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){function r(t){this._path=[],this._root=this,this._state=t}var i=n(3),u=n(4),o=n(1);r.prototype={getPath:function(t){return this._path.concat(t).filter(function(t){return void 0!==t})},getRoot:function(){return this._root},getState:function(){return this.getRoot()._state},commit:function(t){this.getRoot()._state=t},get:function(t,e){var n=o(this.getState(),this.getPath(t));return void 0===n?e:n},set:function(t,e){1===arguments.length&&(e=arguments[0],t=void 0),this.commit(i(this.getState(),this.getPath(t),e))},remove:function(t){this.commit(u(this.getState(),this.getPath(t)))},refine:function(t){return Object.create(this,{_path:{value:this.getPath(t)}})},keys:function(){return Object.keys(this.valueOf()||{})},values:function(){return this.keys().map(function(t){return this.get(t)},this)},valueOf:function(){return o(this.getState(),this.getPath())},toJSON:function(){return this.valueOf()},is:function(t){return t.valueOf()==this.valueOf()},find:function(t,e){return this.filter(t,e)[0]},includes:function(t){return this.indexOf(t)>-1},first:function(){return this.values().shift()},last:function(){return this.values().pop()},size:function(){return this.values().length}};var s=["sort","map","reduce","filter","forEach","some","every","join","indexOf"];s.forEach(function(t){r.prototype[t]=function(){var e;return(e=this.values())[t].apply(e,arguments)}}),t.exports=r},function(t,e,n){t.exports=function(t,e){return e.reduce(function(t,e){return t?t[e]:void 0},t)}},function(t,e,n){t.exports=function(t){if(Array.isArray(t))return t.slice();var e={};for(var n in t)e[n]=t[n];return e}},function(t,e,n){var r=n(2),i=n(1);t.exports=function u(t,e,n){if(i(t,e)===n)return t;var o=e[0],s=e.slice(1),a=r(t);return e.length>1?a[o]=u(i(a,[o])||{},s,n):o?a[o]=n:a=n,a}},function(t,e,n){var r=n(2),i=n(1);t.exports=function u(t,e){if(void 0===i(t,e))return t;var n=e[0],o=e.slice(1),s=r(t);return o.length?(s[n]=u(t[n],o),0===Object.keys(s[n]).length&&delete s[n]):delete s[n],s}}]); |
{ | ||
"name": "foliage", | ||
"version": "0.14.3", | ||
"version": "0.15.0", | ||
"description": "A cursor like tree data structure.", | ||
@@ -5,0 +5,0 @@ "main": "dist/Foliage.js", |
@@ -5,16 +5,17 @@ import dissoc from '../dissoc' | ||
describe('when removing a value that is not already present', function() { | ||
it ('does not modify missing keys', function() { | ||
let sample = { foo: 'bar' } | ||
dissoc(sample, [ 'missing' ]).should.equal(sample) | ||
}) | ||
it ('does nothing', function() { | ||
let sample = { foo: 'bar' } | ||
dissoc(sample, [ 'missing' ]).should.equal(sample) | ||
}) | ||
it ('removes properties', function() { | ||
let sample = { foo: 'bar' } | ||
dissoc(sample, [ 'foo' ]).should.eql({}) | ||
}) | ||
it ('completely removes properties', function() { | ||
let sample = { foo: 'bar' } | ||
dissoc(sample, [ 'foo' ]).should.eql({}) | ||
}) | ||
it ('prunes empty objects', function() { | ||
let sample = { one: { two: 'three' } } | ||
dissoc(sample, [ 'one', 'two' ]).should.eql({}) | ||
}) | ||
}) |
@@ -13,3 +13,4 @@ import Foliage from '../Foliage' | ||
[ 'every', (i => i < 10) ], | ||
[ 'join', ', '] | ||
[ 'join', ', '], | ||
[ 'indexOf', 2] | ||
]) | ||
@@ -105,2 +106,16 @@ | ||
describe('Foliage::includes', function() { | ||
it ('returns a boolean if a value is present in an array', function() { | ||
let plant = new Foliage([ 1, 2, 3, 4]) | ||
plant.includes(1).should.equal(true) | ||
plant.includes('a').should.equal(false) | ||
}) | ||
it ('returns a boolean if a value is present in an object', function() { | ||
let plant = new Foliage({ a: 1, b: 2, c: 3, d: 5 }) | ||
plant.includes(1).should.equal(true) | ||
plant.includes('a').should.equal(false) | ||
}) | ||
}) | ||
}) |
@@ -168,2 +168,10 @@ import Foliage from '../Foliage' | ||
describe('Foliage::values', function() { | ||
it ('properly handles fallbacks', function() { | ||
let plant = new Foliage({ foo: undefined }) | ||
expect(plant.first()).to.equal(undefined) | ||
}) | ||
}) | ||
}) |
@@ -22,4 +22,4 @@ /** | ||
if (tail.length) { | ||
clone[head] = assoc((head in clone) ? clone[head] : {}, tail, value) | ||
if (keys.length > 1) { | ||
clone[head] = assoc(get(clone, [head]) || {}, tail, value) | ||
} else if (head) { | ||
@@ -26,0 +26,0 @@ clone[head] = value |
@@ -10,6 +10,6 @@ /** | ||
let copy = require('./copy') | ||
let has = require('./has') | ||
let get = require('./get') | ||
module.exports = function dissoc (obj, keys) { | ||
if (has(obj, keys) === false) { | ||
if (get(obj, keys) === undefined) { | ||
return obj | ||
@@ -23,2 +23,7 @@ } | ||
clone[head] = dissoc(obj[head], tail) | ||
// Autoprune keys | ||
if (Object.keys(clone[head]).length === 0) { | ||
delete clone[head] | ||
} | ||
} else { | ||
@@ -25,0 +30,0 @@ delete clone[head] |
@@ -65,3 +65,8 @@ /** | ||
values() { | ||
return this.keys().map(i => this.get(i)) | ||
// An anonymous function is used here instead of | ||
// calling `this.get` directly because we have no | ||
// fallback value. | ||
return this.keys().map(function(key) { | ||
return this.get(key) | ||
}, this) | ||
}, | ||
@@ -81,6 +86,10 @@ | ||
find() { | ||
return this.filter(...arguments)[0] | ||
find(fn, scope) { | ||
return this.filter(fn, scope)[0] | ||
}, | ||
includes(value) { | ||
return this.indexOf(value) > -1 | ||
}, | ||
first() { | ||
@@ -101,3 +110,3 @@ return this.values().shift() | ||
// Add collection methods | ||
let methods = [ 'sort', 'map', 'reduce', 'filter', 'forEach', 'some', 'every', 'join' ] | ||
let methods = [ 'sort', 'map', 'reduce', 'filter', 'forEach', 'some', 'every', 'join', 'indexOf' ] | ||
@@ -104,0 +113,0 @@ methods.forEach(function(name) { |
@@ -7,19 +7,8 @@ /** | ||
* @param {Array} keys - A list of string keys | ||
* @param {any} fallback - A value to return if the pathway is undefined | ||
*/ | ||
let has = require('./has') | ||
module.exports = function get (obj, keys) { | ||
let [ head, ...tail ] = keys | ||
if (!head) { | ||
return obj | ||
} | ||
if (has(obj, keys) === false) { | ||
return undefined | ||
} | ||
return tail.length ? get(obj[head], tail) : obj[head] | ||
module.exports = function (obj, keys) { | ||
return keys.reduce(function(tree, key) { | ||
return tree ? tree[key] : undefined | ||
}, obj) | ||
} |
@@ -5,4 +5,2 @@ var Webpack = require('webpack') | ||
module.exports = { | ||
devtool : 'source-map', | ||
entry: { | ||
@@ -16,3 +14,4 @@ Foliage : './src/Foliage.js' | ||
path: Path.join(__dirname, 'dist'), | ||
devtoolModuleFilenameTemplate: '[resource-path]' | ||
devtoolModuleFilenameTemplate: '[resource-path]', | ||
sourcePrefix: ' ' | ||
}, | ||
@@ -19,0 +18,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
0
39640
22
509