malta-js-toolkit
v1.0.16
Published
Malta plugin to enable some special features
Downloads
6
Maintainers
Readme
This plugin can be used on: .js files and even on .coffee and .ts files after using the right plugin
Purpose
Allows to enable some extra features on javascript code
Options
noConsole
disable all console functions, iftrue
is passednoDebugger
removes alldebugger
occurrences, iftrue
is passedlockScriptUrl (*)
allows to lock the execution of the script if thesrc
attribute of the script differs from the one passed (in this case use the generic protocol in the url passed)lockHostUrl (*)
allows to lock the execution of the script if the host where the script is loaded differs from the one passed (even in this case use the generic protocol in the url passed)apiKey && apiName (*)
allows to specify key value and a variable name to execute the script only if in the global scope can be found a variable with the right value.
(*) it is possible to use an additional message
parameter to overwrite the default failure message that will appear in the browser console.
If not option is given the plugin won't modify the file/s interested
Sample usage:
malta app/source/index.js public/js -plugins=malta-js-toolkit[noConsole:true,lockScriptUrl:\"//mydomain.com/js/app.js\",lockHostUrl:\"//mydomain.com\",apiName:\"secretKey\",apiKey:\"foofoo\"]
in this case:
- every console function will be disabled
- the script execution will be locked but if all the following conditions are met
- the script
src
matches/[https?:]?\/\/mydomain\.com\/js\/app\.js/
- the domain where is loaded matches
/[https?:]?\/\/mydomain\.com/
- at execution can be found a variable named
secretKey
in the global scope containing the valuefoofoo
- the script
or in the .json file :
"app/source/index.js" : "public/js -plugins=malta-js-toolkit[noConsole:true,lockScriptUrl:\'//mydomain.com/js/app.js\',lockHostUrl:\'//mydomain.com\',apiName:\'secretKey\',apiKey:\'foofoo\']"
or in a script :
var Malta = require('malta'),
dynKey = "foofoo";
Malta.get().check([
'app/source/index.js',
'public/js',
'-plugins=malta-js-toolkit',
'-options=noConsole:true,lockScriptUrl:"//mydomain.com/js/app.js",lockHostUrl:"//mydomain.com",apiName:"secretKey",apiKey:"' + dynKey + '"'
]).start(function (o) {
var s = this;
console.log('name : ' + o.name)
console.log("content : \n" + o.content);
'plugin' in o && console.log("plugin : " + o.plugin);
console.log('=========');
});
Since the locking of the execution is done with a very simple hash function it is strongly recommended to obfuscate everything using (after malta-js-toolkit) the malta-js-obfuscator plugin.