A Twitch.tv viewer reward and games system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.1 KiB

  1. # constantinople
  2. Determine whether a JavaScript expression evaluates to a constant (using UglifyJS). Here it is assumed to be safe to underestimate how constant something is.
  3. [![Build Status](https://travis-ci.org/ForbesLindesay/constantinople.png?branch=master)](https://travis-ci.org/ForbesLindesay/constantinople)
  4. [![Dependency Status](https://gemnasium.com/ForbesLindesay/constantinople.png)](https://gemnasium.com/ForbesLindesay/constantinople)
  5. [![NPM version](https://badge.fury.io/js/constantinople.png)](http://badge.fury.io/js/constantinople)
  6. ## Installation
  7. npm install constantinople
  8. ## Usage
  9. ```js
  10. var isConstant = require('constantinople')
  11. if (isConstant('"foo" + 5')) {
  12. console.dir(isConstant.toConstant('"foo" + 5'))
  13. }
  14. ```
  15. ## API
  16. ### isConstant(src)
  17. 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.
  18. ### toConstant(src)
  19. 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.
  20. ## License
  21. MIT