@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
29 lines (25 loc) • 805 B
JavaScript
;
var constant = require('./constant.cjs');
const unescapePath = (segment) => {
if (segment.indexOf(constant.TILDE) === -1)
return segment;
let result = '';
for (let i = 0, l = segment.length; i < l; i++) {
const current = segment[i];
if (current === constant.TILDE && i + 1 < l) {
const next = segment[++i];
if (next === ESCAPE_TILDE_VALUE)
result += constant.TILDE;
else if (next === ESCAPE_SEPARATOR_VALUE)
result += constant.SEPARATOR;
else
result += current + next;
}
else
result += current;
}
return result;
};
const ESCAPE_TILDE_VALUE = '0';
const ESCAPE_SEPARATOR_VALUE = '1';
exports.unescapePath = unescapePath;