json-codemod
Advanced tools
| /** | ||
| * JsonMod - A chainable API for modifying JSON strings while preserving formatting | ||
| */ | ||
| export declare class JsonMod { | ||
| /** | ||
| * Creates a new JsonMod instance | ||
| * @param sourceText - The JSON string to modify | ||
| */ | ||
| constructor(sourceText: string); | ||
| /** | ||
| * Replace a value at the specified path | ||
| * @param path - The JSON path or array of path segments | ||
| * @param value - The new value as a JSON string | ||
| * @returns Returns this for chaining | ||
| * @example | ||
| * jsonmod(source).replace("user.name", '"Bob"').apply() | ||
| * jsonmod(source).replace(["user", "name"], '"Bob"').apply() | ||
| */ | ||
| replace(path: string | string[], value: string): JsonMod; | ||
| /** | ||
| * Delete a property or array element at the specified path | ||
| * @param path - The JSON path or array of path segments | ||
| * @returns Returns this for chaining | ||
| * @example | ||
| * jsonmod(source).delete("user.age").apply() | ||
| * jsonmod(source).remove(["user", "age"]).apply() | ||
| */ | ||
| delete(path: string | string[]): JsonMod; | ||
| /** | ||
| * Alias for delete() | ||
| * @param path - The JSON path or array of path segments | ||
| * @returns Returns this for chaining | ||
| */ | ||
| remove(path: string | string[]): JsonMod; | ||
| /** | ||
| * Insert a new property into an object or element into an array | ||
| * @param path - The JSON path pointing to the object/array | ||
| * @param keyOrPosition - For objects: property name; For arrays: index | ||
| * @param value - The value to insert as a JSON string | ||
| * @returns Returns this for chaining | ||
| * @example | ||
| * jsonmod(source).insert("user", "email", '"test@example.com"').apply() | ||
| * jsonmod(source).insert("items", 0, '"newItem"').apply() | ||
| */ | ||
| insert(path: string | string[], keyOrPosition: string | number, value: string): JsonMod; | ||
| /** | ||
| * Apply all queued operations and return the modified JSON string | ||
| * @returns The modified JSON string | ||
| */ | ||
| apply(): string; | ||
| } | ||
| /** | ||
| * Factory function to create a new JsonMod instance | ||
| * @param sourceText - The JSON string to modify | ||
| * @returns A new JsonMod instance | ||
| * @example | ||
| * jsonmod(source).replace("a", "10").delete("b").apply() | ||
| */ | ||
| export declare function jsonmod(sourceText: string): JsonMod; |
| /** | ||
| * Helper utility for formatting values to use in patches. | ||
| * This function makes it easier to create patch values without manually adding quotes. | ||
| */ | ||
| /** | ||
| * Formats a JavaScript value into a JSON string representation for use in patches. | ||
| * Handles all JavaScript types including strings, numbers, booleans, null, objects, and arrays. | ||
| * | ||
| * @param value - The value to format | ||
| * @returns A JSON string representation | ||
| * @example | ||
| * formatValue(42) // "42" | ||
| * formatValue("hello") // '"hello"' | ||
| * formatValue(true) // "true" | ||
| * formatValue(null) // "null" | ||
| * formatValue({a: 1}) // '{"a":1}' | ||
| * formatValue([1, 2, 3]) // '[1,2,3]' | ||
| */ | ||
| export declare function formatValue(value: any): string; |
| /** | ||
| * JsonMod - A chainable API for modifying JSON strings while preserving formatting | ||
| */ | ||
| export declare class JsonMod { | ||
| /** | ||
| * Creates a new JsonMod instance | ||
| * @param sourceText - The JSON string to modify | ||
| */ | ||
| constructor(sourceText: string); | ||
| /** | ||
| * Replace a value at the specified path | ||
| * @param path - The JSON path or array of path segments | ||
| * @param value - The new value as a JSON string | ||
| * @returns Returns this for chaining | ||
| * @example | ||
| * jsonmod(source).replace("user.name", '"Bob"').apply() | ||
| * jsonmod(source).replace(["user", "name"], '"Bob"').apply() | ||
| */ | ||
| replace(path: string | string[], value: string): JsonMod; | ||
| /** | ||
| * Delete a property or array element at the specified path | ||
| * @param path - The JSON path or array of path segments | ||
| * @returns Returns this for chaining | ||
| * @example | ||
| * jsonmod(source).delete("user.age").apply() | ||
| * jsonmod(source).remove(["user", "age"]).apply() | ||
| */ | ||
| delete(path: string | string[]): JsonMod; | ||
| /** | ||
| * Alias for delete() | ||
| * @param path - The JSON path or array of path segments | ||
| * @returns Returns this for chaining | ||
| */ | ||
| remove(path: string | string[]): JsonMod; | ||
| /** | ||
| * Insert a new property into an object or element into an array | ||
| * @param path - The JSON path pointing to the object/array | ||
| * @param keyOrPosition - For objects: property name; For arrays: index | ||
| * @param value - The value to insert as a JSON string | ||
| * @returns Returns this for chaining | ||
| * @example | ||
| * jsonmod(source).insert("user", "email", '"test@example.com"').apply() | ||
| * jsonmod(source).insert("items", 0, '"newItem"').apply() | ||
| */ | ||
| insert(path: string | string[], keyOrPosition: string | number, value: string): JsonMod; | ||
| /** | ||
| * Apply all queued operations and return the modified JSON string | ||
| * @returns The modified JSON string | ||
| */ | ||
| apply(): string; | ||
| } | ||
| /** | ||
| * Factory function to create a new JsonMod instance | ||
| * @param sourceText - The JSON string to modify | ||
| * @returns A new JsonMod instance | ||
| * @example | ||
| * jsonmod(source).replace("a", "10").delete("b").apply() | ||
| */ | ||
| export declare function jsonmod(sourceText: string): JsonMod; |
| /** | ||
| * Helper utility for formatting values to use in patches. | ||
| * This function makes it easier to create patch values without manually adding quotes. | ||
| */ | ||
| /** | ||
| * Formats a JavaScript value into a JSON string representation for use in patches. | ||
| * Handles all JavaScript types including strings, numbers, booleans, null, objects, and arrays. | ||
| * | ||
| * @param value - The value to format | ||
| * @returns A JSON string representation | ||
| * @example | ||
| * formatValue(42) // "42" | ||
| * formatValue("hello") // '"hello"' | ||
| * formatValue(true) // "true" | ||
| * formatValue(null) // "null" | ||
| * formatValue({a: 1}) // '{"a":1}' | ||
| * formatValue([1, 2, 3]) // '[1,2,3]' | ||
| */ | ||
| export declare function formatValue(value: any): string; |
+311
-323
@@ -29,18 +29,18 @@ "use strict"; | ||
| __webpack_require__.d(__webpack_exports__, { | ||
| jsonmod: function() { | ||
| return jsonmod; | ||
| }, | ||
| JsonMod: function() { | ||
| return JsonMod_JsonMod; | ||
| }, | ||
| default: function() { | ||
| return src; | ||
| }, | ||
| insert: function() { | ||
| return insert; | ||
| }, | ||
| batch: function() { | ||
| return batch; | ||
| }, | ||
| remove: function() { | ||
| return remove; | ||
| }, | ||
| replace: function() { | ||
| return replace; | ||
| formatValue: function() { | ||
| return formatValue; | ||
| } | ||
| }); | ||
| function formatValue(value) { | ||
| return JSON.stringify(value); | ||
| } | ||
| function _class_call_check(instance, Constructor) { | ||
@@ -537,325 +537,313 @@ if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); | ||
| } | ||
| function replace(sourceText, patches, root) { | ||
| if (!root) { | ||
| var tokenizer = new Tokenizer_Tokenizer(sourceText); | ||
| var tokens = tokenizer.tokenize(); | ||
| var builder = new CSTBuilder_CSTBuilder(tokens); | ||
| root = builder.build(); | ||
| } | ||
| var reverseNodes = patches.map(function(patch) { | ||
| var node = resolvePath(root, patch.path, sourceText); | ||
| return { | ||
| node: node, | ||
| patch: patch | ||
| }; | ||
| }).filter(function(v) { | ||
| return v.node; | ||
| }).sort(function(a, b) { | ||
| return b.node.start - a.node.start; | ||
| }); | ||
| reverseNodes.reduce(function(lastEnd, param) { | ||
| var node = param.node; | ||
| if (node.end > lastEnd) throw new Error("Patch conflict at path: ".concat(node.path)); | ||
| return node.start; | ||
| }, 1 / 0); | ||
| var result = sourceText; | ||
| var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; | ||
| try { | ||
| for(var _iterator = reverseNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ | ||
| var _step_value = _step.value, node = _step_value.node, patch = _step_value.patch; | ||
| result = result.slice(0, node.start) + patch.value + result.slice(node.end); | ||
| } | ||
| } catch (err) { | ||
| _didIteratorError = true; | ||
| _iteratorError = err; | ||
| } finally{ | ||
| try { | ||
| if (!_iteratorNormalCompletion && null != _iterator.return) _iterator.return(); | ||
| } finally{ | ||
| if (_didIteratorError) throw _iteratorError; | ||
| } | ||
| } | ||
| return result; | ||
| function JsonMod_class_call_check(instance, Constructor) { | ||
| if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); | ||
| } | ||
| function remove(sourceText, patches, root) { | ||
| if (!root) { | ||
| var tokenizer = new Tokenizer_Tokenizer(sourceText); | ||
| var tokens = tokenizer.tokenize(); | ||
| var builder = new CSTBuilder_CSTBuilder(tokens); | ||
| root = builder.build(); | ||
| function JsonMod_defineProperties(target, props) { | ||
| for(var i = 0; i < props.length; i++){ | ||
| var descriptor = props[i]; | ||
| descriptor.enumerable = descriptor.enumerable || false; | ||
| descriptor.configurable = true; | ||
| if ("value" in descriptor) descriptor.writable = true; | ||
| Object.defineProperty(target, descriptor.key, descriptor); | ||
| } | ||
| var reverseNodes = patches.map(function(patch) { | ||
| var pathParts = parsePath(patch.path); | ||
| if (0 === pathParts.length) return null; | ||
| var parentPath = pathParts.slice(0, -1); | ||
| var lastKey = pathParts[pathParts.length - 1]; | ||
| var parentNode = parentPath.length > 0 ? resolvePath(root, parentPath, sourceText) : root; | ||
| if (!parentNode) return null; | ||
| return { | ||
| parentNode: parentNode, | ||
| lastKey: lastKey, | ||
| patch: patch | ||
| }; | ||
| }).filter(function(v) { | ||
| return null !== v; | ||
| }).sort(function(a, b) { | ||
| var aStart = getDeleteStart(a.parentNode, a.lastKey, sourceText); | ||
| var bStart = getDeleteStart(b.parentNode, b.lastKey, sourceText); | ||
| return bStart - aStart; | ||
| }); | ||
| var result = sourceText; | ||
| var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; | ||
| try { | ||
| for(var _iterator = reverseNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ | ||
| var _step_value = _step.value, parentNode = _step_value.parentNode, lastKey = _step_value.lastKey; | ||
| result = deleteFromParent(result, parentNode, lastKey, sourceText); | ||
| } | ||
| } catch (err) { | ||
| _didIteratorError = true; | ||
| _iteratorError = err; | ||
| } finally{ | ||
| try { | ||
| if (!_iteratorNormalCompletion && null != _iterator.return) _iterator.return(); | ||
| } finally{ | ||
| if (_didIteratorError) throw _iteratorError; | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| function getDeleteStart(parentNode, key, sourceText) { | ||
| if ("Object" === parentNode.type) { | ||
| var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; | ||
| try { | ||
| for(var _iterator = parentNode.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ | ||
| var prop = _step.value; | ||
| var keyStr = extractString(prop.key, sourceText); | ||
| if (keyStr === key) return prop.key.start; | ||
| } | ||
| } catch (err) { | ||
| _didIteratorError = true; | ||
| _iteratorError = err; | ||
| } finally{ | ||
| try { | ||
| if (!_iteratorNormalCompletion && null != _iterator.return) _iterator.return(); | ||
| } finally{ | ||
| if (_didIteratorError) throw _iteratorError; | ||
| } | ||
| } | ||
| } else if ("Array" === parentNode.type) { | ||
| if ("number" == typeof key && key >= 0 && key < parentNode.elements.length) return parentNode.elements[key].start; | ||
| } | ||
| return 0; | ||
| function JsonMod_create_class(Constructor, protoProps, staticProps) { | ||
| if (protoProps) JsonMod_defineProperties(Constructor.prototype, protoProps); | ||
| if (staticProps) JsonMod_defineProperties(Constructor, staticProps); | ||
| return Constructor; | ||
| } | ||
| function deleteObjectProperty(sourceText, objectNode, key, originalSource) { | ||
| var propIndex = -1; | ||
| for(var i = 0; i < objectNode.properties.length; i++){ | ||
| var keyStr = extractString(objectNode.properties[i].key, originalSource); | ||
| if (keyStr === key) { | ||
| propIndex = i; | ||
| break; | ||
| } | ||
| var JsonMod_JsonMod = /*#__PURE__*/ function() { | ||
| "use strict"; | ||
| function JsonMod(sourceText) { | ||
| JsonMod_class_call_check(this, JsonMod); | ||
| this.sourceText = sourceText; | ||
| this.operations = []; | ||
| } | ||
| if (-1 === propIndex) return sourceText; | ||
| var prop = objectNode.properties[propIndex]; | ||
| var deleteStart = prop.key.start; | ||
| var deleteEnd = prop.value.end; | ||
| if (propIndex < objectNode.properties.length - 1) { | ||
| var pos = deleteEnd; | ||
| while(pos < sourceText.length && (" " === sourceText[pos] || "\t" === sourceText[pos] || "\n" === sourceText[pos] || "\r" === sourceText[pos]))pos++; | ||
| if ("," === sourceText[pos]) { | ||
| deleteEnd = pos + 1; | ||
| while(deleteEnd < sourceText.length && (" " === sourceText[deleteEnd] || "\t" === sourceText[deleteEnd] || "\n" === sourceText[deleteEnd] || "\r" === sourceText[deleteEnd]))deleteEnd++; | ||
| } | ||
| } else if (propIndex > 0) { | ||
| var pos1 = deleteStart - 1; | ||
| while(pos1 >= 0 && (" " === sourceText[pos1] || "\t" === sourceText[pos1] || "\n" === sourceText[pos1] || "\r" === sourceText[pos1]))pos1--; | ||
| if ("," === sourceText[pos1]) { | ||
| pos1--; | ||
| while(pos1 >= 0 && (" " === sourceText[pos1] || "\t" === sourceText[pos1] || "\n" === sourceText[pos1] || "\r" === sourceText[pos1]))pos1--; | ||
| deleteStart = pos1 + 1; | ||
| } | ||
| } | ||
| return sourceText.slice(0, deleteStart) + sourceText.slice(deleteEnd); | ||
| } | ||
| function deleteArrayElement(sourceText, arrayNode, index, originalSource) { | ||
| if ("number" != typeof index || index < 0 || index >= arrayNode.elements.length) return sourceText; | ||
| var element = arrayNode.elements[index]; | ||
| var deleteStart = element.start; | ||
| var deleteEnd = element.end; | ||
| if (index < arrayNode.elements.length - 1) { | ||
| var pos = deleteEnd; | ||
| while(pos < sourceText.length && (" " === sourceText[pos] || "\t" === sourceText[pos] || "\n" === sourceText[pos] || "\r" === sourceText[pos]))pos++; | ||
| if ("," === sourceText[pos]) { | ||
| deleteEnd = pos + 1; | ||
| while(deleteEnd < sourceText.length && (" " === sourceText[deleteEnd] || "\t" === sourceText[deleteEnd] || "\n" === sourceText[deleteEnd] || "\r" === sourceText[deleteEnd]))deleteEnd++; | ||
| } | ||
| } else if (index > 0) { | ||
| var pos1 = deleteStart - 1; | ||
| while(pos1 >= 0 && (" " === sourceText[pos1] || "\t" === sourceText[pos1] || "\n" === sourceText[pos1] || "\r" === sourceText[pos1]))pos1--; | ||
| if ("," === sourceText[pos1]) { | ||
| pos1--; | ||
| while(pos1 >= 0 && (" " === sourceText[pos1] || "\t" === sourceText[pos1] || "\n" === sourceText[pos1] || "\r" === sourceText[pos1]))pos1--; | ||
| deleteStart = pos1 + 1; | ||
| } | ||
| } | ||
| return sourceText.slice(0, deleteStart) + sourceText.slice(deleteEnd); | ||
| } | ||
| function deleteFromParent(sourceText, parentNode, key, originalSource) { | ||
| if ("Object" === parentNode.type) return deleteObjectProperty(sourceText, parentNode, key, originalSource); | ||
| if ("Array" === parentNode.type) return deleteArrayElement(sourceText, parentNode, key, originalSource); | ||
| return sourceText; | ||
| } | ||
| function insert(sourceText, patches, root) { | ||
| if (!root) { | ||
| var tokenizer = new Tokenizer_Tokenizer(sourceText); | ||
| var tokens = tokenizer.tokenize(); | ||
| var builder = new CSTBuilder_CSTBuilder(tokens); | ||
| root = builder.build(); | ||
| } | ||
| var reverseNodes = patches.map(function(patch) { | ||
| var node = resolvePath(root, patch.path, sourceText); | ||
| return { | ||
| node: node, | ||
| patch: patch | ||
| }; | ||
| }).filter(function(v) { | ||
| return v.node; | ||
| }).sort(function(a, b) { | ||
| return b.node.start - a.node.start; | ||
| }); | ||
| var result = sourceText; | ||
| var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; | ||
| try { | ||
| for(var _iterator = reverseNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ | ||
| var _step_value = _step.value, node = _step_value.node, patch = _step_value.patch; | ||
| result = insertIntoNode(result, node, patch, sourceText); | ||
| } | ||
| } catch (err) { | ||
| _didIteratorError = true; | ||
| _iteratorError = err; | ||
| } finally{ | ||
| try { | ||
| if (!_iteratorNormalCompletion && null != _iterator.return) _iterator.return(); | ||
| } finally{ | ||
| if (_didIteratorError) throw _iteratorError; | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| function insertIntoNode(sourceText, node, patch, originalSource) { | ||
| if ("Object" === node.type) return insertObjectProperty(sourceText, node, patch, originalSource); | ||
| if ("Array" === node.type) return insertArrayElement(sourceText, node, patch, originalSource); | ||
| return sourceText; | ||
| } | ||
| function insertObjectProperty(sourceText, objectNode, patch, originalSource) { | ||
| if (!patch.key) throw new Error("Insert into object requires 'key' property"); | ||
| var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; | ||
| try { | ||
| for(var _iterator = objectNode.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ | ||
| var prop = _step.value; | ||
| var keyStr = extractString(prop.key, originalSource); | ||
| if (keyStr === patch.key) throw new Error('Key "'.concat(patch.key, '" already exists in object')); | ||
| } | ||
| } catch (err) { | ||
| _didIteratorError = true; | ||
| _iteratorError = err; | ||
| } finally{ | ||
| try { | ||
| if (!_iteratorNormalCompletion && null != _iterator.return) _iterator.return(); | ||
| } finally{ | ||
| if (_didIteratorError) throw _iteratorError; | ||
| } | ||
| } | ||
| var newEntry = '"'.concat(patch.key, '": ').concat(patch.value); | ||
| if (0 === objectNode.properties.length) { | ||
| var insertPos = objectNode.start + 1; | ||
| return sourceText.slice(0, insertPos) + newEntry + sourceText.slice(insertPos); | ||
| } | ||
| var lastProp = objectNode.properties[objectNode.properties.length - 1]; | ||
| var insertPos1 = lastProp.value.end; | ||
| return sourceText.slice(0, insertPos1) + ", " + newEntry + sourceText.slice(insertPos1); | ||
| } | ||
| function insertArrayElement(sourceText, arrayNode, patch, originalSource) { | ||
| var position = void 0 !== patch.position ? patch.position : arrayNode.elements.length; | ||
| if (position < 0 || position > arrayNode.elements.length) throw new Error("Invalid position ".concat(position, " for array of length ").concat(arrayNode.elements.length)); | ||
| if (0 === arrayNode.elements.length) { | ||
| var insertPos = arrayNode.start + 1; | ||
| return sourceText.slice(0, insertPos) + patch.value + sourceText.slice(insertPos); | ||
| } | ||
| if (0 === position) { | ||
| var insertPos1 = arrayNode.elements[0].start; | ||
| return sourceText.slice(0, insertPos1) + patch.value + ", " + sourceText.slice(insertPos1); | ||
| } | ||
| if (position >= arrayNode.elements.length) { | ||
| var lastElement = arrayNode.elements[arrayNode.elements.length - 1]; | ||
| var insertPos2 = lastElement.end; | ||
| return sourceText.slice(0, insertPos2) + ", " + patch.value + sourceText.slice(insertPos2); | ||
| } | ||
| var insertPos3 = arrayNode.elements[position].start; | ||
| return sourceText.slice(0, insertPos3) + patch.value + ", " + sourceText.slice(insertPos3); | ||
| } | ||
| function batch(sourceText, patches) { | ||
| var tokenizer = new Tokenizer_Tokenizer(sourceText); | ||
| var tokens = tokenizer.tokenize(); | ||
| var builder = new CSTBuilder_CSTBuilder(tokens); | ||
| var root = builder.build(); | ||
| var replacePatches = []; | ||
| var deletePatches = []; | ||
| var insertPatches = []; | ||
| var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; | ||
| try { | ||
| for(var _iterator = patches[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ | ||
| var p = _step.value; | ||
| if (void 0 !== p.value && void 0 === p.key && void 0 === p.position) replacePatches.push({ | ||
| path: p.path, | ||
| value: p.value | ||
| }); | ||
| else if (void 0 === p.value && void 0 === p.key && void 0 === p.position) deletePatches.push({ | ||
| path: p.path | ||
| }); | ||
| else { | ||
| if (void 0 === p.key && void 0 === p.position || void 0 === p.value) continue; | ||
| insertPatches.push(p); | ||
| JsonMod_create_class(JsonMod, [ | ||
| { | ||
| key: "replace", | ||
| value: function(path, value) { | ||
| this.operations.push({ | ||
| type: "replace", | ||
| path: Array.isArray(path) ? path : path, | ||
| value: value | ||
| }); | ||
| return this; | ||
| } | ||
| }, | ||
| { | ||
| key: "delete", | ||
| value: function(path) { | ||
| this.operations.push({ | ||
| type: "delete", | ||
| path: Array.isArray(path) ? path : path | ||
| }); | ||
| return this; | ||
| } | ||
| }, | ||
| { | ||
| key: "remove", | ||
| value: function(path) { | ||
| return this.delete(path); | ||
| } | ||
| }, | ||
| { | ||
| key: "insert", | ||
| value: function(path, keyOrPosition, value) { | ||
| this.operations.push({ | ||
| type: "insert", | ||
| path: Array.isArray(path) ? path : path, | ||
| keyOrPosition: keyOrPosition, | ||
| value: value | ||
| }); | ||
| return this; | ||
| } | ||
| }, | ||
| { | ||
| key: "apply", | ||
| value: function() { | ||
| if (0 === this.operations.length) return this.sourceText; | ||
| var result = this.sourceText; | ||
| var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; | ||
| try { | ||
| for(var _iterator = this.operations[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ | ||
| var op = _step.value; | ||
| switch(op.type){ | ||
| case "replace": | ||
| result = this._applySingleReplace(result, op); | ||
| break; | ||
| case "delete": | ||
| result = this._applySingleDelete(result, op); | ||
| break; | ||
| case "insert": | ||
| result = this._applySingleInsert(result, op); | ||
| break; | ||
| } | ||
| } | ||
| } catch (err) { | ||
| _didIteratorError = true; | ||
| _iteratorError = err; | ||
| } finally{ | ||
| try { | ||
| if (!_iteratorNormalCompletion && null != _iterator.return) _iterator.return(); | ||
| } finally{ | ||
| if (_didIteratorError) throw _iteratorError; | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| }, | ||
| { | ||
| key: "_applySingleReplace", | ||
| value: function(sourceText, op) { | ||
| var tokenizer = new Tokenizer_Tokenizer(sourceText); | ||
| var tokens = tokenizer.tokenize(); | ||
| var builder = new CSTBuilder_CSTBuilder(tokens); | ||
| var root = builder.build(); | ||
| var node = resolvePath(root, op.path, sourceText); | ||
| if (!node) return sourceText; | ||
| return sourceText.slice(0, node.start) + op.value + sourceText.slice(node.end); | ||
| } | ||
| }, | ||
| { | ||
| key: "_applySingleDelete", | ||
| value: function(sourceText, op) { | ||
| var tokenizer = new Tokenizer_Tokenizer(sourceText); | ||
| var tokens = tokenizer.tokenize(); | ||
| var builder = new CSTBuilder_CSTBuilder(tokens); | ||
| var root = builder.build(); | ||
| var pathParts = parsePath(op.path); | ||
| if (0 === pathParts.length) return sourceText; | ||
| var parentPath = pathParts.slice(0, -1); | ||
| var lastKey = pathParts[pathParts.length - 1]; | ||
| var parentNode = parentPath.length > 0 ? resolvePath(root, parentPath, sourceText) : root; | ||
| if (!parentNode) return sourceText; | ||
| return this._deleteFromParent(sourceText, parentNode, lastKey, sourceText); | ||
| } | ||
| }, | ||
| { | ||
| key: "_applySingleInsert", | ||
| value: function(sourceText, op) { | ||
| var tokenizer = new Tokenizer_Tokenizer(sourceText); | ||
| var tokens = tokenizer.tokenize(); | ||
| var builder = new CSTBuilder_CSTBuilder(tokens); | ||
| var root = builder.build(); | ||
| var node = resolvePath(root, op.path, sourceText); | ||
| if (!node) return sourceText; | ||
| return this._insertIntoNode(sourceText, node, op, sourceText); | ||
| } | ||
| }, | ||
| { | ||
| key: "_getDeleteStart", | ||
| value: function(parentNode, key, sourceText) { | ||
| if ("Object" === parentNode.type) { | ||
| var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; | ||
| try { | ||
| for(var _iterator = parentNode.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ | ||
| var prop = _step.value; | ||
| var keyStr = extractString(prop.key, sourceText); | ||
| if (keyStr === key) return prop.key.start; | ||
| } | ||
| } catch (err) { | ||
| _didIteratorError = true; | ||
| _iteratorError = err; | ||
| } finally{ | ||
| try { | ||
| if (!_iteratorNormalCompletion && null != _iterator.return) _iterator.return(); | ||
| } finally{ | ||
| if (_didIteratorError) throw _iteratorError; | ||
| } | ||
| } | ||
| } else if ("Array" === parentNode.type) { | ||
| if ("number" == typeof key && key >= 0 && key < parentNode.elements.length) return parentNode.elements[key].start; | ||
| } | ||
| return 0; | ||
| } | ||
| }, | ||
| { | ||
| key: "_deleteFromParent", | ||
| value: function(sourceText, parentNode, key, originalSource) { | ||
| if ("Object" === parentNode.type) return this._deleteObjectProperty(sourceText, parentNode, key, originalSource); | ||
| if ("Array" === parentNode.type) return this._deleteArrayElement(sourceText, parentNode, key, originalSource); | ||
| return sourceText; | ||
| } | ||
| }, | ||
| { | ||
| key: "_deleteObjectProperty", | ||
| value: function(sourceText, objectNode, key, originalSource) { | ||
| var propIndex = -1; | ||
| for(var i = 0; i < objectNode.properties.length; i++){ | ||
| var keyStr = extractString(objectNode.properties[i].key, originalSource); | ||
| if (keyStr === key) { | ||
| propIndex = i; | ||
| break; | ||
| } | ||
| } | ||
| if (-1 === propIndex) return sourceText; | ||
| var prop = objectNode.properties[propIndex]; | ||
| var deleteStart = prop.key.start; | ||
| var deleteEnd = prop.value.end; | ||
| if (propIndex < objectNode.properties.length - 1) { | ||
| var pos = deleteEnd; | ||
| while(pos < sourceText.length && (" " === sourceText[pos] || "\t" === sourceText[pos] || "\n" === sourceText[pos] || "\r" === sourceText[pos]))pos++; | ||
| if ("," === sourceText[pos]) { | ||
| deleteEnd = pos + 1; | ||
| while(deleteEnd < sourceText.length && (" " === sourceText[deleteEnd] || "\t" === sourceText[deleteEnd] || "\n" === sourceText[deleteEnd] || "\r" === sourceText[deleteEnd]))deleteEnd++; | ||
| } | ||
| } else if (propIndex > 0) { | ||
| var pos1 = deleteStart - 1; | ||
| while(pos1 >= 0 && (" " === sourceText[pos1] || "\t" === sourceText[pos1] || "\n" === sourceText[pos1] || "\r" === sourceText[pos1]))pos1--; | ||
| if ("," === sourceText[pos1]) { | ||
| pos1--; | ||
| while(pos1 >= 0 && (" " === sourceText[pos1] || "\t" === sourceText[pos1] || "\n" === sourceText[pos1] || "\r" === sourceText[pos1]))pos1--; | ||
| deleteStart = pos1 + 1; | ||
| } | ||
| } | ||
| return sourceText.slice(0, deleteStart) + sourceText.slice(deleteEnd); | ||
| } | ||
| }, | ||
| { | ||
| key: "_deleteArrayElement", | ||
| value: function(sourceText, arrayNode, index, originalSource) { | ||
| if ("number" != typeof index || index < 0 || index >= arrayNode.elements.length) return sourceText; | ||
| var element = arrayNode.elements[index]; | ||
| var deleteStart = element.start; | ||
| var deleteEnd = element.end; | ||
| if (index < arrayNode.elements.length - 1) { | ||
| var pos = deleteEnd; | ||
| while(pos < sourceText.length && (" " === sourceText[pos] || "\t" === sourceText[pos] || "\n" === sourceText[pos] || "\r" === sourceText[pos]))pos++; | ||
| if ("," === sourceText[pos]) { | ||
| deleteEnd = pos + 1; | ||
| while(deleteEnd < sourceText.length && (" " === sourceText[deleteEnd] || "\t" === sourceText[deleteEnd] || "\n" === sourceText[deleteEnd] || "\r" === sourceText[deleteEnd]))deleteEnd++; | ||
| } | ||
| } else if (index > 0) { | ||
| var pos1 = deleteStart - 1; | ||
| while(pos1 >= 0 && (" " === sourceText[pos1] || "\t" === sourceText[pos1] || "\n" === sourceText[pos1] || "\r" === sourceText[pos1]))pos1--; | ||
| if ("," === sourceText[pos1]) { | ||
| pos1--; | ||
| while(pos1 >= 0 && (" " === sourceText[pos1] || "\t" === sourceText[pos1] || "\n" === sourceText[pos1] || "\r" === sourceText[pos1]))pos1--; | ||
| deleteStart = pos1 + 1; | ||
| } | ||
| } | ||
| return sourceText.slice(0, deleteStart) + sourceText.slice(deleteEnd); | ||
| } | ||
| }, | ||
| { | ||
| key: "_insertIntoNode", | ||
| value: function(sourceText, node, patch, originalSource) { | ||
| if ("Object" === node.type) return this._insertObjectProperty(sourceText, node, patch, originalSource); | ||
| if ("Array" === node.type) return this._insertArrayElement(sourceText, node, patch, originalSource); | ||
| return sourceText; | ||
| } | ||
| }, | ||
| { | ||
| key: "_insertObjectProperty", | ||
| value: function(sourceText, objectNode, patch, originalSource) { | ||
| var key = patch.keyOrPosition; | ||
| if ("string" != typeof key) throw new Error("Insert into object requires a string key"); | ||
| var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; | ||
| try { | ||
| for(var _iterator = objectNode.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ | ||
| var prop = _step.value; | ||
| var keyStr = extractString(prop.key, originalSource); | ||
| if (keyStr === key) throw new Error('Key "'.concat(key, '" already exists in object')); | ||
| } | ||
| } catch (err) { | ||
| _didIteratorError = true; | ||
| _iteratorError = err; | ||
| } finally{ | ||
| try { | ||
| if (!_iteratorNormalCompletion && null != _iterator.return) _iterator.return(); | ||
| } finally{ | ||
| if (_didIteratorError) throw _iteratorError; | ||
| } | ||
| } | ||
| var newEntry = '"'.concat(key, '": ').concat(patch.value); | ||
| if (0 === objectNode.properties.length) { | ||
| var insertPos = objectNode.start + 1; | ||
| return sourceText.slice(0, insertPos) + newEntry + sourceText.slice(insertPos); | ||
| } | ||
| var lastProp = objectNode.properties[objectNode.properties.length - 1]; | ||
| var insertPos1 = lastProp.value.end; | ||
| return sourceText.slice(0, insertPos1) + ", " + newEntry + sourceText.slice(insertPos1); | ||
| } | ||
| }, | ||
| { | ||
| key: "_insertArrayElement", | ||
| value: function(sourceText, arrayNode, patch, originalSource) { | ||
| var position = "number" == typeof patch.keyOrPosition ? patch.keyOrPosition : arrayNode.elements.length; | ||
| if (position < 0 || position > arrayNode.elements.length) throw new Error("Invalid position ".concat(position, " for array of length ").concat(arrayNode.elements.length)); | ||
| if (0 === arrayNode.elements.length) { | ||
| var insertPos = arrayNode.start + 1; | ||
| return sourceText.slice(0, insertPos) + patch.value + sourceText.slice(insertPos); | ||
| } | ||
| if (0 === position) { | ||
| var insertPos1 = arrayNode.elements[0].start; | ||
| return sourceText.slice(0, insertPos1) + patch.value + ", " + sourceText.slice(insertPos1); | ||
| } | ||
| if (position >= arrayNode.elements.length) { | ||
| var lastElement = arrayNode.elements[arrayNode.elements.length - 1]; | ||
| var insertPos2 = lastElement.end; | ||
| return sourceText.slice(0, insertPos2) + ", " + patch.value + sourceText.slice(insertPos2); | ||
| } | ||
| var insertPos3 = arrayNode.elements[position].start; | ||
| return sourceText.slice(0, insertPos3) + patch.value + ", " + sourceText.slice(insertPos3); | ||
| } | ||
| } | ||
| } catch (err) { | ||
| _didIteratorError = true; | ||
| _iteratorError = err; | ||
| } finally{ | ||
| try { | ||
| if (!_iteratorNormalCompletion && null != _iterator.return) _iterator.return(); | ||
| } finally{ | ||
| if (_didIteratorError) throw _iteratorError; | ||
| } | ||
| } | ||
| var result = sourceText; | ||
| if (replacePatches.length > 0) result = replace(result, replacePatches, root); | ||
| if (insertPatches.length > 0) { | ||
| var currentRoot = replacePatches.length > 0 ? null : root; | ||
| result = insert(result, insertPatches, currentRoot); | ||
| } | ||
| if (deletePatches.length > 0) { | ||
| var currentRoot1 = replacePatches.length > 0 || insertPatches.length > 0 ? null : root; | ||
| result = remove(result, deletePatches, currentRoot1); | ||
| } | ||
| return result; | ||
| ]); | ||
| return JsonMod; | ||
| }(); | ||
| function jsonmod(sourceText) { | ||
| return new JsonMod_JsonMod(sourceText); | ||
| } | ||
| var jsoncst = { | ||
| replace: replace, | ||
| remove: remove, | ||
| insert: insert, | ||
| batch: batch | ||
| }; | ||
| var src = jsoncst; | ||
| exports.batch = __webpack_exports__.batch; | ||
| var src = jsonmod; | ||
| exports.JsonMod = __webpack_exports__.JsonMod; | ||
| exports["default"] = __webpack_exports__["default"]; | ||
| exports.insert = __webpack_exports__.insert; | ||
| exports.remove = __webpack_exports__.remove; | ||
| exports.replace = __webpack_exports__.replace; | ||
| exports.formatValue = __webpack_exports__.formatValue; | ||
| exports.jsonmod = __webpack_exports__.jsonmod; | ||
| for(var __webpack_i__ in __webpack_exports__)if (-1 === [ | ||
| "batch", | ||
| "JsonMod", | ||
| "default", | ||
| "insert", | ||
| "remove", | ||
| "replace" | ||
| "formatValue", | ||
| "jsonmod" | ||
| ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__]; | ||
@@ -862,0 +850,0 @@ Object.defineProperty(exports, '__esModule', { |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"cjs/index.cjs","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../src/Tokenizer.js","../../src/CSTBuilder.js","../../src/helper.js","../../src/PathResolver.js","../../src/function/replace.js","../../src/function/delete.js","../../src/function/insert.js","../../src/function/batch.js","../../src/index.js"],"sourcesContent":["__webpack_require__.d = function(exports, definition) {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }","// define __esModule on exports\n__webpack_require__.r = function(exports) {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","class Tokenizer {\n\tconstructor(text) {\n\t\tthis.text = text;\n\t\tthis.pos = 0;\n\t\tthis.tokens = [];\n\t}\n\n\ttokenize() {\n\t\twhile (this.pos < this.text.length) {\n\t\t\tconst ch = this.text[this.pos];\n\n\t\t\tif (this.isWhitespace(ch)) {\n\t\t\t\tthis.readWhitespace();\n\t\t\t} else if (ch === '\"') {\n\t\t\t\tthis.readString();\n\t\t\t} else if (this.isNumberStart(ch)) {\n\t\t\t\tthis.readNumber();\n\t\t\t} else if (this.isAlpha(ch)) {\n\t\t\t\tthis.readKeyword();\n\t\t\t} else {\n\t\t\t\tthis.readPunctuationOrComment();\n\t\t\t}\n\t\t}\n\n\t\treturn this.tokens;\n\t}\n\n\t// ---------- helpers ----------\n\n\tisWhitespace(ch) {\n\t\treturn ch === \" \" || ch === \"\\n\" || ch === \"\\r\" || ch === \"\\t\";\n\t}\n\n\tisNumberStart(ch) {\n\t\treturn ch === \"-\" || (ch >= \"0\" && ch <= \"9\");\n\t}\n\n\tisAlpha(ch) {\n\t\treturn (ch >= \"a\" && ch <= \"z\") || (ch >= \"A\" && ch <= \"Z\");\n\t}\n\n\t// ---------- readers ----------\n\n\treadWhitespace() {\n\t\tconst start = this.pos;\n\t\twhile (this.pos < this.text.length && this.isWhitespace(this.text[this.pos])) {\n\t\t\tthis.pos++;\n\t\t}\n\t\tthis.tokens.push({\n\t\t\ttype: \"whitespace\",\n\t\t\tstart,\n\t\t\tend: this.pos,\n\t\t});\n\t}\n\n\treadString() {\n\t\tconst start = this.pos;\n\t\tthis.pos++; // skip opening \"\n\n\t\twhile (this.pos < this.text.length) {\n\t\t\tconst ch = this.text[this.pos];\n\n\t\t\tif (ch === \"\\\\\") {\n\t\t\t\t// skip escaped char\n\t\t\t\tthis.pos += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (ch === '\"') {\n\t\t\t\tthis.pos++; // closing \"\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tthis.pos++;\n\t\t}\n\n\t\tthis.tokens.push({\n\t\t\ttype: \"string\",\n\t\t\tstart,\n\t\t\tend: this.pos,\n\t\t});\n\t}\n\n\treadNumber() {\n\t\tconst start = this.pos;\n\n\t\tif (this.text[this.pos] === \"-\") this.pos++;\n\n\t\twhile (this.pos < this.text.length && this.isDigit(this.text[this.pos])) {\n\t\t\tthis.pos++;\n\t\t}\n\n\t\tif (this.text[this.pos] === \".\") {\n\t\t\tthis.pos++;\n\t\t\twhile (this.pos < this.text.length && this.isDigit(this.text[this.pos])) {\n\t\t\t\tthis.pos++;\n\t\t\t}\n\t\t}\n\n\t\tif (this.text[this.pos] === \"e\" || this.text[this.pos] === \"E\") {\n\t\t\tthis.pos++;\n\t\t\tif (this.text[this.pos] === \"+\" || this.text[this.pos] === \"-\") {\n\t\t\t\tthis.pos++;\n\t\t\t}\n\t\t\twhile (this.pos < this.text.length && this.isDigit(this.text[this.pos])) {\n\t\t\t\tthis.pos++;\n\t\t\t}\n\t\t}\n\n\t\tthis.tokens.push({\n\t\t\ttype: \"number\",\n\t\t\tstart,\n\t\t\tend: this.pos,\n\t\t});\n\t}\n\n\treadKeyword() {\n\t\tconst start = this.pos;\n\n\t\twhile (this.pos < this.text.length && this.isAlpha(this.text[this.pos])) {\n\t\t\tthis.pos++;\n\t\t}\n\n\t\tconst word = this.text.slice(start, this.pos);\n\n\t\tlet type;\n\t\tif (word === \"true\" || word === \"false\") {\n\t\t\ttype = \"boolean\";\n\t\t} else if (word === \"null\") {\n\t\t\ttype = \"null\";\n\t\t} else {\n\t\t\tthrow new Error(`Unexpected identifier: ${word}`);\n\t\t}\n\n\t\tthis.tokens.push({\n\t\t\ttype,\n\t\t\tstart,\n\t\t\tend: this.pos,\n\t\t});\n\t}\n\n\treadPunctuationOrComment() {\n\t\tconst start = this.pos;\n\t\tconst ch = this.text[this.pos];\n\n\t\t// line comment //\n\t\tif (ch === \"/\" && this.text[this.pos + 1] === \"/\") {\n\t\t\tthis.pos += 2;\n\t\t\twhile (this.pos < this.text.length && this.text[this.pos] !== \"\\n\") {\n\t\t\t\tthis.pos++;\n\t\t\t}\n\t\t\tthis.tokens.push({\n\t\t\t\ttype: \"comment\",\n\t\t\t\tstart,\n\t\t\t\tend: this.pos,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\t// block comment /* */\n\t\tif (ch === \"/\" && this.text[this.pos + 1] === \"*\") {\n\t\t\tthis.pos += 2;\n\t\t\twhile (this.pos < this.text.length && !(this.text[this.pos] === \"*\" && this.text[this.pos + 1] === \"/\")) {\n\t\t\t\tthis.pos++;\n\t\t\t}\n\t\t\tthis.pos += 2; // skip */\n\t\t\tthis.tokens.push({\n\t\t\t\ttype: \"comment\",\n\t\t\t\tstart,\n\t\t\t\tend: this.pos,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\t// punctuation\n\t\tthis.pos++;\n\n\t\tconst map = {\n\t\t\t\"{\": \"braceL\",\n\t\t\t\"}\": \"braceR\",\n\t\t\t\"[\": \"bracketL\",\n\t\t\t\"]\": \"bracketR\",\n\t\t\t\":\": \"colon\",\n\t\t\t\",\": \"comma\",\n\t\t};\n\n\t\tconst type = map[ch];\n\t\tif (!type) {\n\t\t\tthrow new Error(`Unexpected character: ${ch} at ${start}`);\n\t\t}\n\n\t\tthis.tokens.push({\n\t\t\ttype,\n\t\t\tstart,\n\t\t\tend: this.pos,\n\t\t});\n\t}\n\n\tisDigit(ch) {\n\t\treturn ch >= \"0\" && ch <= \"9\";\n\t}\n}\n\nexport { Tokenizer };\n","export class CSTBuilder {\n\tconstructor(tokens) {\n\t\tthis.tokens = tokens;\n\t\tthis.pos = 0;\n\t}\n\n\tbuild() {\n\t\tthis.skipTrivia();\n\t\tconst node = this.parseValue();\n\t\tthis.skipTrivia();\n\t\treturn node;\n\t}\n\n\tcurrent() {\n\t\treturn this.tokens[this.pos];\n\t}\n\n\tskipTrivia() {\n\t\twhile (this.pos < this.tokens.length && (this.tokens[this.pos].type === \"whitespace\" || this.tokens[this.pos].type === \"comment\")) {\n\t\t\tthis.pos++;\n\t\t}\n\t}\n\n\tconsume(type) {\n\t\tconst token = this.current();\n\t\tif (!token || token.type !== type) {\n\t\t\tthrow new Error(`Expected ${type}, got ${token && token.type}`);\n\t\t}\n\t\tthis.pos++;\n\t\treturn token;\n\t}\n\n\tparseValue() {\n\t\tthis.skipTrivia();\n\t\tconst token = this.current();\n\n\t\tif (!token) {\n\t\t\tthrow new Error(\"Unexpected end of input\");\n\t\t}\n\n\t\tswitch (token.type) {\n\t\t\tcase \"braceL\":\n\t\t\t\treturn this.parseObject();\n\t\t\tcase \"bracketL\":\n\t\t\t\treturn this.parseArray();\n\t\t\tcase \"string\":\n\t\t\t\treturn this.parsePrimitive(\"String\");\n\t\t\tcase \"number\":\n\t\t\t\treturn this.parsePrimitive(\"Number\");\n\t\t\tcase \"boolean\":\n\t\t\t\treturn this.parsePrimitive(\"Boolean\");\n\t\t\tcase \"null\":\n\t\t\t\treturn this.parsePrimitive(\"Null\");\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unexpected token: ${token.type}`);\n\t\t}\n\t}\n\n\tparsePrimitive(type) {\n\t\tconst token = this.current();\n\t\tthis.pos++;\n\t\treturn {\n\t\t\ttype,\n\t\t\tstart: token.start,\n\t\t\tend: token.end,\n\t\t};\n\t}\n\n\tparseObject() {\n\t\tconst startToken = this.consume(\"braceL\");\n\t\tconst properties = [];\n\n\t\tthis.skipTrivia();\n\n\t\twhile (this.current() && this.current().type !== \"braceR\") {\n\t\t\tconst keyToken = this.consume(\"string\");\n\t\t\tconst keyNode = {\n\t\t\t\ttype: \"String\",\n\t\t\t\tstart: keyToken.start,\n\t\t\t\tend: keyToken.end,\n\t\t\t};\n\n\t\t\tthis.skipTrivia();\n\t\t\tthis.consume(\"colon\");\n\t\t\tthis.skipTrivia();\n\n\t\t\tconst valueNode = this.parseValue();\n\n\t\t\tproperties.push({ key: keyNode, value: valueNode });\n\n\t\t\tthis.skipTrivia();\n\t\t\tif (this.current() && this.current().type === \"comma\") {\n\t\t\t\tthis.pos++;\n\t\t\t\tthis.skipTrivia();\n\t\t\t}\n\t\t}\n\n\t\tconst endToken = this.consume(\"braceR\");\n\n\t\treturn {\n\t\t\ttype: \"Object\",\n\t\t\tstart: startToken.start,\n\t\t\tend: endToken.end,\n\t\t\tproperties,\n\t\t};\n\t}\n\n\tparseArray() {\n\t\tconst startToken = this.consume(\"bracketL\");\n\t\tconst elements = [];\n\n\t\tthis.skipTrivia();\n\n\t\twhile (this.current() && this.current().type !== \"bracketR\") {\n\t\t\tconst valueNode = this.parseValue();\n\t\t\telements.push(valueNode);\n\n\t\t\tthis.skipTrivia();\n\t\t\tif (this.current() && this.current().type === \"comma\") {\n\t\t\t\tthis.pos++;\n\t\t\t\tthis.skipTrivia();\n\t\t\t}\n\t\t}\n\n\t\tconst endToken = this.consume(\"bracketR\");\n\n\t\treturn {\n\t\t\ttype: \"Array\",\n\t\t\tstart: startToken.start,\n\t\t\tend: endToken.end,\n\t\t\telements,\n\t\t};\n\t}\n}\n","function unescapeString(str) {\n\treturn str.replace(/\\\\(.)/g, (_, ch) => {\n\t\tswitch (ch) {\n\t\t\tcase '\"':\n\t\t\t\treturn '\"';\n\t\t\tcase \"\\\\\":\n\t\t\t\treturn \"\\\\\";\n\t\t\tcase \"/\":\n\t\t\t\treturn \"/\";\n\t\t\tcase \"b\":\n\t\t\t\treturn \"\\b\";\n\t\t\tcase \"f\":\n\t\t\t\treturn \"\\f\";\n\t\t\tcase \"n\":\n\t\t\t\treturn \"\\n\";\n\t\t\tcase \"r\":\n\t\t\t\treturn \"\\r\";\n\t\t\tcase \"t\":\n\t\t\t\treturn \"\\t\";\n\t\t\tdefault:\n\t\t\t\treturn ch; // \\uXXXX 可后续增强\n\t\t}\n\t});\n}\n\nexport function extractString(stringNode, sourceText) {\n\t// sourceText 是完整 JSON 文本\n\t// stringNode.start / end 覆盖包含引号\n\tconst raw = sourceText.slice(stringNode.start + 1, stringNode.end - 1);\n\treturn unescapeString(raw);\n}\n\n/**\n *\n * @param {string} path\n * @returns\n */\nexport function parsePath(path) {\n\tif (path.startsWith(\"/\")) {\n\t\treturn parseJSONPointer(path);\n\t}\n\treturn parseDotPath(path);\n}\n\n/**\n *\n * @param {string} path\n * @returns\n */\nfunction parseDotPath(path) {\n\tconst result = [];\n\tlet i = 0;\n\n\twhile (i < path.length) {\n\t\tconst ch = path[i];\n\n\t\t// skip dot\n\t\tif (ch === \".\") {\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// array index: [123]\n\t\tif (ch === \"[\") {\n\t\t\ti++;\n\t\t\tlet num = \"\";\n\t\t\twhile (i < path.length && path[i] !== \"]\") {\n\t\t\t\tnum += path[i++];\n\t\t\t}\n\t\t\ti++; // skip ]\n\t\t\tresult.push(Number(num));\n\t\t\tcontinue;\n\t\t}\n\n\t\t// identifier\n\t\tlet name = \"\";\n\t\twhile (i < path.length && /[a-zA-Z0-9_$]/.test(path[i])) {\n\t\t\tname += path[i++];\n\t\t}\n\t\tresult.push(name);\n\t}\n\n\treturn result;\n}\n\n/**\n *\n * @param {string} pointer\n * @returns\n */\nfunction parseJSONPointer(pointer) {\n\tif (pointer === \"\") return [];\n\n\tif (pointer[0] !== \"/\") {\n\t\tthrow new Error(\"Invalid JSON Pointer\");\n\t}\n\n\treturn pointer\n\t\t.slice(1)\n\t\t.split(\"/\")\n\t\t.map((segment) => segment.replace(/~1/g, \"/\").replace(/~0/g, \"~\"))\n\t\t.map((seg) => {\n\t\t\treturn /^\\d+$/.test(seg) ? Number(seg) : seg;\n\t\t});\n}\n","import { extractString } from \"./helper.js\";\n\nexport function resolvePath(root, path, sourceText) {\n\tconst parts = Array.isArray(path) ? path : parsePath(path);\n\tlet node = root;\n\n\tfor (const part of parts) {\n\t\tif (!node) return null;\n\n\t\tif (node.type === \"Object\") {\n\t\t\tnode = resolveObjectProperty(node, part, sourceText);\n\t\t} else if (node.type === \"Array\") {\n\t\t\tnode = resolveArrayElement(node, part);\n\t\t} else {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\treturn node;\n}\n\n/**\n *\n * @param {import('./CSTBuilder.js').NodeObject} objectNode\n * @param {string} key\n * @param {string} sourceText\n * @returns {import('./CSTBuilder.js').Node | null}\n */\nfunction resolveObjectProperty(objectNode, key, sourceText) {\n\tif (typeof key !== \"string\") return null;\n\n\tfor (const prop of objectNode.properties) {\n\t\tconst name = extractString(prop.key, sourceText);\n\t\tif (name === key) {\n\t\t\treturn prop.value;\n\t\t}\n\t}\n\treturn null;\n}\n\n/**\n *\n * @param {import('./CSTBuilder.js').NodeArray} arrayNode\n * @param {number} index\n * @returns {import('./CSTBuilder.js').Node | null}\n */\nfunction resolveArrayElement(arrayNode, index) {\n\tif (typeof index !== \"number\") return null;\n\treturn arrayNode.elements[index] || null;\n}\n\nfunction parsePath(path) {\n\tif (path.startsWith(\"/\")) {\n\t\treturn parseJSONPointer(path);\n\t}\n\treturn parseDotPath(path);\n}\n\nfunction parseDotPath(path) {\n\tconst result = [];\n\tlet i = 0;\n\n\twhile (i < path.length) {\n\t\tconst ch = path[i];\n\n\t\t// skip dot\n\t\tif (ch === \".\") {\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// array index: [123]\n\t\tif (ch === \"[\") {\n\t\t\ti++;\n\t\t\tlet num = \"\";\n\t\t\twhile (i < path.length && path[i] !== \"]\") {\n\t\t\t\tnum += path[i++];\n\t\t\t}\n\t\t\ti++; // skip ]\n\t\t\tresult.push(Number(num));\n\t\t\tcontinue;\n\t\t}\n\n\t\t// identifier\n\t\tlet name = \"\";\n\t\twhile (i < path.length && /[a-zA-Z0-9_$]/.test(path[i])) {\n\t\t\tname += path[i++];\n\t\t}\n\t\tresult.push(name);\n\t}\n\n\treturn result;\n}\n\nfunction parseJSONPointer(pointer) {\n\tif (pointer === \"\") return [];\n\n\tif (pointer[0] !== \"/\") {\n\t\tthrow new Error(\"Invalid JSON Pointer\");\n\t}\n\n\treturn pointer\n\t\t.slice(1)\n\t\t.split(\"/\")\n\t\t.map((segment) => segment.replace(/~1/g, \"/\").replace(/~0/g, \"~\"))\n\t\t.map((seg) => {\n\t\t\treturn /^\\d+$/.test(seg) ? Number(seg) : seg;\n\t\t});\n}\n","import { Tokenizer } from \"../Tokenizer.js\";\nimport { CSTBuilder } from \"../CSTBuilder.js\";\nimport { resolvePath } from \"../PathResolver.js\";\n\nexport function replace(sourceText, patches, root) {\n\tif (!root) {\n\t\tconst tokenizer = new Tokenizer(sourceText);\n\t\tconst tokens = tokenizer.tokenize();\n\n\t\tconst builder = new CSTBuilder(tokens);\n\t\troot = builder.build();\n\t}\n\n\t// 倒叙替换\n\tconst reverseNodes = patches\n\t\t.map((patch) => {\n\t\t\tconst node = resolvePath(root, patch.path, sourceText);\n\n\t\t\treturn {\n\t\t\t\tnode,\n\t\t\t\tpatch,\n\t\t\t};\n\t\t})\n\t\t.filter((v) => v.node)\n\t\t.sort((a, b) => b.node.start - a.node.start);\n\n\t// 确保不会冲突\n\treverseNodes.reduce((lastEnd, { node }) => {\n\t\tif (node.end > lastEnd) {\n\t\t\tthrow new Error(`Patch conflict at path: ${node.path}`);\n\t\t}\n\n\t\treturn node.start;\n\t}, Infinity);\n\n\tlet result = sourceText;\n\n\tfor (const { node, patch } of reverseNodes) {\n\t\tresult = result.slice(0, node.start) + patch.value + result.slice(node.end);\n\t}\n\n\treturn result;\n}\n","import { Tokenizer } from \"../Tokenizer.js\";\nimport { CSTBuilder } from \"../CSTBuilder.js\";\nimport { resolvePath } from \"../PathResolver.js\";\nimport { parsePath, extractString } from \"../helper.js\";\n\nexport function remove(sourceText, patches, root) {\n\tif (!root) {\n\t\tconst tokenizer = new Tokenizer(sourceText);\n\t\tconst tokens = tokenizer.tokenize();\n\n\t\tconst builder = new CSTBuilder(tokens);\n\t\troot = builder.build();\n\t}\n\n\t// 倒叙删除\n\tconst reverseNodes = patches\n\t\t.map((patch) => {\n\t\t\tconst pathParts = parsePath(patch.path);\n\t\t\tif (pathParts.length === 0) {\n\t\t\t\treturn null; // Cannot delete root\n\t\t\t}\n\n\t\t\t// Find parent and the item to delete\n\t\t\tconst parentPath = pathParts.slice(0, -1);\n\t\t\tconst lastKey = pathParts[pathParts.length - 1];\n\t\t\tconst parentNode = parentPath.length > 0 ? resolvePath(root, parentPath, sourceText) : root;\n\n\t\t\tif (!parentNode) return null;\n\n\t\t\treturn {\n\t\t\t\tparentNode,\n\t\t\t\tlastKey,\n\t\t\t\tpatch,\n\t\t\t};\n\t\t})\n\t\t.filter((v) => v !== null)\n\t\t.sort((a, b) => {\n\t\t\t// Sort by the start position of what we're deleting\n\t\t\tconst aStart = getDeleteStart(a.parentNode, a.lastKey, sourceText);\n\t\t\tconst bStart = getDeleteStart(b.parentNode, b.lastKey, sourceText);\n\t\t\treturn bStart - aStart;\n\t\t});\n\n\tlet result = sourceText;\n\n\tfor (const { parentNode, lastKey } of reverseNodes) {\n\t\tresult = deleteFromParent(result, parentNode, lastKey, sourceText);\n\t}\n\n\treturn result;\n}\n\nfunction getDeleteStart(parentNode, key, sourceText) {\n\tif (parentNode.type === \"Object\") {\n\t\tfor (const prop of parentNode.properties) {\n\t\t\tconst keyStr = extractString(prop.key, sourceText);\n\t\t\tif (keyStr === key) {\n\t\t\t\treturn prop.key.start;\n\t\t\t}\n\t\t}\n\t} else if (parentNode.type === \"Array\") {\n\t\tif (typeof key === \"number\" && key >= 0 && key < parentNode.elements.length) {\n\t\t\treturn parentNode.elements[key].start;\n\t\t}\n\t}\n\treturn 0;\n}\n\nfunction deleteObjectProperty(sourceText, objectNode, key, originalSource) {\n\tlet propIndex = -1;\n\tfor (let i = 0; i < objectNode.properties.length; i++) {\n\t\tconst keyStr = extractString(objectNode.properties[i].key, originalSource);\n\t\tif (keyStr === key) {\n\t\t\tpropIndex = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (propIndex === -1) return sourceText;\n\n\tconst prop = objectNode.properties[propIndex];\n\tlet deleteStart = prop.key.start;\n\tlet deleteEnd = prop.value.end;\n\n\t// Handle comma and whitespace\n\tif (propIndex < objectNode.properties.length - 1) {\n\t\t// Not the last property, look for comma after\n\t\tlet pos = deleteEnd;\n\t\twhile (\n\t\t\tpos < sourceText.length &&\n\t\t\t(sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")\n\t\t) {\n\t\t\tpos++;\n\t\t}\n\t\tif (sourceText[pos] === \",\") {\n\t\t\tdeleteEnd = pos + 1;\n\t\t\t// Skip trailing whitespace after comma\n\t\t\twhile (\n\t\t\t\tdeleteEnd < sourceText.length &&\n\t\t\t\t(sourceText[deleteEnd] === \" \" ||\n\t\t\t\t\tsourceText[deleteEnd] === \"\\t\" ||\n\t\t\t\t\tsourceText[deleteEnd] === \"\\n\" ||\n\t\t\t\t\tsourceText[deleteEnd] === \"\\r\")\n\t\t\t) {\n\t\t\t\tdeleteEnd++;\n\t\t\t}\n\t\t}\n\t} else if (propIndex > 0) {\n\t\t// Last property, look for comma before (and whitespace before the comma)\n\t\tlet pos = deleteStart - 1;\n\t\t// Skip whitespace before the property\n\t\twhile (pos >= 0 && (sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")) {\n\t\t\tpos--;\n\t\t}\n\t\tif (sourceText[pos] === \",\") {\n\t\t\t// Also skip whitespace before the comma\n\t\t\tlet commaPos = pos;\n\t\t\tpos--;\n\t\t\twhile (\n\t\t\t\tpos >= 0 &&\n\t\t\t\t(sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")\n\t\t\t) {\n\t\t\t\tpos--;\n\t\t\t}\n\t\t\tdeleteStart = pos + 1;\n\t\t}\n\t}\n\n\treturn sourceText.slice(0, deleteStart) + sourceText.slice(deleteEnd);\n}\n\nfunction deleteArrayElement(sourceText, arrayNode, index, originalSource) {\n\tif (typeof index !== \"number\" || index < 0 || index >= arrayNode.elements.length) {\n\t\treturn sourceText;\n\t}\n\n\tconst element = arrayNode.elements[index];\n\tlet deleteStart = element.start;\n\tlet deleteEnd = element.end;\n\n\t// Handle comma and whitespace\n\tif (index < arrayNode.elements.length - 1) {\n\t\t// Not the last element, look for comma after\n\t\tlet pos = deleteEnd;\n\t\twhile (\n\t\t\tpos < sourceText.length &&\n\t\t\t(sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")\n\t\t) {\n\t\t\tpos++;\n\t\t}\n\t\tif (sourceText[pos] === \",\") {\n\t\t\tdeleteEnd = pos + 1;\n\t\t\t// Skip trailing whitespace after comma\n\t\t\twhile (\n\t\t\t\tdeleteEnd < sourceText.length &&\n\t\t\t\t(sourceText[deleteEnd] === \" \" ||\n\t\t\t\t\tsourceText[deleteEnd] === \"\\t\" ||\n\t\t\t\t\tsourceText[deleteEnd] === \"\\n\" ||\n\t\t\t\t\tsourceText[deleteEnd] === \"\\r\")\n\t\t\t) {\n\t\t\t\tdeleteEnd++;\n\t\t\t}\n\t\t}\n\t} else if (index > 0) {\n\t\t// Last element, look for comma before (and whitespace before the comma)\n\t\tlet pos = deleteStart - 1;\n\t\t// Skip whitespace before the element\n\t\twhile (pos >= 0 && (sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")) {\n\t\t\tpos--;\n\t\t}\n\t\tif (sourceText[pos] === \",\") {\n\t\t\t// Also skip whitespace before the comma\n\t\t\tlet commaPos = pos;\n\t\t\tpos--;\n\t\t\twhile (\n\t\t\t\tpos >= 0 &&\n\t\t\t\t(sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")\n\t\t\t) {\n\t\t\t\tpos--;\n\t\t\t}\n\t\t\tdeleteStart = pos + 1;\n\t\t}\n\t}\n\n\treturn sourceText.slice(0, deleteStart) + sourceText.slice(deleteEnd);\n}\n\nfunction deleteFromParent(sourceText, parentNode, key, originalSource) {\n\tif (parentNode.type === \"Object\") {\n\t\treturn deleteObjectProperty(sourceText, parentNode, key, originalSource);\n\t} else if (parentNode.type === \"Array\") {\n\t\treturn deleteArrayElement(sourceText, parentNode, key, originalSource);\n\t}\n\treturn sourceText;\n}\n","import { Tokenizer } from \"../Tokenizer.js\";\nimport { CSTBuilder } from \"../CSTBuilder.js\";\nimport { resolvePath } from \"../PathResolver.js\";\nimport { extractString } from \"../helper.js\";\n\nexport function insert(sourceText, patches, root) {\n\tif (!root) {\n\t\tconst tokenizer = new Tokenizer(sourceText);\n\t\tconst tokens = tokenizer.tokenize();\n\n\t\tconst builder = new CSTBuilder(tokens);\n\t\troot = builder.build();\n\t}\n\n\t// 倒叙插入\n\tconst reverseNodes = patches\n\t\t.map((patch) => {\n\t\t\tconst node = resolvePath(root, patch.path, sourceText);\n\t\t\treturn {\n\t\t\t\tnode,\n\t\t\t\tpatch,\n\t\t\t};\n\t\t})\n\t\t.filter((v) => v.node)\n\t\t.sort((a, b) => b.node.start - a.node.start);\n\n\tlet result = sourceText;\n\n\tfor (const { node, patch } of reverseNodes) {\n\t\tresult = insertIntoNode(result, node, patch, sourceText);\n\t}\n\n\treturn result;\n}\n\nfunction insertIntoNode(sourceText, node, patch, originalSource) {\n\tif (node.type === \"Object\") {\n\t\treturn insertObjectProperty(sourceText, node, patch, originalSource);\n\t} else if (node.type === \"Array\") {\n\t\treturn insertArrayElement(sourceText, node, patch, originalSource);\n\t}\n\treturn sourceText;\n}\n\nfunction insertObjectProperty(sourceText, objectNode, patch, originalSource) {\n\tif (!patch.key) {\n\t\tthrow new Error(\"Insert into object requires 'key' property\");\n\t}\n\n\t// Check if key already exists\n\tfor (const prop of objectNode.properties) {\n\t\tconst keyStr = extractString(prop.key, originalSource);\n\t\tif (keyStr === patch.key) {\n\t\t\tthrow new Error(`Key \"${patch.key}\" already exists in object`);\n\t\t}\n\t}\n\n\tconst newEntry = `\"${patch.key}\": ${patch.value}`;\n\n\tif (objectNode.properties.length === 0) {\n\t\t// Empty object\n\t\tconst insertPos = objectNode.start + 1;\n\t\treturn sourceText.slice(0, insertPos) + newEntry + sourceText.slice(insertPos);\n\t} else {\n\t\t// Insert after last property\n\t\tconst lastProp = objectNode.properties[objectNode.properties.length - 1];\n\t\tconst insertPos = lastProp.value.end;\n\t\treturn sourceText.slice(0, insertPos) + \", \" + newEntry + sourceText.slice(insertPos);\n\t}\n}\n\nfunction insertArrayElement(sourceText, arrayNode, patch, originalSource) {\n\tconst position = patch.position !== undefined ? patch.position : arrayNode.elements.length;\n\n\tif (position < 0 || position > arrayNode.elements.length) {\n\t\tthrow new Error(`Invalid position ${position} for array of length ${arrayNode.elements.length}`);\n\t}\n\n\tif (arrayNode.elements.length === 0) {\n\t\t// Empty array\n\t\tconst insertPos = arrayNode.start + 1;\n\t\treturn sourceText.slice(0, insertPos) + patch.value + sourceText.slice(insertPos);\n\t} else if (position === 0) {\n\t\t// Insert at the beginning\n\t\tconst insertPos = arrayNode.elements[0].start;\n\t\treturn sourceText.slice(0, insertPos) + patch.value + \", \" + sourceText.slice(insertPos);\n\t} else if (position >= arrayNode.elements.length) {\n\t\t// Insert at the end\n\t\tconst lastElement = arrayNode.elements[arrayNode.elements.length - 1];\n\t\tconst insertPos = lastElement.end;\n\t\treturn sourceText.slice(0, insertPos) + \", \" + patch.value + sourceText.slice(insertPos);\n\t} else {\n\t\t// Insert in the middle\n\t\tconst insertPos = arrayNode.elements[position].start;\n\t\treturn sourceText.slice(0, insertPos) + patch.value + \", \" + sourceText.slice(insertPos);\n\t}\n}\n","import { replace } from \"./replace.js\";\nimport { remove } from \"./delete.js\";\nimport { insert } from \"./insert.js\";\nimport { Tokenizer } from \"../Tokenizer.js\";\nimport { CSTBuilder } from \"../CSTBuilder.js\";\n\nexport function batch(sourceText, patches) {\n\t// Parse the source text once\n\tconst tokenizer = new Tokenizer(sourceText);\n\tconst tokens = tokenizer.tokenize();\n\tconst builder = new CSTBuilder(tokens);\n\tconst root = builder.build();\n\n\t// Categorize patches by operation type\n\tconst replacePatches = [];\n\tconst deletePatches = [];\n\tconst insertPatches = [];\n\n\tfor (const p of patches) {\n\t\t// Determine patch type based on properties\n\t\tif (p.value !== undefined && p.key === undefined && p.position === undefined) {\n\t\t\t// Has value but no key/position -> replace operation\n\t\t\treplacePatches.push({ path: p.path, value: p.value });\n\t\t} else if (p.value === undefined && p.key === undefined && p.position === undefined) {\n\t\t\t// No value, key, or position -> delete operation\n\t\t\tdeletePatches.push({ path: p.path });\n\t\t} else if ((p.key !== undefined || p.position !== undefined) && p.value !== undefined) {\n\t\t\t// Has key or position with value -> insert operation\n\t\t\tinsertPatches.push(p);\n\t\t} else {\n\t\t\t// Invalid patch - skip it\n\t\t\tcontinue;\n\t\t}\n\t}\n\n\t// Apply patches in order: replace, insert, delete\n\t// This order ensures that replacements happen first, then inserts, then deletes\n\tlet result = sourceText;\n\n\t// Apply replacements\n\tif (replacePatches.length > 0) {\n\t\tresult = replace(result, replacePatches, root);\n\t}\n\n\t// Apply insertions\n\tif (insertPatches.length > 0) {\n\t\t// Need to re-parse if we did replacements\n\t\tconst currentRoot = replacePatches.length > 0 ? null : root;\n\t\tresult = insert(result, insertPatches, currentRoot);\n\t}\n\n\t// Apply deletions\n\tif (deletePatches.length > 0) {\n\t\t// Need to re-parse if we did replacements or insertions\n\t\tconst currentRoot = replacePatches.length > 0 || insertPatches.length > 0 ? null : root;\n\t\tresult = remove(result, deletePatches, currentRoot);\n\t}\n\n\treturn result;\n}\n","import { replace } from \"./function/replace.js\";\nimport { remove } from \"./function/delete.js\";\nimport { insert } from \"./function/insert.js\";\nimport { batch } from \"./function/batch.js\";\n\nconst jsoncst = {\n\treplace: replace,\n\tremove: remove,\n\tinsert: insert,\n\tbatch: batch,\n};\n\nexport { replace, remove, insert, batch };\n\nexport default jsoncst;\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","Tokenizer","text","tokenize","ch","isWhitespace","isNumberStart","isAlpha","readWhitespace","start","readString","readNumber","readKeyword","word","type","Error","readPunctuationOrComment","map","isDigit","CSTBuilder","tokens","build","node","current","skipTrivia","consume","token","parseValue","parsePrimitive","parseObject","startToken","properties","keyToken","keyNode","valueNode","endToken","parseArray","elements","unescapeString","str","_","extractString","stringNode","sourceText","raw","parsePath","path","parseJSONPointer","parseDotPath","result","i","num","Number","name","pointer","segment","seg","resolvePath","root","parts","Array","_iteratorError","part","resolveObjectProperty","resolveArrayElement","objectNode","arrayNode","index","replace","patches","tokenizer","builder","reverseNodes","patch","v","a","b","lastEnd","Infinity","remove","pathParts","parentPath","lastKey","parentNode","aStart","getDeleteStart","bStart","deleteFromParent","keyStr","deleteObjectProperty","originalSource","propIndex","deleteStart","deleteEnd","pos","pos1","deleteArrayElement","element","insert","insertIntoNode","insertObjectProperty","insertArrayElement","newEntry","insertPos","lastProp","insertPos1","position","undefined","lastElement","insertPos2","insertPos3","batch","replacePatches","deletePatches","insertPatches","p","currentRoot","currentRoot1","jsoncst"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,SAAS,QAAO,EAAEC,UAAU;QACnD,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,SAASI,GAAG,EAAEC,IAAI;QAAI,OAAOF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;IAAO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AHAD,cAAc,IAAI,CAACC;;QAKrB;;QAfKtD,oBAAAA;QAAAA,iBAAAA;;;iBAAAA,6BAAAA,AAAAA,QAAAA,UAAAA,MAAAA,EAAAA,UAAAA,MAAAA;;gBAAAA,mB,MAAAA;;;IAmBL,IAAIZ,SAASN;IAGb,IAAIqE,eAAe,MAAM,GAAG,GAC3B/D,SAASmB,QAAQnB,QAAQ+D,gBAAgBtD;IAI1C,IAAIwD,cAAc,MAAM,GAAG,GAAG;QAE7B,IAAME,cAAcJ,eAAe,MAAM,GAAG,IAAI,OAAOtD;QACvDT,SAASiD,OAAOjD,QAAQiE,eAAeE;IACxC;IAGA,IAAIH,cAAc,MAAM,GAAG,GAAG;QAE7B,IAAMI,eAAcL,eAAe,MAAM,GAAG,KAAKE,cAAc,MAAM,GAAG,IAAI,OAAOxD;QACnFT,SAAS8B,OAAO9B,QAAQgE,eAAeI;IACxC;IAEA,OAAOpE;AACR;ACtDA,IAAMqE,UAAU;IACf,SAASlD;IACT,QAAQW;IACR,QAAQmB;IACR,OAAOa;AACR;AAIA,UAAeO"} | ||
| {"version":3,"file":"cjs/index.cjs","sources":["webpack/runtime/define_property_getters","webpack/runtime/has_own_property","webpack/runtime/make_namespace_object","../../src/value-helpers.js","../../src/Tokenizer.js","../../src/CSTBuilder.js","../../src/helper.js","../../src/PathResolver.js","../../src/JsonMod.js","../../src/index.js"],"sourcesContent":["__webpack_require__.d = function(exports, definition) {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }","// define __esModule on exports\n__webpack_require__.r = function(exports) {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/**\n * Helper utility for formatting values to use in patches.\n * This function makes it easier to create patch values without manually adding quotes.\n */\n\n/**\n * Formats a JavaScript value into a JSON string representation for use in patches.\n * Handles all JavaScript types including strings, numbers, booleans, null, objects, and arrays.\n * \n * @param {any} value - The value to format\n * @returns {string} - A JSON string representation\n * @example\n * formatValue(42) // \"42\"\n * formatValue(\"hello\") // '\"hello\"'\n * formatValue(true) // \"true\"\n * formatValue(null) // \"null\"\n * formatValue({a: 1}) // '{\"a\":1}'\n * formatValue([1, 2, 3]) // '[1,2,3]'\n */\nexport function formatValue(value) {\n\treturn JSON.stringify(value);\n}\n","class Tokenizer {\n\tconstructor(text) {\n\t\tthis.text = text;\n\t\tthis.pos = 0;\n\t\tthis.tokens = [];\n\t}\n\n\ttokenize() {\n\t\twhile (this.pos < this.text.length) {\n\t\t\tconst ch = this.text[this.pos];\n\n\t\t\tif (this.isWhitespace(ch)) {\n\t\t\t\tthis.readWhitespace();\n\t\t\t} else if (ch === '\"') {\n\t\t\t\tthis.readString();\n\t\t\t} else if (this.isNumberStart(ch)) {\n\t\t\t\tthis.readNumber();\n\t\t\t} else if (this.isAlpha(ch)) {\n\t\t\t\tthis.readKeyword();\n\t\t\t} else {\n\t\t\t\tthis.readPunctuationOrComment();\n\t\t\t}\n\t\t}\n\n\t\treturn this.tokens;\n\t}\n\n\t// ---------- helpers ----------\n\n\tisWhitespace(ch) {\n\t\treturn ch === \" \" || ch === \"\\n\" || ch === \"\\r\" || ch === \"\\t\";\n\t}\n\n\tisNumberStart(ch) {\n\t\treturn ch === \"-\" || (ch >= \"0\" && ch <= \"9\");\n\t}\n\n\tisAlpha(ch) {\n\t\treturn (ch >= \"a\" && ch <= \"z\") || (ch >= \"A\" && ch <= \"Z\");\n\t}\n\n\t// ---------- readers ----------\n\n\treadWhitespace() {\n\t\tconst start = this.pos;\n\t\twhile (this.pos < this.text.length && this.isWhitespace(this.text[this.pos])) {\n\t\t\tthis.pos++;\n\t\t}\n\t\tthis.tokens.push({\n\t\t\ttype: \"whitespace\",\n\t\t\tstart,\n\t\t\tend: this.pos,\n\t\t});\n\t}\n\n\treadString() {\n\t\tconst start = this.pos;\n\t\tthis.pos++; // skip opening \"\n\n\t\twhile (this.pos < this.text.length) {\n\t\t\tconst ch = this.text[this.pos];\n\n\t\t\tif (ch === \"\\\\\") {\n\t\t\t\t// skip escaped char\n\t\t\t\tthis.pos += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (ch === '\"') {\n\t\t\t\tthis.pos++; // closing \"\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tthis.pos++;\n\t\t}\n\n\t\tthis.tokens.push({\n\t\t\ttype: \"string\",\n\t\t\tstart,\n\t\t\tend: this.pos,\n\t\t});\n\t}\n\n\treadNumber() {\n\t\tconst start = this.pos;\n\n\t\tif (this.text[this.pos] === \"-\") this.pos++;\n\n\t\twhile (this.pos < this.text.length && this.isDigit(this.text[this.pos])) {\n\t\t\tthis.pos++;\n\t\t}\n\n\t\tif (this.text[this.pos] === \".\") {\n\t\t\tthis.pos++;\n\t\t\twhile (this.pos < this.text.length && this.isDigit(this.text[this.pos])) {\n\t\t\t\tthis.pos++;\n\t\t\t}\n\t\t}\n\n\t\tif (this.text[this.pos] === \"e\" || this.text[this.pos] === \"E\") {\n\t\t\tthis.pos++;\n\t\t\tif (this.text[this.pos] === \"+\" || this.text[this.pos] === \"-\") {\n\t\t\t\tthis.pos++;\n\t\t\t}\n\t\t\twhile (this.pos < this.text.length && this.isDigit(this.text[this.pos])) {\n\t\t\t\tthis.pos++;\n\t\t\t}\n\t\t}\n\n\t\tthis.tokens.push({\n\t\t\ttype: \"number\",\n\t\t\tstart,\n\t\t\tend: this.pos,\n\t\t});\n\t}\n\n\treadKeyword() {\n\t\tconst start = this.pos;\n\n\t\twhile (this.pos < this.text.length && this.isAlpha(this.text[this.pos])) {\n\t\t\tthis.pos++;\n\t\t}\n\n\t\tconst word = this.text.slice(start, this.pos);\n\n\t\tlet type;\n\t\tif (word === \"true\" || word === \"false\") {\n\t\t\ttype = \"boolean\";\n\t\t} else if (word === \"null\") {\n\t\t\ttype = \"null\";\n\t\t} else {\n\t\t\tthrow new Error(`Unexpected identifier: ${word}`);\n\t\t}\n\n\t\tthis.tokens.push({\n\t\t\ttype,\n\t\t\tstart,\n\t\t\tend: this.pos,\n\t\t});\n\t}\n\n\treadPunctuationOrComment() {\n\t\tconst start = this.pos;\n\t\tconst ch = this.text[this.pos];\n\n\t\t// line comment //\n\t\tif (ch === \"/\" && this.text[this.pos + 1] === \"/\") {\n\t\t\tthis.pos += 2;\n\t\t\twhile (this.pos < this.text.length && this.text[this.pos] !== \"\\n\") {\n\t\t\t\tthis.pos++;\n\t\t\t}\n\t\t\tthis.tokens.push({\n\t\t\t\ttype: \"comment\",\n\t\t\t\tstart,\n\t\t\t\tend: this.pos,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\t// block comment /* */\n\t\tif (ch === \"/\" && this.text[this.pos + 1] === \"*\") {\n\t\t\tthis.pos += 2;\n\t\t\twhile (this.pos < this.text.length && !(this.text[this.pos] === \"*\" && this.text[this.pos + 1] === \"/\")) {\n\t\t\t\tthis.pos++;\n\t\t\t}\n\t\t\tthis.pos += 2; // skip */\n\t\t\tthis.tokens.push({\n\t\t\t\ttype: \"comment\",\n\t\t\t\tstart,\n\t\t\t\tend: this.pos,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\t// punctuation\n\t\tthis.pos++;\n\n\t\tconst map = {\n\t\t\t\"{\": \"braceL\",\n\t\t\t\"}\": \"braceR\",\n\t\t\t\"[\": \"bracketL\",\n\t\t\t\"]\": \"bracketR\",\n\t\t\t\":\": \"colon\",\n\t\t\t\",\": \"comma\",\n\t\t};\n\n\t\tconst type = map[ch];\n\t\tif (!type) {\n\t\t\tthrow new Error(`Unexpected character: ${ch} at ${start}`);\n\t\t}\n\n\t\tthis.tokens.push({\n\t\t\ttype,\n\t\t\tstart,\n\t\t\tend: this.pos,\n\t\t});\n\t}\n\n\tisDigit(ch) {\n\t\treturn ch >= \"0\" && ch <= \"9\";\n\t}\n}\n\nexport { Tokenizer };\n","export class CSTBuilder {\n\tconstructor(tokens) {\n\t\tthis.tokens = tokens;\n\t\tthis.pos = 0;\n\t}\n\n\tbuild() {\n\t\tthis.skipTrivia();\n\t\tconst node = this.parseValue();\n\t\tthis.skipTrivia();\n\t\treturn node;\n\t}\n\n\tcurrent() {\n\t\treturn this.tokens[this.pos];\n\t}\n\n\tskipTrivia() {\n\t\twhile (this.pos < this.tokens.length && (this.tokens[this.pos].type === \"whitespace\" || this.tokens[this.pos].type === \"comment\")) {\n\t\t\tthis.pos++;\n\t\t}\n\t}\n\n\tconsume(type) {\n\t\tconst token = this.current();\n\t\tif (!token || token.type !== type) {\n\t\t\tthrow new Error(`Expected ${type}, got ${token && token.type}`);\n\t\t}\n\t\tthis.pos++;\n\t\treturn token;\n\t}\n\n\tparseValue() {\n\t\tthis.skipTrivia();\n\t\tconst token = this.current();\n\n\t\tif (!token) {\n\t\t\tthrow new Error(\"Unexpected end of input\");\n\t\t}\n\n\t\tswitch (token.type) {\n\t\t\tcase \"braceL\":\n\t\t\t\treturn this.parseObject();\n\t\t\tcase \"bracketL\":\n\t\t\t\treturn this.parseArray();\n\t\t\tcase \"string\":\n\t\t\t\treturn this.parsePrimitive(\"String\");\n\t\t\tcase \"number\":\n\t\t\t\treturn this.parsePrimitive(\"Number\");\n\t\t\tcase \"boolean\":\n\t\t\t\treturn this.parsePrimitive(\"Boolean\");\n\t\t\tcase \"null\":\n\t\t\t\treturn this.parsePrimitive(\"Null\");\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unexpected token: ${token.type}`);\n\t\t}\n\t}\n\n\tparsePrimitive(type) {\n\t\tconst token = this.current();\n\t\tthis.pos++;\n\t\treturn {\n\t\t\ttype,\n\t\t\tstart: token.start,\n\t\t\tend: token.end,\n\t\t};\n\t}\n\n\tparseObject() {\n\t\tconst startToken = this.consume(\"braceL\");\n\t\tconst properties = [];\n\n\t\tthis.skipTrivia();\n\n\t\twhile (this.current() && this.current().type !== \"braceR\") {\n\t\t\tconst keyToken = this.consume(\"string\");\n\t\t\tconst keyNode = {\n\t\t\t\ttype: \"String\",\n\t\t\t\tstart: keyToken.start,\n\t\t\t\tend: keyToken.end,\n\t\t\t};\n\n\t\t\tthis.skipTrivia();\n\t\t\tthis.consume(\"colon\");\n\t\t\tthis.skipTrivia();\n\n\t\t\tconst valueNode = this.parseValue();\n\n\t\t\tproperties.push({ key: keyNode, value: valueNode });\n\n\t\t\tthis.skipTrivia();\n\t\t\tif (this.current() && this.current().type === \"comma\") {\n\t\t\t\tthis.pos++;\n\t\t\t\tthis.skipTrivia();\n\t\t\t}\n\t\t}\n\n\t\tconst endToken = this.consume(\"braceR\");\n\n\t\treturn {\n\t\t\ttype: \"Object\",\n\t\t\tstart: startToken.start,\n\t\t\tend: endToken.end,\n\t\t\tproperties,\n\t\t};\n\t}\n\n\tparseArray() {\n\t\tconst startToken = this.consume(\"bracketL\");\n\t\tconst elements = [];\n\n\t\tthis.skipTrivia();\n\n\t\twhile (this.current() && this.current().type !== \"bracketR\") {\n\t\t\tconst valueNode = this.parseValue();\n\t\t\telements.push(valueNode);\n\n\t\t\tthis.skipTrivia();\n\t\t\tif (this.current() && this.current().type === \"comma\") {\n\t\t\t\tthis.pos++;\n\t\t\t\tthis.skipTrivia();\n\t\t\t}\n\t\t}\n\n\t\tconst endToken = this.consume(\"bracketR\");\n\n\t\treturn {\n\t\t\ttype: \"Array\",\n\t\t\tstart: startToken.start,\n\t\t\tend: endToken.end,\n\t\t\telements,\n\t\t};\n\t}\n}\n","function unescapeString(str) {\n\treturn str.replace(/\\\\(.)/g, (_, ch) => {\n\t\tswitch (ch) {\n\t\t\tcase '\"':\n\t\t\t\treturn '\"';\n\t\t\tcase \"\\\\\":\n\t\t\t\treturn \"\\\\\";\n\t\t\tcase \"/\":\n\t\t\t\treturn \"/\";\n\t\t\tcase \"b\":\n\t\t\t\treturn \"\\b\";\n\t\t\tcase \"f\":\n\t\t\t\treturn \"\\f\";\n\t\t\tcase \"n\":\n\t\t\t\treturn \"\\n\";\n\t\t\tcase \"r\":\n\t\t\t\treturn \"\\r\";\n\t\t\tcase \"t\":\n\t\t\t\treturn \"\\t\";\n\t\t\tdefault:\n\t\t\t\treturn ch; // \\uXXXX 可后续增强\n\t\t}\n\t});\n}\n\nexport function extractString(stringNode, sourceText) {\n\t// sourceText 是完整 JSON 文本\n\t// stringNode.start / end 覆盖包含引号\n\tconst raw = sourceText.slice(stringNode.start + 1, stringNode.end - 1);\n\treturn unescapeString(raw);\n}\n\n/**\n *\n * @param {string} path\n * @returns\n */\nexport function parsePath(path) {\n\tif (path.startsWith(\"/\")) {\n\t\treturn parseJSONPointer(path);\n\t}\n\treturn parseDotPath(path);\n}\n\n/**\n *\n * @param {string} path\n * @returns\n */\nfunction parseDotPath(path) {\n\tconst result = [];\n\tlet i = 0;\n\n\twhile (i < path.length) {\n\t\tconst ch = path[i];\n\n\t\t// skip dot\n\t\tif (ch === \".\") {\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// array index: [123]\n\t\tif (ch === \"[\") {\n\t\t\ti++;\n\t\t\tlet num = \"\";\n\t\t\twhile (i < path.length && path[i] !== \"]\") {\n\t\t\t\tnum += path[i++];\n\t\t\t}\n\t\t\ti++; // skip ]\n\t\t\tresult.push(Number(num));\n\t\t\tcontinue;\n\t\t}\n\n\t\t// identifier\n\t\tlet name = \"\";\n\t\twhile (i < path.length && /[a-zA-Z0-9_$]/.test(path[i])) {\n\t\t\tname += path[i++];\n\t\t}\n\t\tresult.push(name);\n\t}\n\n\treturn result;\n}\n\n/**\n *\n * @param {string} pointer\n * @returns\n */\nfunction parseJSONPointer(pointer) {\n\tif (pointer === \"\") return [];\n\n\tif (pointer[0] !== \"/\") {\n\t\tthrow new Error(\"Invalid JSON Pointer\");\n\t}\n\n\treturn pointer\n\t\t.slice(1)\n\t\t.split(\"/\")\n\t\t.map((segment) => segment.replace(/~1/g, \"/\").replace(/~0/g, \"~\"))\n\t\t.map((seg) => {\n\t\t\treturn /^\\d+$/.test(seg) ? Number(seg) : seg;\n\t\t});\n}\n","import { extractString } from \"./helper.js\";\n\nexport function resolvePath(root, path, sourceText) {\n\tconst parts = Array.isArray(path) ? path : parsePath(path);\n\tlet node = root;\n\n\tfor (const part of parts) {\n\t\tif (!node) return null;\n\n\t\tif (node.type === \"Object\") {\n\t\t\tnode = resolveObjectProperty(node, part, sourceText);\n\t\t} else if (node.type === \"Array\") {\n\t\t\tnode = resolveArrayElement(node, part);\n\t\t} else {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\treturn node;\n}\n\n/**\n *\n * @param {import('./CSTBuilder.js').NodeObject} objectNode\n * @param {string} key\n * @param {string} sourceText\n * @returns {import('./CSTBuilder.js').Node | null}\n */\nfunction resolveObjectProperty(objectNode, key, sourceText) {\n\tif (typeof key !== \"string\") return null;\n\n\tfor (const prop of objectNode.properties) {\n\t\tconst name = extractString(prop.key, sourceText);\n\t\tif (name === key) {\n\t\t\treturn prop.value;\n\t\t}\n\t}\n\treturn null;\n}\n\n/**\n *\n * @param {import('./CSTBuilder.js').NodeArray} arrayNode\n * @param {number} index\n * @returns {import('./CSTBuilder.js').Node | null}\n */\nfunction resolveArrayElement(arrayNode, index) {\n\tif (typeof index !== \"number\") return null;\n\treturn arrayNode.elements[index] || null;\n}\n\nfunction parsePath(path) {\n\tif (path.startsWith(\"/\")) {\n\t\treturn parseJSONPointer(path);\n\t}\n\treturn parseDotPath(path);\n}\n\nfunction parseDotPath(path) {\n\tconst result = [];\n\tlet i = 0;\n\n\twhile (i < path.length) {\n\t\tconst ch = path[i];\n\n\t\t// skip dot\n\t\tif (ch === \".\") {\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// array index: [123]\n\t\tif (ch === \"[\") {\n\t\t\ti++;\n\t\t\tlet num = \"\";\n\t\t\twhile (i < path.length && path[i] !== \"]\") {\n\t\t\t\tnum += path[i++];\n\t\t\t}\n\t\t\ti++; // skip ]\n\t\t\tresult.push(Number(num));\n\t\t\tcontinue;\n\t\t}\n\n\t\t// identifier\n\t\tlet name = \"\";\n\t\twhile (i < path.length && /[a-zA-Z0-9_$]/.test(path[i])) {\n\t\t\tname += path[i++];\n\t\t}\n\t\tresult.push(name);\n\t}\n\n\treturn result;\n}\n\nfunction parseJSONPointer(pointer) {\n\tif (pointer === \"\") return [];\n\n\tif (pointer[0] !== \"/\") {\n\t\tthrow new Error(\"Invalid JSON Pointer\");\n\t}\n\n\treturn pointer\n\t\t.slice(1)\n\t\t.split(\"/\")\n\t\t.map((segment) => segment.replace(/~1/g, \"/\").replace(/~0/g, \"~\"))\n\t\t.map((seg) => {\n\t\t\treturn /^\\d+$/.test(seg) ? Number(seg) : seg;\n\t\t});\n}\n","import { Tokenizer } from \"./Tokenizer.js\";\nimport { CSTBuilder } from \"./CSTBuilder.js\";\nimport { resolvePath } from \"./PathResolver.js\";\nimport { parsePath, extractString } from \"./helper.js\";\n\n/**\n * JsonMod - A chainable API for modifying JSON strings while preserving formatting\n * @class\n */\nexport class JsonMod {\n\t/**\n\t * Creates a new JsonMod instance\n\t * @param {string} sourceText - The JSON string to modify\n\t */\n\tconstructor(sourceText) {\n\t\tthis.sourceText = sourceText;\n\t\tthis.operations = [];\n\t}\n\n\t/**\n\t * Replace a value at the specified path\n\t * @param {string|string[]} path - The JSON path or array of path segments\n\t * @param {string} value - The new value as a JSON string\n\t * @returns {JsonMod} - Returns this for chaining\n\t * @example\n\t * jsonmod(source).replace(\"user.name\", '\"Bob\"').apply()\n\t * jsonmod(source).replace([\"user\", \"name\"], '\"Bob\"').apply()\n\t */\n\treplace(path, value) {\n\t\tthis.operations.push({\n\t\t\ttype: \"replace\",\n\t\t\tpath: Array.isArray(path) ? path : path,\n\t\t\tvalue,\n\t\t});\n\t\treturn this;\n\t}\n\n\t/**\n\t * Delete a property or array element at the specified path\n\t * @param {string|string[]} path - The JSON path or array of path segments\n\t * @returns {JsonMod} - Returns this for chaining\n\t * @example\n\t * jsonmod(source).delete(\"user.age\").apply()\n\t * jsonmod(source).remove([\"user\", \"age\"]).apply()\n\t */\n\tdelete(path) {\n\t\tthis.operations.push({\n\t\t\ttype: \"delete\",\n\t\t\tpath: Array.isArray(path) ? path : path,\n\t\t});\n\t\treturn this;\n\t}\n\n\t/**\n\t * Alias for delete()\n\t * @param {string|string[]} path - The JSON path or array of path segments\n\t * @returns {JsonMod} - Returns this for chaining\n\t */\n\tremove(path) {\n\t\treturn this.delete(path);\n\t}\n\n\t/**\n\t * Insert a new property into an object or element into an array\n\t * @param {string|string[]} path - The JSON path pointing to the object/array\n\t * @param {string|number} keyOrPosition - For objects: property name; For arrays: index\n\t * @param {string} value - The value to insert as a JSON string\n\t * @returns {JsonMod} - Returns this for chaining\n\t * @example\n\t * jsonmod(source).insert(\"user\", \"email\", '\"test@example.com\"').apply()\n\t * jsonmod(source).insert(\"items\", 0, '\"newItem\"').apply()\n\t */\n\tinsert(path, keyOrPosition, value) {\n\t\tthis.operations.push({\n\t\t\ttype: \"insert\",\n\t\t\tpath: Array.isArray(path) ? path : path,\n\t\t\tkeyOrPosition,\n\t\t\tvalue,\n\t\t});\n\t\treturn this;\n\t}\n\n\t/**\n\t * Apply all queued operations and return the modified JSON string\n\t * @returns {string} - The modified JSON string\n\t */\n\tapply() {\n\t\tif (this.operations.length === 0) {\n\t\t\treturn this.sourceText;\n\t\t}\n\n\t\tlet result = this.sourceText;\n\n\t\t// Apply operations sequentially to avoid conflicts\n\t\tfor (const op of this.operations) {\n\t\t\tswitch (op.type) {\n\t\t\t\tcase \"replace\":\n\t\t\t\t\tresult = this._applySingleReplace(result, op);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"delete\":\n\t\t\t\t\tresult = this._applySingleDelete(result, op);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"insert\":\n\t\t\t\t\tresult = this._applySingleInsert(result, op);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Internal method to apply a single replace operation\n\t * @private\n\t */\n\t_applySingleReplace(sourceText, op) {\n\t\tconst tokenizer = new Tokenizer(sourceText);\n\t\tconst tokens = tokenizer.tokenize();\n\t\tconst builder = new CSTBuilder(tokens);\n\t\tconst root = builder.build();\n\n\t\tconst node = resolvePath(root, op.path, sourceText);\n\t\tif (!node) {\n\t\t\treturn sourceText;\n\t\t}\n\n\t\treturn sourceText.slice(0, node.start) + op.value + sourceText.slice(node.end);\n\t}\n\n\t/**\n\t * Internal method to apply a single delete operation\n\t * @private\n\t */\n\t_applySingleDelete(sourceText, op) {\n\t\tconst tokenizer = new Tokenizer(sourceText);\n\t\tconst tokens = tokenizer.tokenize();\n\t\tconst builder = new CSTBuilder(tokens);\n\t\tconst root = builder.build();\n\n\t\tconst pathParts = parsePath(op.path);\n\t\tif (pathParts.length === 0) {\n\t\t\treturn sourceText;\n\t\t}\n\n\t\tconst parentPath = pathParts.slice(0, -1);\n\t\tconst lastKey = pathParts[pathParts.length - 1];\n\t\tconst parentNode = parentPath.length > 0 ? resolvePath(root, parentPath, sourceText) : root;\n\n\t\tif (!parentNode) {\n\t\t\treturn sourceText;\n\t\t}\n\n\t\treturn this._deleteFromParent(sourceText, parentNode, lastKey, sourceText);\n\t}\n\n\t/**\n\t * Internal method to apply a single insert operation\n\t * @private\n\t */\n\t_applySingleInsert(sourceText, op) {\n\t\tconst tokenizer = new Tokenizer(sourceText);\n\t\tconst tokens = tokenizer.tokenize();\n\t\tconst builder = new CSTBuilder(tokens);\n\t\tconst root = builder.build();\n\n\t\tconst node = resolvePath(root, op.path, sourceText);\n\t\tif (!node) {\n\t\t\treturn sourceText;\n\t\t}\n\n\t\treturn this._insertIntoNode(sourceText, node, op, sourceText);\n\t}\n\n\t_getDeleteStart(parentNode, key, sourceText) {\n\t\tif (parentNode.type === \"Object\") {\n\t\t\tfor (const prop of parentNode.properties) {\n\t\t\t\tconst keyStr = extractString(prop.key, sourceText);\n\t\t\t\tif (keyStr === key) {\n\t\t\t\t\treturn prop.key.start;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (parentNode.type === \"Array\") {\n\t\t\tif (typeof key === \"number\" && key >= 0 && key < parentNode.elements.length) {\n\t\t\t\treturn parentNode.elements[key].start;\n\t\t\t}\n\t\t}\n\t\treturn 0;\n\t}\n\n\t_deleteFromParent(sourceText, parentNode, key, originalSource) {\n\t\tif (parentNode.type === \"Object\") {\n\t\t\treturn this._deleteObjectProperty(sourceText, parentNode, key, originalSource);\n\t\t} else if (parentNode.type === \"Array\") {\n\t\t\treturn this._deleteArrayElement(sourceText, parentNode, key, originalSource);\n\t\t}\n\t\treturn sourceText;\n\t}\n\n\t_deleteObjectProperty(sourceText, objectNode, key, originalSource) {\n\t\tlet propIndex = -1;\n\t\tfor (let i = 0; i < objectNode.properties.length; i++) {\n\t\t\tconst keyStr = extractString(objectNode.properties[i].key, originalSource);\n\t\t\tif (keyStr === key) {\n\t\t\t\tpropIndex = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif (propIndex === -1) return sourceText;\n\n\t\tconst prop = objectNode.properties[propIndex];\n\t\tlet deleteStart = prop.key.start;\n\t\tlet deleteEnd = prop.value.end;\n\n\t\t// Handle comma and whitespace\n\t\tif (propIndex < objectNode.properties.length - 1) {\n\t\t\tlet pos = deleteEnd;\n\t\t\twhile (\n\t\t\t\tpos < sourceText.length &&\n\t\t\t\t(sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")\n\t\t\t) {\n\t\t\t\tpos++;\n\t\t\t}\n\t\t\tif (sourceText[pos] === \",\") {\n\t\t\t\tdeleteEnd = pos + 1;\n\t\t\t\twhile (\n\t\t\t\t\tdeleteEnd < sourceText.length &&\n\t\t\t\t\t(sourceText[deleteEnd] === \" \" ||\n\t\t\t\t\t\tsourceText[deleteEnd] === \"\\t\" ||\n\t\t\t\t\t\tsourceText[deleteEnd] === \"\\n\" ||\n\t\t\t\t\t\tsourceText[deleteEnd] === \"\\r\")\n\t\t\t\t) {\n\t\t\t\t\tdeleteEnd++;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (propIndex > 0) {\n\t\t\tlet pos = deleteStart - 1;\n\t\t\twhile (pos >= 0 && (sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")) {\n\t\t\t\tpos--;\n\t\t\t}\n\t\t\tif (sourceText[pos] === \",\") {\n\t\t\t\tlet commaPos = pos;\n\t\t\t\tpos--;\n\t\t\t\twhile (\n\t\t\t\t\tpos >= 0 &&\n\t\t\t\t\t(sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")\n\t\t\t\t) {\n\t\t\t\t\tpos--;\n\t\t\t\t}\n\t\t\t\tdeleteStart = pos + 1;\n\t\t\t}\n\t\t}\n\n\t\treturn sourceText.slice(0, deleteStart) + sourceText.slice(deleteEnd);\n\t}\n\n\t_deleteArrayElement(sourceText, arrayNode, index, originalSource) {\n\t\tif (typeof index !== \"number\" || index < 0 || index >= arrayNode.elements.length) {\n\t\t\treturn sourceText;\n\t\t}\n\n\t\tconst element = arrayNode.elements[index];\n\t\tlet deleteStart = element.start;\n\t\tlet deleteEnd = element.end;\n\n\t\t// Handle comma and whitespace\n\t\tif (index < arrayNode.elements.length - 1) {\n\t\t\tlet pos = deleteEnd;\n\t\t\twhile (\n\t\t\t\tpos < sourceText.length &&\n\t\t\t\t(sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")\n\t\t\t) {\n\t\t\t\tpos++;\n\t\t\t}\n\t\t\tif (sourceText[pos] === \",\") {\n\t\t\t\tdeleteEnd = pos + 1;\n\t\t\t\twhile (\n\t\t\t\t\tdeleteEnd < sourceText.length &&\n\t\t\t\t\t(sourceText[deleteEnd] === \" \" ||\n\t\t\t\t\t\tsourceText[deleteEnd] === \"\\t\" ||\n\t\t\t\t\t\tsourceText[deleteEnd] === \"\\n\" ||\n\t\t\t\t\t\tsourceText[deleteEnd] === \"\\r\")\n\t\t\t\t) {\n\t\t\t\t\tdeleteEnd++;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (index > 0) {\n\t\t\tlet pos = deleteStart - 1;\n\t\t\twhile (pos >= 0 && (sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")) {\n\t\t\t\tpos--;\n\t\t\t}\n\t\t\tif (sourceText[pos] === \",\") {\n\t\t\t\tlet commaPos = pos;\n\t\t\t\tpos--;\n\t\t\t\twhile (\n\t\t\t\t\tpos >= 0 &&\n\t\t\t\t\t(sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")\n\t\t\t\t) {\n\t\t\t\t\tpos--;\n\t\t\t\t}\n\t\t\t\tdeleteStart = pos + 1;\n\t\t\t}\n\t\t}\n\n\t\treturn sourceText.slice(0, deleteStart) + sourceText.slice(deleteEnd);\n\t}\n\n\t_insertIntoNode(sourceText, node, patch, originalSource) {\n\t\tif (node.type === \"Object\") {\n\t\t\treturn this._insertObjectProperty(sourceText, node, patch, originalSource);\n\t\t} else if (node.type === \"Array\") {\n\t\t\treturn this._insertArrayElement(sourceText, node, patch, originalSource);\n\t\t}\n\t\treturn sourceText;\n\t}\n\n\t_insertObjectProperty(sourceText, objectNode, patch, originalSource) {\n\t\tconst key = patch.keyOrPosition;\n\t\tif (typeof key !== \"string\") {\n\t\t\tthrow new Error(\"Insert into object requires a string key\");\n\t\t}\n\n\t\t// Check if key already exists\n\t\tfor (const prop of objectNode.properties) {\n\t\t\tconst keyStr = extractString(prop.key, originalSource);\n\t\t\tif (keyStr === key) {\n\t\t\t\tthrow new Error(`Key \"${key}\" already exists in object`);\n\t\t\t}\n\t\t}\n\n\t\tconst newEntry = `\"${key}\": ${patch.value}`;\n\n\t\tif (objectNode.properties.length === 0) {\n\t\t\tconst insertPos = objectNode.start + 1;\n\t\t\treturn sourceText.slice(0, insertPos) + newEntry + sourceText.slice(insertPos);\n\t\t} else {\n\t\t\tconst lastProp = objectNode.properties[objectNode.properties.length - 1];\n\t\t\tconst insertPos = lastProp.value.end;\n\t\t\treturn sourceText.slice(0, insertPos) + \", \" + newEntry + sourceText.slice(insertPos);\n\t\t}\n\t}\n\n\t_insertArrayElement(sourceText, arrayNode, patch, originalSource) {\n\t\tconst position = typeof patch.keyOrPosition === \"number\" ? patch.keyOrPosition : arrayNode.elements.length;\n\n\t\tif (position < 0 || position > arrayNode.elements.length) {\n\t\t\tthrow new Error(`Invalid position ${position} for array of length ${arrayNode.elements.length}`);\n\t\t}\n\n\t\tif (arrayNode.elements.length === 0) {\n\t\t\tconst insertPos = arrayNode.start + 1;\n\t\t\treturn sourceText.slice(0, insertPos) + patch.value + sourceText.slice(insertPos);\n\t\t} else if (position === 0) {\n\t\t\tconst insertPos = arrayNode.elements[0].start;\n\t\t\treturn sourceText.slice(0, insertPos) + patch.value + \", \" + sourceText.slice(insertPos);\n\t\t} else if (position >= arrayNode.elements.length) {\n\t\t\tconst lastElement = arrayNode.elements[arrayNode.elements.length - 1];\n\t\t\tconst insertPos = lastElement.end;\n\t\t\treturn sourceText.slice(0, insertPos) + \", \" + patch.value + sourceText.slice(insertPos);\n\t\t} else {\n\t\t\tconst insertPos = arrayNode.elements[position].start;\n\t\t\treturn sourceText.slice(0, insertPos) + patch.value + \", \" + sourceText.slice(insertPos);\n\t\t}\n\t}\n}\n\n/**\n * Factory function to create a new JsonMod instance\n * @param {string} sourceText - The JSON string to modify\n * @returns {JsonMod} - A new JsonMod instance\n * @example\n * jsonmod(source).replace(\"a\", \"10\").delete(\"b\").apply()\n */\nexport function jsonmod(sourceText) {\n\treturn new JsonMod(sourceText);\n}\n","import { formatValue } from \"./value-helpers.js\";\nimport { jsonmod, JsonMod } from \"./JsonMod.js\";\n\n// Export new chainable API as default\nexport default jsonmod;\n\n// Export new API and helper\nexport { jsonmod, JsonMod, formatValue };\n\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","formatValue","value","JSON","Tokenizer","text","tokenize","ch","isWhitespace","isNumberStart","isAlpha","readWhitespace","start","readString","readNumber","readKeyword","word","type","Error","readPunctuationOrComment","map","isDigit","CSTBuilder","tokens","build","node","current","skipTrivia","consume","token","parseValue","parsePrimitive","parseObject","startToken","properties","keyToken","keyNode","valueNode","endToken","parseArray","elements","unescapeString","str","_","extractString","stringNode","sourceText","raw","parsePath","path","parseJSONPointer","parseDotPath","result","i","num","Number","name","pointer","segment","seg","resolvePath","root","parts","Array","_iteratorError","part","resolveObjectProperty","resolveArrayElement","objectNode","arrayNode","index","JsonMod","replace","_delete","remove","insert","keyOrPosition","apply","op","_applySingleReplace","tokenizer","builder","_applySingleDelete","pathParts","parentPath","lastKey","parentNode","_applySingleInsert","_getDeleteStart","keyStr","_deleteFromParent","originalSource","_deleteObjectProperty","propIndex","deleteStart","deleteEnd","pos","pos1","_deleteArrayElement","element","_insertIntoNode","patch","_insertObjectProperty","newEntry","insertPos","lastProp","insertPos1","_insertArrayElement","position","lastElement","insertPos2","insertPos3","jsonmod"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,SAAS,QAAO,EAAEC,UAAU;QACnD,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,SAASI,GAAG,EAAEC,IAAI;QAAI,OAAOF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;IAAO;;;ICCtGL,oBAAoB,CAAC,GAAG,SA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AA1BvC,UAAU,QAAQ,CAAC,MAAM;gBAG9F,IAAIA,AAA8B,MAA9BA,UAAU,QAAQ,CAAC,MAAM,EAAQ;oBACpC,IAAMmC,YAAYnC,UAAU,KAAK,GAAG;oBACpC,OAAOvB,WAAW,KAAK,CAAC,GAAG0D,aAAaH,MAAM,KAAK,GAAGvD,WAAW,KAAK,CAAC0D;gBACxE;gBAAO,IAAII,AAAa,MAAbA,UAAgB;oBAC1B,IAAMF,aAAYrC,UAAU,QAAQ,CAAC,EAAE,CAAC,KAAK;oBAC7C,OAAOvB,WAAW,KAAK,CAAC,GAAG4D,cAAaL,MAAM,KAAK,GAAG,OAAOvD,WAAW,KAAK,CAAC4D;gBAC/E;gBAAO,IAAIE,YAAYvC,UAAU,QAAQ,CAAC,MAAM,EAAE;oBACjD,IAAMwC,cAAcxC,UAAU,QAAQ,CAACA,UAAU,QAAQ,CAAC,MAAM,GAAG,EAAE;oBACrE,IAAMyC,aAAYD,YAAY,GAAG;oBACjC,OAAO/D,WAAW,KAAK,CAAC,GAAGgE,cAAa,OAAOT,MAAM,KAAK,GAAGvD,WAAW,KAAK,CAACgE;gBAC/E;gBACC,IAAMC,aAAY1C,UAAU,QAAQ,CAACuC,SAAS,CAAC,KAAK;gBACpD,OAAO9D,WAAW,KAAK,CAAC,GAAGiE,cAAaV,MAAM,KAAK,GAAG,OAAOvD,WAAW,KAAK,CAACiE;YAEhF;;;WAlWYxC;;AA4WN,SAASyC,QAAQlE,UAAU;IACjC,OAAO,IAAIyB,gBAAQzB;AACpB;ACnXA,UAAekE"} |
+9
-14
@@ -1,16 +0,11 @@ | ||
| import { replace, ReplacePatch } from "./function/replace.cts"; | ||
| import { remove, DeletePatch } from "./function/delete.cts"; | ||
| import { insert, InsertPatch } from "./function/insert.cts"; | ||
| import { batch, BatchPatch } from "./function/batch.cts"; | ||
| import { formatValue } from "./value-helpers.cts"; | ||
| import { jsonmod, JsonMod } from "./JsonMod.cts"; | ||
| export { ReplacePatch, DeletePatch, InsertPatch, BatchPatch, replace, remove, insert, batch }; | ||
| interface JSONCTS { | ||
| replace: typeof replace; | ||
| remove: typeof remove; | ||
| insert: typeof insert; | ||
| batch: typeof batch; | ||
| } | ||
| export { | ||
| formatValue, | ||
| jsonmod, | ||
| JsonMod, | ||
| }; | ||
| declare const jsoncts: JSONCTS; | ||
| export default jsoncts; | ||
| // New chainable API is the default export | ||
| export default jsonmod; |
+9
-14
@@ -1,16 +0,11 @@ | ||
| import { replace, ReplacePatch } from "./function/replace.mts"; | ||
| import { remove, DeletePatch } from "./function/delete.mts"; | ||
| import { insert, InsertPatch } from "./function/insert.mts"; | ||
| import { batch, BatchPatch } from "./function/batch.mts"; | ||
| import { formatValue } from "./value-helpers.mts"; | ||
| import { jsonmod, JsonMod } from "./JsonMod.mts"; | ||
| export { ReplacePatch, DeletePatch, InsertPatch, BatchPatch, replace, remove, insert, batch }; | ||
| interface JSONCTS { | ||
| replace: typeof replace; | ||
| remove: typeof remove; | ||
| insert: typeof insert; | ||
| batch: typeof batch; | ||
| } | ||
| export { | ||
| formatValue, | ||
| jsonmod, | ||
| JsonMod, | ||
| }; | ||
| declare const jsoncts: JSONCTS; | ||
| export default jsoncts; | ||
| // New chainable API is the default export | ||
| export default jsonmod; |
+298
-305
@@ -0,1 +1,4 @@ | ||
| function formatValue(value) { | ||
| return JSON.stringify(value); | ||
| } | ||
| function _class_call_check(instance, Constructor) { | ||
@@ -492,316 +495,306 @@ if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); | ||
| } | ||
| function replace(sourceText, patches, root) { | ||
| if (!root) { | ||
| var tokenizer = new Tokenizer_Tokenizer(sourceText); | ||
| var tokens = tokenizer.tokenize(); | ||
| var builder = new CSTBuilder_CSTBuilder(tokens); | ||
| root = builder.build(); | ||
| } | ||
| var reverseNodes = patches.map(function(patch) { | ||
| var node = resolvePath(root, patch.path, sourceText); | ||
| return { | ||
| node: node, | ||
| patch: patch | ||
| }; | ||
| }).filter(function(v) { | ||
| return v.node; | ||
| }).sort(function(a, b) { | ||
| return b.node.start - a.node.start; | ||
| }); | ||
| reverseNodes.reduce(function(lastEnd, param) { | ||
| var node = param.node; | ||
| if (node.end > lastEnd) throw new Error("Patch conflict at path: ".concat(node.path)); | ||
| return node.start; | ||
| }, 1 / 0); | ||
| var result = sourceText; | ||
| var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; | ||
| try { | ||
| for(var _iterator = reverseNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ | ||
| var _step_value = _step.value, node = _step_value.node, patch = _step_value.patch; | ||
| result = result.slice(0, node.start) + patch.value + result.slice(node.end); | ||
| } | ||
| } catch (err) { | ||
| _didIteratorError = true; | ||
| _iteratorError = err; | ||
| } finally{ | ||
| try { | ||
| if (!_iteratorNormalCompletion && null != _iterator.return) _iterator.return(); | ||
| } finally{ | ||
| if (_didIteratorError) throw _iteratorError; | ||
| } | ||
| } | ||
| return result; | ||
| function JsonMod_class_call_check(instance, Constructor) { | ||
| if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); | ||
| } | ||
| function remove(sourceText, patches, root) { | ||
| if (!root) { | ||
| var tokenizer = new Tokenizer_Tokenizer(sourceText); | ||
| var tokens = tokenizer.tokenize(); | ||
| var builder = new CSTBuilder_CSTBuilder(tokens); | ||
| root = builder.build(); | ||
| function JsonMod_defineProperties(target, props) { | ||
| for(var i = 0; i < props.length; i++){ | ||
| var descriptor = props[i]; | ||
| descriptor.enumerable = descriptor.enumerable || false; | ||
| descriptor.configurable = true; | ||
| if ("value" in descriptor) descriptor.writable = true; | ||
| Object.defineProperty(target, descriptor.key, descriptor); | ||
| } | ||
| var reverseNodes = patches.map(function(patch) { | ||
| var pathParts = parsePath(patch.path); | ||
| if (0 === pathParts.length) return null; | ||
| var parentPath = pathParts.slice(0, -1); | ||
| var lastKey = pathParts[pathParts.length - 1]; | ||
| var parentNode = parentPath.length > 0 ? resolvePath(root, parentPath, sourceText) : root; | ||
| if (!parentNode) return null; | ||
| return { | ||
| parentNode: parentNode, | ||
| lastKey: lastKey, | ||
| patch: patch | ||
| }; | ||
| }).filter(function(v) { | ||
| return null !== v; | ||
| }).sort(function(a, b) { | ||
| var aStart = getDeleteStart(a.parentNode, a.lastKey, sourceText); | ||
| var bStart = getDeleteStart(b.parentNode, b.lastKey, sourceText); | ||
| return bStart - aStart; | ||
| }); | ||
| var result = sourceText; | ||
| var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; | ||
| try { | ||
| for(var _iterator = reverseNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ | ||
| var _step_value = _step.value, parentNode = _step_value.parentNode, lastKey = _step_value.lastKey; | ||
| result = deleteFromParent(result, parentNode, lastKey, sourceText); | ||
| } | ||
| } catch (err) { | ||
| _didIteratorError = true; | ||
| _iteratorError = err; | ||
| } finally{ | ||
| try { | ||
| if (!_iteratorNormalCompletion && null != _iterator.return) _iterator.return(); | ||
| } finally{ | ||
| if (_didIteratorError) throw _iteratorError; | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| function getDeleteStart(parentNode, key, sourceText) { | ||
| if ("Object" === parentNode.type) { | ||
| var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; | ||
| try { | ||
| for(var _iterator = parentNode.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ | ||
| var prop = _step.value; | ||
| var keyStr = extractString(prop.key, sourceText); | ||
| if (keyStr === key) return prop.key.start; | ||
| } | ||
| } catch (err) { | ||
| _didIteratorError = true; | ||
| _iteratorError = err; | ||
| } finally{ | ||
| try { | ||
| if (!_iteratorNormalCompletion && null != _iterator.return) _iterator.return(); | ||
| } finally{ | ||
| if (_didIteratorError) throw _iteratorError; | ||
| } | ||
| } | ||
| } else if ("Array" === parentNode.type) { | ||
| if ("number" == typeof key && key >= 0 && key < parentNode.elements.length) return parentNode.elements[key].start; | ||
| } | ||
| return 0; | ||
| function JsonMod_create_class(Constructor, protoProps, staticProps) { | ||
| if (protoProps) JsonMod_defineProperties(Constructor.prototype, protoProps); | ||
| if (staticProps) JsonMod_defineProperties(Constructor, staticProps); | ||
| return Constructor; | ||
| } | ||
| function deleteObjectProperty(sourceText, objectNode, key, originalSource) { | ||
| var propIndex = -1; | ||
| for(var i = 0; i < objectNode.properties.length; i++){ | ||
| var keyStr = extractString(objectNode.properties[i].key, originalSource); | ||
| if (keyStr === key) { | ||
| propIndex = i; | ||
| break; | ||
| } | ||
| var JsonMod_JsonMod = /*#__PURE__*/ function() { | ||
| "use strict"; | ||
| function JsonMod(sourceText) { | ||
| JsonMod_class_call_check(this, JsonMod); | ||
| this.sourceText = sourceText; | ||
| this.operations = []; | ||
| } | ||
| if (-1 === propIndex) return sourceText; | ||
| var prop = objectNode.properties[propIndex]; | ||
| var deleteStart = prop.key.start; | ||
| var deleteEnd = prop.value.end; | ||
| if (propIndex < objectNode.properties.length - 1) { | ||
| var pos = deleteEnd; | ||
| while(pos < sourceText.length && (" " === sourceText[pos] || "\t" === sourceText[pos] || "\n" === sourceText[pos] || "\r" === sourceText[pos]))pos++; | ||
| if ("," === sourceText[pos]) { | ||
| deleteEnd = pos + 1; | ||
| while(deleteEnd < sourceText.length && (" " === sourceText[deleteEnd] || "\t" === sourceText[deleteEnd] || "\n" === sourceText[deleteEnd] || "\r" === sourceText[deleteEnd]))deleteEnd++; | ||
| } | ||
| } else if (propIndex > 0) { | ||
| var pos1 = deleteStart - 1; | ||
| while(pos1 >= 0 && (" " === sourceText[pos1] || "\t" === sourceText[pos1] || "\n" === sourceText[pos1] || "\r" === sourceText[pos1]))pos1--; | ||
| if ("," === sourceText[pos1]) { | ||
| pos1--; | ||
| while(pos1 >= 0 && (" " === sourceText[pos1] || "\t" === sourceText[pos1] || "\n" === sourceText[pos1] || "\r" === sourceText[pos1]))pos1--; | ||
| deleteStart = pos1 + 1; | ||
| } | ||
| } | ||
| return sourceText.slice(0, deleteStart) + sourceText.slice(deleteEnd); | ||
| } | ||
| function deleteArrayElement(sourceText, arrayNode, index, originalSource) { | ||
| if ("number" != typeof index || index < 0 || index >= arrayNode.elements.length) return sourceText; | ||
| var element = arrayNode.elements[index]; | ||
| var deleteStart = element.start; | ||
| var deleteEnd = element.end; | ||
| if (index < arrayNode.elements.length - 1) { | ||
| var pos = deleteEnd; | ||
| while(pos < sourceText.length && (" " === sourceText[pos] || "\t" === sourceText[pos] || "\n" === sourceText[pos] || "\r" === sourceText[pos]))pos++; | ||
| if ("," === sourceText[pos]) { | ||
| deleteEnd = pos + 1; | ||
| while(deleteEnd < sourceText.length && (" " === sourceText[deleteEnd] || "\t" === sourceText[deleteEnd] || "\n" === sourceText[deleteEnd] || "\r" === sourceText[deleteEnd]))deleteEnd++; | ||
| } | ||
| } else if (index > 0) { | ||
| var pos1 = deleteStart - 1; | ||
| while(pos1 >= 0 && (" " === sourceText[pos1] || "\t" === sourceText[pos1] || "\n" === sourceText[pos1] || "\r" === sourceText[pos1]))pos1--; | ||
| if ("," === sourceText[pos1]) { | ||
| pos1--; | ||
| while(pos1 >= 0 && (" " === sourceText[pos1] || "\t" === sourceText[pos1] || "\n" === sourceText[pos1] || "\r" === sourceText[pos1]))pos1--; | ||
| deleteStart = pos1 + 1; | ||
| } | ||
| } | ||
| return sourceText.slice(0, deleteStart) + sourceText.slice(deleteEnd); | ||
| } | ||
| function deleteFromParent(sourceText, parentNode, key, originalSource) { | ||
| if ("Object" === parentNode.type) return deleteObjectProperty(sourceText, parentNode, key, originalSource); | ||
| if ("Array" === parentNode.type) return deleteArrayElement(sourceText, parentNode, key, originalSource); | ||
| return sourceText; | ||
| } | ||
| function insert(sourceText, patches, root) { | ||
| if (!root) { | ||
| var tokenizer = new Tokenizer_Tokenizer(sourceText); | ||
| var tokens = tokenizer.tokenize(); | ||
| var builder = new CSTBuilder_CSTBuilder(tokens); | ||
| root = builder.build(); | ||
| } | ||
| var reverseNodes = patches.map(function(patch) { | ||
| var node = resolvePath(root, patch.path, sourceText); | ||
| return { | ||
| node: node, | ||
| patch: patch | ||
| }; | ||
| }).filter(function(v) { | ||
| return v.node; | ||
| }).sort(function(a, b) { | ||
| return b.node.start - a.node.start; | ||
| }); | ||
| var result = sourceText; | ||
| var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; | ||
| try { | ||
| for(var _iterator = reverseNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ | ||
| var _step_value = _step.value, node = _step_value.node, patch = _step_value.patch; | ||
| result = insertIntoNode(result, node, patch, sourceText); | ||
| } | ||
| } catch (err) { | ||
| _didIteratorError = true; | ||
| _iteratorError = err; | ||
| } finally{ | ||
| try { | ||
| if (!_iteratorNormalCompletion && null != _iterator.return) _iterator.return(); | ||
| } finally{ | ||
| if (_didIteratorError) throw _iteratorError; | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| function insertIntoNode(sourceText, node, patch, originalSource) { | ||
| if ("Object" === node.type) return insertObjectProperty(sourceText, node, patch, originalSource); | ||
| if ("Array" === node.type) return insertArrayElement(sourceText, node, patch, originalSource); | ||
| return sourceText; | ||
| } | ||
| function insertObjectProperty(sourceText, objectNode, patch, originalSource) { | ||
| if (!patch.key) throw new Error("Insert into object requires 'key' property"); | ||
| var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; | ||
| try { | ||
| for(var _iterator = objectNode.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ | ||
| var prop = _step.value; | ||
| var keyStr = extractString(prop.key, originalSource); | ||
| if (keyStr === patch.key) throw new Error('Key "'.concat(patch.key, '" already exists in object')); | ||
| } | ||
| } catch (err) { | ||
| _didIteratorError = true; | ||
| _iteratorError = err; | ||
| } finally{ | ||
| try { | ||
| if (!_iteratorNormalCompletion && null != _iterator.return) _iterator.return(); | ||
| } finally{ | ||
| if (_didIteratorError) throw _iteratorError; | ||
| } | ||
| } | ||
| var newEntry = '"'.concat(patch.key, '": ').concat(patch.value); | ||
| if (0 === objectNode.properties.length) { | ||
| var insertPos = objectNode.start + 1; | ||
| return sourceText.slice(0, insertPos) + newEntry + sourceText.slice(insertPos); | ||
| } | ||
| var lastProp = objectNode.properties[objectNode.properties.length - 1]; | ||
| var insertPos1 = lastProp.value.end; | ||
| return sourceText.slice(0, insertPos1) + ", " + newEntry + sourceText.slice(insertPos1); | ||
| } | ||
| function insertArrayElement(sourceText, arrayNode, patch, originalSource) { | ||
| var position = void 0 !== patch.position ? patch.position : arrayNode.elements.length; | ||
| if (position < 0 || position > arrayNode.elements.length) throw new Error("Invalid position ".concat(position, " for array of length ").concat(arrayNode.elements.length)); | ||
| if (0 === arrayNode.elements.length) { | ||
| var insertPos = arrayNode.start + 1; | ||
| return sourceText.slice(0, insertPos) + patch.value + sourceText.slice(insertPos); | ||
| } | ||
| if (0 === position) { | ||
| var insertPos1 = arrayNode.elements[0].start; | ||
| return sourceText.slice(0, insertPos1) + patch.value + ", " + sourceText.slice(insertPos1); | ||
| } | ||
| if (position >= arrayNode.elements.length) { | ||
| var lastElement = arrayNode.elements[arrayNode.elements.length - 1]; | ||
| var insertPos2 = lastElement.end; | ||
| return sourceText.slice(0, insertPos2) + ", " + patch.value + sourceText.slice(insertPos2); | ||
| } | ||
| var insertPos3 = arrayNode.elements[position].start; | ||
| return sourceText.slice(0, insertPos3) + patch.value + ", " + sourceText.slice(insertPos3); | ||
| } | ||
| function batch(sourceText, patches) { | ||
| var tokenizer = new Tokenizer_Tokenizer(sourceText); | ||
| var tokens = tokenizer.tokenize(); | ||
| var builder = new CSTBuilder_CSTBuilder(tokens); | ||
| var root = builder.build(); | ||
| var replacePatches = []; | ||
| var deletePatches = []; | ||
| var insertPatches = []; | ||
| var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; | ||
| try { | ||
| for(var _iterator = patches[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ | ||
| var p = _step.value; | ||
| if (void 0 !== p.value && void 0 === p.key && void 0 === p.position) replacePatches.push({ | ||
| path: p.path, | ||
| value: p.value | ||
| }); | ||
| else if (void 0 === p.value && void 0 === p.key && void 0 === p.position) deletePatches.push({ | ||
| path: p.path | ||
| }); | ||
| else { | ||
| if (void 0 === p.key && void 0 === p.position || void 0 === p.value) continue; | ||
| insertPatches.push(p); | ||
| JsonMod_create_class(JsonMod, [ | ||
| { | ||
| key: "replace", | ||
| value: function(path, value) { | ||
| this.operations.push({ | ||
| type: "replace", | ||
| path: Array.isArray(path) ? path : path, | ||
| value: value | ||
| }); | ||
| return this; | ||
| } | ||
| }, | ||
| { | ||
| key: "delete", | ||
| value: function(path) { | ||
| this.operations.push({ | ||
| type: "delete", | ||
| path: Array.isArray(path) ? path : path | ||
| }); | ||
| return this; | ||
| } | ||
| }, | ||
| { | ||
| key: "remove", | ||
| value: function(path) { | ||
| return this.delete(path); | ||
| } | ||
| }, | ||
| { | ||
| key: "insert", | ||
| value: function(path, keyOrPosition, value) { | ||
| this.operations.push({ | ||
| type: "insert", | ||
| path: Array.isArray(path) ? path : path, | ||
| keyOrPosition: keyOrPosition, | ||
| value: value | ||
| }); | ||
| return this; | ||
| } | ||
| }, | ||
| { | ||
| key: "apply", | ||
| value: function() { | ||
| if (0 === this.operations.length) return this.sourceText; | ||
| var result = this.sourceText; | ||
| var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; | ||
| try { | ||
| for(var _iterator = this.operations[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ | ||
| var op = _step.value; | ||
| switch(op.type){ | ||
| case "replace": | ||
| result = this._applySingleReplace(result, op); | ||
| break; | ||
| case "delete": | ||
| result = this._applySingleDelete(result, op); | ||
| break; | ||
| case "insert": | ||
| result = this._applySingleInsert(result, op); | ||
| break; | ||
| } | ||
| } | ||
| } catch (err) { | ||
| _didIteratorError = true; | ||
| _iteratorError = err; | ||
| } finally{ | ||
| try { | ||
| if (!_iteratorNormalCompletion && null != _iterator.return) _iterator.return(); | ||
| } finally{ | ||
| if (_didIteratorError) throw _iteratorError; | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
| }, | ||
| { | ||
| key: "_applySingleReplace", | ||
| value: function(sourceText, op) { | ||
| var tokenizer = new Tokenizer_Tokenizer(sourceText); | ||
| var tokens = tokenizer.tokenize(); | ||
| var builder = new CSTBuilder_CSTBuilder(tokens); | ||
| var root = builder.build(); | ||
| var node = resolvePath(root, op.path, sourceText); | ||
| if (!node) return sourceText; | ||
| return sourceText.slice(0, node.start) + op.value + sourceText.slice(node.end); | ||
| } | ||
| }, | ||
| { | ||
| key: "_applySingleDelete", | ||
| value: function(sourceText, op) { | ||
| var tokenizer = new Tokenizer_Tokenizer(sourceText); | ||
| var tokens = tokenizer.tokenize(); | ||
| var builder = new CSTBuilder_CSTBuilder(tokens); | ||
| var root = builder.build(); | ||
| var pathParts = parsePath(op.path); | ||
| if (0 === pathParts.length) return sourceText; | ||
| var parentPath = pathParts.slice(0, -1); | ||
| var lastKey = pathParts[pathParts.length - 1]; | ||
| var parentNode = parentPath.length > 0 ? resolvePath(root, parentPath, sourceText) : root; | ||
| if (!parentNode) return sourceText; | ||
| return this._deleteFromParent(sourceText, parentNode, lastKey, sourceText); | ||
| } | ||
| }, | ||
| { | ||
| key: "_applySingleInsert", | ||
| value: function(sourceText, op) { | ||
| var tokenizer = new Tokenizer_Tokenizer(sourceText); | ||
| var tokens = tokenizer.tokenize(); | ||
| var builder = new CSTBuilder_CSTBuilder(tokens); | ||
| var root = builder.build(); | ||
| var node = resolvePath(root, op.path, sourceText); | ||
| if (!node) return sourceText; | ||
| return this._insertIntoNode(sourceText, node, op, sourceText); | ||
| } | ||
| }, | ||
| { | ||
| key: "_getDeleteStart", | ||
| value: function(parentNode, key, sourceText) { | ||
| if ("Object" === parentNode.type) { | ||
| var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; | ||
| try { | ||
| for(var _iterator = parentNode.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ | ||
| var prop = _step.value; | ||
| var keyStr = extractString(prop.key, sourceText); | ||
| if (keyStr === key) return prop.key.start; | ||
| } | ||
| } catch (err) { | ||
| _didIteratorError = true; | ||
| _iteratorError = err; | ||
| } finally{ | ||
| try { | ||
| if (!_iteratorNormalCompletion && null != _iterator.return) _iterator.return(); | ||
| } finally{ | ||
| if (_didIteratorError) throw _iteratorError; | ||
| } | ||
| } | ||
| } else if ("Array" === parentNode.type) { | ||
| if ("number" == typeof key && key >= 0 && key < parentNode.elements.length) return parentNode.elements[key].start; | ||
| } | ||
| return 0; | ||
| } | ||
| }, | ||
| { | ||
| key: "_deleteFromParent", | ||
| value: function(sourceText, parentNode, key, originalSource) { | ||
| if ("Object" === parentNode.type) return this._deleteObjectProperty(sourceText, parentNode, key, originalSource); | ||
| if ("Array" === parentNode.type) return this._deleteArrayElement(sourceText, parentNode, key, originalSource); | ||
| return sourceText; | ||
| } | ||
| }, | ||
| { | ||
| key: "_deleteObjectProperty", | ||
| value: function(sourceText, objectNode, key, originalSource) { | ||
| var propIndex = -1; | ||
| for(var i = 0; i < objectNode.properties.length; i++){ | ||
| var keyStr = extractString(objectNode.properties[i].key, originalSource); | ||
| if (keyStr === key) { | ||
| propIndex = i; | ||
| break; | ||
| } | ||
| } | ||
| if (-1 === propIndex) return sourceText; | ||
| var prop = objectNode.properties[propIndex]; | ||
| var deleteStart = prop.key.start; | ||
| var deleteEnd = prop.value.end; | ||
| if (propIndex < objectNode.properties.length - 1) { | ||
| var pos = deleteEnd; | ||
| while(pos < sourceText.length && (" " === sourceText[pos] || "\t" === sourceText[pos] || "\n" === sourceText[pos] || "\r" === sourceText[pos]))pos++; | ||
| if ("," === sourceText[pos]) { | ||
| deleteEnd = pos + 1; | ||
| while(deleteEnd < sourceText.length && (" " === sourceText[deleteEnd] || "\t" === sourceText[deleteEnd] || "\n" === sourceText[deleteEnd] || "\r" === sourceText[deleteEnd]))deleteEnd++; | ||
| } | ||
| } else if (propIndex > 0) { | ||
| var pos1 = deleteStart - 1; | ||
| while(pos1 >= 0 && (" " === sourceText[pos1] || "\t" === sourceText[pos1] || "\n" === sourceText[pos1] || "\r" === sourceText[pos1]))pos1--; | ||
| if ("," === sourceText[pos1]) { | ||
| pos1--; | ||
| while(pos1 >= 0 && (" " === sourceText[pos1] || "\t" === sourceText[pos1] || "\n" === sourceText[pos1] || "\r" === sourceText[pos1]))pos1--; | ||
| deleteStart = pos1 + 1; | ||
| } | ||
| } | ||
| return sourceText.slice(0, deleteStart) + sourceText.slice(deleteEnd); | ||
| } | ||
| }, | ||
| { | ||
| key: "_deleteArrayElement", | ||
| value: function(sourceText, arrayNode, index, originalSource) { | ||
| if ("number" != typeof index || index < 0 || index >= arrayNode.elements.length) return sourceText; | ||
| var element = arrayNode.elements[index]; | ||
| var deleteStart = element.start; | ||
| var deleteEnd = element.end; | ||
| if (index < arrayNode.elements.length - 1) { | ||
| var pos = deleteEnd; | ||
| while(pos < sourceText.length && (" " === sourceText[pos] || "\t" === sourceText[pos] || "\n" === sourceText[pos] || "\r" === sourceText[pos]))pos++; | ||
| if ("," === sourceText[pos]) { | ||
| deleteEnd = pos + 1; | ||
| while(deleteEnd < sourceText.length && (" " === sourceText[deleteEnd] || "\t" === sourceText[deleteEnd] || "\n" === sourceText[deleteEnd] || "\r" === sourceText[deleteEnd]))deleteEnd++; | ||
| } | ||
| } else if (index > 0) { | ||
| var pos1 = deleteStart - 1; | ||
| while(pos1 >= 0 && (" " === sourceText[pos1] || "\t" === sourceText[pos1] || "\n" === sourceText[pos1] || "\r" === sourceText[pos1]))pos1--; | ||
| if ("," === sourceText[pos1]) { | ||
| pos1--; | ||
| while(pos1 >= 0 && (" " === sourceText[pos1] || "\t" === sourceText[pos1] || "\n" === sourceText[pos1] || "\r" === sourceText[pos1]))pos1--; | ||
| deleteStart = pos1 + 1; | ||
| } | ||
| } | ||
| return sourceText.slice(0, deleteStart) + sourceText.slice(deleteEnd); | ||
| } | ||
| }, | ||
| { | ||
| key: "_insertIntoNode", | ||
| value: function(sourceText, node, patch, originalSource) { | ||
| if ("Object" === node.type) return this._insertObjectProperty(sourceText, node, patch, originalSource); | ||
| if ("Array" === node.type) return this._insertArrayElement(sourceText, node, patch, originalSource); | ||
| return sourceText; | ||
| } | ||
| }, | ||
| { | ||
| key: "_insertObjectProperty", | ||
| value: function(sourceText, objectNode, patch, originalSource) { | ||
| var key = patch.keyOrPosition; | ||
| if ("string" != typeof key) throw new Error("Insert into object requires a string key"); | ||
| var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0; | ||
| try { | ||
| for(var _iterator = objectNode.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){ | ||
| var prop = _step.value; | ||
| var keyStr = extractString(prop.key, originalSource); | ||
| if (keyStr === key) throw new Error('Key "'.concat(key, '" already exists in object')); | ||
| } | ||
| } catch (err) { | ||
| _didIteratorError = true; | ||
| _iteratorError = err; | ||
| } finally{ | ||
| try { | ||
| if (!_iteratorNormalCompletion && null != _iterator.return) _iterator.return(); | ||
| } finally{ | ||
| if (_didIteratorError) throw _iteratorError; | ||
| } | ||
| } | ||
| var newEntry = '"'.concat(key, '": ').concat(patch.value); | ||
| if (0 === objectNode.properties.length) { | ||
| var insertPos = objectNode.start + 1; | ||
| return sourceText.slice(0, insertPos) + newEntry + sourceText.slice(insertPos); | ||
| } | ||
| var lastProp = objectNode.properties[objectNode.properties.length - 1]; | ||
| var insertPos1 = lastProp.value.end; | ||
| return sourceText.slice(0, insertPos1) + ", " + newEntry + sourceText.slice(insertPos1); | ||
| } | ||
| }, | ||
| { | ||
| key: "_insertArrayElement", | ||
| value: function(sourceText, arrayNode, patch, originalSource) { | ||
| var position = "number" == typeof patch.keyOrPosition ? patch.keyOrPosition : arrayNode.elements.length; | ||
| if (position < 0 || position > arrayNode.elements.length) throw new Error("Invalid position ".concat(position, " for array of length ").concat(arrayNode.elements.length)); | ||
| if (0 === arrayNode.elements.length) { | ||
| var insertPos = arrayNode.start + 1; | ||
| return sourceText.slice(0, insertPos) + patch.value + sourceText.slice(insertPos); | ||
| } | ||
| if (0 === position) { | ||
| var insertPos1 = arrayNode.elements[0].start; | ||
| return sourceText.slice(0, insertPos1) + patch.value + ", " + sourceText.slice(insertPos1); | ||
| } | ||
| if (position >= arrayNode.elements.length) { | ||
| var lastElement = arrayNode.elements[arrayNode.elements.length - 1]; | ||
| var insertPos2 = lastElement.end; | ||
| return sourceText.slice(0, insertPos2) + ", " + patch.value + sourceText.slice(insertPos2); | ||
| } | ||
| var insertPos3 = arrayNode.elements[position].start; | ||
| return sourceText.slice(0, insertPos3) + patch.value + ", " + sourceText.slice(insertPos3); | ||
| } | ||
| } | ||
| } catch (err) { | ||
| _didIteratorError = true; | ||
| _iteratorError = err; | ||
| } finally{ | ||
| try { | ||
| if (!_iteratorNormalCompletion && null != _iterator.return) _iterator.return(); | ||
| } finally{ | ||
| if (_didIteratorError) throw _iteratorError; | ||
| } | ||
| } | ||
| var result = sourceText; | ||
| if (replacePatches.length > 0) result = replace(result, replacePatches, root); | ||
| if (insertPatches.length > 0) { | ||
| var currentRoot = replacePatches.length > 0 ? null : root; | ||
| result = insert(result, insertPatches, currentRoot); | ||
| } | ||
| if (deletePatches.length > 0) { | ||
| var currentRoot1 = replacePatches.length > 0 || insertPatches.length > 0 ? null : root; | ||
| result = remove(result, deletePatches, currentRoot1); | ||
| } | ||
| return result; | ||
| ]); | ||
| return JsonMod; | ||
| }(); | ||
| function jsonmod(sourceText) { | ||
| return new JsonMod_JsonMod(sourceText); | ||
| } | ||
| var jsoncst = { | ||
| replace: replace, | ||
| remove: remove, | ||
| insert: insert, | ||
| batch: batch | ||
| }; | ||
| var src = jsoncst; | ||
| export { batch, src as default, insert, remove, replace }; | ||
| var src = jsonmod; | ||
| export { JsonMod_JsonMod as JsonMod, src as default, formatValue, jsonmod }; | ||
| //# sourceMappingURL=index.mjs.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"esm/index.mjs","sources":["../../src/Tokenizer.js","../../src/CSTBuilder.js","../../src/helper.js","../../src/PathResolver.js","../../src/function/replace.js","../../src/function/delete.js","../../src/function/insert.js","../../src/function/batch.js","../../src/index.js"],"sourcesContent":["class Tokenizer {\n\tconstructor(text) {\n\t\tthis.text = text;\n\t\tthis.pos = 0;\n\t\tthis.tokens = [];\n\t}\n\n\ttokenize() {\n\t\twhile (this.pos < this.text.length) {\n\t\t\tconst ch = this.text[this.pos];\n\n\t\t\tif (this.isWhitespace(ch)) {\n\t\t\t\tthis.readWhitespace();\n\t\t\t} else if (ch === '\"') {\n\t\t\t\tthis.readString();\n\t\t\t} else if (this.isNumberStart(ch)) {\n\t\t\t\tthis.readNumber();\n\t\t\t} else if (this.isAlpha(ch)) {\n\t\t\t\tthis.readKeyword();\n\t\t\t} else {\n\t\t\t\tthis.readPunctuationOrComment();\n\t\t\t}\n\t\t}\n\n\t\treturn this.tokens;\n\t}\n\n\t// ---------- helpers ----------\n\n\tisWhitespace(ch) {\n\t\treturn ch === \" \" || ch === \"\\n\" || ch === \"\\r\" || ch === \"\\t\";\n\t}\n\n\tisNumberStart(ch) {\n\t\treturn ch === \"-\" || (ch >= \"0\" && ch <= \"9\");\n\t}\n\n\tisAlpha(ch) {\n\t\treturn (ch >= \"a\" && ch <= \"z\") || (ch >= \"A\" && ch <= \"Z\");\n\t}\n\n\t// ---------- readers ----------\n\n\treadWhitespace() {\n\t\tconst start = this.pos;\n\t\twhile (this.pos < this.text.length && this.isWhitespace(this.text[this.pos])) {\n\t\t\tthis.pos++;\n\t\t}\n\t\tthis.tokens.push({\n\t\t\ttype: \"whitespace\",\n\t\t\tstart,\n\t\t\tend: this.pos,\n\t\t});\n\t}\n\n\treadString() {\n\t\tconst start = this.pos;\n\t\tthis.pos++; // skip opening \"\n\n\t\twhile (this.pos < this.text.length) {\n\t\t\tconst ch = this.text[this.pos];\n\n\t\t\tif (ch === \"\\\\\") {\n\t\t\t\t// skip escaped char\n\t\t\t\tthis.pos += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (ch === '\"') {\n\t\t\t\tthis.pos++; // closing \"\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tthis.pos++;\n\t\t}\n\n\t\tthis.tokens.push({\n\t\t\ttype: \"string\",\n\t\t\tstart,\n\t\t\tend: this.pos,\n\t\t});\n\t}\n\n\treadNumber() {\n\t\tconst start = this.pos;\n\n\t\tif (this.text[this.pos] === \"-\") this.pos++;\n\n\t\twhile (this.pos < this.text.length && this.isDigit(this.text[this.pos])) {\n\t\t\tthis.pos++;\n\t\t}\n\n\t\tif (this.text[this.pos] === \".\") {\n\t\t\tthis.pos++;\n\t\t\twhile (this.pos < this.text.length && this.isDigit(this.text[this.pos])) {\n\t\t\t\tthis.pos++;\n\t\t\t}\n\t\t}\n\n\t\tif (this.text[this.pos] === \"e\" || this.text[this.pos] === \"E\") {\n\t\t\tthis.pos++;\n\t\t\tif (this.text[this.pos] === \"+\" || this.text[this.pos] === \"-\") {\n\t\t\t\tthis.pos++;\n\t\t\t}\n\t\t\twhile (this.pos < this.text.length && this.isDigit(this.text[this.pos])) {\n\t\t\t\tthis.pos++;\n\t\t\t}\n\t\t}\n\n\t\tthis.tokens.push({\n\t\t\ttype: \"number\",\n\t\t\tstart,\n\t\t\tend: this.pos,\n\t\t});\n\t}\n\n\treadKeyword() {\n\t\tconst start = this.pos;\n\n\t\twhile (this.pos < this.text.length && this.isAlpha(this.text[this.pos])) {\n\t\t\tthis.pos++;\n\t\t}\n\n\t\tconst word = this.text.slice(start, this.pos);\n\n\t\tlet type;\n\t\tif (word === \"true\" || word === \"false\") {\n\t\t\ttype = \"boolean\";\n\t\t} else if (word === \"null\") {\n\t\t\ttype = \"null\";\n\t\t} else {\n\t\t\tthrow new Error(`Unexpected identifier: ${word}`);\n\t\t}\n\n\t\tthis.tokens.push({\n\t\t\ttype,\n\t\t\tstart,\n\t\t\tend: this.pos,\n\t\t});\n\t}\n\n\treadPunctuationOrComment() {\n\t\tconst start = this.pos;\n\t\tconst ch = this.text[this.pos];\n\n\t\t// line comment //\n\t\tif (ch === \"/\" && this.text[this.pos + 1] === \"/\") {\n\t\t\tthis.pos += 2;\n\t\t\twhile (this.pos < this.text.length && this.text[this.pos] !== \"\\n\") {\n\t\t\t\tthis.pos++;\n\t\t\t}\n\t\t\tthis.tokens.push({\n\t\t\t\ttype: \"comment\",\n\t\t\t\tstart,\n\t\t\t\tend: this.pos,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\t// block comment /* */\n\t\tif (ch === \"/\" && this.text[this.pos + 1] === \"*\") {\n\t\t\tthis.pos += 2;\n\t\t\twhile (this.pos < this.text.length && !(this.text[this.pos] === \"*\" && this.text[this.pos + 1] === \"/\")) {\n\t\t\t\tthis.pos++;\n\t\t\t}\n\t\t\tthis.pos += 2; // skip */\n\t\t\tthis.tokens.push({\n\t\t\t\ttype: \"comment\",\n\t\t\t\tstart,\n\t\t\t\tend: this.pos,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\t// punctuation\n\t\tthis.pos++;\n\n\t\tconst map = {\n\t\t\t\"{\": \"braceL\",\n\t\t\t\"}\": \"braceR\",\n\t\t\t\"[\": \"bracketL\",\n\t\t\t\"]\": \"bracketR\",\n\t\t\t\":\": \"colon\",\n\t\t\t\",\": \"comma\",\n\t\t};\n\n\t\tconst type = map[ch];\n\t\tif (!type) {\n\t\t\tthrow new Error(`Unexpected character: ${ch} at ${start}`);\n\t\t}\n\n\t\tthis.tokens.push({\n\t\t\ttype,\n\t\t\tstart,\n\t\t\tend: this.pos,\n\t\t});\n\t}\n\n\tisDigit(ch) {\n\t\treturn ch >= \"0\" && ch <= \"9\";\n\t}\n}\n\nexport { Tokenizer };\n","export class CSTBuilder {\n\tconstructor(tokens) {\n\t\tthis.tokens = tokens;\n\t\tthis.pos = 0;\n\t}\n\n\tbuild() {\n\t\tthis.skipTrivia();\n\t\tconst node = this.parseValue();\n\t\tthis.skipTrivia();\n\t\treturn node;\n\t}\n\n\tcurrent() {\n\t\treturn this.tokens[this.pos];\n\t}\n\n\tskipTrivia() {\n\t\twhile (this.pos < this.tokens.length && (this.tokens[this.pos].type === \"whitespace\" || this.tokens[this.pos].type === \"comment\")) {\n\t\t\tthis.pos++;\n\t\t}\n\t}\n\n\tconsume(type) {\n\t\tconst token = this.current();\n\t\tif (!token || token.type !== type) {\n\t\t\tthrow new Error(`Expected ${type}, got ${token && token.type}`);\n\t\t}\n\t\tthis.pos++;\n\t\treturn token;\n\t}\n\n\tparseValue() {\n\t\tthis.skipTrivia();\n\t\tconst token = this.current();\n\n\t\tif (!token) {\n\t\t\tthrow new Error(\"Unexpected end of input\");\n\t\t}\n\n\t\tswitch (token.type) {\n\t\t\tcase \"braceL\":\n\t\t\t\treturn this.parseObject();\n\t\t\tcase \"bracketL\":\n\t\t\t\treturn this.parseArray();\n\t\t\tcase \"string\":\n\t\t\t\treturn this.parsePrimitive(\"String\");\n\t\t\tcase \"number\":\n\t\t\t\treturn this.parsePrimitive(\"Number\");\n\t\t\tcase \"boolean\":\n\t\t\t\treturn this.parsePrimitive(\"Boolean\");\n\t\t\tcase \"null\":\n\t\t\t\treturn this.parsePrimitive(\"Null\");\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unexpected token: ${token.type}`);\n\t\t}\n\t}\n\n\tparsePrimitive(type) {\n\t\tconst token = this.current();\n\t\tthis.pos++;\n\t\treturn {\n\t\t\ttype,\n\t\t\tstart: token.start,\n\t\t\tend: token.end,\n\t\t};\n\t}\n\n\tparseObject() {\n\t\tconst startToken = this.consume(\"braceL\");\n\t\tconst properties = [];\n\n\t\tthis.skipTrivia();\n\n\t\twhile (this.current() && this.current().type !== \"braceR\") {\n\t\t\tconst keyToken = this.consume(\"string\");\n\t\t\tconst keyNode = {\n\t\t\t\ttype: \"String\",\n\t\t\t\tstart: keyToken.start,\n\t\t\t\tend: keyToken.end,\n\t\t\t};\n\n\t\t\tthis.skipTrivia();\n\t\t\tthis.consume(\"colon\");\n\t\t\tthis.skipTrivia();\n\n\t\t\tconst valueNode = this.parseValue();\n\n\t\t\tproperties.push({ key: keyNode, value: valueNode });\n\n\t\t\tthis.skipTrivia();\n\t\t\tif (this.current() && this.current().type === \"comma\") {\n\t\t\t\tthis.pos++;\n\t\t\t\tthis.skipTrivia();\n\t\t\t}\n\t\t}\n\n\t\tconst endToken = this.consume(\"braceR\");\n\n\t\treturn {\n\t\t\ttype: \"Object\",\n\t\t\tstart: startToken.start,\n\t\t\tend: endToken.end,\n\t\t\tproperties,\n\t\t};\n\t}\n\n\tparseArray() {\n\t\tconst startToken = this.consume(\"bracketL\");\n\t\tconst elements = [];\n\n\t\tthis.skipTrivia();\n\n\t\twhile (this.current() && this.current().type !== \"bracketR\") {\n\t\t\tconst valueNode = this.parseValue();\n\t\t\telements.push(valueNode);\n\n\t\t\tthis.skipTrivia();\n\t\t\tif (this.current() && this.current().type === \"comma\") {\n\t\t\t\tthis.pos++;\n\t\t\t\tthis.skipTrivia();\n\t\t\t}\n\t\t}\n\n\t\tconst endToken = this.consume(\"bracketR\");\n\n\t\treturn {\n\t\t\ttype: \"Array\",\n\t\t\tstart: startToken.start,\n\t\t\tend: endToken.end,\n\t\t\telements,\n\t\t};\n\t}\n}\n","function unescapeString(str) {\n\treturn str.replace(/\\\\(.)/g, (_, ch) => {\n\t\tswitch (ch) {\n\t\t\tcase '\"':\n\t\t\t\treturn '\"';\n\t\t\tcase \"\\\\\":\n\t\t\t\treturn \"\\\\\";\n\t\t\tcase \"/\":\n\t\t\t\treturn \"/\";\n\t\t\tcase \"b\":\n\t\t\t\treturn \"\\b\";\n\t\t\tcase \"f\":\n\t\t\t\treturn \"\\f\";\n\t\t\tcase \"n\":\n\t\t\t\treturn \"\\n\";\n\t\t\tcase \"r\":\n\t\t\t\treturn \"\\r\";\n\t\t\tcase \"t\":\n\t\t\t\treturn \"\\t\";\n\t\t\tdefault:\n\t\t\t\treturn ch; // \\uXXXX 可后续增强\n\t\t}\n\t});\n}\n\nexport function extractString(stringNode, sourceText) {\n\t// sourceText 是完整 JSON 文本\n\t// stringNode.start / end 覆盖包含引号\n\tconst raw = sourceText.slice(stringNode.start + 1, stringNode.end - 1);\n\treturn unescapeString(raw);\n}\n\n/**\n *\n * @param {string} path\n * @returns\n */\nexport function parsePath(path) {\n\tif (path.startsWith(\"/\")) {\n\t\treturn parseJSONPointer(path);\n\t}\n\treturn parseDotPath(path);\n}\n\n/**\n *\n * @param {string} path\n * @returns\n */\nfunction parseDotPath(path) {\n\tconst result = [];\n\tlet i = 0;\n\n\twhile (i < path.length) {\n\t\tconst ch = path[i];\n\n\t\t// skip dot\n\t\tif (ch === \".\") {\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// array index: [123]\n\t\tif (ch === \"[\") {\n\t\t\ti++;\n\t\t\tlet num = \"\";\n\t\t\twhile (i < path.length && path[i] !== \"]\") {\n\t\t\t\tnum += path[i++];\n\t\t\t}\n\t\t\ti++; // skip ]\n\t\t\tresult.push(Number(num));\n\t\t\tcontinue;\n\t\t}\n\n\t\t// identifier\n\t\tlet name = \"\";\n\t\twhile (i < path.length && /[a-zA-Z0-9_$]/.test(path[i])) {\n\t\t\tname += path[i++];\n\t\t}\n\t\tresult.push(name);\n\t}\n\n\treturn result;\n}\n\n/**\n *\n * @param {string} pointer\n * @returns\n */\nfunction parseJSONPointer(pointer) {\n\tif (pointer === \"\") return [];\n\n\tif (pointer[0] !== \"/\") {\n\t\tthrow new Error(\"Invalid JSON Pointer\");\n\t}\n\n\treturn pointer\n\t\t.slice(1)\n\t\t.split(\"/\")\n\t\t.map((segment) => segment.replace(/~1/g, \"/\").replace(/~0/g, \"~\"))\n\t\t.map((seg) => {\n\t\t\treturn /^\\d+$/.test(seg) ? Number(seg) : seg;\n\t\t});\n}\n","import { extractString } from \"./helper.js\";\n\nexport function resolvePath(root, path, sourceText) {\n\tconst parts = Array.isArray(path) ? path : parsePath(path);\n\tlet node = root;\n\n\tfor (const part of parts) {\n\t\tif (!node) return null;\n\n\t\tif (node.type === \"Object\") {\n\t\t\tnode = resolveObjectProperty(node, part, sourceText);\n\t\t} else if (node.type === \"Array\") {\n\t\t\tnode = resolveArrayElement(node, part);\n\t\t} else {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\treturn node;\n}\n\n/**\n *\n * @param {import('./CSTBuilder.js').NodeObject} objectNode\n * @param {string} key\n * @param {string} sourceText\n * @returns {import('./CSTBuilder.js').Node | null}\n */\nfunction resolveObjectProperty(objectNode, key, sourceText) {\n\tif (typeof key !== \"string\") return null;\n\n\tfor (const prop of objectNode.properties) {\n\t\tconst name = extractString(prop.key, sourceText);\n\t\tif (name === key) {\n\t\t\treturn prop.value;\n\t\t}\n\t}\n\treturn null;\n}\n\n/**\n *\n * @param {import('./CSTBuilder.js').NodeArray} arrayNode\n * @param {number} index\n * @returns {import('./CSTBuilder.js').Node | null}\n */\nfunction resolveArrayElement(arrayNode, index) {\n\tif (typeof index !== \"number\") return null;\n\treturn arrayNode.elements[index] || null;\n}\n\nfunction parsePath(path) {\n\tif (path.startsWith(\"/\")) {\n\t\treturn parseJSONPointer(path);\n\t}\n\treturn parseDotPath(path);\n}\n\nfunction parseDotPath(path) {\n\tconst result = [];\n\tlet i = 0;\n\n\twhile (i < path.length) {\n\t\tconst ch = path[i];\n\n\t\t// skip dot\n\t\tif (ch === \".\") {\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// array index: [123]\n\t\tif (ch === \"[\") {\n\t\t\ti++;\n\t\t\tlet num = \"\";\n\t\t\twhile (i < path.length && path[i] !== \"]\") {\n\t\t\t\tnum += path[i++];\n\t\t\t}\n\t\t\ti++; // skip ]\n\t\t\tresult.push(Number(num));\n\t\t\tcontinue;\n\t\t}\n\n\t\t// identifier\n\t\tlet name = \"\";\n\t\twhile (i < path.length && /[a-zA-Z0-9_$]/.test(path[i])) {\n\t\t\tname += path[i++];\n\t\t}\n\t\tresult.push(name);\n\t}\n\n\treturn result;\n}\n\nfunction parseJSONPointer(pointer) {\n\tif (pointer === \"\") return [];\n\n\tif (pointer[0] !== \"/\") {\n\t\tthrow new Error(\"Invalid JSON Pointer\");\n\t}\n\n\treturn pointer\n\t\t.slice(1)\n\t\t.split(\"/\")\n\t\t.map((segment) => segment.replace(/~1/g, \"/\").replace(/~0/g, \"~\"))\n\t\t.map((seg) => {\n\t\t\treturn /^\\d+$/.test(seg) ? Number(seg) : seg;\n\t\t});\n}\n","import { Tokenizer } from \"../Tokenizer.js\";\nimport { CSTBuilder } from \"../CSTBuilder.js\";\nimport { resolvePath } from \"../PathResolver.js\";\n\nexport function replace(sourceText, patches, root) {\n\tif (!root) {\n\t\tconst tokenizer = new Tokenizer(sourceText);\n\t\tconst tokens = tokenizer.tokenize();\n\n\t\tconst builder = new CSTBuilder(tokens);\n\t\troot = builder.build();\n\t}\n\n\t// 倒叙替换\n\tconst reverseNodes = patches\n\t\t.map((patch) => {\n\t\t\tconst node = resolvePath(root, patch.path, sourceText);\n\n\t\t\treturn {\n\t\t\t\tnode,\n\t\t\t\tpatch,\n\t\t\t};\n\t\t})\n\t\t.filter((v) => v.node)\n\t\t.sort((a, b) => b.node.start - a.node.start);\n\n\t// 确保不会冲突\n\treverseNodes.reduce((lastEnd, { node }) => {\n\t\tif (node.end > lastEnd) {\n\t\t\tthrow new Error(`Patch conflict at path: ${node.path}`);\n\t\t}\n\n\t\treturn node.start;\n\t}, Infinity);\n\n\tlet result = sourceText;\n\n\tfor (const { node, patch } of reverseNodes) {\n\t\tresult = result.slice(0, node.start) + patch.value + result.slice(node.end);\n\t}\n\n\treturn result;\n}\n","import { Tokenizer } from \"../Tokenizer.js\";\nimport { CSTBuilder } from \"../CSTBuilder.js\";\nimport { resolvePath } from \"../PathResolver.js\";\nimport { parsePath, extractString } from \"../helper.js\";\n\nexport function remove(sourceText, patches, root) {\n\tif (!root) {\n\t\tconst tokenizer = new Tokenizer(sourceText);\n\t\tconst tokens = tokenizer.tokenize();\n\n\t\tconst builder = new CSTBuilder(tokens);\n\t\troot = builder.build();\n\t}\n\n\t// 倒叙删除\n\tconst reverseNodes = patches\n\t\t.map((patch) => {\n\t\t\tconst pathParts = parsePath(patch.path);\n\t\t\tif (pathParts.length === 0) {\n\t\t\t\treturn null; // Cannot delete root\n\t\t\t}\n\n\t\t\t// Find parent and the item to delete\n\t\t\tconst parentPath = pathParts.slice(0, -1);\n\t\t\tconst lastKey = pathParts[pathParts.length - 1];\n\t\t\tconst parentNode = parentPath.length > 0 ? resolvePath(root, parentPath, sourceText) : root;\n\n\t\t\tif (!parentNode) return null;\n\n\t\t\treturn {\n\t\t\t\tparentNode,\n\t\t\t\tlastKey,\n\t\t\t\tpatch,\n\t\t\t};\n\t\t})\n\t\t.filter((v) => v !== null)\n\t\t.sort((a, b) => {\n\t\t\t// Sort by the start position of what we're deleting\n\t\t\tconst aStart = getDeleteStart(a.parentNode, a.lastKey, sourceText);\n\t\t\tconst bStart = getDeleteStart(b.parentNode, b.lastKey, sourceText);\n\t\t\treturn bStart - aStart;\n\t\t});\n\n\tlet result = sourceText;\n\n\tfor (const { parentNode, lastKey } of reverseNodes) {\n\t\tresult = deleteFromParent(result, parentNode, lastKey, sourceText);\n\t}\n\n\treturn result;\n}\n\nfunction getDeleteStart(parentNode, key, sourceText) {\n\tif (parentNode.type === \"Object\") {\n\t\tfor (const prop of parentNode.properties) {\n\t\t\tconst keyStr = extractString(prop.key, sourceText);\n\t\t\tif (keyStr === key) {\n\t\t\t\treturn prop.key.start;\n\t\t\t}\n\t\t}\n\t} else if (parentNode.type === \"Array\") {\n\t\tif (typeof key === \"number\" && key >= 0 && key < parentNode.elements.length) {\n\t\t\treturn parentNode.elements[key].start;\n\t\t}\n\t}\n\treturn 0;\n}\n\nfunction deleteObjectProperty(sourceText, objectNode, key, originalSource) {\n\tlet propIndex = -1;\n\tfor (let i = 0; i < objectNode.properties.length; i++) {\n\t\tconst keyStr = extractString(objectNode.properties[i].key, originalSource);\n\t\tif (keyStr === key) {\n\t\t\tpropIndex = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (propIndex === -1) return sourceText;\n\n\tconst prop = objectNode.properties[propIndex];\n\tlet deleteStart = prop.key.start;\n\tlet deleteEnd = prop.value.end;\n\n\t// Handle comma and whitespace\n\tif (propIndex < objectNode.properties.length - 1) {\n\t\t// Not the last property, look for comma after\n\t\tlet pos = deleteEnd;\n\t\twhile (\n\t\t\tpos < sourceText.length &&\n\t\t\t(sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")\n\t\t) {\n\t\t\tpos++;\n\t\t}\n\t\tif (sourceText[pos] === \",\") {\n\t\t\tdeleteEnd = pos + 1;\n\t\t\t// Skip trailing whitespace after comma\n\t\t\twhile (\n\t\t\t\tdeleteEnd < sourceText.length &&\n\t\t\t\t(sourceText[deleteEnd] === \" \" ||\n\t\t\t\t\tsourceText[deleteEnd] === \"\\t\" ||\n\t\t\t\t\tsourceText[deleteEnd] === \"\\n\" ||\n\t\t\t\t\tsourceText[deleteEnd] === \"\\r\")\n\t\t\t) {\n\t\t\t\tdeleteEnd++;\n\t\t\t}\n\t\t}\n\t} else if (propIndex > 0) {\n\t\t// Last property, look for comma before (and whitespace before the comma)\n\t\tlet pos = deleteStart - 1;\n\t\t// Skip whitespace before the property\n\t\twhile (pos >= 0 && (sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")) {\n\t\t\tpos--;\n\t\t}\n\t\tif (sourceText[pos] === \",\") {\n\t\t\t// Also skip whitespace before the comma\n\t\t\tlet commaPos = pos;\n\t\t\tpos--;\n\t\t\twhile (\n\t\t\t\tpos >= 0 &&\n\t\t\t\t(sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")\n\t\t\t) {\n\t\t\t\tpos--;\n\t\t\t}\n\t\t\tdeleteStart = pos + 1;\n\t\t}\n\t}\n\n\treturn sourceText.slice(0, deleteStart) + sourceText.slice(deleteEnd);\n}\n\nfunction deleteArrayElement(sourceText, arrayNode, index, originalSource) {\n\tif (typeof index !== \"number\" || index < 0 || index >= arrayNode.elements.length) {\n\t\treturn sourceText;\n\t}\n\n\tconst element = arrayNode.elements[index];\n\tlet deleteStart = element.start;\n\tlet deleteEnd = element.end;\n\n\t// Handle comma and whitespace\n\tif (index < arrayNode.elements.length - 1) {\n\t\t// Not the last element, look for comma after\n\t\tlet pos = deleteEnd;\n\t\twhile (\n\t\t\tpos < sourceText.length &&\n\t\t\t(sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")\n\t\t) {\n\t\t\tpos++;\n\t\t}\n\t\tif (sourceText[pos] === \",\") {\n\t\t\tdeleteEnd = pos + 1;\n\t\t\t// Skip trailing whitespace after comma\n\t\t\twhile (\n\t\t\t\tdeleteEnd < sourceText.length &&\n\t\t\t\t(sourceText[deleteEnd] === \" \" ||\n\t\t\t\t\tsourceText[deleteEnd] === \"\\t\" ||\n\t\t\t\t\tsourceText[deleteEnd] === \"\\n\" ||\n\t\t\t\t\tsourceText[deleteEnd] === \"\\r\")\n\t\t\t) {\n\t\t\t\tdeleteEnd++;\n\t\t\t}\n\t\t}\n\t} else if (index > 0) {\n\t\t// Last element, look for comma before (and whitespace before the comma)\n\t\tlet pos = deleteStart - 1;\n\t\t// Skip whitespace before the element\n\t\twhile (pos >= 0 && (sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")) {\n\t\t\tpos--;\n\t\t}\n\t\tif (sourceText[pos] === \",\") {\n\t\t\t// Also skip whitespace before the comma\n\t\t\tlet commaPos = pos;\n\t\t\tpos--;\n\t\t\twhile (\n\t\t\t\tpos >= 0 &&\n\t\t\t\t(sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")\n\t\t\t) {\n\t\t\t\tpos--;\n\t\t\t}\n\t\t\tdeleteStart = pos + 1;\n\t\t}\n\t}\n\n\treturn sourceText.slice(0, deleteStart) + sourceText.slice(deleteEnd);\n}\n\nfunction deleteFromParent(sourceText, parentNode, key, originalSource) {\n\tif (parentNode.type === \"Object\") {\n\t\treturn deleteObjectProperty(sourceText, parentNode, key, originalSource);\n\t} else if (parentNode.type === \"Array\") {\n\t\treturn deleteArrayElement(sourceText, parentNode, key, originalSource);\n\t}\n\treturn sourceText;\n}\n","import { Tokenizer } from \"../Tokenizer.js\";\nimport { CSTBuilder } from \"../CSTBuilder.js\";\nimport { resolvePath } from \"../PathResolver.js\";\nimport { extractString } from \"../helper.js\";\n\nexport function insert(sourceText, patches, root) {\n\tif (!root) {\n\t\tconst tokenizer = new Tokenizer(sourceText);\n\t\tconst tokens = tokenizer.tokenize();\n\n\t\tconst builder = new CSTBuilder(tokens);\n\t\troot = builder.build();\n\t}\n\n\t// 倒叙插入\n\tconst reverseNodes = patches\n\t\t.map((patch) => {\n\t\t\tconst node = resolvePath(root, patch.path, sourceText);\n\t\t\treturn {\n\t\t\t\tnode,\n\t\t\t\tpatch,\n\t\t\t};\n\t\t})\n\t\t.filter((v) => v.node)\n\t\t.sort((a, b) => b.node.start - a.node.start);\n\n\tlet result = sourceText;\n\n\tfor (const { node, patch } of reverseNodes) {\n\t\tresult = insertIntoNode(result, node, patch, sourceText);\n\t}\n\n\treturn result;\n}\n\nfunction insertIntoNode(sourceText, node, patch, originalSource) {\n\tif (node.type === \"Object\") {\n\t\treturn insertObjectProperty(sourceText, node, patch, originalSource);\n\t} else if (node.type === \"Array\") {\n\t\treturn insertArrayElement(sourceText, node, patch, originalSource);\n\t}\n\treturn sourceText;\n}\n\nfunction insertObjectProperty(sourceText, objectNode, patch, originalSource) {\n\tif (!patch.key) {\n\t\tthrow new Error(\"Insert into object requires 'key' property\");\n\t}\n\n\t// Check if key already exists\n\tfor (const prop of objectNode.properties) {\n\t\tconst keyStr = extractString(prop.key, originalSource);\n\t\tif (keyStr === patch.key) {\n\t\t\tthrow new Error(`Key \"${patch.key}\" already exists in object`);\n\t\t}\n\t}\n\n\tconst newEntry = `\"${patch.key}\": ${patch.value}`;\n\n\tif (objectNode.properties.length === 0) {\n\t\t// Empty object\n\t\tconst insertPos = objectNode.start + 1;\n\t\treturn sourceText.slice(0, insertPos) + newEntry + sourceText.slice(insertPos);\n\t} else {\n\t\t// Insert after last property\n\t\tconst lastProp = objectNode.properties[objectNode.properties.length - 1];\n\t\tconst insertPos = lastProp.value.end;\n\t\treturn sourceText.slice(0, insertPos) + \", \" + newEntry + sourceText.slice(insertPos);\n\t}\n}\n\nfunction insertArrayElement(sourceText, arrayNode, patch, originalSource) {\n\tconst position = patch.position !== undefined ? patch.position : arrayNode.elements.length;\n\n\tif (position < 0 || position > arrayNode.elements.length) {\n\t\tthrow new Error(`Invalid position ${position} for array of length ${arrayNode.elements.length}`);\n\t}\n\n\tif (arrayNode.elements.length === 0) {\n\t\t// Empty array\n\t\tconst insertPos = arrayNode.start + 1;\n\t\treturn sourceText.slice(0, insertPos) + patch.value + sourceText.slice(insertPos);\n\t} else if (position === 0) {\n\t\t// Insert at the beginning\n\t\tconst insertPos = arrayNode.elements[0].start;\n\t\treturn sourceText.slice(0, insertPos) + patch.value + \", \" + sourceText.slice(insertPos);\n\t} else if (position >= arrayNode.elements.length) {\n\t\t// Insert at the end\n\t\tconst lastElement = arrayNode.elements[arrayNode.elements.length - 1];\n\t\tconst insertPos = lastElement.end;\n\t\treturn sourceText.slice(0, insertPos) + \", \" + patch.value + sourceText.slice(insertPos);\n\t} else {\n\t\t// Insert in the middle\n\t\tconst insertPos = arrayNode.elements[position].start;\n\t\treturn sourceText.slice(0, insertPos) + patch.value + \", \" + sourceText.slice(insertPos);\n\t}\n}\n","import { replace } from \"./replace.js\";\nimport { remove } from \"./delete.js\";\nimport { insert } from \"./insert.js\";\nimport { Tokenizer } from \"../Tokenizer.js\";\nimport { CSTBuilder } from \"../CSTBuilder.js\";\n\nexport function batch(sourceText, patches) {\n\t// Parse the source text once\n\tconst tokenizer = new Tokenizer(sourceText);\n\tconst tokens = tokenizer.tokenize();\n\tconst builder = new CSTBuilder(tokens);\n\tconst root = builder.build();\n\n\t// Categorize patches by operation type\n\tconst replacePatches = [];\n\tconst deletePatches = [];\n\tconst insertPatches = [];\n\n\tfor (const p of patches) {\n\t\t// Determine patch type based on properties\n\t\tif (p.value !== undefined && p.key === undefined && p.position === undefined) {\n\t\t\t// Has value but no key/position -> replace operation\n\t\t\treplacePatches.push({ path: p.path, value: p.value });\n\t\t} else if (p.value === undefined && p.key === undefined && p.position === undefined) {\n\t\t\t// No value, key, or position -> delete operation\n\t\t\tdeletePatches.push({ path: p.path });\n\t\t} else if ((p.key !== undefined || p.position !== undefined) && p.value !== undefined) {\n\t\t\t// Has key or position with value -> insert operation\n\t\t\tinsertPatches.push(p);\n\t\t} else {\n\t\t\t// Invalid patch - skip it\n\t\t\tcontinue;\n\t\t}\n\t}\n\n\t// Apply patches in order: replace, insert, delete\n\t// This order ensures that replacements happen first, then inserts, then deletes\n\tlet result = sourceText;\n\n\t// Apply replacements\n\tif (replacePatches.length > 0) {\n\t\tresult = replace(result, replacePatches, root);\n\t}\n\n\t// Apply insertions\n\tif (insertPatches.length > 0) {\n\t\t// Need to re-parse if we did replacements\n\t\tconst currentRoot = replacePatches.length > 0 ? null : root;\n\t\tresult = insert(result, insertPatches, currentRoot);\n\t}\n\n\t// Apply deletions\n\tif (deletePatches.length > 0) {\n\t\t// Need to re-parse if we did replacements or insertions\n\t\tconst currentRoot = replacePatches.length > 0 || insertPatches.length > 0 ? null : root;\n\t\tresult = remove(result, deletePatches, currentRoot);\n\t}\n\n\treturn result;\n}\n","import { replace } from \"./function/replace.js\";\nimport { remove } from \"./function/delete.js\";\nimport { insert } from \"./function/insert.js\";\nimport { batch } from \"./function/batch.js\";\n\nconst jsoncst = {\n\treplace: replace,\n\tremove: remove,\n\tinsert: insert,\n\tbatch: batch,\n};\n\nexport { replace, remove, insert, batch };\n\nexport default jsoncst;\n"],"names":["Tokenizer","text","tokenize","ch","isWhitespace","isNumberStart","isAlpha","readWhitespace","start","readString","readNumber","readKeyword","word","type","Error","readPunctuationOrComment","map","isDigit","CSTBuilder","tokens","build","node","current","skipTrivia","consume","token","parseValue","parsePrimitive","parseObject","startToken","properties","keyToken","keyNode","valueNode","endToken","parseArray","elements","unescapeString","str","_","extractString","stringNode","sourceText","raw","parsePath","path","parseJSONPointer","parseDotPath","result","i","num","Number","name","pointer","segment","seg","resolvePath","root","parts","Array","_iteratorError","part","resolveObjectProperty","resolveArrayElement","objectNode","key","prop","arrayNode","index","replace","patches","tokenizer","builder","reverseNodes","patch","v","a","b","lastEnd","Infinity","remove","pathParts","parentPath","lastKey","parentNode","aStart","getDeleteStart","bStart","deleteFromParent","keyStr","deleteObjectProperty","originalSource","propIndex","deleteStart","deleteEnd","pos","pos1","deleteArrayElement","element","insert","insertIntoNode","insertObjectProperty","insertArrayElement","newEntry","insertPos","lastProp","insertPos1","position","undefined","lastElement","insertPos2","insertPos3","batch","replacePatches","deletePatches","insertPatches","p","currentRoot","currentRoot1","jsoncst"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAMA,sBAASA,WAAAA,GAAf;;aAAMA,UACOC,IAAI;gCADXD;QAEJ,IAAI,CAAC,IAAI,GAAGC;QACZ,IAAI,CAAC,GAAG,GAAG;QACX,IAAI,CAAC,MAAM,GAAG,EAAE;;kBAJZD,WAAAA;;YAOLE,KAAAA;mBAAAA;gBACC,MAAO,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,IA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xC;IAEA,OAAOtE;AACR;ACtDA,IAAMuE,UAAU;IACf,SAASlD;IACT,QAAQW;IACR,QAAQmB;IACR,OAAOa;AACR;AAIA,UAAeO"} | ||
| {"version":3,"file":"esm/index.mjs","sources":["../../src/value-helpers.js","../../src/Tokenizer.js","../../src/CSTBuilder.js","../../src/helper.js","../../src/PathResolver.js","../../src/JsonMod.js","../../src/index.js"],"sourcesContent":["/**\n * Helper utility for formatting values to use in patches.\n * This function makes it easier to create patch values without manually adding quotes.\n */\n\n/**\n * Formats a JavaScript value into a JSON string representation for use in patches.\n * Handles all JavaScript types including strings, numbers, booleans, null, objects, and arrays.\n * \n * @param {any} value - The value to format\n * @returns {string} - A JSON string representation\n * @example\n * formatValue(42) // \"42\"\n * formatValue(\"hello\") // '\"hello\"'\n * formatValue(true) // \"true\"\n * formatValue(null) // \"null\"\n * formatValue({a: 1}) // '{\"a\":1}'\n * formatValue([1, 2, 3]) // '[1,2,3]'\n */\nexport function formatValue(value) {\n\treturn JSON.stringify(value);\n}\n","class Tokenizer {\n\tconstructor(text) {\n\t\tthis.text = text;\n\t\tthis.pos = 0;\n\t\tthis.tokens = [];\n\t}\n\n\ttokenize() {\n\t\twhile (this.pos < this.text.length) {\n\t\t\tconst ch = this.text[this.pos];\n\n\t\t\tif (this.isWhitespace(ch)) {\n\t\t\t\tthis.readWhitespace();\n\t\t\t} else if (ch === '\"') {\n\t\t\t\tthis.readString();\n\t\t\t} else if (this.isNumberStart(ch)) {\n\t\t\t\tthis.readNumber();\n\t\t\t} else if (this.isAlpha(ch)) {\n\t\t\t\tthis.readKeyword();\n\t\t\t} else {\n\t\t\t\tthis.readPunctuationOrComment();\n\t\t\t}\n\t\t}\n\n\t\treturn this.tokens;\n\t}\n\n\t// ---------- helpers ----------\n\n\tisWhitespace(ch) {\n\t\treturn ch === \" \" || ch === \"\\n\" || ch === \"\\r\" || ch === \"\\t\";\n\t}\n\n\tisNumberStart(ch) {\n\t\treturn ch === \"-\" || (ch >= \"0\" && ch <= \"9\");\n\t}\n\n\tisAlpha(ch) {\n\t\treturn (ch >= \"a\" && ch <= \"z\") || (ch >= \"A\" && ch <= \"Z\");\n\t}\n\n\t// ---------- readers ----------\n\n\treadWhitespace() {\n\t\tconst start = this.pos;\n\t\twhile (this.pos < this.text.length && this.isWhitespace(this.text[this.pos])) {\n\t\t\tthis.pos++;\n\t\t}\n\t\tthis.tokens.push({\n\t\t\ttype: \"whitespace\",\n\t\t\tstart,\n\t\t\tend: this.pos,\n\t\t});\n\t}\n\n\treadString() {\n\t\tconst start = this.pos;\n\t\tthis.pos++; // skip opening \"\n\n\t\twhile (this.pos < this.text.length) {\n\t\t\tconst ch = this.text[this.pos];\n\n\t\t\tif (ch === \"\\\\\") {\n\t\t\t\t// skip escaped char\n\t\t\t\tthis.pos += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (ch === '\"') {\n\t\t\t\tthis.pos++; // closing \"\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tthis.pos++;\n\t\t}\n\n\t\tthis.tokens.push({\n\t\t\ttype: \"string\",\n\t\t\tstart,\n\t\t\tend: this.pos,\n\t\t});\n\t}\n\n\treadNumber() {\n\t\tconst start = this.pos;\n\n\t\tif (this.text[this.pos] === \"-\") this.pos++;\n\n\t\twhile (this.pos < this.text.length && this.isDigit(this.text[this.pos])) {\n\t\t\tthis.pos++;\n\t\t}\n\n\t\tif (this.text[this.pos] === \".\") {\n\t\t\tthis.pos++;\n\t\t\twhile (this.pos < this.text.length && this.isDigit(this.text[this.pos])) {\n\t\t\t\tthis.pos++;\n\t\t\t}\n\t\t}\n\n\t\tif (this.text[this.pos] === \"e\" || this.text[this.pos] === \"E\") {\n\t\t\tthis.pos++;\n\t\t\tif (this.text[this.pos] === \"+\" || this.text[this.pos] === \"-\") {\n\t\t\t\tthis.pos++;\n\t\t\t}\n\t\t\twhile (this.pos < this.text.length && this.isDigit(this.text[this.pos])) {\n\t\t\t\tthis.pos++;\n\t\t\t}\n\t\t}\n\n\t\tthis.tokens.push({\n\t\t\ttype: \"number\",\n\t\t\tstart,\n\t\t\tend: this.pos,\n\t\t});\n\t}\n\n\treadKeyword() {\n\t\tconst start = this.pos;\n\n\t\twhile (this.pos < this.text.length && this.isAlpha(this.text[this.pos])) {\n\t\t\tthis.pos++;\n\t\t}\n\n\t\tconst word = this.text.slice(start, this.pos);\n\n\t\tlet type;\n\t\tif (word === \"true\" || word === \"false\") {\n\t\t\ttype = \"boolean\";\n\t\t} else if (word === \"null\") {\n\t\t\ttype = \"null\";\n\t\t} else {\n\t\t\tthrow new Error(`Unexpected identifier: ${word}`);\n\t\t}\n\n\t\tthis.tokens.push({\n\t\t\ttype,\n\t\t\tstart,\n\t\t\tend: this.pos,\n\t\t});\n\t}\n\n\treadPunctuationOrComment() {\n\t\tconst start = this.pos;\n\t\tconst ch = this.text[this.pos];\n\n\t\t// line comment //\n\t\tif (ch === \"/\" && this.text[this.pos + 1] === \"/\") {\n\t\t\tthis.pos += 2;\n\t\t\twhile (this.pos < this.text.length && this.text[this.pos] !== \"\\n\") {\n\t\t\t\tthis.pos++;\n\t\t\t}\n\t\t\tthis.tokens.push({\n\t\t\t\ttype: \"comment\",\n\t\t\t\tstart,\n\t\t\t\tend: this.pos,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\t// block comment /* */\n\t\tif (ch === \"/\" && this.text[this.pos + 1] === \"*\") {\n\t\t\tthis.pos += 2;\n\t\t\twhile (this.pos < this.text.length && !(this.text[this.pos] === \"*\" && this.text[this.pos + 1] === \"/\")) {\n\t\t\t\tthis.pos++;\n\t\t\t}\n\t\t\tthis.pos += 2; // skip */\n\t\t\tthis.tokens.push({\n\t\t\t\ttype: \"comment\",\n\t\t\t\tstart,\n\t\t\t\tend: this.pos,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\t// punctuation\n\t\tthis.pos++;\n\n\t\tconst map = {\n\t\t\t\"{\": \"braceL\",\n\t\t\t\"}\": \"braceR\",\n\t\t\t\"[\": \"bracketL\",\n\t\t\t\"]\": \"bracketR\",\n\t\t\t\":\": \"colon\",\n\t\t\t\",\": \"comma\",\n\t\t};\n\n\t\tconst type = map[ch];\n\t\tif (!type) {\n\t\t\tthrow new Error(`Unexpected character: ${ch} at ${start}`);\n\t\t}\n\n\t\tthis.tokens.push({\n\t\t\ttype,\n\t\t\tstart,\n\t\t\tend: this.pos,\n\t\t});\n\t}\n\n\tisDigit(ch) {\n\t\treturn ch >= \"0\" && ch <= \"9\";\n\t}\n}\n\nexport { Tokenizer };\n","export class CSTBuilder {\n\tconstructor(tokens) {\n\t\tthis.tokens = tokens;\n\t\tthis.pos = 0;\n\t}\n\n\tbuild() {\n\t\tthis.skipTrivia();\n\t\tconst node = this.parseValue();\n\t\tthis.skipTrivia();\n\t\treturn node;\n\t}\n\n\tcurrent() {\n\t\treturn this.tokens[this.pos];\n\t}\n\n\tskipTrivia() {\n\t\twhile (this.pos < this.tokens.length && (this.tokens[this.pos].type === \"whitespace\" || this.tokens[this.pos].type === \"comment\")) {\n\t\t\tthis.pos++;\n\t\t}\n\t}\n\n\tconsume(type) {\n\t\tconst token = this.current();\n\t\tif (!token || token.type !== type) {\n\t\t\tthrow new Error(`Expected ${type}, got ${token && token.type}`);\n\t\t}\n\t\tthis.pos++;\n\t\treturn token;\n\t}\n\n\tparseValue() {\n\t\tthis.skipTrivia();\n\t\tconst token = this.current();\n\n\t\tif (!token) {\n\t\t\tthrow new Error(\"Unexpected end of input\");\n\t\t}\n\n\t\tswitch (token.type) {\n\t\t\tcase \"braceL\":\n\t\t\t\treturn this.parseObject();\n\t\t\tcase \"bracketL\":\n\t\t\t\treturn this.parseArray();\n\t\t\tcase \"string\":\n\t\t\t\treturn this.parsePrimitive(\"String\");\n\t\t\tcase \"number\":\n\t\t\t\treturn this.parsePrimitive(\"Number\");\n\t\t\tcase \"boolean\":\n\t\t\t\treturn this.parsePrimitive(\"Boolean\");\n\t\t\tcase \"null\":\n\t\t\t\treturn this.parsePrimitive(\"Null\");\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unexpected token: ${token.type}`);\n\t\t}\n\t}\n\n\tparsePrimitive(type) {\n\t\tconst token = this.current();\n\t\tthis.pos++;\n\t\treturn {\n\t\t\ttype,\n\t\t\tstart: token.start,\n\t\t\tend: token.end,\n\t\t};\n\t}\n\n\tparseObject() {\n\t\tconst startToken = this.consume(\"braceL\");\n\t\tconst properties = [];\n\n\t\tthis.skipTrivia();\n\n\t\twhile (this.current() && this.current().type !== \"braceR\") {\n\t\t\tconst keyToken = this.consume(\"string\");\n\t\t\tconst keyNode = {\n\t\t\t\ttype: \"String\",\n\t\t\t\tstart: keyToken.start,\n\t\t\t\tend: keyToken.end,\n\t\t\t};\n\n\t\t\tthis.skipTrivia();\n\t\t\tthis.consume(\"colon\");\n\t\t\tthis.skipTrivia();\n\n\t\t\tconst valueNode = this.parseValue();\n\n\t\t\tproperties.push({ key: keyNode, value: valueNode });\n\n\t\t\tthis.skipTrivia();\n\t\t\tif (this.current() && this.current().type === \"comma\") {\n\t\t\t\tthis.pos++;\n\t\t\t\tthis.skipTrivia();\n\t\t\t}\n\t\t}\n\n\t\tconst endToken = this.consume(\"braceR\");\n\n\t\treturn {\n\t\t\ttype: \"Object\",\n\t\t\tstart: startToken.start,\n\t\t\tend: endToken.end,\n\t\t\tproperties,\n\t\t};\n\t}\n\n\tparseArray() {\n\t\tconst startToken = this.consume(\"bracketL\");\n\t\tconst elements = [];\n\n\t\tthis.skipTrivia();\n\n\t\twhile (this.current() && this.current().type !== \"bracketR\") {\n\t\t\tconst valueNode = this.parseValue();\n\t\t\telements.push(valueNode);\n\n\t\t\tthis.skipTrivia();\n\t\t\tif (this.current() && this.current().type === \"comma\") {\n\t\t\t\tthis.pos++;\n\t\t\t\tthis.skipTrivia();\n\t\t\t}\n\t\t}\n\n\t\tconst endToken = this.consume(\"bracketR\");\n\n\t\treturn {\n\t\t\ttype: \"Array\",\n\t\t\tstart: startToken.start,\n\t\t\tend: endToken.end,\n\t\t\telements,\n\t\t};\n\t}\n}\n","function unescapeString(str) {\n\treturn str.replace(/\\\\(.)/g, (_, ch) => {\n\t\tswitch (ch) {\n\t\t\tcase '\"':\n\t\t\t\treturn '\"';\n\t\t\tcase \"\\\\\":\n\t\t\t\treturn \"\\\\\";\n\t\t\tcase \"/\":\n\t\t\t\treturn \"/\";\n\t\t\tcase \"b\":\n\t\t\t\treturn \"\\b\";\n\t\t\tcase \"f\":\n\t\t\t\treturn \"\\f\";\n\t\t\tcase \"n\":\n\t\t\t\treturn \"\\n\";\n\t\t\tcase \"r\":\n\t\t\t\treturn \"\\r\";\n\t\t\tcase \"t\":\n\t\t\t\treturn \"\\t\";\n\t\t\tdefault:\n\t\t\t\treturn ch; // \\uXXXX 可后续增强\n\t\t}\n\t});\n}\n\nexport function extractString(stringNode, sourceText) {\n\t// sourceText 是完整 JSON 文本\n\t// stringNode.start / end 覆盖包含引号\n\tconst raw = sourceText.slice(stringNode.start + 1, stringNode.end - 1);\n\treturn unescapeString(raw);\n}\n\n/**\n *\n * @param {string} path\n * @returns\n */\nexport function parsePath(path) {\n\tif (path.startsWith(\"/\")) {\n\t\treturn parseJSONPointer(path);\n\t}\n\treturn parseDotPath(path);\n}\n\n/**\n *\n * @param {string} path\n * @returns\n */\nfunction parseDotPath(path) {\n\tconst result = [];\n\tlet i = 0;\n\n\twhile (i < path.length) {\n\t\tconst ch = path[i];\n\n\t\t// skip dot\n\t\tif (ch === \".\") {\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// array index: [123]\n\t\tif (ch === \"[\") {\n\t\t\ti++;\n\t\t\tlet num = \"\";\n\t\t\twhile (i < path.length && path[i] !== \"]\") {\n\t\t\t\tnum += path[i++];\n\t\t\t}\n\t\t\ti++; // skip ]\n\t\t\tresult.push(Number(num));\n\t\t\tcontinue;\n\t\t}\n\n\t\t// identifier\n\t\tlet name = \"\";\n\t\twhile (i < path.length && /[a-zA-Z0-9_$]/.test(path[i])) {\n\t\t\tname += path[i++];\n\t\t}\n\t\tresult.push(name);\n\t}\n\n\treturn result;\n}\n\n/**\n *\n * @param {string} pointer\n * @returns\n */\nfunction parseJSONPointer(pointer) {\n\tif (pointer === \"\") return [];\n\n\tif (pointer[0] !== \"/\") {\n\t\tthrow new Error(\"Invalid JSON Pointer\");\n\t}\n\n\treturn pointer\n\t\t.slice(1)\n\t\t.split(\"/\")\n\t\t.map((segment) => segment.replace(/~1/g, \"/\").replace(/~0/g, \"~\"))\n\t\t.map((seg) => {\n\t\t\treturn /^\\d+$/.test(seg) ? Number(seg) : seg;\n\t\t});\n}\n","import { extractString } from \"./helper.js\";\n\nexport function resolvePath(root, path, sourceText) {\n\tconst parts = Array.isArray(path) ? path : parsePath(path);\n\tlet node = root;\n\n\tfor (const part of parts) {\n\t\tif (!node) return null;\n\n\t\tif (node.type === \"Object\") {\n\t\t\tnode = resolveObjectProperty(node, part, sourceText);\n\t\t} else if (node.type === \"Array\") {\n\t\t\tnode = resolveArrayElement(node, part);\n\t\t} else {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\treturn node;\n}\n\n/**\n *\n * @param {import('./CSTBuilder.js').NodeObject} objectNode\n * @param {string} key\n * @param {string} sourceText\n * @returns {import('./CSTBuilder.js').Node | null}\n */\nfunction resolveObjectProperty(objectNode, key, sourceText) {\n\tif (typeof key !== \"string\") return null;\n\n\tfor (const prop of objectNode.properties) {\n\t\tconst name = extractString(prop.key, sourceText);\n\t\tif (name === key) {\n\t\t\treturn prop.value;\n\t\t}\n\t}\n\treturn null;\n}\n\n/**\n *\n * @param {import('./CSTBuilder.js').NodeArray} arrayNode\n * @param {number} index\n * @returns {import('./CSTBuilder.js').Node | null}\n */\nfunction resolveArrayElement(arrayNode, index) {\n\tif (typeof index !== \"number\") return null;\n\treturn arrayNode.elements[index] || null;\n}\n\nfunction parsePath(path) {\n\tif (path.startsWith(\"/\")) {\n\t\treturn parseJSONPointer(path);\n\t}\n\treturn parseDotPath(path);\n}\n\nfunction parseDotPath(path) {\n\tconst result = [];\n\tlet i = 0;\n\n\twhile (i < path.length) {\n\t\tconst ch = path[i];\n\n\t\t// skip dot\n\t\tif (ch === \".\") {\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// array index: [123]\n\t\tif (ch === \"[\") {\n\t\t\ti++;\n\t\t\tlet num = \"\";\n\t\t\twhile (i < path.length && path[i] !== \"]\") {\n\t\t\t\tnum += path[i++];\n\t\t\t}\n\t\t\ti++; // skip ]\n\t\t\tresult.push(Number(num));\n\t\t\tcontinue;\n\t\t}\n\n\t\t// identifier\n\t\tlet name = \"\";\n\t\twhile (i < path.length && /[a-zA-Z0-9_$]/.test(path[i])) {\n\t\t\tname += path[i++];\n\t\t}\n\t\tresult.push(name);\n\t}\n\n\treturn result;\n}\n\nfunction parseJSONPointer(pointer) {\n\tif (pointer === \"\") return [];\n\n\tif (pointer[0] !== \"/\") {\n\t\tthrow new Error(\"Invalid JSON Pointer\");\n\t}\n\n\treturn pointer\n\t\t.slice(1)\n\t\t.split(\"/\")\n\t\t.map((segment) => segment.replace(/~1/g, \"/\").replace(/~0/g, \"~\"))\n\t\t.map((seg) => {\n\t\t\treturn /^\\d+$/.test(seg) ? Number(seg) : seg;\n\t\t});\n}\n","import { Tokenizer } from \"./Tokenizer.js\";\nimport { CSTBuilder } from \"./CSTBuilder.js\";\nimport { resolvePath } from \"./PathResolver.js\";\nimport { parsePath, extractString } from \"./helper.js\";\n\n/**\n * JsonMod - A chainable API for modifying JSON strings while preserving formatting\n * @class\n */\nexport class JsonMod {\n\t/**\n\t * Creates a new JsonMod instance\n\t * @param {string} sourceText - The JSON string to modify\n\t */\n\tconstructor(sourceText) {\n\t\tthis.sourceText = sourceText;\n\t\tthis.operations = [];\n\t}\n\n\t/**\n\t * Replace a value at the specified path\n\t * @param {string|string[]} path - The JSON path or array of path segments\n\t * @param {string} value - The new value as a JSON string\n\t * @returns {JsonMod} - Returns this for chaining\n\t * @example\n\t * jsonmod(source).replace(\"user.name\", '\"Bob\"').apply()\n\t * jsonmod(source).replace([\"user\", \"name\"], '\"Bob\"').apply()\n\t */\n\treplace(path, value) {\n\t\tthis.operations.push({\n\t\t\ttype: \"replace\",\n\t\t\tpath: Array.isArray(path) ? path : path,\n\t\t\tvalue,\n\t\t});\n\t\treturn this;\n\t}\n\n\t/**\n\t * Delete a property or array element at the specified path\n\t * @param {string|string[]} path - The JSON path or array of path segments\n\t * @returns {JsonMod} - Returns this for chaining\n\t * @example\n\t * jsonmod(source).delete(\"user.age\").apply()\n\t * jsonmod(source).remove([\"user\", \"age\"]).apply()\n\t */\n\tdelete(path) {\n\t\tthis.operations.push({\n\t\t\ttype: \"delete\",\n\t\t\tpath: Array.isArray(path) ? path : path,\n\t\t});\n\t\treturn this;\n\t}\n\n\t/**\n\t * Alias for delete()\n\t * @param {string|string[]} path - The JSON path or array of path segments\n\t * @returns {JsonMod} - Returns this for chaining\n\t */\n\tremove(path) {\n\t\treturn this.delete(path);\n\t}\n\n\t/**\n\t * Insert a new property into an object or element into an array\n\t * @param {string|string[]} path - The JSON path pointing to the object/array\n\t * @param {string|number} keyOrPosition - For objects: property name; For arrays: index\n\t * @param {string} value - The value to insert as a JSON string\n\t * @returns {JsonMod} - Returns this for chaining\n\t * @example\n\t * jsonmod(source).insert(\"user\", \"email\", '\"test@example.com\"').apply()\n\t * jsonmod(source).insert(\"items\", 0, '\"newItem\"').apply()\n\t */\n\tinsert(path, keyOrPosition, value) {\n\t\tthis.operations.push({\n\t\t\ttype: \"insert\",\n\t\t\tpath: Array.isArray(path) ? path : path,\n\t\t\tkeyOrPosition,\n\t\t\tvalue,\n\t\t});\n\t\treturn this;\n\t}\n\n\t/**\n\t * Apply all queued operations and return the modified JSON string\n\t * @returns {string} - The modified JSON string\n\t */\n\tapply() {\n\t\tif (this.operations.length === 0) {\n\t\t\treturn this.sourceText;\n\t\t}\n\n\t\tlet result = this.sourceText;\n\n\t\t// Apply operations sequentially to avoid conflicts\n\t\tfor (const op of this.operations) {\n\t\t\tswitch (op.type) {\n\t\t\t\tcase \"replace\":\n\t\t\t\t\tresult = this._applySingleReplace(result, op);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"delete\":\n\t\t\t\t\tresult = this._applySingleDelete(result, op);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"insert\":\n\t\t\t\t\tresult = this._applySingleInsert(result, op);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Internal method to apply a single replace operation\n\t * @private\n\t */\n\t_applySingleReplace(sourceText, op) {\n\t\tconst tokenizer = new Tokenizer(sourceText);\n\t\tconst tokens = tokenizer.tokenize();\n\t\tconst builder = new CSTBuilder(tokens);\n\t\tconst root = builder.build();\n\n\t\tconst node = resolvePath(root, op.path, sourceText);\n\t\tif (!node) {\n\t\t\treturn sourceText;\n\t\t}\n\n\t\treturn sourceText.slice(0, node.start) + op.value + sourceText.slice(node.end);\n\t}\n\n\t/**\n\t * Internal method to apply a single delete operation\n\t * @private\n\t */\n\t_applySingleDelete(sourceText, op) {\n\t\tconst tokenizer = new Tokenizer(sourceText);\n\t\tconst tokens = tokenizer.tokenize();\n\t\tconst builder = new CSTBuilder(tokens);\n\t\tconst root = builder.build();\n\n\t\tconst pathParts = parsePath(op.path);\n\t\tif (pathParts.length === 0) {\n\t\t\treturn sourceText;\n\t\t}\n\n\t\tconst parentPath = pathParts.slice(0, -1);\n\t\tconst lastKey = pathParts[pathParts.length - 1];\n\t\tconst parentNode = parentPath.length > 0 ? resolvePath(root, parentPath, sourceText) : root;\n\n\t\tif (!parentNode) {\n\t\t\treturn sourceText;\n\t\t}\n\n\t\treturn this._deleteFromParent(sourceText, parentNode, lastKey, sourceText);\n\t}\n\n\t/**\n\t * Internal method to apply a single insert operation\n\t * @private\n\t */\n\t_applySingleInsert(sourceText, op) {\n\t\tconst tokenizer = new Tokenizer(sourceText);\n\t\tconst tokens = tokenizer.tokenize();\n\t\tconst builder = new CSTBuilder(tokens);\n\t\tconst root = builder.build();\n\n\t\tconst node = resolvePath(root, op.path, sourceText);\n\t\tif (!node) {\n\t\t\treturn sourceText;\n\t\t}\n\n\t\treturn this._insertIntoNode(sourceText, node, op, sourceText);\n\t}\n\n\t_getDeleteStart(parentNode, key, sourceText) {\n\t\tif (parentNode.type === \"Object\") {\n\t\t\tfor (const prop of parentNode.properties) {\n\t\t\t\tconst keyStr = extractString(prop.key, sourceText);\n\t\t\t\tif (keyStr === key) {\n\t\t\t\t\treturn prop.key.start;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (parentNode.type === \"Array\") {\n\t\t\tif (typeof key === \"number\" && key >= 0 && key < parentNode.elements.length) {\n\t\t\t\treturn parentNode.elements[key].start;\n\t\t\t}\n\t\t}\n\t\treturn 0;\n\t}\n\n\t_deleteFromParent(sourceText, parentNode, key, originalSource) {\n\t\tif (parentNode.type === \"Object\") {\n\t\t\treturn this._deleteObjectProperty(sourceText, parentNode, key, originalSource);\n\t\t} else if (parentNode.type === \"Array\") {\n\t\t\treturn this._deleteArrayElement(sourceText, parentNode, key, originalSource);\n\t\t}\n\t\treturn sourceText;\n\t}\n\n\t_deleteObjectProperty(sourceText, objectNode, key, originalSource) {\n\t\tlet propIndex = -1;\n\t\tfor (let i = 0; i < objectNode.properties.length; i++) {\n\t\t\tconst keyStr = extractString(objectNode.properties[i].key, originalSource);\n\t\t\tif (keyStr === key) {\n\t\t\t\tpropIndex = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif (propIndex === -1) return sourceText;\n\n\t\tconst prop = objectNode.properties[propIndex];\n\t\tlet deleteStart = prop.key.start;\n\t\tlet deleteEnd = prop.value.end;\n\n\t\t// Handle comma and whitespace\n\t\tif (propIndex < objectNode.properties.length - 1) {\n\t\t\tlet pos = deleteEnd;\n\t\t\twhile (\n\t\t\t\tpos < sourceText.length &&\n\t\t\t\t(sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")\n\t\t\t) {\n\t\t\t\tpos++;\n\t\t\t}\n\t\t\tif (sourceText[pos] === \",\") {\n\t\t\t\tdeleteEnd = pos + 1;\n\t\t\t\twhile (\n\t\t\t\t\tdeleteEnd < sourceText.length &&\n\t\t\t\t\t(sourceText[deleteEnd] === \" \" ||\n\t\t\t\t\t\tsourceText[deleteEnd] === \"\\t\" ||\n\t\t\t\t\t\tsourceText[deleteEnd] === \"\\n\" ||\n\t\t\t\t\t\tsourceText[deleteEnd] === \"\\r\")\n\t\t\t\t) {\n\t\t\t\t\tdeleteEnd++;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (propIndex > 0) {\n\t\t\tlet pos = deleteStart - 1;\n\t\t\twhile (pos >= 0 && (sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")) {\n\t\t\t\tpos--;\n\t\t\t}\n\t\t\tif (sourceText[pos] === \",\") {\n\t\t\t\tlet commaPos = pos;\n\t\t\t\tpos--;\n\t\t\t\twhile (\n\t\t\t\t\tpos >= 0 &&\n\t\t\t\t\t(sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")\n\t\t\t\t) {\n\t\t\t\t\tpos--;\n\t\t\t\t}\n\t\t\t\tdeleteStart = pos + 1;\n\t\t\t}\n\t\t}\n\n\t\treturn sourceText.slice(0, deleteStart) + sourceText.slice(deleteEnd);\n\t}\n\n\t_deleteArrayElement(sourceText, arrayNode, index, originalSource) {\n\t\tif (typeof index !== \"number\" || index < 0 || index >= arrayNode.elements.length) {\n\t\t\treturn sourceText;\n\t\t}\n\n\t\tconst element = arrayNode.elements[index];\n\t\tlet deleteStart = element.start;\n\t\tlet deleteEnd = element.end;\n\n\t\t// Handle comma and whitespace\n\t\tif (index < arrayNode.elements.length - 1) {\n\t\t\tlet pos = deleteEnd;\n\t\t\twhile (\n\t\t\t\tpos < sourceText.length &&\n\t\t\t\t(sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")\n\t\t\t) {\n\t\t\t\tpos++;\n\t\t\t}\n\t\t\tif (sourceText[pos] === \",\") {\n\t\t\t\tdeleteEnd = pos + 1;\n\t\t\t\twhile (\n\t\t\t\t\tdeleteEnd < sourceText.length &&\n\t\t\t\t\t(sourceText[deleteEnd] === \" \" ||\n\t\t\t\t\t\tsourceText[deleteEnd] === \"\\t\" ||\n\t\t\t\t\t\tsourceText[deleteEnd] === \"\\n\" ||\n\t\t\t\t\t\tsourceText[deleteEnd] === \"\\r\")\n\t\t\t\t) {\n\t\t\t\t\tdeleteEnd++;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (index > 0) {\n\t\t\tlet pos = deleteStart - 1;\n\t\t\twhile (pos >= 0 && (sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")) {\n\t\t\t\tpos--;\n\t\t\t}\n\t\t\tif (sourceText[pos] === \",\") {\n\t\t\t\tlet commaPos = pos;\n\t\t\t\tpos--;\n\t\t\t\twhile (\n\t\t\t\t\tpos >= 0 &&\n\t\t\t\t\t(sourceText[pos] === \" \" || sourceText[pos] === \"\\t\" || sourceText[pos] === \"\\n\" || sourceText[pos] === \"\\r\")\n\t\t\t\t) {\n\t\t\t\t\tpos--;\n\t\t\t\t}\n\t\t\t\tdeleteStart = pos + 1;\n\t\t\t}\n\t\t}\n\n\t\treturn sourceText.slice(0, deleteStart) + sourceText.slice(deleteEnd);\n\t}\n\n\t_insertIntoNode(sourceText, node, patch, originalSource) {\n\t\tif (node.type === \"Object\") {\n\t\t\treturn this._insertObjectProperty(sourceText, node, patch, originalSource);\n\t\t} else if (node.type === \"Array\") {\n\t\t\treturn this._insertArrayElement(sourceText, node, patch, originalSource);\n\t\t}\n\t\treturn sourceText;\n\t}\n\n\t_insertObjectProperty(sourceText, objectNode, patch, originalSource) {\n\t\tconst key = patch.keyOrPosition;\n\t\tif (typeof key !== \"string\") {\n\t\t\tthrow new Error(\"Insert into object requires a string key\");\n\t\t}\n\n\t\t// Check if key already exists\n\t\tfor (const prop of objectNode.properties) {\n\t\t\tconst keyStr = extractString(prop.key, originalSource);\n\t\t\tif (keyStr === key) {\n\t\t\t\tthrow new Error(`Key \"${key}\" already exists in object`);\n\t\t\t}\n\t\t}\n\n\t\tconst newEntry = `\"${key}\": ${patch.value}`;\n\n\t\tif (objectNode.properties.length === 0) {\n\t\t\tconst insertPos = objectNode.start + 1;\n\t\t\treturn sourceText.slice(0, insertPos) + newEntry + sourceText.slice(insertPos);\n\t\t} else {\n\t\t\tconst lastProp = objectNode.properties[objectNode.properties.length - 1];\n\t\t\tconst insertPos = lastProp.value.end;\n\t\t\treturn sourceText.slice(0, insertPos) + \", \" + newEntry + sourceText.slice(insertPos);\n\t\t}\n\t}\n\n\t_insertArrayElement(sourceText, arrayNode, patch, originalSource) {\n\t\tconst position = typeof patch.keyOrPosition === \"number\" ? patch.keyOrPosition : arrayNode.elements.length;\n\n\t\tif (position < 0 || position > arrayNode.elements.length) {\n\t\t\tthrow new Error(`Invalid position ${position} for array of length ${arrayNode.elements.length}`);\n\t\t}\n\n\t\tif (arrayNode.elements.length === 0) {\n\t\t\tconst insertPos = arrayNode.start + 1;\n\t\t\treturn sourceText.slice(0, insertPos) + patch.value + sourceText.slice(insertPos);\n\t\t} else if (position === 0) {\n\t\t\tconst insertPos = arrayNode.elements[0].start;\n\t\t\treturn sourceText.slice(0, insertPos) + patch.value + \", \" + sourceText.slice(insertPos);\n\t\t} else if (position >= arrayNode.elements.length) {\n\t\t\tconst lastElement = arrayNode.elements[arrayNode.elements.length - 1];\n\t\t\tconst insertPos = lastElement.end;\n\t\t\treturn sourceText.slice(0, insertPos) + \", \" + patch.value + sourceText.slice(insertPos);\n\t\t} else {\n\t\t\tconst insertPos = arrayNode.elements[position].start;\n\t\t\treturn sourceText.slice(0, insertPos) + patch.value + \", \" + sourceText.slice(insertPos);\n\t\t}\n\t}\n}\n\n/**\n * Factory function to create a new JsonMod instance\n * @param {string} sourceText - The JSON string to modify\n * @returns {JsonMod} - A new JsonMod instance\n * @example\n * jsonmod(source).replace(\"a\", \"10\").delete(\"b\").apply()\n */\nexport function jsonmod(sourceText) {\n\treturn new JsonMod(sourceText);\n}\n","import { formatValue } from \"./value-helpers.js\";\nimport { jsonmod, JsonMod } from \"./JsonMod.js\";\n\n// Export new chainable API as default\nexport default jsonmod;\n\n// Export new API and helper\nexport { jsonmod, JsonMod, formatValue };\n\n"],"names":["formatValue","value","JSON","Tokenizer","text","tokenize","ch","isWhitespace","isNumberStart","isAlpha","readWhitespace","start","readString","readNumber","readKeyword","word","type","Error","readPunctuationOrComment","map","isDigit","CSTBuilder","tokens","build","node","current","skipTrivia","consume","token","parseValue","parsePrimitive","parseObject","startToken","properties","keyToken","keyNode","valueNode","endToken","parseArray","elements","unescapeString","str","_","extractString","stringNode","sourceText","raw","parsePath","path","parseJSONPointer","parseDotPath","result","i","num","Number","name","pointer","segment","seg","resolvePath","root","parts","Array","_iteratorError","part","resolveObjectProperty","resolveArrayElement","objectNode","key","prop","arrayNode","index","JsonMod","replace","_delete","remove","insert","keyOrPosition","apply","op","_applySingleReplace","tokenizer","builder","_applySingleDelete","pathParts","parentPath","lastKey","parentNode","_applySingleInsert","_getDeleteStart","keyStr","_deleteFromParent","originalSource","_deleteObjectProperty","propIndex","deleteStart","deleteEnd","pos","pos1","_deleteArrayElement","element","_insertIntoNode","patch","_insertObjectProperty","newEntry","insertPos","lastProp","insertPos1","_insertArrayElement","position","lastElement","insertPos2","insertPos3","jsonmod"],"mappings":"AAmBO,SAASA,YAAYC,KAAK;IAChC,OAAOC,KAAK,SAAS,CAACD;AACvB;;;;;;;;;;;;;;;;;;ACrBA,IAAME,sBAASA,WAAAA,GAAf;;aAAMA,UACOC,IAAI;gCADXD;QAEJ,IAAI,CAAC,IAAI,G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GAAG,OAAOzD,WAAW,KAAK,CAAC8D;gBAC/E;gBAAO,IAAIE,YAAYvC,UAAU,QAAQ,CAAC,MAAM,EAAE;oBACjD,IAAMwC,cAAcxC,UAAU,QAAQ,CAACA,UAAU,QAAQ,CAAC,MAAM,GAAG,EAAE;oBACrE,IAAMyC,aAAYD,YAAY,GAAG;oBACjC,OAAOjE,WAAW,KAAK,CAAC,GAAGkE,cAAa,OAAOT,MAAM,KAAK,GAAGzD,WAAW,KAAK,CAACkE;gBAC/E;gBACC,IAAMC,aAAY1C,UAAU,QAAQ,CAACuC,SAAS,CAAC,KAAK;gBACpD,OAAOhE,WAAW,KAAK,CAAC,GAAGmE,cAAaV,MAAM,KAAK,GAAG,OAAOzD,WAAW,KAAK,CAACmE;YAEhF;;;WAlWYxC;;AA4WN,SAASyC,QAAQpE,UAAU;IACjC,OAAO,IAAI2B,gBAAQ3B;AACpB;ACnXA,UAAeoE"} |
+1
-1
| { | ||
| "name": "json-codemod", | ||
| "version": "1.1.0", | ||
| "version": "2.0.0", | ||
| "private": false, | ||
@@ -5,0 +5,0 @@ "description": "A utility to patch the JSON string and preserve the original formatting, including comments and whitespace.", |
+210
-485
@@ -8,3 +8,3 @@ # json-codemod | ||
| A utility to patch JSON strings while preserving the original formatting, including comments and whitespace. | ||
| Modify JSON strings with a fluent chainable API while preserving formatting, comments, and whitespace. | ||
@@ -14,4 +14,4 @@ ## ✨ Features | ||
| - 🎨 **Format Preservation** - Maintains comments, whitespace, and original formatting | ||
| - 🔄 **Precise Modifications** - Replace, delete, and insert values while leaving everything else intact | ||
| - ⚡ **Unified Patch API** - Apply multiple operations efficiently in a single call | ||
| - 🔗 **Chainable API** - Fluent interface for readable modifications | ||
| - ⚡ **Sequential Operations** - Apply multiple changes in order | ||
| - 🚀 **Fast & Lightweight** - Zero dependencies, minimal footprint | ||
@@ -38,543 +38,284 @@ - 📦 **Dual module support** - Works with both ESM and CommonJS | ||
| ### Using Patch (Recommended for Multiple Operations) | ||
| ```js | ||
| import { batch } from "json-codemod"; | ||
| import jsonmod from "json-codemod"; | ||
| const source = '{"name": "Alice", "age": 30, "items": [1, 2]}'; | ||
| const source = '{"name": "Alice", "age": 30, "items": [1, 2, 3]}'; | ||
| // Apply multiple operations at once (most efficient) | ||
| const result = batch(source, [ | ||
| { path: "age", value: "31" }, // Replace | ||
| { path: "name" }, // Delete (no value means delete) | ||
| { path: "items", position: 2, value: "3" }, // Insert | ||
| ]); | ||
| const result = jsonmod(source) | ||
| .replace("name", '"Bob"') | ||
| .replace("age", "31") | ||
| .delete("items[1]") | ||
| .insert("items", 2, "4") | ||
| .apply(); | ||
| console.log(result); | ||
| // Output: {"age": 31, "items": [1, 2, 3]} | ||
| // Result: {"name": "Bob", "age": 31, "items": [1, 4, 3]} | ||
| ``` | ||
| ### Replace Values | ||
| ### With Value Helpers | ||
| Use `formatValue` for automatic type handling: | ||
| ```js | ||
| import { replace } from "json-codemod"; | ||
| import jsonmod, { formatValue } from "json-codemod"; | ||
| const source = '{"name": "Alice", "age": 30}'; | ||
| const source = '{"name": "Alice", "age": 30, "active": false}'; | ||
| // Replace a single value | ||
| const result = replace(source, [{ path: "age", value: "31" }]); | ||
| const result = jsonmod(source) | ||
| .replace("name", formatValue("Bob")) // Strings quoted automatically | ||
| .replace("age", formatValue(31)) // Numbers handled correctly | ||
| .replace("active", formatValue(true)) // Booleans too | ||
| .apply(); | ||
| console.log(result); | ||
| // Output: {"name": "Alice", "age": 31} | ||
| // Result: {"name": "Bob", "age": 31, "active": true} | ||
| ``` | ||
| ### Delete Properties and Elements | ||
| ## 📖 API Reference | ||
| ```js | ||
| import { remove } from "json-codemod"; | ||
| ### `jsonmod(sourceText)` | ||
| const source = '{"name": "Alice", "age": 30, "city": "Beijing"}'; | ||
| Creates a chainable instance for JSON modifications. | ||
| // Delete a property | ||
| const result = remove(source, [{ path: "age" }]); | ||
| **Parameters:** | ||
| - `sourceText` (string): JSON string to modify | ||
| console.log(result); | ||
| // Output: {"name": "Alice", "city": "Beijing"} | ||
| ``` | ||
| **Returns:** `JsonMod` instance | ||
| ### Insert Properties and Elements | ||
| **Example:** | ||
| ```js | ||
| import { insert } from "json-codemod"; | ||
| // Insert into object | ||
| const source1 = '{"name": "Alice"}'; | ||
| const result1 = insert(source1, [{ path: "", key: "age", value: "30" }]); | ||
| console.log(result1); | ||
| // Output: {"name": "Alice", "age": 30} | ||
| // Insert into array | ||
| const source2 = '{"numbers": [1, 3, 4]}'; | ||
| const result2 = insert(source2, [{ path: "numbers", position: 1, value: "2" }]); | ||
| console.log(result2); | ||
| // Output: {"numbers": [1, 2, 3, 4]} | ||
| const mod = jsonmod('{"name": "Alice"}'); | ||
| ``` | ||
| ### Preserving Format and Comments | ||
| ### `.replace(path, value)` | ||
| ```js | ||
| const source = `{ | ||
| // User information | ||
| "name": "Alice", | ||
| "age": 30, /* years old */ | ||
| "city": "Beijing" | ||
| }`; | ||
| Replace a value at the specified path. | ||
| const result = replace(source, [{ path: "age", value: "31" }]); | ||
| **Parameters:** | ||
| - `path` (string | string[]): JSON path | ||
| - `value` (string): New value as JSON string | ||
| console.log(result); | ||
| // Output: { | ||
| // // User information | ||
| // "name": "Alice", | ||
| // "age": 31, /* years old */ | ||
| // "city": "Beijing" | ||
| // } | ||
| ``` | ||
| **Returns:** `this` (chainable) | ||
| ## 📖 Usage Examples | ||
| **Examples:** | ||
| ```js | ||
| // Simple replacement | ||
| jsonmod(source).replace("name", '"Bob"').apply(); | ||
| ### Replace Operations | ||
| // Nested path | ||
| jsonmod(source).replace("user.profile.age", "31").apply(); | ||
| #### Modifying Nested Objects | ||
| // Array element | ||
| jsonmod(source).replace("items[1]", "99").apply(); | ||
| ```js | ||
| const source = '{"user": {"name": "Alice", "profile": {"age": 30}}}'; | ||
| const result = replace(source, [{ path: "user.profile.age", value: "31" }]); | ||
| // Result: {"user": {"name": "Alice", "profile": {"age": 31}}} | ||
| // Using formatValue | ||
| jsonmod(source).replace("name", formatValue("Bob")).apply(); | ||
| ``` | ||
| #### Modifying Array Elements | ||
| ### `.delete(path)` / `.remove(path)` | ||
| ```js | ||
| const source = '{"scores": [85, 90, 95]}'; | ||
| Delete a property or array element. | ||
| const result = replace(source, [{ path: "scores[1]", value: "92" }]); | ||
| **Parameters:** | ||
| - `path` (string | string[]): JSON path | ||
| // Result: {"scores": [85, 92, 95]} | ||
| ``` | ||
| **Returns:** `this` (chainable) | ||
| #### Using JSON Pointer | ||
| **Examples:** | ||
| ```js | ||
| const source = '{"data": {"items": [1, 2, 3]}}'; | ||
| // Delete property | ||
| jsonmod(source).delete("age").apply(); | ||
| const result = replace(source, [{ path: "/data/items/2", value: "99" }]); | ||
| // Delete array element | ||
| jsonmod(source).delete("items[0]").apply(); | ||
| // Result: {"data": {"items": [1, 2, 99]}} | ||
| ``` | ||
| // Delete nested property | ||
| jsonmod(source).delete("user.email").apply(); | ||
| #### Batch Modifications | ||
| ```js | ||
| const source = '{"x": 1, "y": 2, "arr": [3, 4]}'; | ||
| const result = replace(source, [ | ||
| { path: "x", value: "10" }, | ||
| { path: "y", value: "20" }, | ||
| { path: "arr[0]", value: "30" }, | ||
| ]); | ||
| // Result: {"x": 10, "y": 20, "arr": [30, 4]} | ||
| // Multiple deletions (remove is alias) | ||
| jsonmod(source) | ||
| .delete("a") | ||
| .remove("b") | ||
| .apply(); | ||
| ``` | ||
| #### Modifying String Values | ||
| ### `.insert(path, keyOrPosition, value)` | ||
| ```js | ||
| const source = '{"message": "Hello"}'; | ||
| Insert into objects or arrays. | ||
| const result = replace(source, [{ path: "message", value: '"World"' }]); | ||
| **Parameters:** | ||
| - `path` (string | string[]): Path to container | ||
| - `keyOrPosition` (string | number): Property name (object) or index (array) | ||
| - `value` (string): Value as JSON string | ||
| // Result: {"message": "World"} | ||
| // Note: value needs to include quotes for strings | ||
| ``` | ||
| **Returns:** `this` (chainable) | ||
| ### Delete Operations | ||
| #### Deleting Object Properties | ||
| **Examples:** | ||
| ```js | ||
| import { remove } from "json-codemod"; | ||
| // Insert into object | ||
| jsonmod(source) | ||
| .insert("", "email", '"test@example.com"') | ||
| .apply(); | ||
| const source = '{"name": "Alice", "age": 30, "city": "Beijing"}'; | ||
| // Insert into array at position | ||
| jsonmod(source) | ||
| .insert("items", 0, '"first"') | ||
| .apply(); | ||
| // Delete a single property | ||
| const result = remove(source, [{ path: "age" }]); | ||
| // Append to array | ||
| jsonmod(source) | ||
| .insert("items", 3, '"last"') | ||
| .apply(); | ||
| // Result: {"name": "Alice", "city": "Beijing"} | ||
| // Using formatValue | ||
| jsonmod(source) | ||
| .insert("user", "age", formatValue(30)) | ||
| .apply(); | ||
| ``` | ||
| #### Deleting Array Elements | ||
| ### `.apply()` | ||
| ```js | ||
| const source = '{"items": [1, 2, 3, 4, 5]}'; | ||
| Execute all queued operations and return modified JSON. | ||
| // Delete an element by index | ||
| const result = remove(source, [{ path: "items[2]" }]); | ||
| **Returns:** Modified JSON string | ||
| // Result: {"items": [1, 2, 4, 5]} | ||
| ``` | ||
| #### Deleting Nested Properties | ||
| **Example:** | ||
| ```js | ||
| const source = '{"user": {"name": "Alice", "age": 30, "email": "alice@example.com"}}'; | ||
| const result = remove(source, [{ path: "user.email" }]); | ||
| // Result: {"user": {"name": "Alice", "age": 30}} | ||
| const result = jsonmod(source) | ||
| .replace("a", "1") | ||
| .delete("b") | ||
| .insert("", "c", "3") | ||
| .apply(); // Execute and return result | ||
| ``` | ||
| #### Batch Deletions | ||
| ### `formatValue(value)` | ||
| ```js | ||
| const source = '{"a": 1, "b": 2, "c": 3, "d": 4}'; | ||
| Convert JavaScript values to JSON strings automatically. | ||
| const result = remove(source, [{ path: "b" }, { path: "d" }]); | ||
| **Parameters:** | ||
| - `value` (any): JavaScript value | ||
| // Result: {"a": 1, "c": 3} | ||
| ``` | ||
| **Returns:** JSON string representation | ||
| ### Insert Operations | ||
| #### Inserting into Objects | ||
| **Examples:** | ||
| ```js | ||
| import { insert } from "json-codemod"; | ||
| import { formatValue } from "json-codemod"; | ||
| const source = '{"name": "Alice"}'; | ||
| // Insert a new property (key is required for objects) | ||
| const result = insert(source, [{ path: "", key: "age", value: "30" }]); | ||
| // Result: {"name": "Alice", "age": 30} | ||
| formatValue(42) // "42" | ||
| formatValue("hello") // '"hello"' | ||
| formatValue(true) // "true" | ||
| formatValue(null) // "null" | ||
| formatValue({a: 1}) // '{"a":1}' | ||
| formatValue([1, 2, 3]) // '[1,2,3]' | ||
| ``` | ||
| #### Inserting into Arrays | ||
| ## 🎯 Examples | ||
| ```js | ||
| const source = '{"numbers": [1, 2, 4, 5]}'; | ||
| ### Configuration File Updates | ||
| // Insert at specific position | ||
| const result = insert(source, [{ path: "numbers", position: 2, value: "3" }]); | ||
| // Result: {"numbers": [1, 2, 3, 4, 5]} | ||
| ``` | ||
| #### Inserting at Array Start | ||
| ```js | ||
| const source = '{"list": [2, 3, 4]}'; | ||
| import jsonmod, { formatValue } from "json-codemod"; | ||
| import { readFileSync, writeFileSync } from "fs"; | ||
| const result = insert(source, [{ path: "list", position: 0, value: "1" }]); | ||
| const config = readFileSync("tsconfig.json", "utf-8"); | ||
| // Result: {"list": [1, 2, 3, 4]} | ||
| ``` | ||
| const updated = jsonmod(config) | ||
| .replace("compilerOptions.target", formatValue("ES2022")) | ||
| .replace("compilerOptions.strict", formatValue(true)) | ||
| .delete("compilerOptions.experimentalDecorators") | ||
| .insert("compilerOptions", "moduleResolution", formatValue("bundler")) | ||
| .apply(); | ||
| #### Appending to Array | ||
| ```js | ||
| const source = '{"list": [1, 2, 3]}'; | ||
| // Omit position to append at the end | ||
| const result = insert(source, [{ path: "list", value: "4" }]); | ||
| // Result: {"list": [1, 2, 3, 4]} | ||
| writeFileSync("tsconfig.json", updated); | ||
| ``` | ||
| #### Inserting into Nested Structures | ||
| ### Preserving Comments and Formatting | ||
| ```js | ||
| const source = '{"data": {"items": [1, 2]}}'; | ||
| const source = `{ | ||
| // User configuration | ||
| "name": "Alice", | ||
| "age": 30, /* years */ | ||
| "active": true | ||
| }`; | ||
| // Insert into nested array | ||
| const result = insert(source, [{ path: "data.items", position: 1, value: "99" }]); | ||
| const result = jsonmod(source) | ||
| .replace("age", "31") | ||
| .replace("active", "false") | ||
| .apply(); | ||
| // Result: {"data": {"items": [1, 99, 2]}} | ||
| // Comments and formatting preserved! | ||
| ``` | ||
| ### Modifying Complex Values | ||
| ### Complex Nested Operations | ||
| ```js | ||
| const source = '{"config": {"timeout": 3000}}'; | ||
| const data = '{"user": {"name": "Alice", "settings": {"theme": "dark"}}}'; | ||
| // Replace with an object | ||
| const result1 = replace(source, [{ path: "config", value: '{"timeout": 5000, "retry": 3}' }]); | ||
| // Replace with an array | ||
| const result2 = replace(source, [{ path: "config", value: "[1, 2, 3]" }]); | ||
| const result = jsonmod(data) | ||
| .replace("user.name", formatValue("Bob")) | ||
| .replace("user.settings.theme", formatValue("light")) | ||
| .insert("user.settings", "language", formatValue("en")) | ||
| .apply(); | ||
| ``` | ||
| ### Handling Special Characters in Keys | ||
| ### Array Manipulations | ||
| Use JSON Pointer to handle keys with special characters: | ||
| ```js | ||
| const source = '{"a/b": {"c~d": 5}}'; | ||
| const source = '{"items": [1, 2, 3, 4, 5]}'; | ||
| // In JSON Pointer: | ||
| // ~0 represents ~ | ||
| // ~1 represents / | ||
| const result = replace(source, [{ path: "/a~1b/c~0d", value: "42" }]); | ||
| const result = jsonmod(source) | ||
| .delete("items[1]") // Remove second item | ||
| .delete("items[2]") // Remove what is now third item | ||
| .insert("items", 0, "0") // Insert at beginning | ||
| .apply(); | ||
| // Result: {"a/b": {"c~d": 42}} | ||
| // Result: {"items": [0, 1, 4, 5]} | ||
| ``` | ||
| ## 📚 API Documentation | ||
| ### Conditional Operations | ||
| ### `batch(sourceText, patches)` ⭐ Recommended | ||
| Applies multiple operations (replace, delete, insert) in a single call. This is the most efficient way to apply multiple changes as it only parses the source once. | ||
| #### Parameters | ||
| - **sourceText** (`string`): The original JSON string | ||
| - **patches** (`Array<ReplacePatch | DeletePatch | InsertPatch>`): Array of mixed operations to apply | ||
| #### Batch Types | ||
| The function automatically detects the operation type based on the batch properties: | ||
| ```typescript | ||
| // Replace: has value but no key/position | ||
| { path: string, value: string } | ||
| // Delete: no value, key, or position | ||
| { path: string } | ||
| // Insert (object): has key and value | ||
| { path: string, key: string, value: string } | ||
| // Insert (array): has position and value | ||
| { path: string, position: number, value: string } | ||
| ``` | ||
| #### Return Value | ||
| Returns the modified JSON string with all patches applied. | ||
| #### Example | ||
| ```js | ||
| const result = batch('{"a": 1, "b": 2, "items": [1, 2]}', [ | ||
| { path: "a", value: "10" }, // Replace | ||
| { path: "b" }, // Delete | ||
| { path: "items", position: 2, value: "3" }, // Insert | ||
| ]); | ||
| // Returns: '{"a": 10, "items": [1, 2, 3]}' | ||
| ``` | ||
| let mod = jsonmod(config); | ||
| --- | ||
| ### `replace(sourceText, patches)` | ||
| Modifies values in a JSON string. | ||
| #### Parameters | ||
| - **sourceText** (`string`): The original JSON string | ||
| - **patches** (`Array<Patch>`): Array of modifications to apply | ||
| #### Patch Object | ||
| ```typescript | ||
| interface Patch { | ||
| /** | ||
| * A JSON path where the replacement should occur. | ||
| */ | ||
| path: string; | ||
| /** | ||
| * The value to insert at the specified path. | ||
| */ | ||
| value: string; | ||
| if (isDevelopment) { | ||
| mod = mod.replace("debug", "true"); | ||
| } | ||
| ``` | ||
| #### Return Value | ||
| Returns the modified JSON string. | ||
| #### Error Handling | ||
| - If a path doesn't exist, that modification is silently ignored without throwing an error | ||
| - If multiple modifications have conflicting (overlapping) paths, an error is thrown | ||
| --- | ||
| ### `remove(sourceText, patches)` | ||
| Deletes properties from objects or elements from arrays in a JSON string. | ||
| #### Parameters | ||
| - **sourceText** (`string`): The original JSON string | ||
| - **patches** (`Array<DeletePatch>`): Array of deletions to apply | ||
| #### DeletePatch Object | ||
| ```typescript | ||
| interface DeletePatch { | ||
| /** | ||
| * A JSON path to delete. | ||
| */ | ||
| path: string; | ||
| if (needsUpdate) { | ||
| mod = mod.replace("version", formatValue("2.0.0")); | ||
| } | ||
| ``` | ||
| #### Return Value | ||
| Returns the modified JSON string with specified paths removed. | ||
| #### Error Handling | ||
| - If a path doesn't exist, the deletion is silently ignored | ||
| - Whitespace and commas are automatically handled to maintain valid JSON | ||
| --- | ||
| ### `insert(sourceText, patches)` | ||
| Inserts new properties into objects or elements into arrays in a JSON string. | ||
| #### Parameters | ||
| - **sourceText** (`string`): The original JSON string | ||
| - **patches** (`Array<InsertPatch>`): Array of insertions to apply | ||
| #### InsertPatch Object | ||
| ```typescript | ||
| interface InsertPatch { | ||
| /** | ||
| * A JSON path where the insertion should occur. | ||
| * For arrays: the path should point to the array, and position specifies the index. | ||
| * For objects: the path should point to the object, and key specifies the property name. | ||
| */ | ||
| path: string; | ||
| /** | ||
| * The value to insert. | ||
| */ | ||
| value: string; | ||
| /** | ||
| * For array insertion: the index where to insert the value. | ||
| * If omitted, the value is appended to the end. | ||
| */ | ||
| position?: number; | ||
| /** | ||
| * For object insertion: the key name for the new property. | ||
| * Required when inserting into objects. | ||
| */ | ||
| key?: string; | ||
| } | ||
| const result = mod.apply(); | ||
| ``` | ||
| #### Return Value | ||
| ## 📚 Path Syntax | ||
| Returns the modified JSON string with new values inserted. | ||
| ### Dot Notation | ||
| #### Error Handling | ||
| - For object insertions, `key` is required | ||
| - For object insertions, if the key already exists, an error is thrown | ||
| - For array insertions, position must be within valid bounds (0 to array.length) | ||
| --- | ||
| ### Path Syntax | ||
| Two path syntaxes are supported for all operations: | ||
| 1. **Dot Notation** (recommended for simple cases) | ||
| - Object properties: `"user.name"` | ||
| - Array indices: `"items[0]"` | ||
| - Nested paths: `"data.users[0].name"` | ||
| 2. **JSON Pointer** (RFC 6901) | ||
| - Format: starts with `/` | ||
| - Object properties: `"/user/name"` | ||
| - Array indices: `"/items/0"` | ||
| - Escape sequences: | ||
| - `~0` represents `~` | ||
| - `~1` represents `/` | ||
| - Example: `"/a~1b/c~0d"` refers to the `c~d` property of the `a/b` object | ||
| ### Value Format | ||
| The `value` parameter must be a string representation of a JSON value: | ||
| - Numbers: `"42"`, `"3.14"` | ||
| - Strings: `'"hello"'` (must include quotes) | ||
| - Booleans: `"true"`, `"false"` | ||
| - null: `"null"` | ||
| - Objects: `'{"key": "value"}'` | ||
| - Arrays: `'[1, 2, 3]'` | ||
| ## 🎯 Use Cases | ||
| ### Configuration File Modification | ||
| Perfect for modifying configuration files with comments (like `tsconfig.json`, `package.json`, etc.): | ||
| ```js | ||
| import { readFileSync, writeFileSync } from "fs"; | ||
| import { replace, remove, insert } from "json-codemod"; | ||
| // Read configuration file | ||
| const config = readFileSync("tsconfig.json", "utf-8"); | ||
| // Modify configuration | ||
| const updated = replace(config, [ | ||
| { path: "compilerOptions.target", value: '"ES2020"' }, | ||
| { path: "compilerOptions.strict", value: "true" }, | ||
| ]); | ||
| // Save configuration (preserving original format and comments) | ||
| writeFileSync("tsconfig.json", updated); | ||
| jsonmod(source).replace("user.profile.name", '"Bob"').apply(); | ||
| ``` | ||
| ### Managing Dependencies | ||
| ### Bracket Notation for Arrays | ||
| ```js | ||
| import { readFileSync, writeFileSync } from "fs"; | ||
| import { insert, remove } from "json-codemod"; | ||
| const pkg = readFileSync("package.json", "utf-8"); | ||
| // Add a new dependency | ||
| const withNewDep = insert(pkg, [{ path: "dependencies", key: "lodash", value: '"^4.17.21"' }]); | ||
| // Remove a dependency | ||
| const cleaned = remove(pkg, [{ path: "dependencies.old-package" }]); | ||
| writeFileSync("package.json", cleaned); | ||
| jsonmod(source).replace("items[0]", "1").apply(); | ||
| jsonmod(source).delete("items[2]").apply(); | ||
| ``` | ||
| ### JSON Data Transformation | ||
| ### JSON Pointer | ||
| ```js | ||
| // Batch update JSON data | ||
| const data = fetchDataAsString(); | ||
| const updated = replace(data, [ | ||
| { path: "metadata.version", value: '"2.0"' }, | ||
| { path: "metadata.updatedAt", value: `"${new Date().toISOString()}"` }, | ||
| ]); | ||
| jsonmod(source).replace("/user/profile/name", '"Bob"').apply(); | ||
| ``` | ||
| ### Array Manipulation | ||
| ### Special Characters | ||
| ```js | ||
| import { insert, remove } from "json-codemod"; | ||
| For keys with special characters, use JSON Pointer: | ||
| const data = '{"tasks": ["task1", "task2", "task4"]}'; | ||
| // Insert a task in the middle | ||
| const withTask = insert(data, [{ path: "tasks", position: 2, value: '"task3"' }]); | ||
| // Remove a completed task | ||
| const updated = remove(withTask, [{ path: "tasks[0]" }]); | ||
| ``` | ||
| ### Automation Scripts | ||
| ```js | ||
| // Automated version number updates | ||
| const pkg = readFileSync("package.json", "utf-8"); | ||
| const version = "1.2.3"; | ||
| // Key with slash: "a/b" | ||
| jsonmod(source).replace("/a~1b", "value").apply(); | ||
| const updated = replace(pkg, [{ path: "version", value: `"${version}"` }]); | ||
| writeFileSync("package.json", updated); | ||
| // Key with tilde: "a~b" | ||
| jsonmod(source).replace("/a~0b", "value").apply(); | ||
| ``` | ||
@@ -584,20 +325,15 @@ | ||
| The package includes full TypeScript type definitions: | ||
| Full TypeScript support with type definitions: | ||
| ```typescript | ||
| import { replace, remove, insert, Patch, DeletePatch, InsertPatch } from "json-codemod"; | ||
| import jsonmod, { JsonMod, formatValue } from "json-codemod"; | ||
| const source: string = '{"count": 0}'; | ||
| const source = '{"name": "Alice", "age": 30}'; | ||
| // Replace | ||
| const patches: Patch[] = [{ path: "count", value: "1" }]; | ||
| const result: string = replace(source, patches); | ||
| const instance: JsonMod = jsonmod(source); | ||
| // Delete | ||
| const deletePatches: DeletePatch[] = [{ path: "count" }]; | ||
| const deleted: string = remove(source, deletePatches); | ||
| // Insert | ||
| const insertPatches: InsertPatch[] = [{ path: "", key: "name", value: '"example"' }]; | ||
| const inserted: string = insert(source, insertPatches); | ||
| const result: string = instance | ||
| .replace("name", formatValue("Bob")) | ||
| .delete("age") | ||
| .apply(); | ||
| ``` | ||
@@ -607,70 +343,59 @@ | ||
| json-codemod uses Concrete Syntax Tree (CST) technology: | ||
| 1. **Parse:** Creates a Concrete Syntax Tree (CST) preserving all formatting | ||
| 2. **Queue:** Operations are queued, not executed immediately | ||
| 3. **Execute:** `.apply()` runs operations sequentially, re-parsing after each | ||
| 4. **Return:** Returns the modified JSON string with formatting preserved | ||
| 1. **Tokenization** (Tokenizer): Breaks down the JSON string into tokens, including values, whitespace, and comments | ||
| 2. **Parsing** (CSTBuilder): Builds a syntax tree that preserves all formatting information | ||
| 3. **Path Resolution** (PathResolver): Locates the node to modify based on the path | ||
| 4. **Precise Replacement**: Replaces only the target value, preserving everything else | ||
| This approach ensures that everything except the modified values (including whitespace, comments, and formatting) remains unchanged. | ||
| ## ❓ FAQ | ||
| ### Q: Why does the value parameter need to be a string? | ||
| ### Why use formatValue? | ||
| A: For flexibility and precision. You have complete control over the output format, including quotes, spacing, etc. | ||
| **Without formatValue:** | ||
| ```js | ||
| .replace("name", '"Bob"') // Must remember quotes | ||
| .replace("age", "30") // No quotes for numbers | ||
| .replace("active", "true") // No quotes for booleans | ||
| ``` | ||
| **With formatValue:** | ||
| ```js | ||
| // Numbers don't need quotes | ||
| replace(source, [{ path: "age", value: "30" }]); | ||
| // Strings need quotes | ||
| replace(source, [{ path: "name", value: '"Alice"' }]); | ||
| // You can control formatting | ||
| replace(source, [{ path: "data", value: '{\n "key": "value"\n}' }]); | ||
| .replace("name", formatValue("Bob")) // Automatic | ||
| .replace("age", formatValue(30)) // Automatic | ||
| .replace("active", formatValue(true)) // Automatic | ||
| ``` | ||
| ### Q: How are non-existent paths handled? | ||
| ### How are comments preserved? | ||
| A: If a path doesn't exist, that modification is automatically ignored without throwing an error. The original string remains unchanged. | ||
| The library parses JSON into a Concrete Syntax Tree that includes comments and whitespace as tokens. Modifications only change value tokens, leaving everything else intact. | ||
| ### Q: What JSON extensions are supported? | ||
| ### What about performance? | ||
| A: Supported: | ||
| Operations are applied sequentially with re-parsing between each. This ensures correctness but means: | ||
| - Fast for small to medium JSON files | ||
| - For large files with many operations, consider batching similar changes | ||
| - ✅ Single-line comments `//` | ||
| - ✅ Block comments `/* */` | ||
| - ✅ All standard JSON syntax | ||
| ### Can I reuse a JsonMod instance? | ||
| Not supported: | ||
| No, call `.apply()` returns a string and operations are cleared. Create a new instance for new modifications: | ||
| - ❌ Other JSON5 features (like unquoted keys, trailing commas, etc.) | ||
| ```js | ||
| const result1 = jsonmod(source).replace("a", "1").apply(); | ||
| const result2 = jsonmod(result1).replace("b", "2").apply(); | ||
| ``` | ||
| ### Q: How is the performance? | ||
| A: json-codemod is specifically designed for precise modifications with excellent performance. For large files (hundreds of KB), parsing and modification typically complete in milliseconds. | ||
| ## 🤝 Contributing | ||
| Contributions are welcome! If you'd like to contribute to the project: | ||
| Contributions are welcome! Please feel free to submit a Pull Request. | ||
| 1. Fork the repository | ||
| 2. Create your feature branch (`git checkout -b feature/AmazingFeature`) | ||
| 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`) | ||
| 4. Push to the branch (`git push origin feature/AmazingFeature`) | ||
| 5. Open a Pull Request | ||
| ## 📄 License | ||
| This project is licensed under the [Anti 996 License](LICENSE). | ||
| [Anti 996 License](https://github.com/996icu/996.ICU/blob/master/LICENSE) | ||
| ## 🔗 Links | ||
| - [npm package](https://www.npmjs.com/package/json-codemod) | ||
| - [GitHub repository](https://github.com/axetroy/json-codemod) | ||
| - [Issue tracker](https://github.com/axetroy/json-codemod/issues) | ||
| - [GitHub](https://github.com/axetroy/json-codemod) | ||
| - [npm](https://www.npmjs.com/package/json-codemod) | ||
| ## 🌟 Star History | ||
| If this project helps you, please give it a ⭐️! | ||
| [](https://star-history.com/#axetroy/json-codemod&Date) |
| import { ReplacePatch } from "./replace.cts"; | ||
| import { DeletePatch } from "./delete.cts"; | ||
| import { InsertPatch } from "./insert.cts"; | ||
| export type BatchPatch = ReplacePatch | DeletePatch | InsertPatch; | ||
| /** | ||
| * Applies a batch of patches to the source text. | ||
| * @param sourceText - The original source text. | ||
| * @param patches - An array of patches to apply. | ||
| * @returns The modified source text after applying all patches. | ||
| */ | ||
| export declare function batch(sourceText: string, patches: Array<BatchPatch>): string; |
| import { Node } from "../CSTBuilder.cts"; | ||
| export interface DeletePatch { | ||
| /** | ||
| * A JSON path to delete. | ||
| */ | ||
| path: string; | ||
| } | ||
| /** | ||
| * Deletes nodes from the JSON content based on the provided patches. | ||
| * @param sourceText - The original JSON content as a string. | ||
| * @param patches - An array of delete patches specifying the paths to remove. | ||
| * @param root - Optional CST root node to avoid re-parsing. | ||
| */ | ||
| export declare function remove(sourceText: string, patches: Array<DeletePatch>, root?: Node): string; |
| import { Node } from "../CSTBuilder.cts"; | ||
| export interface InsertPatchArray { | ||
| /** | ||
| * A JSON path where the insertion should occur. | ||
| * For arrays: the path should point to the array, and position specifies the index. | ||
| * For objects: the path should point to the object, and key specifies the property name. | ||
| */ | ||
| path: string; | ||
| /** | ||
| * For array insertion: the index where to insert the value. | ||
| */ | ||
| position: number; | ||
| /** | ||
| * The value to insert. | ||
| */ | ||
| value: string; | ||
| } | ||
| export interface InsertPatchObject { | ||
| /** | ||
| * A JSON path where the insertion should occur. | ||
| * For arrays: the path should point to the array, and position specifies the index. | ||
| * For objects: the path should point to the object, and key specifies the property name. | ||
| */ | ||
| path: string; | ||
| /** | ||
| * For object insertion: the key name for the new property. | ||
| */ | ||
| key: string; | ||
| /** | ||
| * The value to insert. | ||
| */ | ||
| value: string; | ||
| } | ||
| export type InsertPatch = InsertPatchArray | InsertPatchObject; | ||
| /** | ||
| * Inserts values into a JSON structure at specified paths. | ||
| * @param sourceText - The original JSON text. | ||
| * @param patches - An array of insertion patches. | ||
| * @param root - Optional CST root node to avoid re-parsing. | ||
| */ | ||
| export declare function insert(sourceText: string, patches: Array<InsertPatch>, root?: Node): string; |
| import { Node } from "../CSTBuilder.cts"; | ||
| export interface ReplacePatch { | ||
| /** | ||
| * A JSON path where the replacement should occur. | ||
| */ | ||
| path: string; | ||
| /** | ||
| * The value to insert at the specified path. | ||
| */ | ||
| value: string; | ||
| } | ||
| /** | ||
| * Replaces values in a JSON-like string at specified paths with new values. | ||
| * @param sourceText - The original JSON content as a string. | ||
| * @param patches - An array of replacement instructions. | ||
| * @param root - Optional CST root node to avoid re-parsing. | ||
| */ | ||
| export declare function replace(sourceText: string, patches: Array<ReplacePatch>, root?: Node): string; |
| import { ReplacePatch } from "./replace.mts"; | ||
| import { DeletePatch } from "./delete.mts"; | ||
| import { InsertPatch } from "./insert.mts"; | ||
| export type BatchPatch = ReplacePatch | DeletePatch | InsertPatch; | ||
| /** | ||
| * Applies a batch of patches to the source text. | ||
| * @param sourceText - The original source text. | ||
| * @param patches - An array of patches to apply. | ||
| * @returns The modified source text after applying all patches. | ||
| */ | ||
| export declare function batch(sourceText: string, patches: Array<BatchPatch>): string; |
| import { Node } from "../CSTBuilder.mts"; | ||
| export interface DeletePatch { | ||
| /** | ||
| * A JSON path to delete. | ||
| */ | ||
| path: string; | ||
| } | ||
| /** | ||
| * Deletes nodes from the JSON content based on the provided patches. | ||
| * @param sourceText - The original JSON content as a string. | ||
| * @param patches - An array of delete patches specifying the paths to remove. | ||
| * @param root - Optional CST root node to avoid re-parsing. | ||
| */ | ||
| export declare function remove(sourceText: string, patches: Array<DeletePatch>, root?: Node): string; |
| import { Node } from "../CSTBuilder.mts"; | ||
| export interface InsertPatchArray { | ||
| /** | ||
| * A JSON path where the insertion should occur. | ||
| * For arrays: the path should point to the array, and position specifies the index. | ||
| * For objects: the path should point to the object, and key specifies the property name. | ||
| */ | ||
| path: string; | ||
| /** | ||
| * For array insertion: the index where to insert the value. | ||
| */ | ||
| position: number; | ||
| /** | ||
| * The value to insert. | ||
| */ | ||
| value: string; | ||
| } | ||
| export interface InsertPatchObject { | ||
| /** | ||
| * A JSON path where the insertion should occur. | ||
| * For arrays: the path should point to the array, and position specifies the index. | ||
| * For objects: the path should point to the object, and key specifies the property name. | ||
| */ | ||
| path: string; | ||
| /** | ||
| * For object insertion: the key name for the new property. | ||
| */ | ||
| key: string; | ||
| /** | ||
| * The value to insert. | ||
| */ | ||
| value: string; | ||
| } | ||
| export type InsertPatch = InsertPatchArray | InsertPatchObject; | ||
| /** | ||
| * Inserts values into a JSON structure at specified paths. | ||
| * @param sourceText - The original JSON text. | ||
| * @param patches - An array of insertion patches. | ||
| * @param root - Optional CST root node to avoid re-parsing. | ||
| */ | ||
| export declare function insert(sourceText: string, patches: Array<InsertPatch>, root?: Node): string; |
| import { Node } from "../CSTBuilder.mts"; | ||
| export interface ReplacePatch { | ||
| /** | ||
| * A JSON path where the replacement should occur. | ||
| */ | ||
| path: string; | ||
| /** | ||
| * The value to insert at the specified path. | ||
| */ | ||
| value: string; | ||
| } | ||
| /** | ||
| * Replaces values in a JSON-like string at specified paths with new values. | ||
| * @param sourceText - The original JSON content as a string. | ||
| * @param patches - An array of replacement instructions. | ||
| * @param root - Optional CST root node to avoid re-parsing. | ||
| */ | ||
| export declare function replace(sourceText: string, patches: Array<ReplacePatch>, root?: Node): string; |
Unidentified License
LicenseSomething that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Unidentified License
LicenseSomething that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
185389
-5.04%21
-16%1647
-1.14%397
-40.92%1
Infinity%