UNPKG

immutablepatch

Version:

Apply RFC 6902 style patches to Immutable.JS data structures

27 lines (22 loc) 558 B
'use strict'; var slashRe = new RegExp('/', 'g'); var escapedSlashRe = new RegExp('~1', 'g'); var tildeRe = /~/g; var escapedTildeRe = /~0/g; var Path = { escape: function (str) { if(typeof(str) !== 'string'){ throw 'param str (' + str + ') is not a string'; } return str.replace(tildeRe, '~0').replace(slashRe, '~1'); }, unescape: function (str) { if(typeof(str) == 'string') { return str.replace(escapedSlashRe, '/').replace(escapedTildeRe, '~'); } else { return str; } } }; module.exports = Path;