constantinople
Advanced tools
Comparing version 3.1.0 to 3.1.1
{ | ||
"name": "constantinople", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"description": "Determine whether a JavaScript expression evaluates to a constant (using acorn)", | ||
@@ -11,9 +13,16 @@ "keywords": [ | ||
"dependencies": { | ||
"acorn": "^3.1.0", | ||
"is-expression": "^2.0.1" | ||
"@types/babylon": "^6.16.2", | ||
"babel-types": "^6.16.0", | ||
"babylon": "^6.18.0", | ||
"babylon-walk": "^1.0.2" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*" | ||
"@types/node": "^9.4.4", | ||
"mocha": "*", | ||
"typescript": "^2.7.1" | ||
}, | ||
"scripts": { | ||
"prepublish": "npm run build", | ||
"build": "tsc", | ||
"pretest": "npm run build", | ||
"test": "mocha -R spec" | ||
@@ -20,0 +29,0 @@ }, |
# constantinople | ||
Determine whether a JavaScript expression evaluates to a constant (using acorn). Here it is assumed to be safe to underestimate how constant something is. | ||
Determine whether a JavaScript expression evaluates to a constant (using Babylon). Here it is assumed to be safe to underestimate how constant something is. | ||
[![Build Status](https://img.shields.io/travis/ForbesLindesay/constantinople/master.svg)](https://travis-ci.org/ForbesLindesay/constantinople) | ||
[![Dependency Status](https://img.shields.io/david/ForbesLindesay/constantinople.svg)](https://david-dm.org/ForbesLindesay/constantinople) | ||
[![Build Status](https://img.shields.io/travis/pugjs/constantinople/master.svg)](https://travis-ci.org/pugjs/constantinople) | ||
[![Dependency Status](https://img.shields.io/david/pugjs/constantinople.svg)](https://david-dm.org/pugjs/constantinople) | ||
[![NPM version](https://img.shields.io/npm/v/constantinople.svg)](https://www.npmjs.org/package/constantinople) | ||
@@ -28,3 +28,3 @@ | ||
### isConstant(src, [constants]) | ||
### isConstant(src, [constants, [options]]) | ||
@@ -35,4 +35,6 @@ 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. | ||
### toConstant(src, [constants]) | ||
Options are directly passed-through to [Babylon](https://github.com/babel/babylon#options). | ||
### toConstant(src, [constants, [options]]) | ||
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. | ||
@@ -42,4 +44,6 @@ | ||
Options are directly passed-through to [Babylon](https://github.com/babel/babylon#options). | ||
## License | ||
MIT |
@@ -1,71 +0,86 @@ | ||
'use strict' | ||
'use strict'; | ||
var assert = require('assert') | ||
var constaninople = require('../') | ||
var assert = require('assert'); | ||
var constaninople = require('../'); | ||
describe('isConstant(src)', function () { | ||
it('handles "[5 + 3 + 10]"', function () { | ||
assert(constaninople.isConstant('[5 + 3 + 10]') === true) | ||
}) | ||
it('handles "/[a-z]/.test(\'a\')"', function () { | ||
assert(constaninople.isConstant('/[a-z]/.test(\'a\')') === true) | ||
}) | ||
it('handles "{\'class\': [(\'data\')]}"', function () { | ||
assert(constaninople.isConstant('{\'class\': [(\'data\')]}') === true) | ||
}) | ||
it('handles "Math.random()"', function () { | ||
assert(constaninople.isConstant('Math.random()') === false) | ||
}) | ||
it('handles "Math.random("', function () { | ||
assert(constaninople.isConstant('Math.random(') === false) | ||
}) | ||
it('handles "Math.floor(10.5)" with {Math: Math} as constants', function () { | ||
assert(constaninople.isConstant('Math.floor(10.5)', {Math: Math}) === true) | ||
}) | ||
it('handles "this.myVar"', function () { | ||
assert(constaninople.isConstant('this.myVar') === false) | ||
}) | ||
it('handles "(function () { while (true); return 10; }())"', function () { | ||
assert(constaninople.isConstant('(function () { while (true); return 10; }())') === false) | ||
}) | ||
}) | ||
describe('isConstant(src)', function() { | ||
it('handles "[5 + 3 + 10]"', function() { | ||
assert(constaninople.isConstant('[5 + 3 + 10]') === true); | ||
}); | ||
it('handles "/[a-z]/i.test(\'a\')"', function() { | ||
assert(constaninople.isConstant("/[a-z]/i.test('a')") === true); | ||
}); | ||
it("handles \"{'class': [('data')]}\"", function() { | ||
assert(constaninople.isConstant("{'class': [('data')]}") === true); | ||
}); | ||
it('handles "Math.random()"', function() { | ||
assert(constaninople.isConstant('Math.random()') === false); | ||
}); | ||
it('handles "Math.random("', function() { | ||
assert(constaninople.isConstant('Math.random(') === false); | ||
}); | ||
it('handles "Math.floor(10.5)" with {Math: Math} as constants', function() { | ||
assert(constaninople.isConstant('Math.floor(10.5)', {Math: Math}) === true); | ||
}); | ||
it('handles "this.myVar"', function() { | ||
assert(constaninople.isConstant('this.myVar') === false); | ||
}); | ||
it('handles "(function () { while (true); return 10; }())"', function() { | ||
assert( | ||
constaninople.isConstant( | ||
'(function () { while (true); return 10; }())', | ||
) === false, | ||
); | ||
}); | ||
it('handles "({}).toString.constructor("console.log(1)")()"', function() { | ||
assert( | ||
constaninople.isConstant( | ||
'({}).toString.constructor("console.log(1)")()', | ||
) === false, | ||
); | ||
}); | ||
}); | ||
describe('toConstant(src)', function () { | ||
it('handles "[5 + 3 + 10]"', function () { | ||
assert.deepEqual(constaninople.toConstant('[5 + 3 + 10]'), [5 + 3 + 10]) | ||
}) | ||
it('handles "/[a-z]/.test(\'a\')"', function () { | ||
assert(constaninople.toConstant('/[a-z]/.test(\'a\')') === true) | ||
}) | ||
it('handles "{\'class\': [(\'data\')]}"', function () { | ||
assert.deepEqual(constaninople.toConstant('{\'class\': [(\'data\')]}'), {'class': ['data']}) | ||
}) | ||
it('handles "Math.random()"', function () { | ||
describe('toConstant(src)', function() { | ||
it('handles "[5 + 3 + 10]"', function() { | ||
assert.deepEqual(constaninople.toConstant('[5 + 3 + 10]'), [5 + 3 + 10]); | ||
}); | ||
it('handles "/[a-z]/i.test(\'a\')"', function() { | ||
assert(constaninople.toConstant("/[a-z]/i.test('a')") === true); | ||
}); | ||
it("handles \"{'class': [('data')]}\"", function() { | ||
assert.deepEqual(constaninople.toConstant("{'class': [('data')]}"), { | ||
class: ['data'], | ||
}); | ||
}); | ||
it('handles "Math.random()"', function() { | ||
try { | ||
constaninople.toConstant('Math.random()') | ||
constaninople.toConstant('Math.random()'); | ||
} catch (ex) { | ||
return | ||
return; | ||
} | ||
assert(false, 'Math.random() should result in an error') | ||
}) | ||
it('handles "Math.random("', function () { | ||
assert(false, 'Math.random() should result in an error'); | ||
}); | ||
it('handles "Math.random("', function() { | ||
try { | ||
constaninople.toConstant('Math.random(') | ||
constaninople.toConstant('Math.random('); | ||
} catch (ex) { | ||
return | ||
return; | ||
} | ||
assert(false, 'Math.random( should result in an error') | ||
}) | ||
it('handles "Math.floor(10.5)" with {Math: Math} as constants', function () { | ||
assert(constaninople.toConstant('Math.floor(10.5)', {Math: Math}) === 10) | ||
}) | ||
it('handles "(function () { while (true); return 10; }())"', function () { | ||
assert(false, 'Math.random( should result in an error'); | ||
}); | ||
it('handles "Math.floor(10.5)" with {Math: Math} as constants', function() { | ||
assert(constaninople.toConstant('Math.floor(10.5)', {Math: Math}) === 10); | ||
}); | ||
it('handles "(function () { while (true); return 10; }())"', function() { | ||
try { | ||
constaninople.toConstant('(function () { while (true); return 10; }())') | ||
constaninople.toConstant('(function () { while (true); return 10; }())'); | ||
} catch (ex) { | ||
return | ||
return; | ||
} | ||
assert(false, '(function () { while (true); return 10; }()) should result in an error') | ||
}) | ||
}) | ||
assert( | ||
false, | ||
'(function () { while (true); return 10; }()) should result in an error', | ||
); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
34091
14
942
0
47
4
3
+ Added@types/babylon@^6.16.2
+ Addedbabel-types@^6.16.0
+ Addedbabylon@^6.18.0
+ Addedbabylon-walk@^1.0.2
+ Added@types/babel-types@7.0.15(transitive)
+ Added@types/babylon@6.16.9(transitive)
+ Addedbabel-runtime@6.26.0(transitive)
+ Addedbabel-types@6.26.0(transitive)
+ Addedbabylon@6.18.0(transitive)
+ Addedbabylon-walk@1.0.2(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlodash.clone@4.5.0(transitive)
+ Addedregenerator-runtime@0.11.1(transitive)
+ Addedto-fast-properties@1.0.3(transitive)
- Removedacorn@^3.1.0
- Removedis-expression@^2.0.1
- Removedacorn@3.3.0(transitive)
- Removedis-expression@2.1.0(transitive)
- Removedobject-assign@4.1.1(transitive)