simple-update-in
Advanced tools
Comparing version 2.1.2-master.954b348 to 2.1.2-master.e25f669
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
@@ -9,4 +10,21 @@ | ||
### Changed | ||
- Bump dependencies, in PR [#29](https://github.com/compulim/simple-update-in/pulls/29) | ||
- [`@babel/cli@7.8.4`](https://npmjs.com/package/@babel/cli) | ||
- [`@babel/core@7.9.6`](https://npmjs.com/package/@babel/core) | ||
- [`@babel/plugin-proposal-object-rest-spread@7.9.6`](https://npmjs.com/package/@babel/plugin-proposal-object-rest-spread) | ||
- [`@babel/preset-env@7.9.6`](https://npmjs.com/package/@babel/preset-env) | ||
- [`babel-jest@26.0.1`](https://npmjs.com/package/babel-jest) | ||
- [`coveralls@3.1.0`](https://npmjs.com/package/coveralls) | ||
- [`jest@26.0.1`](https://npmjs.com/package/jest) | ||
- [`regenerator-runtime@0.13.5`](https://npmjs.com/package/regenerator-runtime) | ||
- [`rollup@2.10.9`](https://npmjs.com/package/rollup) | ||
- [`rollup-plugin-babel@4.4.0`](https://npmjs.com/package/rollup-plugin-babel) | ||
- [`rollup-plugin-uglify@6.0.4`](https://npmjs.com/package/rollup-plugin-uglify) | ||
## [2.1.1] - 2019-08-01 | ||
### Changed | ||
- Fix [#24](https://github.com/compulim/simple-update-in/issues/24), polyfill `Object.is` for IE11, in PR [#25](https://github.com/compulim/simple-update-in/pull/25) | ||
@@ -16,3 +34,5 @@ - Polyfill code is adopted from [`core-js`](https://npmjs.com/package/core-js) to maintain zero dependency | ||
## [2.1.0] - 2019-07-18 | ||
### Changed | ||
- Bump dependencies, in PR [#18](https://github.com/compulim/simple-update-in/pulls/18) | ||
@@ -35,10 +55,15 @@ - [`@babel/cli@^7.5.5`](https://www.npmjs.com/package/@babel/cli) | ||
### Added | ||
- Will skip paths containing `__proto__`, `constructor`, and `prototype`, in PR [#19](https://github.com/compulim/simple-update-in/pull/19) | ||
## [2.0.2] - 2018-12-06 | ||
### Fixed | ||
- Fix [#16](https://github.com/compulim/simple-update-in/issues/16), parents should not be removed when `updater` is or returned `undefined`, in PR [#17](https://github.com/compulim/simple-update-in/pull/17) | ||
## [2.0.1] - 2018-12-03 | ||
### Added | ||
- Emitting UMD bundle for browser | ||
@@ -49,3 +74,5 @@ - `<script src="https://unpkg.com/simple-update-in/dist/simple-update-in.production.min.js"></script>` | ||
## [2.0.0] - 2018-12-03 | ||
### Added | ||
- Support async predicate | ||
@@ -57,5 +84,7 @@ - `await updateIn([1, 2, 3, 4, 5], [v => Promise.resolve(v % 2)], v => v * 10)` will return `[10, 2, 30, 4, 50]` | ||
### Changed | ||
- Use Node.js 10 and 11 for Travis CI | ||
### Removed | ||
- Removed array insertion using index number of `-1` | ||
@@ -65,3 +94,5 @@ - This introduces API inconfirmity: `-1` could means append, prepend, or the last item | ||
## [1.4.0] - 2018-10-08 | ||
### Changed | ||
- Add default exports for CommonJS | ||
@@ -74,3 +105,5 @@ - Bump | ||
## [1.3.1] - 2018-10-05 | ||
### Fixed | ||
- Using a predicate on a non-existing key/index should not throw error and return the original value as-is | ||
@@ -81,3 +114,5 @@ - `updateIn({}, ['Hello', () => true], () => 'World!'])` will return `{}` | ||
## [1.3.0] - 2018-08-17 | ||
### Added | ||
- Support predicate function | ||
@@ -88,3 +123,5 @@ - `updateIn([1, 2, 3, 4, 5], [v => v % 2], v => v * 10)` will return `[10, 2, 30, 4, 50]` | ||
## [1.2.0] - 2018-04-14 | ||
### Added | ||
- If after `updater` result in nothing change (triple-equal `===`), will return untouched | ||
@@ -94,2 +131,3 @@ - `updater` returned `undefined` will be treated as removing the item | ||
### Fixed | ||
- Append not creating sub-structure correctly | ||
@@ -99,7 +137,11 @@ - `updateIn([1, 2], [-1, 0], 'Hello')` should return `[1, 2, ['Hello']]` instead of `[1, 2, 'Hello']` | ||
## [1.1.1] - 2018-04-06 | ||
### Fixed | ||
- Move `babel` and `gulp` into `devDependencies` | ||
## [1.1.0] - 2018-03-31 | ||
### Added | ||
- Automatic expansion | ||
@@ -110,3 +152,5 @@ - Replace incompatible types | ||
## [1.0.0] - 2018-03-21 | ||
### Added | ||
- Initial commit |
@@ -5,5 +5,7 @@ (function (global, factory) { | ||
(global = global || self, global.simpleUpdateIn = factory()); | ||
}(this, function () { 'use strict'; | ||
}(this, (function () { 'use strict'; | ||
function _typeof(obj) { | ||
"@babel/helpers - typeof"; | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
@@ -92,3 +94,3 @@ _typeof = function (obj) { | ||
if (i % 2) { | ||
ownKeys(source, true).forEach(function (key) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
@@ -99,3 +101,3 @@ }); | ||
} else { | ||
ownKeys(source).forEach(function (key) { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
@@ -110,15 +112,11 @@ }); | ||
function _toArray(arr) { | ||
return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest(); | ||
return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); | ||
} | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
if (Array.isArray(arr)) return _arrayLikeToArray(arr); | ||
} | ||
@@ -131,13 +129,85 @@ | ||
function _iterableToArray(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
function _nonIterableRest() { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
function _createForOfIteratorHelper(o) { | ||
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { | ||
if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) { | ||
var i = 0; | ||
var F = function () {}; | ||
return { | ||
s: F, | ||
n: function () { | ||
if (i >= o.length) return { | ||
done: true | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}, | ||
e: function (e) { | ||
throw e; | ||
}, | ||
f: F | ||
}; | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var it, | ||
normalCompletion = true, | ||
didErr = false, | ||
err; | ||
return { | ||
s: function () { | ||
it = o[Symbol.iterator](); | ||
}, | ||
n: function () { | ||
var step = it.next(); | ||
normalCompletion = step.done; | ||
return step; | ||
}, | ||
e: function (e) { | ||
didErr = true; | ||
err = e; | ||
}, | ||
f: function () { | ||
try { | ||
if (!normalCompletion && it.return != null) it.return(); | ||
} finally { | ||
if (didErr) throw err; | ||
} | ||
} | ||
}; | ||
} | ||
var objectIs = Object.is || function (x, y) { | ||
@@ -150,8 +220,8 @@ return x === y ? x !== 0 || 1 / x === 1 / y : x != x && y != y; | ||
var paths = getPaths(obj, path); | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
var _iterator = _createForOfIteratorHelper(paths), | ||
_step; | ||
try { | ||
for (var _iterator = paths[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var _path = _step.value; | ||
@@ -161,14 +231,5 @@ obj = setValue(obj, _path, updater ? updater(getValue(obj, _path)) : undefined); | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
_iterator.e(err); | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator["return"] != null) { | ||
_iterator["return"](); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
_iterator.f(); | ||
} | ||
@@ -184,6 +245,4 @@ | ||
function _updateInAsync() { | ||
_updateInAsync = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee(obj, path, updater) { | ||
var paths, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, _path4; | ||
_updateInAsync = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(obj, path, updater) { | ||
var paths, _iterator2, _step2, _path4; | ||
@@ -200,11 +259,10 @@ return regeneratorRuntime.wrap(function _callee$(_context) { | ||
paths = _context.sent; | ||
_iteratorNormalCompletion2 = true; | ||
_didIteratorError2 = false; | ||
_iteratorError2 = undefined; | ||
_context.prev = 7; | ||
_iterator2 = paths[Symbol.iterator](); | ||
_iterator2 = _createForOfIteratorHelper(paths); | ||
_context.prev = 5; | ||
case 9: | ||
if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) { | ||
_context.next = 26; | ||
_iterator2.s(); | ||
case 7: | ||
if ((_step2 = _iterator2.n()).done) { | ||
_context.next = 23; | ||
break; | ||
@@ -219,64 +277,46 @@ } | ||
if (!updater) { | ||
_context.next = 20; | ||
_context.next = 18; | ||
break; | ||
} | ||
_context.next = 17; | ||
_context.next = 15; | ||
return updater(getValue(obj, _path4)); | ||
case 17: | ||
case 15: | ||
_context.t3 = _context.sent; | ||
_context.next = 21; | ||
_context.next = 19; | ||
break; | ||
case 20: | ||
case 18: | ||
_context.t3 = undefined; | ||
case 21: | ||
case 19: | ||
_context.t4 = _context.t3; | ||
obj = (0, _context.t0)(_context.t1, _context.t2, _context.t4); | ||
case 23: | ||
_iteratorNormalCompletion2 = true; | ||
_context.next = 9; | ||
case 21: | ||
_context.next = 7; | ||
break; | ||
case 26: | ||
_context.next = 32; | ||
case 23: | ||
_context.next = 28; | ||
break; | ||
case 25: | ||
_context.prev = 25; | ||
_context.t5 = _context["catch"](5); | ||
_iterator2.e(_context.t5); | ||
case 28: | ||
_context.prev = 28; | ||
_context.t5 = _context["catch"](7); | ||
_didIteratorError2 = true; | ||
_iteratorError2 = _context.t5; | ||
case 32: | ||
_context.prev = 32; | ||
_context.prev = 33; | ||
_iterator2.f(); | ||
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) { | ||
_iterator2["return"](); | ||
} | ||
return _context.finish(28); | ||
case 35: | ||
_context.prev = 35; | ||
if (!_didIteratorError2) { | ||
_context.next = 38; | ||
break; | ||
} | ||
throw _iteratorError2; | ||
case 38: | ||
return _context.finish(35); | ||
case 39: | ||
return _context.finish(32); | ||
case 40: | ||
case 31: | ||
return _context.abrupt("return", obj); | ||
case 41: | ||
case 32: | ||
case "end": | ||
@@ -286,3 +326,3 @@ return _context.stop(); | ||
} | ||
}, _callee, null, [[7, 28, 32, 40], [33,, 35, 39]]); | ||
}, _callee, null, [[5, 25, 28, 31]]); | ||
})); | ||
@@ -342,5 +382,3 @@ return _updateInAsync.apply(this, arguments); | ||
function _getPathsAsync() { | ||
_getPathsAsync = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee2(obj, path) { | ||
_getPathsAsync = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(obj, path) { | ||
var _path5, accessor, nextPath, results, index, length, key, result; | ||
@@ -545,3 +583,3 @@ | ||
} else { | ||
return _objectSpread2({}, nextObj, _defineProperty({}, accessor, _nextValue)); | ||
return _objectSpread2(_objectSpread2({}, nextObj), {}, _defineProperty({}, accessor, _nextValue)); | ||
} | ||
@@ -554,2 +592,2 @@ } | ||
})); | ||
}))); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).simpleUpdateIn=e()}(this,function(){"use strict";function p(t){return(p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function c(t,e,r,n,o,a,i){try{var u=t[a](i),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function t(u){return function(){var t=this,i=arguments;return new Promise(function(e,r){var n=u.apply(t,i);function o(t){c(n,e,r,o,a,"next",t)}function a(t){c(n,e,r,o,a,"throw",t)}o(void 0)})}}function l(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function n(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function y(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?n(r,!0).forEach(function(t){l(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(r).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function b(t){return function(t){if(Array.isArray(t))return t}(t)||e(t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function v(t){return function(t){if(Array.isArray(t)){for(var e=0,r=new Array(t.length);e<t.length;e++)r[e]=t[e];return r}}(t)||e(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function e(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}var d=Object.is||function(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e};function r(t,e,r){h(e);var n=function t(e,r){if(!r.length)return;var n=b(r),o=n[0],a=n.slice(1);if("function"==typeof o){var i=[];if(Array.isArray(e))for(var u=0,c=e.length;u<c;u++)o.call(e,e[u],u)&&i.push.apply(i,v(t(e,[u].concat(v(a)))));else for(var f in e||{})o.call(e,e[f],f)&&i.push.apply(i,v(t(e,[f].concat(v(a)))));return i}var s=t(void 0!==e&&e[o],a);return s?s.map(function(t){return[o].concat(v(t))}):[[o]]}(t,e),o=!0,a=!1,i=void 0;try{for(var u,c=n[Symbol.iterator]();!(o=(u=c.next()).done);o=!0){var f=u.value;t=w(t,f,r?r(g(t,f)):void 0)}}catch(t){a=!0,i=t}finally{try{o||null==c.return||c.return()}finally{if(a)throw i}}return t}function o(){return(o=t(regeneratorRuntime.mark(function t(e,r,n){var o,a,i,u,c,f,s;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return h(r),t.next=3,x(e,r);case 3:o=t.sent,i=!(a=!0),u=void 0,t.prev=7,c=o[Symbol.iterator]();case 9:if(a=(f=c.next()).done){t.next=26;break}if(s=f.value,t.t0=w,t.t1=e,t.t2=s,n)return t.next=17,n(g(e,s));t.next=20;break;case 17:t.t3=t.sent,t.next=21;break;case 20:t.t3=void 0;case 21:t.t4=t.t3,e=(0,t.t0)(t.t1,t.t2,t.t4);case 23:a=!0,t.next=9;break;case 26:t.next=32;break;case 28:t.prev=28,t.t5=t.catch(7),i=!0,u=t.t5;case 32:t.prev=32,t.prev=33,a||null==c.return||c.return();case 35:if(t.prev=35,i)throw u;t.next=38;break;case 38:return t.finish(35);case 39:return t.finish(32);case 40:return t.abrupt("return",e);case 41:case"end":return t.stop()}},t,null,[[7,28,32,40],[33,,35,39]])}))).apply(this,arguments)}function h(t){if(!Array.isArray(t))throw new Error("path must be an array")}r.updateInAsync=function(t,e,r){return o.apply(this,arguments)};var m=["__proto__","constructor","prototype"];function x(t,e){return a.apply(this,arguments)}function a(){return(a=t(regeneratorRuntime.mark(function t(e,r){var n,o,a,i,u,c,f,s;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r.length){t.next=2;break}return t.abrupt("return");case 2:if(n=b(r),o=n[0],a=n.slice(1),"function"!=typeof o){t.next=43;break}if(i=[],!Array.isArray(e)){t.next=25;break}u=0,c=e.length;case 7:if(u<c)return t.next=10,o.call(e,e[u],u);t.next=23;break;case 10:if(t.t0=t.sent,t.t0)return t.t1=i.push,t.t2=i,t.t3=v,t.next=17,x(e,[u].concat(v(a)));t.next=20;break;case 17:t.t4=t.sent,t.t5=(0,t.t3)(t.t4),t.t1.apply.call(t.t1,t.t2,t.t5);case 20:u++,t.next=7;break;case 23:t.next=42;break;case 25:t.t6=regeneratorRuntime.keys(e||{});case 26:if((t.t7=t.t6()).done){t.next=42;break}return f=t.t7.value,t.next=30,o.call(e,e[f],f);case 30:if(t.t8=t.sent,t.t8)return t.t9=i.push,t.t10=i,t.t11=v,t.next=37,x(e,[f].concat(v(a)));t.next=40;break;case 37:t.t12=t.sent,t.t13=(0,t.t11)(t.t12),t.t9.apply.call(t.t9,t.t10,t.t13);case 40:t.next=26;break;case 42:return t.abrupt("return",i);case 43:return t.next=45,x(void 0!==e&&e[o],a);case 45:return s=t.sent,t.abrupt("return",s?s.map(function(t){return[o].concat(v(t))}):[[o]]);case 47:case"end":return t.stop()}},t)}))).apply(this,arguments)}function g(t,e){return e.reduce(function(t,e){return t&&t[e]},t)}function w(t,e,r){if(!e.length)return r;var n,o=b(e),a=o[0],i=o.slice(1),u=void 0!==t&&t[a],c=t;if(n=a,m.includes(n))return t;if("string"!=typeof a||"object"===p(c)&&!Array.isArray(c)?"number"!=typeof a||Array.isArray(c)||(c=[]):c={},"number"==typeof a){var f=w(u,i,r);return void 0===f?void 0===t?t:(a in c&&(c=v(c)).splice(a,1),c):d(f,u)?t:((c=v(c))[a]=f,c)}var s=w(u,i,r);return void 0===s?void 0===t?t:(a in c&&delete(c=y({},c))[a],c):d(s,u)?t:y({},c,l({},a,s))}return r}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).simpleUpdateIn=e()}(this,function(){"use strict";function l(t){return(l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function c(t,e,r,n,o,a,i){try{var u=t[a](i),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function t(u){return function(){var t=this,i=arguments;return new Promise(function(e,r){var n=u.apply(t,i);function o(t){c(n,e,r,o,a,"next",t)}function a(t){c(n,e,r,o,a,"throw",t)}o(void 0)})}}function p(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function n(e,t){var r,n=Object.keys(e);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(e),t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)),n}function y(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?n(Object(r),!0).forEach(function(t){p(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function b(t){return function(t){if(Array.isArray(t))return t}(t)||e(t)||u(t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function v(t){return function(t){if(Array.isArray(t))return o(t)}(t)||e(t)||u(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function e(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}function u(t,e){if(t){if("string"==typeof t)return o(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(t,e):void 0}}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function f(t){if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(t=u(t))){var e=0,r=function(){};return{s:r,n:function(){return e>=t.length?{done:!0}:{done:!1,value:t[e++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var n,o,a=!0,i=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return a=t.done,t},e:function(t){i=!0,o=t},f:function(){try{a||null==n.return||n.return()}finally{if(i)throw o}}}}var d=Object.is||function(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e};function r(t,e,r){s(e);var n,o=f(function t(e,r){if(!r.length)return;var n=b(r),o=n[0],a=n.slice(1);if("function"==typeof o){var i=[];if(Array.isArray(e))for(var u=0,c=e.length;u<c;u++)o.call(e,e[u],u)&&i.push.apply(i,v(t(e,[u].concat(v(a)))));else for(var f in e||{})o.call(e,e[f],f)&&i.push.apply(i,v(t(e,[f].concat(v(a)))));return i}var s=t(void 0!==e&&e[o],a);return s?s.map(function(t){return[o].concat(v(t))}):[[o]]}(t,e));try{for(o.s();!(n=o.n()).done;){var a=n.value;t=g(t,a,r?r(x(t,a)):void 0)}}catch(t){o.e(t)}finally{o.f()}return t}function a(){return(a=t(regeneratorRuntime.mark(function t(e,r,n){var o,a,i,u;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return s(r),t.next=3,h(e,r);case 3:o=t.sent,a=f(o),t.prev=5,a.s();case 7:if((i=a.n()).done){t.next=23;break}if(u=i.value,t.t0=g,t.t1=e,t.t2=u,n)return t.next=15,n(x(e,u));t.next=18;break;case 15:t.t3=t.sent,t.next=19;break;case 18:t.t3=void 0;case 19:t.t4=t.t3,e=(0,t.t0)(t.t1,t.t2,t.t4);case 21:t.next=7;break;case 23:t.next=28;break;case 25:t.prev=25,t.t5=t.catch(5),a.e(t.t5);case 28:return t.prev=28,a.f(),t.finish(28);case 31:return t.abrupt("return",e);case 32:case"end":return t.stop()}},t,null,[[5,25,28,31]])}))).apply(this,arguments)}function s(t){if(!Array.isArray(t))throw new Error("path must be an array")}r.updateInAsync=function(t,e,r){return a.apply(this,arguments)};var m=["__proto__","constructor","prototype"];function h(){return i.apply(this,arguments)}function i(){return(i=t(regeneratorRuntime.mark(function t(e,r){var n,o,a,i,u,c,f,s;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r.length){t.next=2;break}return t.abrupt("return");case 2:if(n=b(r),o=n[0],a=n.slice(1),"function"!=typeof o){t.next=43;break}if(i=[],!Array.isArray(e)){t.next=25;break}u=0,c=e.length;case 7:if(u<c)return t.next=10,o.call(e,e[u],u);t.next=23;break;case 10:if(t.t0=t.sent,t.t0)return t.t1=i.push,t.t2=i,t.t3=v,t.next=17,h(e,[u].concat(v(a)));t.next=20;break;case 17:t.t4=t.sent,t.t5=(0,t.t3)(t.t4),t.t1.apply.call(t.t1,t.t2,t.t5);case 20:u++,t.next=7;break;case 23:t.next=42;break;case 25:t.t6=regeneratorRuntime.keys(e||{});case 26:if((t.t7=t.t6()).done){t.next=42;break}return f=t.t7.value,t.next=30,o.call(e,e[f],f);case 30:if(t.t8=t.sent,t.t8)return t.t9=i.push,t.t10=i,t.t11=v,t.next=37,h(e,[f].concat(v(a)));t.next=40;break;case 37:t.t12=t.sent,t.t13=(0,t.t11)(t.t12),t.t9.apply.call(t.t9,t.t10,t.t13);case 40:t.next=26;break;case 42:return t.abrupt("return",i);case 43:return t.next=45,h(void 0!==e&&e[o],a);case 45:return s=t.sent,t.abrupt("return",s?s.map(function(t){return[o].concat(v(t))}):[[o]]);case 47:case"end":return t.stop()}},t)}))).apply(this,arguments)}function x(t,e){return e.reduce(function(t,e){return t&&t[e]},t)}function g(t,e,r){if(!e.length)return r;var n,o=b(e),a=o[0],i=o.slice(1),u=void 0!==t&&t[a],c=t;if(n=a,m.includes(n))return t;if("string"!=typeof a||"object"===l(c)&&!Array.isArray(c)?"number"!=typeof a||Array.isArray(c)||(c=[]):c={},"number"==typeof a){var f=g(u,i,r);return void 0===f?void 0===t?t:(a in c&&(c=v(c)).splice(a,1),c):d(f,u)?t:((c=v(c))[a]=f,c)}var s=g(u,i,r);return void 0===s?void 0===t?t:(a in c&&delete(c=y({},c))[a],c):d(s,u)?t:y(y({},c),{},p({},a,s))}return r}); |
130
lib/index.js
@@ -14,19 +14,19 @@ "use strict"; | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest(); } | ||
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); } | ||
@@ -39,11 +39,17 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _createForOfIteratorHelper(o) { if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) { var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var it, normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function simpleUpdateIn(obj, path, updater) { | ||
validatePath(path); | ||
var paths = getPaths(obj, path); | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
var _iterator = _createForOfIteratorHelper(paths), | ||
_step; | ||
try { | ||
for (var _iterator = paths[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var _path = _step.value; | ||
@@ -53,14 +59,5 @@ obj = setValue(obj, _path, updater ? updater(getValue(obj, _path)) : undefined); | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
_iterator.e(err); | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator["return"] != null) { | ||
_iterator["return"](); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
_iterator.f(); | ||
} | ||
@@ -76,6 +73,4 @@ | ||
function _updateInAsync() { | ||
_updateInAsync = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee(obj, path, updater) { | ||
var paths, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, _path4; | ||
_updateInAsync = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(obj, path, updater) { | ||
var paths, _iterator2, _step2, _path4; | ||
@@ -92,11 +87,10 @@ return regeneratorRuntime.wrap(function _callee$(_context) { | ||
paths = _context.sent; | ||
_iteratorNormalCompletion2 = true; | ||
_didIteratorError2 = false; | ||
_iteratorError2 = undefined; | ||
_context.prev = 7; | ||
_iterator2 = paths[Symbol.iterator](); | ||
_iterator2 = _createForOfIteratorHelper(paths); | ||
_context.prev = 5; | ||
case 9: | ||
if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) { | ||
_context.next = 26; | ||
_iterator2.s(); | ||
case 7: | ||
if ((_step2 = _iterator2.n()).done) { | ||
_context.next = 23; | ||
break; | ||
@@ -111,64 +105,46 @@ } | ||
if (!updater) { | ||
_context.next = 20; | ||
_context.next = 18; | ||
break; | ||
} | ||
_context.next = 17; | ||
_context.next = 15; | ||
return updater(getValue(obj, _path4)); | ||
case 17: | ||
case 15: | ||
_context.t3 = _context.sent; | ||
_context.next = 21; | ||
_context.next = 19; | ||
break; | ||
case 20: | ||
case 18: | ||
_context.t3 = undefined; | ||
case 21: | ||
case 19: | ||
_context.t4 = _context.t3; | ||
obj = (0, _context.t0)(_context.t1, _context.t2, _context.t4); | ||
case 23: | ||
_iteratorNormalCompletion2 = true; | ||
_context.next = 9; | ||
case 21: | ||
_context.next = 7; | ||
break; | ||
case 26: | ||
_context.next = 32; | ||
case 23: | ||
_context.next = 28; | ||
break; | ||
case 25: | ||
_context.prev = 25; | ||
_context.t5 = _context["catch"](5); | ||
_iterator2.e(_context.t5); | ||
case 28: | ||
_context.prev = 28; | ||
_context.t5 = _context["catch"](7); | ||
_didIteratorError2 = true; | ||
_iteratorError2 = _context.t5; | ||
case 32: | ||
_context.prev = 32; | ||
_context.prev = 33; | ||
_iterator2.f(); | ||
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) { | ||
_iterator2["return"](); | ||
} | ||
return _context.finish(28); | ||
case 35: | ||
_context.prev = 35; | ||
if (!_didIteratorError2) { | ||
_context.next = 38; | ||
break; | ||
} | ||
throw _iteratorError2; | ||
case 38: | ||
return _context.finish(35); | ||
case 39: | ||
return _context.finish(32); | ||
case 40: | ||
case 31: | ||
return _context.abrupt("return", obj); | ||
case 41: | ||
case 32: | ||
case "end": | ||
@@ -178,3 +154,3 @@ return _context.stop(); | ||
} | ||
}, _callee, null, [[7, 28, 32, 40], [33,, 35, 39]]); | ||
}, _callee, null, [[5, 25, 28, 31]]); | ||
})); | ||
@@ -234,5 +210,3 @@ return _updateInAsync.apply(this, arguments); | ||
function _getPathsAsync() { | ||
_getPathsAsync = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee2(obj, path) { | ||
_getPathsAsync = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(obj, path) { | ||
var _path5, accessor, nextPath, results, index, length, key, result; | ||
@@ -437,3 +411,3 @@ | ||
} else { | ||
return _objectSpread({}, nextObj, _defineProperty({}, accessor, _nextValue)); | ||
return _objectSpread(_objectSpread({}, nextObj), {}, _defineProperty({}, accessor, _nextValue)); | ||
} | ||
@@ -440,0 +414,0 @@ } |
{ | ||
"name": "simple-update-in", | ||
"version": "2.1.2-master.954b348", | ||
"version": "2.1.2-master.e25f669", | ||
"description": "", | ||
@@ -12,8 +12,11 @@ "browser": "dist/simple-update-in.production.min.js", | ||
"scripts": { | ||
"build": "babel --out-dir lib src --ignore **/*.spec.js,**/*.test.js", | ||
"clean": "npx rimraf coverage dist lib", | ||
"build": "npm run build:babel && npm run build:rollup", | ||
"build:babel": "babel --out-dir lib src --ignore **/*.spec.js,**/*.test.js", | ||
"build:rollup": "rollup --config", | ||
"coveralls": "cat ./coverage/lcov.info | coveralls", | ||
"prepublishOnly": "rollup -c", | ||
"test": "jest", | ||
"watch": "npm run build -- --watch" | ||
"prestart": "npm run build:babel", | ||
"start": "concurrently --kill-others --names \"babel,rollup\" \"npm run start:babel\" \"npm run start:rollup\"", | ||
"start:babel": "npm run build:babel -- --skip-initial-build --watch", | ||
"start:rollup": "npm run build:rollup -- --watch", | ||
"test": "jest --collectCoverage true" | ||
}, | ||
@@ -38,21 +41,17 @@ "repository": { | ||
"homepage": "https://github.com/compulim/simple-update-in#readme", | ||
"jest": { | ||
"collectCoverage": true, | ||
"testEnvironment": "node" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.5.5", | ||
"@babel/core": "^7.5.5", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.5.5", | ||
"@babel/preset-env": "^7.5.5", | ||
"babel-core": "^7.0.0-bridge.0", | ||
"babel-jest": "^24.8.0", | ||
"@babel/cli": "^7.8.4", | ||
"@babel/core": "^7.9.6", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.9.6", | ||
"@babel/preset-env": "^7.9.6", | ||
"babel-jest": "^26.0.1", | ||
"babel-plugin-add-module-exports": "^1.0.2", | ||
"coveralls": "^3.0.5", | ||
"jest": "^24.8.0", | ||
"regenerator-runtime": "^0.13.2", | ||
"rollup": "^1.17.0", | ||
"rollup-plugin-babel": "^4.3.3", | ||
"rollup-plugin-uglify": "^6.0.2" | ||
"concurrently": "^5.2.0", | ||
"coveralls": "^3.1.0", | ||
"jest": "^26.0.1", | ||
"regenerator-runtime": "^0.13.5", | ||
"rollup": "^2.10.9", | ||
"rollup-plugin-babel": "^4.4.0", | ||
"rollup-plugin-uglify": "^6.0.4" | ||
} | ||
} |
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
54279
820