Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

babel-plugin-ceval

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-ceval

a babel pluging for compile time evaluation.

Source
npmnpm
Version
1.4.3
Version published
Weekly downloads
4
-75%
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-ceval

This plugin allows Babel to execute ceval functions at compile time.

API

ceval(expression: string)

Return value is used as is, it cannot return code fragments.

ceval(fn: function([args..])[, args..])

If it returns a string, it is expected to be a code fragment. If you need to return a string value, simply enclose it with quotations.

Examples

// In:
var envPath = ceval('process.env.PATH');
// Out:
var envPath = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games';
// In:
var dirname = ceval('__dirname');
// Out:
var dirname = '/home/arash16/Projects/ceval-test';
// In:
var version = ceval('require("./package.json").version');
// Out:
var version = '1.0.0';
// In:
ceval(function() {
	var r = '';
	for (var i=0; i<4; ++i)
		r += 'console.log('+i+');';
	return r;
});
// Out:
console.log(0);console.log(1);console.log(2);console.log(3);
// In:
var code = ceval(function() {
	var r = '';
	for (var i=0; i<3; ++i)
		r += 'console.log('+i+');';
	return '"' + r + '"';
});
// Out:
var code = 'console.log(0);console.log(1);console.log(2);';
// In:
ceval(function() {
	if (process.env.DEBUG)
		return function checker(x) { 
			return x>2; 
		};
	
	return function checker(x) { 
		return x>0; 
	};
});
// Out:
function checker(x) {
	return x > 0;
}

Installation

npm install --save-dev babel-plugin-ceval

Usage

.babelrc

{
  "plugins": ["ceval"]
}

Via CLI

babel --plugins ceval script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["ceval"]
});

Keywords

babel-plugin

FAQs

Package last updated on 26 Apr 2017

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