@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
18 lines (15 loc) • 527 B
JavaScript
import { JSONPointer } from '../../enum.mjs';
import { escapeSegment } from './escapeSegment.mjs';
const escapePath = (path) => {
const segments = path.split(JSONPointer.Separator);
const length = segments.length;
if (length === 0)
return '';
if (length === 1)
return escapeSegment(segments[0]);
let result = escapeSegment(segments[0]);
for (let i = 1; i < length; i++)
result += JSONPointer.Separator + escapeSegment(segments[i]);
return result;
};
export { escapePath };