@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 (17 loc) • 586 B
JavaScript
import { SEPARATOR, TILDE, ESCAPE_TILDE, ESCAPE_SEPARATOR } from './constant.mjs';
const escapeSegment = (segment) => {
if (segment.indexOf(SEPARATOR) === -1 && segment.indexOf(TILDE) === -1)
return segment;
let result = '';
for (let i = 0, l = segment.length; i < l; i++) {
const character = segment[i];
if (character === TILDE)
result += ESCAPE_TILDE;
else if (character === SEPARATOR)
result += ESCAPE_SEPARATOR;
else
result += character;
}
return result;
};
export { escapeSegment };