const encodeToken = (pointer: string) => {
return pointer
.replace(new RegExp('~', 'g'), '~0')
.replace(new RegExp('/', 'g'), '~1');
};
export {
encodeToken,
};
The encodeToken
function encodes a string for use as a JSON pointer token
replacing the values ‘~’ with ‘~0’ and ‘/‘ with ‘~1’.
import { encodeToken } from '@jdw/jst';
encodeToken('~/home') // '~0~1home'
Arguments
Returns
string
: The escaped stringThrows
const encodeToken = (pointer: string) => {
return pointer
.replace(new RegExp('~', 'g'), '~0')
.replace(new RegExp('/', 'g'), '~1');
};
export {
encodeToken,
};