I'm looking for a Javascript obfuscation tool that will be able to obfuscate specific string literals.
I have a class function like this:
function Mapper() {
var map = {};
this.put = function(name, val) {
map[name] = val;
};
this.get = function(name) {
return map[name];
};
}
And it's used like this throughout my code:
var mapper = new Mapper();
mapper.put("first", 123);
mapper.put("second", 999);
var value = mapper.get("first");
// etc...
I want to obfuscate the key names - "first", "second"
- since they are only relevant during development.
I obviously need these strings to be obfuscated only where they are used in context with the mapper
put()
or get()
methods, but this is not an issue because the keys I use are not used anywhere else in my application.
However, I don't want ALL the string literals in my app to be obfuscated. Not all string literals are used as object property keys.
I wouldn't mind manually defining a list of keys that should be obfuscated if the tool requires me to do so.
How can this be done?
Is there a way to do this with one of the commonly used obfuscation tools like Closure Compiler, YUI, unglifyjs, or anything similar?