Created
November 17, 2014 11:32
-
-
Save radiosilence/788911b9f3dc76afd66e to your computer and use it in GitHub Desktop.
Handy function to turning a nested object into a list of string based constants.
This file contains hidden or 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
"use strict"; | |
module.exports = { | |
constantify: function constantify(app, obj, prevK) { | |
for (var k in obj) { | |
var nextK = prevK ? prevK + '.' + k : app + '.' + k; | |
if (obj[k] === null) obj[k] = nextK; | |
else constantify(app, obj[k], nextK); | |
} | |
return obj; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: