const decodeToken = (pointer: string) => {
return pointer
.replace(new RegExp('~1', 'g'), '/')
.replace(new RegExp('~0', 'g'), '~');
};
export {
decodeToken,
};
The decodeToken
function unescapes a previously escaped JSON pointer reference
token replacing the values ‘~1’ with ‘/‘ and ‘~0’ with ‘~’.
import { decodeToken } from '@jdw/jst';
decodeToken('~0~1home') // '~/home'
Arguments
Returns
string
: The decoded string.Throws
const decodeToken = (pointer: string) => {
return pointer
.replace(new RegExp('~1', 'g'), '/')
.replace(new RegExp('~0', 'g'), '~');
};
export {
decodeToken,
};