This package intent is to make "safe" JavaScript runtime by checking types at runtime and disallowing most of implicit coercion
In Node project add in package.json:
"main": "dist/index.js",
"scripts": {
"prepare": "safec ./src -d ./dist --src-map true --allow-ts",
"start": "npm run prepare && node ./dist/index.js"
},
"devDependencies": {
"typescript-plugin-safescript": "^0.5.3"
},
"dependencies": {
"@redradist/module-runtime-safescript": "^0.4.1"
}Then in your main script before any code import @redradist/module-runtime-safescript runtime:
import"@redradist/module-runtime-safescript";lety=8;
...
y+="233";// Possible error behaviour
...The dist/index.js will look like:
import"@redradist/module-runtime-safescript";lety=8;
...
y=SafeScript.add(y,"233");// SafeScript will throw TypeError exception
...Now you can go in your code and fix the issue:
import"@redradist/module-runtime-safescript";lety=8;
...
y+=Number("233");// Now it is "safe" behaviour
...Using this SafeScript runtime fills like Python on V8 ;)
The Philosophy of SafeScript:
- Allow subset of "safe" operations in
JavaScriptandTypeScript - Do not introduce a new valid behaviour in runtime, in such way it is easier just to remove
SafeScriptruntime at anytime
