pathington
Advanced tools
Comparing version 1.1.6 to 1.1.7
# pathington CHANGELOG | ||
## 1.1.7 | ||
- Use custom `map` implementation for performance | ||
## 1.1.6 | ||
@@ -9,36 +13,36 @@ | ||
* Simplify valid key regex (reduce filesize) | ||
- Simplify valid key regex (reduce filesize) | ||
## 1.1.4 | ||
* Improve regexp coverage for dotty syntax | ||
* Simplify `isNumericKey` regexp | ||
- Improve regexp coverage for dotty syntax | ||
- Simplify `isNumericKey` regexp | ||
## 1.1.3 | ||
* Add caching of string keys (huge performance boost for common use-cases) | ||
- Add caching of string keys (huge performance boost for common use-cases) | ||
## 1.1.2 | ||
* Ensure quoted numeric keys (indices) will be parsed as numbers | ||
- Ensure quoted numeric keys (indices) will be parsed as numbers | ||
## 1.1.1 | ||
* Improve performance of `isQuotedKey` test | ||
- Improve performance of `isQuotedKey` test | ||
## 1.1.0 | ||
* If a value is not a standard type, `parse` will coerce the value to string and use that as key (`null` => `'null'`) | ||
* Empty strings are now supported as keys | ||
- If a value is not a standard type, `parse` will coerce the value to string and use that as key (`null` => `'null'`) | ||
- Empty strings are now supported as keys | ||
## 1.0.2 | ||
* Fix issue where single multi-space string was being split into separate keys (should be single quoted key) | ||
- Fix issue where single multi-space string was being split into separate keys (should be single quoted key) | ||
## 1.0.1 | ||
* Ensure `es` transpilation is usable by bundles by including the `module` definition in `package.json` | ||
- Ensure `es` transpilation is usable by bundles by including the `module` definition in `package.json` | ||
## 1.0.0 | ||
* Initial release | ||
- Initial release |
@@ -186,2 +186,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var isArray = Array.isArray; | ||
/** | ||
@@ -203,3 +204,3 @@ * @function create | ||
if (!Array.isArray(path)) { | ||
if (!isArray(path)) { | ||
throw new ReferenceError('path passed must be an array'); | ||
@@ -230,7 +231,8 @@ } | ||
if (Array.isArray(path)) { | ||
return path.map(_utils__WEBPACK_IMPORTED_MODULE_1__["getNormalizedParseKey"]); | ||
if (isArray(path)) { | ||
return Object(_utils__WEBPACK_IMPORTED_MODULE_1__["map"])(path, _utils__WEBPACK_IMPORTED_MODULE_1__["getNormalizedParseKey"]); | ||
} | ||
return [typeof path === 'number' ? path : "" + path]; | ||
var normalizedParseKey = Object(_utils__WEBPACK_IMPORTED_MODULE_1__["getNormalizedParseKey"])(path); | ||
return [typeof normalizedParseKey === 'number' ? normalizedParseKey : "" + normalizedParseKey]; | ||
}; | ||
@@ -244,3 +246,3 @@ | ||
\**********************/ | ||
/*! exports provided: isNumericKey, isQuotedKey, shouldBeInBrackets, shouldBeInQuotes, createGetNormalizedCreateKey, getNormalizedParseKey, parseStringPath */ | ||
/*! exports provided: isNumericKey, isQuotedKey, map, shouldBeInBrackets, shouldBeInQuotes, createGetNormalizedCreateKey, getNormalizedParseKey, parseStringPath */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
@@ -252,2 +254,3 @@ | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isQuotedKey", function() { return isQuotedKey; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "map", function() { return map; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "shouldBeInBrackets", function() { return shouldBeInBrackets; }); | ||
@@ -272,3 +275,3 @@ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "shouldBeInQuotes", function() { return shouldBeInQuotes; }); | ||
var isNumericKey = function isNumericKey(key) { | ||
return !!key.length && _constants__WEBPACK_IMPORTED_MODULE_0__["NUMBER"].test(key); | ||
return !!(key && key.length) && _constants__WEBPACK_IMPORTED_MODULE_0__["NUMBER"].test(key); | ||
}; | ||
@@ -289,2 +292,23 @@ /** | ||
/** | ||
* @function map | ||
* | ||
* @description | ||
* map the array to a new array based on fn | ||
* | ||
* @param {Array<*>} array the array to map | ||
* @param {function} fn the function to call with each iteration value | ||
* @returns {Array<*>} the mapped array | ||
*/ | ||
var map = function map(array, fn) { | ||
var length = array.length; | ||
var mapped = []; | ||
for (var index = 0; index < length; index++) { | ||
mapped[index] = fn(array[index]); | ||
} | ||
return mapped; | ||
}; | ||
/** | ||
* @function shouldBeInBrackets | ||
@@ -328,3 +352,3 @@ * | ||
var normalizedKey = shouldBeInQuotes(key) ? "" + quote + key + quote : key; | ||
return shouldBeInBrackets(normalizedKey) ? existingString + "[" + normalizedKey + "]" : existingString + "." + normalizedKey; | ||
return existingString + (shouldBeInBrackets(normalizedKey) ? "[" + normalizedKey + "]" : "." + normalizedKey); | ||
}; | ||
@@ -343,3 +367,3 @@ }; | ||
var getNormalizedParseKey = function getNormalizedParseKey(key) { | ||
var cleanKey = isQuotedKey(key) ? key.substring(1, key.length - 1) : key; | ||
var cleanKey = isQuotedKey(key) ? key.slice(1, key.length - 1) : key; | ||
return isNumericKey(cleanKey) ? +cleanKey : cleanKey; | ||
@@ -366,3 +390,3 @@ }; | ||
_constants__WEBPACK_IMPORTED_MODULE_0__["CACHE"].results[path] = path ? path.match(_constants__WEBPACK_IMPORTED_MODULE_0__["DOTTY_WITH_BRACKETS_SYNTAX"]).map(getNormalizedParseKey) : [path]; | ||
_constants__WEBPACK_IMPORTED_MODULE_0__["CACHE"].results[path] = path ? map(path.match(_constants__WEBPACK_IMPORTED_MODULE_0__["DOTTY_WITH_BRACKETS_SYNTAX"]), getNormalizedParseKey) : [path]; | ||
_constants__WEBPACK_IMPORTED_MODULE_0__["CACHE"].size++; | ||
@@ -369,0 +393,0 @@ return _constants__WEBPACK_IMPORTED_MODULE_0__["CACHE"].results[path]; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("pathington",[],t):"object"==typeof exports?exports.pathington=t():e.pathington=t()}(window,function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";r.r(t);var n={clear:function(){n.results={},n.size=0},results:{},size:0},o=/"[^"]+"|`[^`]+`|'[^']+'|[^.[\]]+/g,u=/^\d+$/i,i=/^"[^"]+"|`[^`]+`|'[^']+'$/,f=/^["'`]{1}$/,s=/^\d+$|^[a-zA-Z_$][\w$]+$/,c=/\s/,a=function(e){return!!e.length&&u.test(e)},l=function(e){return i.test(e)},p=function(e){return function(t,r){var n=function(e){return c.test(e)||!s.test(e)}(r)?""+e+r+e:r;return function(e){return"number"==typeof e||a(e)||l(e)}(n)?t+"["+n+"]":t+"."+n}},d=function(e){var t=l(e)?e.substring(1,e.length-1):e;return a(t)?+t:t};r.d(t,"create",function(){return y}),r.d(t,"parse",function(){return b});var y=function(e,t){if(void 0===t&&(t='"'),!Array.isArray(e))throw new ReferenceError("path passed must be an array");if(!f.test(t))throw new SyntaxError("quote "+t+" passed is invalid, must be \", `, or '.");var r=e.reduce(p(t),"");return"."===r[0]?r.slice(1):r},b=function(e){return"string"==typeof e?function(e){return n.results[e]?n.results[e]:(n.size>500&&n.clear(),n.results[e]=e?e.match(o).map(d):[e],n.size++,n.results[e])}(e):Array.isArray(e)?e.map(d):["number"==typeof e?e:""+e]}}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("pathington",[],t):"object"==typeof exports?exports.pathington=t():e.pathington=t()}(window,function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";r.r(t);var n={clear:function(){n.results={},n.size=0},results:{},size:0},o=/"[^"]+"|`[^`]+`|'[^']+'|[^.[\]]+/g,u=/^\d+$/i,i=/^"[^"]+"|`[^`]+`|'[^']+'$/,f=/^["'`]{1}$/,c=/^\d+$|^[a-zA-Z_$][\w$]+$/,s=/\s/,a=function(e){return!(!e||!e.length)&&u.test(e)},l=function(e){return i.test(e)},p=function(e,t){for(var r=e.length,n=[],o=0;o<r;o++)n[o]=t(e[o]);return n},d=function(e){return function(t,r){var n=function(e){return s.test(e)||!c.test(e)}(r)?""+e+r+e:r;return t+(function(e){return"number"==typeof e||a(e)||l(e)}(n)?"["+n+"]":"."+n)}},y=function(e){var t=l(e)?e.slice(1,e.length-1):e;return a(t)?+t:t};r.d(t,"create",function(){return v}),r.d(t,"parse",function(){return g});var b=Array.isArray,v=function(e,t){if(void 0===t&&(t='"'),!b(e))throw new ReferenceError("path passed must be an array");if(!f.test(t))throw new SyntaxError("quote "+t+" passed is invalid, must be \", `, or '.");var r=e.reduce(d(t),"");return"."===r[0]?r.slice(1):r},g=function(e){if("string"==typeof e)return function(e){return n.results[e]?n.results[e]:(n.size>500&&n.clear(),n.results[e]=e?p(e.match(o),y):[e],n.size++,n.results[e])}(e);if(b(e))return p(e,y);var t=y(e);return["number"==typeof t?t:""+t]}}])}); |
// constants | ||
import { VALID_QUOTES } from './constants'; // utils | ||
import { createGetNormalizedCreateKey, getNormalizedParseKey, parseStringPath } from './utils'; | ||
import { createGetNormalizedCreateKey, getNormalizedParseKey, map, parseStringPath } from './utils'; | ||
var isArray = Array.isArray; | ||
/** | ||
@@ -21,3 +22,3 @@ * @function create | ||
if (!Array.isArray(path)) { | ||
if (!isArray(path)) { | ||
throw new ReferenceError('path passed must be an array'); | ||
@@ -48,7 +49,8 @@ } | ||
if (Array.isArray(path)) { | ||
return path.map(getNormalizedParseKey); | ||
if (isArray(path)) { | ||
return map(path, getNormalizedParseKey); | ||
} | ||
return [typeof path === 'number' ? path : "" + path]; | ||
var normalizedParseKey = getNormalizedParseKey(path); | ||
return [typeof normalizedParseKey === 'number' ? normalizedParseKey : "" + normalizedParseKey]; | ||
}; |
@@ -14,3 +14,3 @@ // constants | ||
export var isNumericKey = function isNumericKey(key) { | ||
return !!key.length && NUMBER.test(key); | ||
return !!(key && key.length) && NUMBER.test(key); | ||
}; | ||
@@ -31,2 +31,23 @@ /** | ||
/** | ||
* @function map | ||
* | ||
* @description | ||
* map the array to a new array based on fn | ||
* | ||
* @param {Array<*>} array the array to map | ||
* @param {function} fn the function to call with each iteration value | ||
* @returns {Array<*>} the mapped array | ||
*/ | ||
export var map = function map(array, fn) { | ||
var length = array.length; | ||
var mapped = []; | ||
for (var index = 0; index < length; index++) { | ||
mapped[index] = fn(array[index]); | ||
} | ||
return mapped; | ||
}; | ||
/** | ||
* @function shouldBeInBrackets | ||
@@ -70,3 +91,3 @@ * | ||
var normalizedKey = shouldBeInQuotes(key) ? "" + quote + key + quote : key; | ||
return shouldBeInBrackets(normalizedKey) ? existingString + "[" + normalizedKey + "]" : existingString + "." + normalizedKey; | ||
return existingString + (shouldBeInBrackets(normalizedKey) ? "[" + normalizedKey + "]" : "." + normalizedKey); | ||
}; | ||
@@ -85,3 +106,3 @@ }; | ||
export var getNormalizedParseKey = function getNormalizedParseKey(key) { | ||
var cleanKey = isQuotedKey(key) ? key.substring(1, key.length - 1) : key; | ||
var cleanKey = isQuotedKey(key) ? key.slice(1, key.length - 1) : key; | ||
return isNumericKey(cleanKey) ? +cleanKey : cleanKey; | ||
@@ -108,5 +129,5 @@ }; | ||
CACHE.results[path] = path ? path.match(DOTTY_WITH_BRACKETS_SYNTAX).map(getNormalizedParseKey) : [path]; | ||
CACHE.results[path] = path ? map(path.match(DOTTY_WITH_BRACKETS_SYNTAX), getNormalizedParseKey) : [path]; | ||
CACHE.size++; | ||
return CACHE.results[path]; | ||
}; |
@@ -12,3 +12,3 @@ "use strict"; | ||
// utils | ||
var isArray = Array.isArray; | ||
/** | ||
@@ -24,2 +24,3 @@ * @function create | ||
*/ | ||
var create = function create(path, quote) { | ||
@@ -30,3 +31,3 @@ if (quote === void 0) { | ||
if (!Array.isArray(path)) { | ||
if (!isArray(path)) { | ||
throw new ReferenceError('path passed must be an array'); | ||
@@ -60,9 +61,10 @@ } | ||
if (Array.isArray(path)) { | ||
return path.map(_utils.getNormalizedParseKey); | ||
if (isArray(path)) { | ||
return (0, _utils.map)(path, _utils.getNormalizedParseKey); | ||
} | ||
return [typeof path === 'number' ? path : "" + path]; | ||
var normalizedParseKey = (0, _utils.getNormalizedParseKey)(path); | ||
return [typeof normalizedParseKey === 'number' ? normalizedParseKey : "" + normalizedParseKey]; | ||
}; | ||
exports.parse = parse; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.parseStringPath = exports.getNormalizedParseKey = exports.createGetNormalizedCreateKey = exports.shouldBeInQuotes = exports.shouldBeInBrackets = exports.isQuotedKey = exports.isNumericKey = void 0; | ||
exports.parseStringPath = exports.getNormalizedParseKey = exports.createGetNormalizedCreateKey = exports.shouldBeInQuotes = exports.shouldBeInBrackets = exports.map = exports.isQuotedKey = exports.isNumericKey = void 0; | ||
@@ -20,3 +20,3 @@ var _constants = require("./constants"); | ||
var isNumericKey = function isNumericKey(key) { | ||
return !!key.length && _constants.NUMBER.test(key); | ||
return !!(key && key.length) && _constants.NUMBER.test(key); | ||
}; | ||
@@ -40,2 +40,26 @@ /** | ||
/** | ||
* @function map | ||
* | ||
* @description | ||
* map the array to a new array based on fn | ||
* | ||
* @param {Array<*>} array the array to map | ||
* @param {function} fn the function to call with each iteration value | ||
* @returns {Array<*>} the mapped array | ||
*/ | ||
exports.isQuotedKey = isQuotedKey; | ||
var map = function map(array, fn) { | ||
var length = array.length; | ||
var mapped = []; | ||
for (var index = 0; index < length; index++) { | ||
mapped[index] = fn(array[index]); | ||
} | ||
return mapped; | ||
}; | ||
/** | ||
* @function shouldBeInBrackets | ||
@@ -51,3 +75,3 @@ * | ||
exports.isQuotedKey = isQuotedKey; | ||
exports.map = map; | ||
@@ -89,3 +113,3 @@ var shouldBeInBrackets = function shouldBeInBrackets(key) { | ||
var normalizedKey = shouldBeInQuotes(key) ? "" + quote + key + quote : key; | ||
return shouldBeInBrackets(normalizedKey) ? existingString + "[" + normalizedKey + "]" : existingString + "." + normalizedKey; | ||
return existingString + (shouldBeInBrackets(normalizedKey) ? "[" + normalizedKey + "]" : "." + normalizedKey); | ||
}; | ||
@@ -107,3 +131,3 @@ }; | ||
var getNormalizedParseKey = function getNormalizedParseKey(key) { | ||
var cleanKey = isQuotedKey(key) ? key.substring(1, key.length - 1) : key; | ||
var cleanKey = isQuotedKey(key) ? key.slice(1, key.length - 1) : key; | ||
return isNumericKey(cleanKey) ? +cleanKey : cleanKey; | ||
@@ -133,3 +157,3 @@ }; | ||
_constants.CACHE.results[path] = path ? path.match(_constants.DOTTY_WITH_BRACKETS_SYNTAX).map(getNormalizedParseKey) : [path]; | ||
_constants.CACHE.results[path] = path ? map(path.match(_constants.DOTTY_WITH_BRACKETS_SYNTAX), getNormalizedParseKey) : [path]; | ||
_constants.CACHE.size++; | ||
@@ -136,0 +160,0 @@ return _constants.CACHE.results[path]; |
@@ -42,6 +42,6 @@ { | ||
"@babel/register": "^7.0.0", | ||
"ava": "^1.0.1", | ||
"ava": "^1.1.0", | ||
"babel-eslint": "^10.0.1", | ||
"babel-loader": "^8.0.4", | ||
"eslint": "^5.11.1", | ||
"babel-loader": "^8.0.5", | ||
"eslint": "^5.12.1", | ||
"eslint-config-rapid7": "^3.1.0", | ||
@@ -55,5 +55,5 @@ "eslint-friendly-formatter": "^4.0.1", | ||
"react-dom": "^16.7.0", | ||
"sinon": "^7.2.2", | ||
"webpack": "^4.28.3", | ||
"webpack-cli": "^3.1.2", | ||
"sinon": "^7.2.3", | ||
"webpack": "^4.29.0", | ||
"webpack-cli": "^3.2.1", | ||
"webpack-dev-server": "^3.1.14" | ||
@@ -94,3 +94,3 @@ }, | ||
}, | ||
"version": "1.1.6" | ||
"version": "1.1.7" | ||
} |
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
354645
782