firebase-encode
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -6,11 +6,32 @@ 'use strict'; | ||
}); | ||
// http://stackoverflow.com/a/6969486/692528 | ||
var escapeRegExp = function escapeRegExp(str) { | ||
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); | ||
}; | ||
// http://stackoverflow.com/a/19148116/692528 | ||
var dots = /\./g; | ||
var escapedDot = '%2E'; | ||
var chars = '.$[]#/%'.split(''); | ||
var charCodes = chars.map(function (c) { | ||
return '%' + c.charCodeAt(0).toString(16).toUpperCase(); | ||
}); | ||
var charToCode = {}; | ||
var codeToChar = {}; | ||
chars.forEach(function (c, i) { | ||
charToCode[c] = charCodes[i]; | ||
codeToChar[charCodes[i]] = c; | ||
}); | ||
var charsRegex = new RegExp('[' + escapeRegExp(chars.join('')) + ']', 'g'); | ||
var charCodesRegex = new RegExp(charCodes.join('|'), 'g'); | ||
var encode = function encode(str) { | ||
return encodeURIComponent(str).replace(dots, escapedDot); | ||
return str.replace(charsRegex, function (match) { | ||
return charToCode[match]; | ||
}); | ||
}; | ||
var decode = function decode(str) { | ||
return decodeURIComponent(str.replace(escapedDot, '.')); | ||
return str.replace(charCodesRegex, function (match) { | ||
return codeToChar[match]; | ||
}); | ||
}; | ||
@@ -17,0 +38,0 @@ |
{ | ||
"name": "firebase-encode", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Encode (escape) and decode firebase key string to avoid unexpected results.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3721
36