UNPKG

@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

27 lines (24 loc) 751 B
import { TILDE, SEPARATOR } from './constant.mjs'; const unescapePath = (segment) => { if (segment.indexOf(TILDE) === -1) return segment; let result = ''; for (let i = 0, l = segment.length; i < l; i++) { const current = segment[i]; if (current === TILDE && i + 1 < l) { const next = segment[++i]; if (next === ESCAPE_TILDE_VALUE) result += TILDE; else if (next === ESCAPE_SEPARATOR_VALUE) result += SEPARATOR; else result += current + next; } else result += current; } return result; }; const ESCAPE_TILDE_VALUE = '0'; const ESCAPE_SEPARATOR_VALUE = '1'; export { unescapePath };