Created
January 12, 2017 16:39
-
-
Save katowulf/0535e2568443a2c1e328a1704a74c053 to your computer and use it in GitHub Desktop.
Encode Firebase keys to escape any restricted meta characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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