GrauKatze 05f70669c9 Сконфигурирована и подготовлена база для проекта | 2 роки тому | |
---|---|---|
.. | ||
lib | 2 роки тому | |
node_modules | 2 роки тому | |
src | 2 роки тому | |
test | 2 роки тому | |
.editorconfig | 2 роки тому | |
.gitattributes | 2 роки тому | |
.prettierrc | 2 роки тому | |
.travis.yml | 2 роки тому | |
LICENSE | 2 роки тому | |
README.md | 2 роки тому | |
package.json | 2 роки тому | |
tsconfig.json | 2 роки тому |
Determine whether a JavaScript expression evaluates to a constant (using Babylon). Here it is assumed to be safe to underestimate how constant something is.
npm install constantinople
var isConstant = require('constantinople');
if (isConstant('"foo" + 5')) {
console.dir(isConstant.toConstant('"foo" + 5'));
}
if (isConstant('Math.floor(10.5)', {Math: Math})) {
console.dir(isConstant.toConstant('Math.floor(10.5)', {Math: Math}));
}
Returns true
if src
evaluates to a constant, false
otherwise. It will also return false
if there is a syntax error, which makes it safe to use on potentially ES6 code.
Constants is an object mapping strings to values, where those values should be treated as constants. Note that this makes it a pretty bad idea to have Math
in there if the user might make use of Math.random
and a pretty bad idea to have Date
in there.
Options are directly passed-through to Babylon.
Returns the value resulting from evaluating src
. This method throws an error if the expression is not constant. e.g. toConstant("Math.random()")
would throw an error.
Constants is an object mapping strings to values, where those values should be treated as constants. Note that this makes it a pretty bad idea to have Math
in there if the user might make use of Math.random
and a pretty bad idea to have Date
in there.
Options are directly passed-through to Babylon.
MIT