From 259edb69dc74e4d73249ebd38d3fd6c4bdef6384 Mon Sep 17 00:00:00 2001 From: lukasz_brainhub Date: Thu, 14 Dec 2017 11:05:09 +0100 Subject: [PATCH] Updated readme, removed commented code --- lib/perfect-immutable.js | 1 - lib/perfect-immutable.js.map | 2 +- lib/perfect-immutable.mjs | 1 - lib/perfect-immutable.mjs.map | 2 +- package.json | 2 +- src/set.js | 1 - 6 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/perfect-immutable.js b/lib/perfect-immutable.js index ec14351..17dddac 100644 --- a/lib/perfect-immutable.js +++ b/lib/perfect-immutable.js @@ -69,7 +69,6 @@ var immutableSet = function immutableSet(object, path) { var value = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; var delimiter = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.'; - // console.log('immutableSet', {object, path, value, delimiter}); if (!path) { return value; } diff --git a/lib/perfect-immutable.js.map b/lib/perfect-immutable.js.map index 368dd01..0463be0 100644 --- a/lib/perfect-immutable.js.map +++ b/lib/perfect-immutable.js.map @@ -1 +1 @@ -{"version":3,"file":"perfect-immutable.js","sources":["../src/set.js","../src/index.js"],"sourcesContent":["import { tail, isPlainObject, isEmpty, has, reduce } from 'lodash';\n\n/**\n * Works like lodash _.set() but does not mutate object (doesn't work with array style keys like `someArray[2].anotherField`)\n * @param {object} object source object\n * @param {string|object} path in object to set value in or object with paths as keys and values as values (if path is an object it ignores 'value')\n * @param {any} value to set in given path\n * @param {string} delimiter path delimiter; by default: '.'\n * @return {object} new object with value(s) changed\n */\nconst immutableSet = (object, path, value = null, delimiter = '.') => {\n // console.log('immutableSet', {object, path, value, delimiter});\n if (!path) {\n return value;\n }\n if (isPlainObject(path)) {\n if (isEmpty(path)) {\n return object;\n }\n return reduce(path, (accu, value, path) => immutableSet(accu, path, value, delimiter), object);\n }\n\n const pathSplit = path.split(delimiter);\n if (pathSplit.length === 1) {\n return {\n ...object,\n [path]: value,\n };\n }\n let childObject = {};\n if (has(object, pathSplit[0])) {\n childObject = object[pathSplit[0]];\n if (!isPlainObject(childObject)) {\n throw new Error(`Part of 'path' provided is defined in 'object' and is not a plain JS object but ${typeof childObject}. It's most likely an error. Check the path and object provided to immutableSet function`);\n }\n }\n return {\n ...object,\n [pathSplit[0]]: immutableSet(childObject, tail(pathSplit).join(delimiter), value, delimiter),\n };\n};\n\nexport default immutableSet;\n","import immuSet from './set';\nexport const set = immuSet;\n\nexport default {\n set: immuSet,\n};\n\n\n"],"names":["immutableSet","object","path","value","delimiter","isPlainObject","isEmpty","reduce","accu","pathSplit","split","length","childObject","has","Error","tail","join","set","immuSet"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;;;;;;;AAQA,IAAMA,eAAe,SAAfA,YAAe,CAACC,MAAD,EAASC,IAAT,EAAiD;MAAlCC,KAAkC,uEAA1B,IAA0B;MAApBC,SAAoB,uEAAR,GAAQ;;;MAEhE,CAACF,IAAL,EAAW;WACFC,KAAP;;MAEEE,qBAAcH,IAAd,CAAJ,EAAyB;QACnBI,eAAQJ,IAAR,CAAJ,EAAmB;aACVD,MAAP;;WAEKM,cAAOL,IAAP,EAAa,UAACM,IAAD,EAAOL,KAAP,EAAcD,IAAd;aAAuBF,aAAaQ,IAAb,EAAmBN,IAAnB,EAAyBC,KAAzB,EAAgCC,SAAhC,CAAvB;KAAb,EAAgFH,MAAhF,CAAP;;;MAGIQ,YAAYP,KAAKQ,KAAL,CAAWN,SAAX,CAAlB;MACIK,UAAUE,MAAV,KAAqB,CAAzB,EAA4B;wBAErBV,MADL,qBAEGC,IAFH,EAEUC,KAFV;;MAKES,cAAc,EAAlB;MACIC,WAAIZ,MAAJ,EAAYQ,UAAU,CAAV,CAAZ,CAAJ,EAA+B;kBACfR,OAAOQ,UAAU,CAAV,CAAP,CAAd;QACI,CAACJ,qBAAcO,WAAd,CAAL,EAAiC;YACzB,IAAIE,KAAJ,kGAAoGF,WAApG,yCAAoGA,WAApG,iGAAN;;;sBAICX,MADL,qBAEGQ,UAAU,CAAV,CAFH,EAEkBT,aAAaY,WAAb,EAA0BG,YAAKN,SAAL,EAAgBO,IAAhB,CAAqBZ,SAArB,CAA1B,EAA2DD,KAA3D,EAAkEC,SAAlE,CAFlB;CA1BF;;ACTO,IAAMa,MAAMC,YAAZ;;AAEP,YAAe;OACRA;CADP;;;;;;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"perfect-immutable.js","sources":["../src/set.js","../src/index.js"],"sourcesContent":["import { tail, isPlainObject, isEmpty, has, reduce } from 'lodash';\n\n/**\n * Works like lodash _.set() but does not mutate object (doesn't work with array style keys like `someArray[2].anotherField`)\n * @param {object} object source object\n * @param {string|object} path in object to set value in or object with paths as keys and values as values (if path is an object it ignores 'value')\n * @param {any} value to set in given path\n * @param {string} delimiter path delimiter; by default: '.'\n * @return {object} new object with value(s) changed\n */\nconst immutableSet = (object, path, value = null, delimiter = '.') => {\n if (!path) {\n return value;\n }\n if (isPlainObject(path)) {\n if (isEmpty(path)) {\n return object;\n }\n return reduce(path, (accu, value, path) => immutableSet(accu, path, value, delimiter), object);\n }\n\n const pathSplit = path.split(delimiter);\n if (pathSplit.length === 1) {\n return {\n ...object,\n [path]: value,\n };\n }\n let childObject = {};\n if (has(object, pathSplit[0])) {\n childObject = object[pathSplit[0]];\n if (!isPlainObject(childObject)) {\n throw new Error(`Part of 'path' provided is defined in 'object' and is not a plain JS object but ${typeof childObject}. It's most likely an error. Check the path and object provided to immutableSet function`);\n }\n }\n return {\n ...object,\n [pathSplit[0]]: immutableSet(childObject, tail(pathSplit).join(delimiter), value, delimiter),\n };\n};\n\nexport default immutableSet;\n","import immuSet from './set';\nexport const set = immuSet;\n\nexport default {\n set: immuSet,\n};\n\n\n"],"names":["immutableSet","object","path","value","delimiter","isPlainObject","isEmpty","reduce","accu","pathSplit","split","length","childObject","has","Error","tail","join","set","immuSet"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;;;;;;;AAQA,IAAMA,eAAe,SAAfA,YAAe,CAACC,MAAD,EAASC,IAAT,EAAiD;MAAlCC,KAAkC,uEAA1B,IAA0B;MAApBC,SAAoB,uEAAR,GAAQ;;MAChE,CAACF,IAAL,EAAW;WACFC,KAAP;;MAEEE,qBAAcH,IAAd,CAAJ,EAAyB;QACnBI,eAAQJ,IAAR,CAAJ,EAAmB;aACVD,MAAP;;WAEKM,cAAOL,IAAP,EAAa,UAACM,IAAD,EAAOL,KAAP,EAAcD,IAAd;aAAuBF,aAAaQ,IAAb,EAAmBN,IAAnB,EAAyBC,KAAzB,EAAgCC,SAAhC,CAAvB;KAAb,EAAgFH,MAAhF,CAAP;;;MAGIQ,YAAYP,KAAKQ,KAAL,CAAWN,SAAX,CAAlB;MACIK,UAAUE,MAAV,KAAqB,CAAzB,EAA4B;wBAErBV,MADL,qBAEGC,IAFH,EAEUC,KAFV;;MAKES,cAAc,EAAlB;MACIC,WAAIZ,MAAJ,EAAYQ,UAAU,CAAV,CAAZ,CAAJ,EAA+B;kBACfR,OAAOQ,UAAU,CAAV,CAAP,CAAd;QACI,CAACJ,qBAAcO,WAAd,CAAL,EAAiC;YACzB,IAAIE,KAAJ,kGAAoGF,WAApG,yCAAoGA,WAApG,iGAAN;;;sBAICX,MADL,qBAEGQ,UAAU,CAAV,CAFH,EAEkBT,aAAaY,WAAb,EAA0BG,YAAKN,SAAL,EAAgBO,IAAhB,CAAqBZ,SAArB,CAA1B,EAA2DD,KAA3D,EAAkEC,SAAlE,CAFlB;CAzBF;;ACTO,IAAMa,MAAMC,YAAZ;;AAEP,YAAe;OACRA;CADP;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/lib/perfect-immutable.mjs b/lib/perfect-immutable.mjs index 620ec9e..133d0fc 100644 --- a/lib/perfect-immutable.mjs +++ b/lib/perfect-immutable.mjs @@ -65,7 +65,6 @@ var immutableSet = function immutableSet(object, path) { var value = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; var delimiter = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '.'; - // console.log('immutableSet', {object, path, value, delimiter}); if (!path) { return value; } diff --git a/lib/perfect-immutable.mjs.map b/lib/perfect-immutable.mjs.map index ae7d533..caedaa7 100644 --- a/lib/perfect-immutable.mjs.map +++ b/lib/perfect-immutable.mjs.map @@ -1 +1 @@ -{"version":3,"file":"perfect-immutable.mjs","sources":["../src/set.js","../src/index.js"],"sourcesContent":["import { tail, isPlainObject, isEmpty, has, reduce } from 'lodash';\n\n/**\n * Works like lodash _.set() but does not mutate object (doesn't work with array style keys like `someArray[2].anotherField`)\n * @param {object} object source object\n * @param {string|object} path in object to set value in or object with paths as keys and values as values (if path is an object it ignores 'value')\n * @param {any} value to set in given path\n * @param {string} delimiter path delimiter; by default: '.'\n * @return {object} new object with value(s) changed\n */\nconst immutableSet = (object, path, value = null, delimiter = '.') => {\n // console.log('immutableSet', {object, path, value, delimiter});\n if (!path) {\n return value;\n }\n if (isPlainObject(path)) {\n if (isEmpty(path)) {\n return object;\n }\n return reduce(path, (accu, value, path) => immutableSet(accu, path, value, delimiter), object);\n }\n\n const pathSplit = path.split(delimiter);\n if (pathSplit.length === 1) {\n return {\n ...object,\n [path]: value,\n };\n }\n let childObject = {};\n if (has(object, pathSplit[0])) {\n childObject = object[pathSplit[0]];\n if (!isPlainObject(childObject)) {\n throw new Error(`Part of 'path' provided is defined in 'object' and is not a plain JS object but ${typeof childObject}. It's most likely an error. Check the path and object provided to immutableSet function`);\n }\n }\n return {\n ...object,\n [pathSplit[0]]: immutableSet(childObject, tail(pathSplit).join(delimiter), value, delimiter),\n };\n};\n\nexport default immutableSet;\n","import immuSet from './set';\nexport const set = immuSet;\n\nexport default {\n set: immuSet,\n};\n\n\n"],"names":["immutableSet","object","path","value","delimiter","isPlainObject","isEmpty","reduce","accu","pathSplit","split","length","childObject","has","Error","tail","join","set","immuSet"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;;;;;;;AAQA,IAAMA,eAAe,SAAfA,YAAe,CAACC,MAAD,EAASC,IAAT,EAAiD;MAAlCC,KAAkC,uEAA1B,IAA0B;MAApBC,SAAoB,uEAAR,GAAQ;;;MAEhE,CAACF,IAAL,EAAW;WACFC,KAAP;;MAEEE,cAAcH,IAAd,CAAJ,EAAyB;QACnBI,QAAQJ,IAAR,CAAJ,EAAmB;aACVD,MAAP;;WAEKM,OAAOL,IAAP,EAAa,UAACM,IAAD,EAAOL,KAAP,EAAcD,IAAd;aAAuBF,aAAaQ,IAAb,EAAmBN,IAAnB,EAAyBC,KAAzB,EAAgCC,SAAhC,CAAvB;KAAb,EAAgFH,MAAhF,CAAP;;;MAGIQ,YAAYP,KAAKQ,KAAL,CAAWN,SAAX,CAAlB;MACIK,UAAUE,MAAV,KAAqB,CAAzB,EAA4B;wBAErBV,MADL,qBAEGC,IAFH,EAEUC,KAFV;;MAKES,cAAc,EAAlB;MACIC,IAAIZ,MAAJ,EAAYQ,UAAU,CAAV,CAAZ,CAAJ,EAA+B;kBACfR,OAAOQ,UAAU,CAAV,CAAP,CAAd;QACI,CAACJ,cAAcO,WAAd,CAAL,EAAiC;YACzB,IAAIE,KAAJ,kGAAoGF,WAApG,yCAAoGA,WAApG,iGAAN;;;sBAICX,MADL,qBAEGQ,UAAU,CAAV,CAFH,EAEkBT,aAAaY,WAAb,EAA0BG,KAAKN,SAAL,EAAgBO,IAAhB,CAAqBZ,SAArB,CAA1B,EAA2DD,KAA3D,EAAkEC,SAAlE,CAFlB;CA1BF;;ACTO,IAAMa,MAAMC,YAAZ;;AAEP,YAAe;OACRA;CADP;;;;;"} \ No newline at end of file +{"version":3,"file":"perfect-immutable.mjs","sources":["../src/set.js","../src/index.js"],"sourcesContent":["import { tail, isPlainObject, isEmpty, has, reduce } from 'lodash';\n\n/**\n * Works like lodash _.set() but does not mutate object (doesn't work with array style keys like `someArray[2].anotherField`)\n * @param {object} object source object\n * @param {string|object} path in object to set value in or object with paths as keys and values as values (if path is an object it ignores 'value')\n * @param {any} value to set in given path\n * @param {string} delimiter path delimiter; by default: '.'\n * @return {object} new object with value(s) changed\n */\nconst immutableSet = (object, path, value = null, delimiter = '.') => {\n if (!path) {\n return value;\n }\n if (isPlainObject(path)) {\n if (isEmpty(path)) {\n return object;\n }\n return reduce(path, (accu, value, path) => immutableSet(accu, path, value, delimiter), object);\n }\n\n const pathSplit = path.split(delimiter);\n if (pathSplit.length === 1) {\n return {\n ...object,\n [path]: value,\n };\n }\n let childObject = {};\n if (has(object, pathSplit[0])) {\n childObject = object[pathSplit[0]];\n if (!isPlainObject(childObject)) {\n throw new Error(`Part of 'path' provided is defined in 'object' and is not a plain JS object but ${typeof childObject}. It's most likely an error. Check the path and object provided to immutableSet function`);\n }\n }\n return {\n ...object,\n [pathSplit[0]]: immutableSet(childObject, tail(pathSplit).join(delimiter), value, delimiter),\n };\n};\n\nexport default immutableSet;\n","import immuSet from './set';\nexport const set = immuSet;\n\nexport default {\n set: immuSet,\n};\n\n\n"],"names":["immutableSet","object","path","value","delimiter","isPlainObject","isEmpty","reduce","accu","pathSplit","split","length","childObject","has","Error","tail","join","set","immuSet"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;;;;;;;AAQA,IAAMA,eAAe,SAAfA,YAAe,CAACC,MAAD,EAASC,IAAT,EAAiD;MAAlCC,KAAkC,uEAA1B,IAA0B;MAApBC,SAAoB,uEAAR,GAAQ;;MAChE,CAACF,IAAL,EAAW;WACFC,KAAP;;MAEEE,cAAcH,IAAd,CAAJ,EAAyB;QACnBI,QAAQJ,IAAR,CAAJ,EAAmB;aACVD,MAAP;;WAEKM,OAAOL,IAAP,EAAa,UAACM,IAAD,EAAOL,KAAP,EAAcD,IAAd;aAAuBF,aAAaQ,IAAb,EAAmBN,IAAnB,EAAyBC,KAAzB,EAAgCC,SAAhC,CAAvB;KAAb,EAAgFH,MAAhF,CAAP;;;MAGIQ,YAAYP,KAAKQ,KAAL,CAAWN,SAAX,CAAlB;MACIK,UAAUE,MAAV,KAAqB,CAAzB,EAA4B;wBAErBV,MADL,qBAEGC,IAFH,EAEUC,KAFV;;MAKES,cAAc,EAAlB;MACIC,IAAIZ,MAAJ,EAAYQ,UAAU,CAAV,CAAZ,CAAJ,EAA+B;kBACfR,OAAOQ,UAAU,CAAV,CAAP,CAAd;QACI,CAACJ,cAAcO,WAAd,CAAL,EAAiC;YACzB,IAAIE,KAAJ,kGAAoGF,WAApG,yCAAoGA,WAApG,iGAAN;;;sBAICX,MADL,qBAEGQ,UAAU,CAAV,CAFH,EAEkBT,aAAaY,WAAb,EAA0BG,KAAKN,SAAL,EAAgBO,IAAhB,CAAqBZ,SAArB,CAA1B,EAA2DD,KAA3D,EAAkEC,SAAlE,CAFlB;CAzBF;;ACTO,IAAMa,MAAMC,YAAZ;;AAEP,YAAe;OACRA;CADP;;;;;"} \ No newline at end of file diff --git a/package.json b/package.json index 7ae19b7..a9fbc01 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "perfect-immutable", - "version": "1.0.0", + "version": "1.0.1", "description": "", "repository": { "type": "git", diff --git a/src/set.js b/src/set.js index 9db3d46..3df12b0 100644 --- a/src/set.js +++ b/src/set.js @@ -9,7 +9,6 @@ import { tail, isPlainObject, isEmpty, has, reduce } from 'lodash'; * @return {object} new object with value(s) changed */ const immutableSet = (object, path, value = null, delimiter = '.') => { - // console.log('immutableSet', {object, path, value, delimiter}); if (!path) { return value; }