Comparing version 1.3.0 to 1.3.5
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("Notation",[],t):"object"==typeof exports?exports.Notation=t():e.Notation=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="lib/",t(t.s=2)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=Object.prototype.toString,i={isObject:function(e){return"[object Object]"===r.call(e)},isArray:function(e){return"[object Array]"===r.call(e)},ensureArray:function(e){return i.isArray(e)?e:null===e||void 0===e?[]:[e]},hasOwn:function(e,t){return e&&"function"==typeof e.hasOwnProperty&&e.hasOwnProperty(t)},deepCopy:function(e){if(!i.isObject(e))return e;var t,n,r={};for(t in e)i.hasOwn(e,t)&&(n=e[t],r[t]=i.isObject(n)?i.deepCopy(n):n);return r},each:function(e,t,n){for(var r=e.length,i=-1;++i<r&&!1!==t.call(n,e[i],i,e););},eachRight:function(e,t){for(var n=e.length;n--&&!1!==t(e[n],n,e););},pregQuote:function(e,t){return String(e).replace(new RegExp("[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\"+(t||"")+"-]","g"),"\\$&")},stringOrArrayOf:function(e,t){return"string"==typeof e&&e===t||i.isArray(e)&&1===e.length&&e[0]===t},hasSingleItemOf:function(e,t){return 1===e.length&&(2!==arguments.length||e[0]===t)}};t.default=i},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";r(this,t);var n=i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.name=n.constructor.name,Object.defineProperty(n,"name",{enumerable:!1,writable:!1,value:"NotationError"}),Object.defineProperty(n,"message",{enumerable:!1,writable:!0,value:e}),Error.hasOwnProperty("captureStackTrace")?Error.captureStackTrace(n,n.constructor):Object.defineProperty(n,"stack",{enumerable:!1,writable:!1,value:new Error(e).stack}),n}return u(t,e),t}(Error);t.default=o},function(e,t,n){"use strict";var r=n(3),i=function(e){return e&&e.__esModule?e:{default:e}}(r);e.exports=i.default},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var u=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=n(0),a=r(o),l=n(4),s=r(l),c=n(1),f=r(c),v={SOURCE:"Invalid source object.",DEST:"Invalid destination object.",NOTATION:"Invalid notation: ",NOTA_OBJ:"Invalid notations object: "},h=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(i(this,e),!a.default.isObject(t))throw new f.default(v.SOURCE);this._source=t}return u(e,[{key:"each",value:function(t){var n=this,r=this._source,i=Object.keys(r);a.default.each(i,function(i,u,o){var l=r[i],s=void 0;a.default.isObject(l)?(s=new e(l),s.each(function(e,n,u,o){var a=i+"."+e;t.call(s,a,n,u,r)})):t.call(n,i,i,l,r)})}},{key:"eachKey",value:function(e){return this.each(e)}},{key:"eachValue",value:function(t,n){if(!e.isValid(t))throw new f.default(v.NOTATION+"`"+t+"`");var r=this._source;e.eachNote(t,function(e,t,i,u){if(r=a.default.hasOwn(r,t)?r[t]:void 0,!1===n(r,e,t,i,u))return!1})}},{key:"getNotations",value:function(){var e=[];return this.each(function(t,n,r,i){e.push(t)}),e}},{key:"flatten",value:function(){var e={};return this.each(function(t,n,r,i){e[t]=r}),this._source=e,this}},{key:"expand",value:function(){return this._source=e.create({}).merge(this._source).value,this}},{key:"aggregate",value:function(){return this.expand()}},{key:"inspect",value:function(t){if(!e.isValid(t))throw new f.default(v.NOTATION+"`"+t+"`");var n=this._source,r={has:!1,value:void 0};return e.eachNote(t,function(e,t,i,u){if(!a.default.hasOwn(n,t))return r={has:!1,value:void 0},!1;n=n[t],r={has:!0,value:n}}),r}},{key:"inspectRemove",value:function(t){if(!e.isValid(t))throw new f.default(v.NOTATION+"`"+t+"`");var n=void 0,r=void 0;if(t.indexOf(".")<0)r=t,n=this._source;else{var i=e.parent(t);r=e.last(t),n=this.inspect(i).value}var u=void 0;return a.default.hasOwn(n,r)?(u={has:!0,value:n[r]},delete n[r]):u={has:!1,value:void 0},u}},{key:"has",value:function(e){return this.inspect(e).has}},{key:"hasDefined",value:function(e){return void 0!==this.inspect(e).value}},{key:"get",value:function(e,t){var n=this.inspect(e);return n.has?n.value:t}},{key:"set",value:function(t,n){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(!e.isValid(t))throw new f.default(v.NOTATION+"`"+t+"`");var i=this._source,u=void 0;return e.eachNote(t,function(e,t,o,l){u=o===l.length-1,a.default.hasOwn(i,t)?u?r&&(i[t]=n):i=i[t]:i=i[t]=u?n:{}}),this}},{key:"merge",value:function(e){var t=this,n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(!a.default.isObject(e))throw new f.default(v.NOTA_OBJ+"`"+e+"`");var r=void 0;return a.default.each(Object.keys(e),function(i,u,o){r=e[i],t.set(i,r,n)}),this}},{key:"separate",value:function(t){var n=this;if(!a.default.isArray(t))throw new f.default(v.NOTA_OBJ+"`"+t+"`");var r=new e({});return a.default.each(t,function(e,t,i){var u=n.inspectRemove(e);r.set(e,u.value)}),this._source=r._source,this}},{key:"filter",value:function(t){var n=this,r=this.value,i=a.default.deepCopy(r),u=s.default.normalize(t).concat();if(a.default.stringOrArrayOf(u,"*"))return this._source=i,this;if(0===arguments.length||a.default.stringOrArrayOf(u,"")||a.default.stringOrArrayOf(u,"!*"))return this._source={},this;var o=void 0;"*"===u[0]?(o=new e(i),u.shift()):o=new e({});var l=void 0,c=void 0,f=void 0;return a.default.each(u,function(t,i,u){if(l=new s.default(t),c=".*"===l.absGlob.slice(-2),f=c?l.absGlob.slice(0,-2):l.absGlob,f.indexOf("*")<0)return l.isNegated?(o.remove(f),c&&o.set(f,{},!0)):o.copyFrom(r,f,null,!0),!0;n.each(function(t,n,r,i){e.eachNote(t,function(e,t,n,i){if(l.test(e)){if(l.isNegated)return o.remove(e),!1;o.set(e,r,!0)}})})}),this._source=o.value,this}},{key:"remove",value:function(e){return this.inspectRemove(e),this}},{key:"delete",value:function(e){return this.remove(e),this}},{key:"clone",value:function(){return new e(a.default.deepCopy(this.value))}},{key:"copyTo",value:function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];if(!a.default.isObject(t))throw new f.default(v.DEST);var u=this.inspect(n);return u.has&&new e(t).set(r||n,u.value,i),this}},{key:"copyFrom",value:function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];if(!a.default.isObject(t))throw new f.default(v.DEST);var u=new e(t).inspect(n);return u.has&&this.set(r||n,u.value,i),this}},{key:"moveTo",value:function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];if(!a.default.isObject(t))throw new f.default(v.DEST);var u=this.inspectRemove(n);return u.has&&new e(t).set(r||n,u.value,i),this}},{key:"moveFrom",value:function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];if(!a.default.isObject(t))throw new f.default(v.DEST);var u=new e(t).inspectRemove(n);return u.has&&this.set(r||n,u.value,i),this}},{key:"rename",value:function(e,t,n){return t?this.moveTo(this._source,e,t,n):this}},{key:"renote",value:function(e,t,n){return this.rename(e,t,n)}},{key:"extract",value:function(e,t){var n={};return this.copyTo(n,e,t),n}},{key:"copyToNew",value:function(e,t){return this.extract(e,t)}},{key:"extrude",value:function(e,t){var n={};return this.moveTo(n,e,t),n}},{key:"moveToNew",value:function(e,t){return this.extrude(e,t)}},{key:"value",get:function(){return this._source}}],[{key:"create",value:function(){return new e(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})}},{key:"isValid",value:function(e){return"string"==typeof e&&/^[^\s.!]+(\.[^\s.!]+)*$/.test(e)}},{key:"countNotes",value:function(t){if(!e.isValid(t))throw new f.default(v.NOTATION+"`"+t+"`");return t.split(".").length+1}},{key:"countLevels",value:function(t){return e.countNotes(t)}},{key:"first",value:function(t){if(!e.isValid(t))throw new f.default(v.NOTATION+"`"+t+"`");return t.split(".")[0]}},{key:"last",value:function(t){if(!e.isValid(t))throw new f.default(v.NOTATION+"`"+t+"`");return t.split(".").reverse()[0]}},{key:"parent",value:function(t){if(!e.isValid(t))throw new f.default(v.NOTATION+"`"+t+"`");return t.indexOf(".")>=0?t.replace(/\.[^.]*$/,""):null}},{key:"eachNote",value:function(t,n){if(!e.isValid(t))throw new f.default(v.NOTATION+"`"+t+"`");var r=t.split("."),i=[],u=void 0;a.default.each(r,function(e,t,o){if(i.push(e),u=i.join("."),!1===n(u,e,t,r))return!1},e)}},{key:"eachLevel",value:function(t,n){e.eachNote(t,n)}}]),e}();h.Error=f.default,h.Glob=s.default,t.default=h},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var u=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=n(0),a=r(o),l=n(1),s=r(l),c=function(){function e(t){if(i(this,e),!e.isValid(t))throw new s.default('Invalid notation glob: "'+t+'"');var n=e.inspect(t);this._={glob:t,absGlob:n.absGlob,isNegated:n.isNegated,regexp:e.toRegExp(n.absGlob),levels:n.absGlob.split(".")}}return u(e,[{key:"test",value:function(e){return"*"===this.absGlob||""!==this.absGlob&&""!==e&&this.regexp.test(e)}},{key:"glob",get:function(){return this._.glob}},{key:"absGlob",get:function(){return this._.absGlob}},{key:"isNegated",get:function(){return this._.isNegated}},{key:"regexp",get:function(){return this._.regexp}},{key:"notes",get:function(){return this._.levels}},{key:"levels",get:function(){return this._.levels}}],[{key:"create",value:function(t){return new e(t)}},{key:"toRegExp",value:function(e){return 0===e.indexOf("!")&&(e=e.slice(1)),e=a.default.pregQuote(e).replace(/\\\*/g,"[^\\s\\.]*").replace(/\\\?/g,"."),new RegExp("^"+e)}},{key:"inspect",value:function(e){var t="!"===e.slice(0,1);return e=t?e.slice(1):e,{absGlob:e,isNegated:t}}},{key:"isValid",value:function(e){return"string"==typeof e&&/^(!?([^\s.!*]+|\*)(\.([^\s.!*]+|\*))*)$/.test(e)}},{key:"compare",value:function(e,t){if(e===t)return 0;var n=e.split("."),r=t.split(".");if(n.length===r.length){var i=/(?:^|\.)\*(?:$|\.)/g,u=e.match(i),o=t.match(i),a=u?u.length:0,l=o?o.length:0;if(a===l){var s=0===e.indexOf("!"),c=0===t.indexOf("!");if(s===c)return e<t?-1:1;var f=s?e.slice(1):e,v=c?t.slice(1):t;return f===v?s?1:-1:f<v?-1:1}return a>l?-1:1}return n.length<r.length?-1:1}},{key:"sort",value:function(t){return t.sort(e.compare)}},{key:"normalize",value:function(t){t=a.default.ensureArray(t).map(function(e){return e.trim()}),t=e.sort(t),a.default.eachRight(t,function(n,r){var i=t.indexOf(n);if(i>=0&&i!==r)return void t.splice(r,1);0!==n.indexOf("!")&&a.default.eachRight(t,function(i,u){if(u!==r){var o=e.inspect(i);return e.toRegExp(o.absGlob).test(n)?(o.isNegated&&n!==o.absGlob||t.splice(r,1),!1):void 0}})});var n=t.indexOf("!*");return n>=0&&t.splice(n,1),t}},{key:"union",value:function(t,n){if(a.default.hasSingleItemOf(t,"*")||a.default.hasSingleItemOf(n,"*"))return["*"];var r=t.concat(),i=n.concat(),u=void 0,o=void 0,l=void 0,s=void 0,c=[];a.default.eachRight(r,function(t,n){l=e.inspect(t),u=e.toRegExp(l.absGlob),a.default.eachRight(i,function(a,f){if(s=e.inspect(a),o=e.toRegExp(s.absGlob),l.isNegated&&!s.isNegated){if(l.absGlob===s.absGlob)return r.splice(n,1),!1;if(o.test(l.absGlob)&&-1===i.indexOf(t)&&-1===c.indexOf(t))return r.splice(n,1),!1}if(!l.isNegated&&s.isNegated){if(l.absGlob===s.absGlob)return void i.splice(f,1);if(u.test(s.absGlob)&&-1===r.indexOf(a)&&-1===c.indexOf(a))return void i.splice(f,1)}if(l.isNegated&&s.isNegated&&t!==a){if(o.test(l.absGlob))return i.splice(f,1),void c.push(t);if(u.test(s.absGlob))return r.splice(n,1),c.push(a),!1}if(!l.isNegated&&!s.isNegated&&t===a)return r.splice(n,1),!1})});var f=r.concat(i);return e.normalize(f)}}]),e}();t.default=c}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("Notation",[],t):"object"==typeof exports?exports.Notation=t():e.Notation=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="lib/",t(t.s=2)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=Object.prototype.toString,i={isObject:function(e){return"[object Object]"===r.call(e)},isArray:function(e){return"[object Array]"===r.call(e)},ensureArray:function(e){return i.isArray(e)?e:null===e||void 0===e?[]:[e]},hasOwn:function(e,t){return e&&"function"==typeof e.hasOwnProperty&&e.hasOwnProperty(t)},deepCopy:function(e){if(!i.isObject(e))return e;var t=void 0,n=void 0,r={};for(t in e)i.hasOwn(e,t)&&(n=e[t],r[t]=i.isObject(n)?i.deepCopy(n):n);return r},each:function(e,t,n){for(var r=e.length,i=-1;++i<r&&!1!==t.call(n,e[i],i,e););},eachRight:function(e,t){for(var n=e.length;n--&&!1!==t(e[n],n,e););},pregQuote:function(e,t){return String(e).replace(new RegExp("[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\"+(t||"")+"-]","g"),"\\$&")},stringOrArrayOf:function(e,t){return"string"==typeof e&&e===t||i.isArray(e)&&1===e.length&&e[0]===t},hasSingleItemOf:function(e,t){return 1===e.length&&(2!==arguments.length||e[0]===t)}};t.default=i},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var a=function(e){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";r(this,t);var n=i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.name=n.constructor.name,Object.defineProperty(n,"name",{enumerable:!1,writable:!1,value:"NotationError"}),Object.defineProperty(n,"message",{enumerable:!1,writable:!0,value:e}),Error.hasOwnProperty("captureStackTrace")?Error.captureStackTrace(n,n.constructor):Object.defineProperty(n,"stack",{enumerable:!1,writable:!1,value:new Error(e).stack}),n}return u(t,e),t}(Error);t.default=a},function(e,t,n){"use strict";var r=n(3),i=function(e){return e&&e.__esModule?e:{default:e}}(r);e.exports=i.default},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var u=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),a=n(0),o=r(a),s=n(4),l=r(s),c=n(1),f=r(c),v={SOURCE:"Invalid source object.",DEST:"Invalid destination object.",NOTATION:"Invalid notation: ",NOTA_OBJ:"Invalid notations object: "},h=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(i(this,e),!o.default.isObject(t))throw new f.default(v.SOURCE);this._source=t}return u(e,[{key:"each",value:function(t){var n=this,r=this._source,i=Object.keys(r);o.default.each(i,function(i,u,a){var s=r[i],l=void 0;o.default.isObject(s)?(l=new e(s),l.each(function(e,n,u,a){var o=i+"."+e;t.call(l,o,n,u,r)})):t.call(n,i,i,s,r)})}},{key:"eachKey",value:function(e){return this.each(e)}},{key:"eachValue",value:function(t,n){if(!e.isValid(t))throw new f.default(v.NOTATION+"`"+t+"`");var r=this._source;e.eachNote(t,function(e,t,i,u){if(r=o.default.hasOwn(r,t)?r[t]:void 0,!1===n(r,e,t,i,u))return!1})}},{key:"getNotations",value:function(){var e=[];return this.each(function(t,n,r,i){e.push(t)}),e}},{key:"flatten",value:function(){var e={};return this.each(function(t,n,r,i){e[t]=r}),this._source=e,this}},{key:"expand",value:function(){return this._source=e.create({}).merge(this._source).value,this}},{key:"aggregate",value:function(){return this.expand()}},{key:"inspect",value:function(t){if(!e.isValid(t))throw new f.default(v.NOTATION+"`"+t+"`");var n=this._source,r={has:!1,value:void 0};return e.eachNote(t,function(e,t,i,u){if(!o.default.hasOwn(n,t))return r={has:!1,value:void 0},!1;n=n[t],r={has:!0,value:n}}),r}},{key:"inspectRemove",value:function(t){if(!e.isValid(t))throw new f.default(v.NOTATION+"`"+t+"`");var n=void 0,r=void 0;if(t.indexOf(".")<0)r=t,n=this._source;else{var i=e.parent(t);r=e.last(t),n=this.inspect(i).value}var u=void 0;return o.default.hasOwn(n,r)?(u={has:!0,value:n[r]},delete n[r]):u={has:!1,value:void 0},u}},{key:"has",value:function(e){return this.inspect(e).has}},{key:"hasDefined",value:function(e){return void 0!==this.inspect(e).value}},{key:"get",value:function(e,t){var n=this.inspect(e);return n.has?n.value:t}},{key:"set",value:function(t,n){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(!e.isValid(t))throw new f.default(v.NOTATION+"`"+t+"`");var i=this._source,u=void 0;return e.eachNote(t,function(e,t,a,s){u=a===s.length-1,o.default.hasOwn(i,t)?u?r&&(i[t]=n):i=i[t]:i=i[t]=u?n:{}}),this}},{key:"merge",value:function(e){var t=this,n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(!o.default.isObject(e))throw new f.default(v.NOTA_OBJ+"`"+e+"`");var r=void 0;return o.default.each(Object.keys(e),function(i,u,a){r=e[i],t.set(i,r,n)}),this}},{key:"separate",value:function(t){var n=this;if(!o.default.isArray(t))throw new f.default(v.NOTA_OBJ+"`"+t+"`");var r=new e({});return o.default.each(t,function(e,t,i){var u=n.inspectRemove(e);r.set(e,u.value)}),this._source=r._source,this}},{key:"filter",value:function(t){var n=this,r=this.value,i=o.default.deepCopy(r),u=l.default.normalize(t).concat();if(o.default.stringOrArrayOf(u,"*"))return this._source=i,this;if(0===arguments.length||o.default.stringOrArrayOf(u,"")||o.default.stringOrArrayOf(u,"!*"))return this._source={},this;var a=void 0;"*"===u[0]?(a=new e(i),u.shift()):a=new e({});var s=void 0,c=void 0,f=void 0;return o.default.each(u,function(t,i,u){if(s=new l.default(t),c=".*"===s.absGlob.slice(-2),f=c?s.absGlob.slice(0,-2):s.absGlob,f.indexOf("*")<0)return s.isNegated?(a.remove(f),c&&a.set(f,{},!0)):a.copyFrom(r,f,null,!0),!0;n.each(function(t,n,r,i){e.eachNote(t,function(e,t,n,i){if(s.test(e)){if(s.isNegated)return a.remove(e),!1;a.set(e,r,!0)}})})}),this._source=a.value,this}},{key:"remove",value:function(e){return this.inspectRemove(e),this}},{key:"delete",value:function(e){return this.remove(e),this}},{key:"clone",value:function(){return new e(o.default.deepCopy(this.value))}},{key:"copyTo",value:function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];if(!o.default.isObject(t))throw new f.default(v.DEST);var u=this.inspect(n);return u.has&&new e(t).set(r||n,u.value,i),this}},{key:"copyFrom",value:function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];if(!o.default.isObject(t))throw new f.default(v.DEST);var u=new e(t).inspect(n);return u.has&&this.set(r||n,u.value,i),this}},{key:"moveTo",value:function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];if(!o.default.isObject(t))throw new f.default(v.DEST);var u=this.inspectRemove(n);return u.has&&new e(t).set(r||n,u.value,i),this}},{key:"moveFrom",value:function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];if(!o.default.isObject(t))throw new f.default(v.DEST);var u=new e(t).inspectRemove(n);return u.has&&this.set(r||n,u.value,i),this}},{key:"rename",value:function(e,t,n){return t?this.moveTo(this._source,e,t,n):this}},{key:"renote",value:function(e,t,n){return this.rename(e,t,n)}},{key:"extract",value:function(e,t){var n={};return this.copyTo(n,e,t),n}},{key:"copyToNew",value:function(e,t){return this.extract(e,t)}},{key:"extrude",value:function(e,t){var n={};return this.moveTo(n,e,t),n}},{key:"moveToNew",value:function(e,t){return this.extrude(e,t)}},{key:"value",get:function(){return this._source}}],[{key:"create",value:function(){return new e(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})}},{key:"isValid",value:function(e){return"string"==typeof e&&/^[^\s.!]+(\.[^\s.!]+)*$/.test(e)}},{key:"countNotes",value:function(t){if(!e.isValid(t))throw new f.default(v.NOTATION+"`"+t+"`");return t.split(".").length}},{key:"countLevels",value:function(t){return e.countNotes(t)}},{key:"first",value:function(t){if(!e.isValid(t))throw new f.default(v.NOTATION+"`"+t+"`");return t.split(".")[0]}},{key:"last",value:function(t){if(!e.isValid(t))throw new f.default(v.NOTATION+"`"+t+"`");return t.split(".").reverse()[0]}},{key:"parent",value:function(t){if(!e.isValid(t))throw new f.default(v.NOTATION+"`"+t+"`");return t.indexOf(".")>=0?t.replace(/\.[^.]*$/,""):null}},{key:"eachNote",value:function(t,n){if(!e.isValid(t))throw new f.default(v.NOTATION+"`"+t+"`");var r=t.split("."),i=[],u=void 0;o.default.each(r,function(e,t,a){if(i.push(e),u=i.join("."),!1===n(u,e,t,r))return!1},e)}},{key:"eachLevel",value:function(t,n){e.eachNote(t,n)}}]),e}();h.Error=f.default,h.Glob=l.default,t.default=h},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var u=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),a=n(0),o=r(a),s=n(1),l=r(s),c=function(){function e(t){if(i(this,e),!e.isValid(t))throw new l.default('Invalid notation glob: "'+t+'"');var n=e.inspect(t);this._={glob:t,absGlob:n.absGlob,isNegated:n.isNegated,regexp:e.toRegExp(n.absGlob),levels:n.absGlob.split(".")}}return u(e,[{key:"test",value:function(e){return"*"===this.absGlob||""!==this.absGlob&&""!==e&&this.regexp.test(e)}},{key:"glob",get:function(){return this._.glob}},{key:"absGlob",get:function(){return this._.absGlob}},{key:"isNegated",get:function(){return this._.isNegated}},{key:"regexp",get:function(){return this._.regexp}},{key:"notes",get:function(){return this._.levels}},{key:"levels",get:function(){return this._.levels}}],[{key:"create",value:function(t){return new e(t)}},{key:"toRegExp",value:function(e){return 0===e.indexOf("!")&&(e=e.slice(1)),e=o.default.pregQuote(e).replace(/\\\*/g,"[^\\s\\.]*").replace(/\\\?/g,"."),new RegExp("^"+e)}},{key:"inspect",value:function(e){var t="!"===e.slice(0,1);return e=t?e.slice(1):e,{absGlob:e,isNegated:t}}},{key:"isValid",value:function(e){return"string"==typeof e&&/^(!?([^\s.!*]+|\*)(\.([^\s.!*]+|\*))*)$/.test(e)}},{key:"compare",value:function(e,t){if(e===t)return 0;var n=e.split("."),r=t.split(".");if(n.length===r.length){var i=/(?:^|\.)\*(?:$|\.)/g,u=e.match(i),a=t.match(i),o=u?u.length:0,s=a?a.length:0;if(o===s){var l=0===e.indexOf("!"),c=0===t.indexOf("!");if(l===c)return e<t?-1:1;var f=l?e.slice(1):e,v=c?t.slice(1):t;return f===v?l?1:-1:f<v?-1:1}return o>s?-1:1}return n.length<r.length?-1:1}},{key:"sort",value:function(t){return t.sort(e.compare)}},{key:"normalize",value:function(t){t=o.default.ensureArray(t).map(function(e){return e.trim()}),t=e.sort(t),o.default.eachRight(t,function(n,r){var i=e.inspect(n),u=!1,a=!1,s=!1,l=!0,c=!1,f=!0;o.default.eachRight(t,function(t,o){if(o!==r){var v=e.inspect(t),h=e.toRegExp(v.absGlob);if(n===t)return u=!0,!1;if(v.isNegated&&n===v.absGlob)return a=!0,!1;if(i.isNegated){if(v.isNegated&&h.test(i.absGlob))return s=!0,!1;l&&h.test(i.absGlob)&&(l=!1)}else!v.isNegated&&h.test(i.absGlob)?c=!0:f&&h.test(i.absGlob)&&(f=!1)}});var v=i.isNegated?s||l:c&&f;(u||a||v)&&t.splice(r,1)});var n=t.indexOf("!*");return n>=0&&t.splice(n,1),t}},{key:"union",value:function(t,n){if(o.default.hasSingleItemOf(t,"*")||o.default.hasSingleItemOf(n,"*"))return["*"];var r=t.concat(),i=n.concat(),u=void 0,a=void 0,s=void 0,l=void 0,c=[];o.default.eachRight(r,function(t,n){s=e.inspect(t),u=e.toRegExp(s.absGlob),o.default.eachRight(i,function(o,f){if(l=e.inspect(o),a=e.toRegExp(l.absGlob),s.isNegated&&!l.isNegated){if(s.absGlob===l.absGlob)return r.splice(n,1),!1;if(a.test(s.absGlob)&&-1===i.indexOf(t)&&-1===c.indexOf(t))return r.splice(n,1),!1}if(!s.isNegated&&l.isNegated){if(s.absGlob===l.absGlob)return void i.splice(f,1);if(u.test(l.absGlob)&&-1===r.indexOf(o)&&-1===c.indexOf(o))return void i.splice(f,1)}if(s.isNegated&&l.isNegated&&t!==o){if(a.test(s.absGlob))return i.splice(f,1),void c.push(t);if(u.test(l.absGlob))return r.splice(n,1),c.push(o),!1}if(!s.isNegated&&!l.isNegated&&t===o)return r.splice(n,1),!1})});var f=r.concat(i);return e.normalize(f)}}]),e}();t.default=c}])}); | ||
//# sourceMappingURL=notation.min.js.map |
{ | ||
"name": "notation", | ||
"version": "1.3.0", | ||
"version": "1.3.5", | ||
"description": "Utility for modifying / processing the contents of Javascript objects by object notation strings or globs.", | ||
@@ -28,4 +28,4 @@ "license": "MIT", | ||
"watch": "webpack --env.WEBPACK_OUT=nomin --progress --colors --watch", | ||
"test": "npm run build && node test", | ||
"dev": "npm run build:nomin && npm run test", | ||
"dev": "npm run build && node test", | ||
"test": "npm run build:nomin && node test", | ||
"docs": "docma -c ./docma.config.json", | ||
@@ -32,0 +32,0 @@ "release": "npm run build && node test && npm run docs" |
@@ -10,7 +10,8 @@ ## Notation.js | ||
[](https://github.com/onury/notation/blob/master/LICENSE) | ||
[](https://github.com/onury/notation/graphs/commit-activity) | ||
[](https://github.com/onury/notation/graphs/commit-activity) | ||
[](http://onury.io/notation/?api=notation) | ||
> © 2017, Onur Yıldırım ([@onury](https://github.com/onury)). MIT License. | ||
Utility for modifying / processing the contents of Javascript objects by parsing object notation strings or globs. | ||
Utility for modifying / processing the contents of Javascript objects via object notation strings or globs. | ||
@@ -28,8 +29,11 @@ Note that this library will only deal with enumerable properties of the source object; so it should be used to manipulate data objects. It will not deal with preserving the prototype-chain of the given object. | ||
### Notation | ||
Modify the contents of a data object: | ||
```js | ||
var Notation = require('notation'); | ||
const Notation = require('notation'); | ||
var obj = { car: { brand: "Dodge", model: "Charger" }, dog: { breed: "Akita" } }; | ||
var notation = new Notation(obj); | ||
notation.get('car.model'); // "Charger" | ||
const obj = { car: { brand: "Dodge", model: "Charger" }, dog: { breed: "Akita" } }; | ||
const notation = new Notation(obj); | ||
notation.get('car.model'); // "Charger" | ||
notation | ||
@@ -44,5 +48,72 @@ .set('car.color', 'red') // { car: { brand: "Dodge", model: "Charger", color: "red" }, dog: { breed: "Akita" } } | ||
.rename('boat.name', 'dog.name') // { dog: { breed: "Akita", color: "white", name: "Mojo" } } | ||
.value; // source object | ||
.value; // modified source object ^ | ||
``` | ||
### Glob Notation | ||
With a glob-notation, you can use wildcard stars `*` and bang `!` prefixes. A wildcard star will include all the properties at that level and a bang negates that notation for exclusion. | ||
- Only **`Notation#filter()`** method accepts glob notations. Regular notations (without any wildcard or `!`) should be used with all other members of the **`Notation`** class. | ||
- For raw Glob operations, you can use the **`Notation.Glob`** class. | ||
#### Normalize a glob notation list | ||
Removes duplicates, redundant items and logically sorts the array: | ||
```js | ||
const globs = ['*', '!id', 'name', 'car.model', '!car.*', 'id', 'name', 'age']; | ||
console.log(Notation.Glob.normalize(globs)); | ||
// => ['*', '!car.*', '!id', 'car.model'] | ||
``` | ||
In the normalized result `['*', '!car.*', '!id', 'car.model']`: | ||
- `id` is removed and `!id` (negated version) is kept. (In normalization, negated wins over the positive, if both are same). | ||
- Duplicate glob, `name` is removed. The remaining `name` is also removed bec. `*` renders it redundant; which covers all possible notations. | ||
- `car.model` is kept (although `*` matches it) bec. we have a negated glob that also matches it: `!car.*`. | ||
#### Union two glob notation lists | ||
Unites two glob arrays optimistically and sorts the result array logically: | ||
```js | ||
const globsA = ['*', '!car.model', 'car.brand', '!*.age']; | ||
const globsB = ['car.model', 'user.age', 'user.name']; | ||
const union = Notation.Glob.union(globsA, globsB); | ||
console.log(union); | ||
// => ['*', '!*.age', 'user.age'] | ||
``` | ||
In the united result `['*', '!*.age', 'user.age']`: | ||
- (negated) `!car.model` of `globsA` is removed because `globsB` has the exact positive version of it. (In union, positive wins over the negated, if both are same.) | ||
- But then, `car.model` is redundant and removed bec. we have `*` wildcard, which covers all possible notations. | ||
- Same applies to other redundant globs except `user.age` bec. we have a `!*.age` in `globsA`, which matches `user.age`. So both are kept in the final array. | ||
Now, filter a data object with this united globs array: | ||
```js | ||
const data = { | ||
car: { | ||
brand: 'Ford', | ||
model: 'Mustang', | ||
age: 52 | ||
}, | ||
user: { | ||
name: 'John', | ||
age: 40 | ||
} | ||
}; | ||
const globs = ['*', '!*.age', 'user.age']; // our union'ed globs | ||
const filtered = Notation.create(data).filter(globs).value; | ||
console.log(filtered); | ||
// => | ||
// { | ||
// car: { | ||
// brand: 'Ford', | ||
// model: 'Mustang' | ||
// }, | ||
// user: { | ||
// name: 'John', | ||
// age: 40 | ||
// } | ||
// } | ||
``` | ||
> _**Note**: `Notation#filter()` and `Notation.Glob.union()` methods automtically normalizes the given glob list(s)._ | ||
## Documentation | ||
@@ -54,2 +125,9 @@ | ||
**1.3.5** (2017-10-04) | ||
- Redundant, negated globs should are also removed when normalized. Fixes [issue #5](https://github.com/onury/notation/issues/5). | ||
- Fixed shifted index issue with `Notation.Glob.normalize(array)`. | ||
- Fixed `countNotes()` method. | ||
- Minor revisions. | ||
**1.3.0** (2017-09-30) | ||
@@ -65,3 +143,3 @@ | ||
- Added `Notation.Glob.toRegExp(glob)` static method. | ||
- Aded `Notation.countNotes(notation)` convenience method. | ||
- Added `Notation.countNotes(notation)` convenience method. | ||
- Improved glob validation. | ||
@@ -68,0 +146,0 @@ - Fix import typo that prevents Travis builds succeed. |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
395043
2013
161
0