You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

constantinople

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

constantinople

Determine whether a JavaScript expression evaluates to a constant (using UglifyJS)


Version published
Weekly downloads
1.7M
increased by2.47%
Maintainers
1
Install size
383 kB
Created
Weekly downloads
 

Package description

What is constantinople?

The 'constantinople' npm package is primarily used to determine if a JavaScript expression is a constant at compile time. This can be particularly useful in template engines, build tools, and other environments where compile-time evaluation can optimize runtime performance by reducing the need for unnecessary computations.

What are constantinople's main functionalities?

Compile-time constant evaluation

This feature allows developers to check if an expression is constant at compile time. The provided code checks if '2 + 2' is a constant expression.

const constantinople = require('constantinople');
if (constantinople.isConstant('2 + 2')) {
  console.log('This is a constant expression.');
}

Other packages similar to constantinople

Readme

Source

constantinople

Determine whether a JavaScript expression evaluates to a constant (using UglifyJS). Here it is assumed to be safe to underestimate how constant something is.

Build Status Dependency Status NPM version

Installation

npm install constantinople

Usage

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}))
}

API

isConstant(src, [constants])

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.

toConstant(src, [constants])

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.

License

MIT

FAQs

Package last updated on 22 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc