Skip to content

Instantly share code, notes, and snippets.

@katowulf
Created January 12, 2017 16:39
Show Gist options
  • Save katowulf/0535e2568443a2c1e328a1704a74c053 to your computer and use it in GitHub Desktop.
Save katowulf/0535e2568443a2c1e328a1704a74c053 to your computer and use it in GitHub Desktop.
Encode Firebase keys to escape any restricted meta characters
function encodeKeys(data) {
let encodedData = null;
if( typeof(data) === 'function' ) {
encodedData = data + '';
}
else if (typeof(data) !== 'object') {
encodedData = data;
}
else if(data !== null) {
encodedData = {};
Object.keys(data).forEach(key => encodedData[encodeKey(key)] = encodeKeys(data[key]));
}
return encodedData;
}
function encodeKey(key) {
return encodeURIComponent(key).replace('.', ' %2E');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment