From 51964ed42eac9e3c302a53695e4928d87f092ff1 Mon Sep 17 00:00:00 2001 From: Joachim Wester Date: Thu, 24 Mar 2022 18:58:23 +0100 Subject: [PATCH] feat: Cleaned up vars vs consts --- commonjs/helpers.js | 18 +++++++++--------- dist/fast-json-patch.js | 18 +++++++++--------- dist/fast-json-patch.min.js | 6 +++--- module/helpers.d.ts | 4 ++-- module/helpers.mjs | 18 +++++++++--------- src/helpers.ts | 36 ++++++++++++++++++------------------ 6 files changed, 50 insertions(+), 50 deletions(-) diff --git a/commonjs/helpers.js b/commonjs/helpers.js index 0ac28b4d..5f2350e4 100644 --- a/commonjs/helpers.js +++ b/commonjs/helpers.js @@ -1,7 +1,7 @@ /*! * https://github.com/Starcounter-Jack/JSON-Patch - * (c) 2017 Joachim Wester - * MIT license + * (c) 2017-2022 Joachim Wester + * MIT licensed */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { @@ -24,11 +24,11 @@ function hasOwnProperty(obj, key) { exports.hasOwnProperty = hasOwnProperty; function _objectKeys(obj) { if (Array.isArray(obj)) { - var keys = new Array(obj.length); - for (var k = 0; k < keys.length; k++) { - keys[k] = "" + k; + var keys_1 = new Array(obj.length); + for (var k = 0; k < keys_1.length; k++) { + keys_1[k] = "" + k; } - return keys; + return keys_1; } if (Object.keys) { return Object.keys(obj); @@ -122,7 +122,7 @@ function getPath(root, obj) { if (path === '') { throw new Error("Object not found in root"); } - return '/' + path; + return "/" + path; } exports.getPath = getPath; /** @@ -134,8 +134,8 @@ function hasUndefined(obj) { } if (obj) { if (Array.isArray(obj)) { - for (var i = 0, len = obj.length; i < len; i++) { - if (hasUndefined(obj[i])) { + for (var i_1 = 0, len = obj.length; i_1 < len; i_1++) { + if (hasUndefined(obj[i_1])) { return true; } } diff --git a/dist/fast-json-patch.js b/dist/fast-json-patch.js index 16217bd8..0825c482 100644 --- a/dist/fast-json-patch.js +++ b/dist/fast-json-patch.js @@ -92,8 +92,8 @@ var jsonpatch = /*! * https://github.com/Starcounter-Jack/JSON-Patch - * (c) 2017 Joachim Wester - * MIT license + * (c) 2017-2022 Joachim Wester + * MIT licensed */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { @@ -116,11 +116,11 @@ function hasOwnProperty(obj, key) { exports.hasOwnProperty = hasOwnProperty; function _objectKeys(obj) { if (Array.isArray(obj)) { - var keys = new Array(obj.length); - for (var k = 0; k < keys.length; k++) { - keys[k] = "" + k; + var keys_1 = new Array(obj.length); + for (var k = 0; k < keys_1.length; k++) { + keys_1[k] = "" + k; } - return keys; + return keys_1; } if (Object.keys) { return Object.keys(obj); @@ -214,7 +214,7 @@ function getPath(root, obj) { if (path === '') { throw new Error("Object not found in root"); } - return '/' + path; + return "/" + path; } exports.getPath = getPath; /** @@ -226,8 +226,8 @@ function hasUndefined(obj) { } if (obj) { if (Array.isArray(obj)) { - for (var i = 0, len = obj.length; i < len; i++) { - if (hasUndefined(obj[i])) { + for (var i_1 = 0, len = obj.length; i_1 < len; i_1++) { + if (hasUndefined(obj[i_1])) { return true; } } diff --git a/dist/fast-json-patch.min.js b/dist/fast-json-patch.min.js index f254a20b..9ab5c764 100644 --- a/dist/fast-json-patch.min.js +++ b/dist/fast-json-patch.min.js @@ -2,10 +2,10 @@ var jsonpatch=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=2)}([function(e,t){ /*! * https://github.com/Starcounter-Jack/JSON-Patch - * (c) 2017 Joachim Wester - * MIT license + * (c) 2017-2022 Joachim Wester + * MIT licensed */ -var r,n=this&&this.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0});var o=Object.prototype.hasOwnProperty;function a(e,t){return o.call(e,t)}function i(e){if(Array.isArray(e)){for(var t=new Array(e.length),r=0;r=48&&t<=57))return!1;r++}return!0},t.escapePathComponent=p,t.unescapePathComponent=function(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")},t._getPathRecursive=u,t.getPath=function(e,t){if(e===t)return"/";var r=u(e,t);if(""===r)throw new Error("Object not found in root");return"/"+r},t.hasUndefined=function e(t){if(void 0===t)return!0;if(t)if(Array.isArray(t)){for(var r=0,n=t.length;r0&&"constructor"==d[y-1]))throw new TypeError("JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README");if(p&&void 0===_&&(void 0===v[O]?_=d.slice(0,y).join("/"):y==w-1&&(_=r.path),void 0!==_&&m(r,0,e,_)),y++,Array.isArray(v)){if("-"===O)O=v.length;else{if(p&&!n.isInteger(O))throw new t.JsonPatchError("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index","OPERATION_PATH_ILLEGAL_ARRAY_INDEX",h,r,e);n.isInteger(O)&&(O=~~O)}if(y>=w){if(p&&"add"===r.op&&O>v.length)throw new t.JsonPatchError("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",h,r,e);if(!1===(l=a[r.op].call(r,v,O,e)).test)throw new t.JsonPatchError("Test operation failed","TEST_OPERATION_FAILED",h,r,e);return l}}else if(y>=w){if(!1===(l=o[r.op].call(r,v,O,e)).test)throw new t.JsonPatchError("Test operation failed","TEST_OPERATION_FAILED",h,r,e);return l}if(v=v[O],p&&y0)throw new t.JsonPatchError('Operation `path` property must start with "/"',"OPERATION_PATH_INVALID",r,e,a);if(("move"===e.op||"copy"===e.op)&&"string"!=typeof e.from)throw new t.JsonPatchError("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",r,e,a);if(("add"===e.op||"replace"===e.op||"test"===e.op)&&void 0===e.value)throw new t.JsonPatchError("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",r,e,a);if(("add"===e.op||"replace"===e.op||"test"===e.op)&&n.hasUndefined(e.value))throw new t.JsonPatchError("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",r,e,a);if(a)if("add"==e.op){var p=e.path.split("/").length,u=i.split("/").length;if(p!==u+1&&p!==u)throw new t.JsonPatchError("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",r,e,a)}else if("replace"===e.op||"remove"===e.op||"_get"===e.op){if(e.path!==i)throw new t.JsonPatchError("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",r,e,a)}else if("move"===e.op||"copy"===e.op){var s=c([{op:"_get",path:e.from,value:void 0}],a);if(s&&"OPERATION_PATH_UNRESOLVABLE"===s.name)throw new t.JsonPatchError("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",r,e,a)}}function c(e,r,o){try{if(!Array.isArray(e))throw new t.JsonPatchError("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(r)u(n._deepClone(r),n._deepClone(e),o||!0);else{o=o||s;for(var a=0;a=48&&t<=57))return!1;r++}return!0},t.escapePathComponent=p,t.unescapePathComponent=function(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")},t._getPathRecursive=u,t.getPath=function(e,t){if(e===t)return"/";var r=u(e,t);if(""===r)throw new Error("Object not found in root");return"/"+r},t.hasUndefined=function e(t){if(void 0===t)return!0;if(t)if(Array.isArray(t)){for(var r=0,n=t.length;r0&&"constructor"==d[y-1]))throw new TypeError("JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README");if(p&&void 0===_&&(void 0===v[O]?_=d.slice(0,y).join("/"):y==w-1&&(_=r.path),void 0!==_&&m(r,0,e,_)),y++,Array.isArray(v)){if("-"===O)O=v.length;else{if(p&&!n.isInteger(O))throw new t.JsonPatchError("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index","OPERATION_PATH_ILLEGAL_ARRAY_INDEX",h,r,e);n.isInteger(O)&&(O=~~O)}if(y>=w){if(p&&"add"===r.op&&O>v.length)throw new t.JsonPatchError("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",h,r,e);if(!1===(l=a[r.op].call(r,v,O,e)).test)throw new t.JsonPatchError("Test operation failed","TEST_OPERATION_FAILED",h,r,e);return l}}else if(y>=w){if(!1===(l=o[r.op].call(r,v,O,e)).test)throw new t.JsonPatchError("Test operation failed","TEST_OPERATION_FAILED",h,r,e);return l}if(v=v[O],p&&y0)throw new t.JsonPatchError('Operation `path` property must start with "/"',"OPERATION_PATH_INVALID",r,e,a);if(("move"===e.op||"copy"===e.op)&&"string"!=typeof e.from)throw new t.JsonPatchError("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",r,e,a);if(("add"===e.op||"replace"===e.op||"test"===e.op)&&void 0===e.value)throw new t.JsonPatchError("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",r,e,a);if(("add"===e.op||"replace"===e.op||"test"===e.op)&&n.hasUndefined(e.value))throw new t.JsonPatchError("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",r,e,a);if(a)if("add"==e.op){var p=e.path.split("/").length,u=i.split("/").length;if(p!==u+1&&p!==u)throw new t.JsonPatchError("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",r,e,a)}else if("replace"===e.op||"remove"===e.op||"_get"===e.op){if(e.path!==i)throw new t.JsonPatchError("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",r,e,a)}else if("move"===e.op||"copy"===e.op){var s=c([{op:"_get",path:e.from,value:void 0}],a);if(s&&"OPERATION_PATH_UNRESOLVABLE"===s.name)throw new t.JsonPatchError("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",r,e,a)}}function c(e,r,o){try{if(!Array.isArray(e))throw new t.JsonPatchError("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(r)u(n._deepClone(r),n._deepClone(e),o||!0);else{o=o||s;for(var a=0;a= 48 && charCode <= 57) { @@ -77,8 +77,8 @@ export function unescapePathComponent(path: string): string { } export function _getPathRecursive(root: Object, obj: Object): string { - var found; - for (var key in root) { + let found; + for (let key in root) { if (hasOwnProperty(root, key)) { if (root[key] === obj) { return escapePathComponent(key) + '/'; @@ -98,11 +98,11 @@ export function getPath(root: Object, obj: Object): string { if (root === obj) { return '/'; } - var path = _getPathRecursive(root, obj); + const path = _getPathRecursive(root, obj); if (path === '') { throw new Error("Object not found in root"); } - return '/' + path; + return `/${path}`; } /** * Recursively checks whether an object has any undefined values inside. @@ -113,15 +113,15 @@ export function hasUndefined(obj: any): boolean { } if (obj) { if (Array.isArray(obj)) { - for (var i = 0, len = obj.length; i < len; i++) { + for (let i = 0, len = obj.length; i < len; i++) { if (hasUndefined(obj[i])) { return true; } } } else if (typeof obj === "object") { - var objKeys = _objectKeys(obj); - var objKeysLength = objKeys.length; + const objKeys = _objectKeys(obj); + const objKeysLength = objKeys.length; for (var i = 0; i < objKeysLength; i++) { if (hasUndefined(obj[objKeys[i]])) { return true; @@ -148,9 +148,9 @@ export type JsonPatchErrorName = 'SEQUENCE_NOT_AN_ARRAY' | function patchErrorMessageFormatter(message: String, args: Object): string { const messageParts = [message]; - for(const key in args) { + for (const key in args) { const value = typeof args[key] === 'object' ? JSON.stringify(args[key], null, 2) : args[key]; // pretty print - if(typeof value !== 'undefined') { + if (typeof value !== 'undefined') { messageParts.push(`${key}: ${value}`); } }