You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-5Lines changed: 9 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
1
# constantinople
2
2
3
-
Determine whether a JavaScript expression evaluates to a constant (using acorn). Here it is assumed to be safe to underestimate how constant something is.
3
+
Determine whether a JavaScript expression evaluates to a constant (using Babylon). Here it is assumed to be safe to underestimate how constant something is.
@@ -25,18 +25,22 @@ if (isConstant('Math.floor(10.5)', {Math: Math})) {
25
25
26
26
## API
27
27
28
-
### isConstant(src, [constants])
28
+
### isConstant(src, [constants, [options]])
29
29
30
30
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.
31
31
32
32
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.
33
33
34
-
### toConstant(src, [constants])
34
+
Options are directly passed-through to [Babylon](https://github.com/babel/babylon#options).
35
+
36
+
### toConstant(src, [constants, [options]])
35
37
36
38
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.
37
39
38
40
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.
39
41
42
+
Options are directly passed-through to [Babylon](https://github.com/babel/babylon#options).
0 commit comments