@winglet/json
Version:
TypeScript library for safe and efficient JSON data manipulation with RFC 6901 (JSON Pointer) and RFC 6902 (JSON Patch) compliance, featuring prototype pollution protection and immutable operations
20 lines (16 loc) • 598 B
JavaScript
;
var _enum = require('../../enum.cjs');
var escapeSegment = require('./escapeSegment.cjs');
const escapePath = (path) => {
const segments = path.split(_enum.JSONPointer.Separator);
const length = segments.length;
if (length === 0)
return '';
if (length === 1)
return escapeSegment.escapeSegment(segments[0]);
let result = escapeSegment.escapeSegment(segments[0]);
for (let i = 1; i < length; i++)
result += _enum.JSONPointer.Separator + escapeSegment.escapeSegment(segments[i]);
return result;
};
exports.escapePath = escapePath;