Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsexpr

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsexpr

String and JSON expression interpolator and evaluator. Interpolates or evaluates a string against a json object, or transforms an object into another based on a json template

  • 0.5.12
  • npm
  • Socket score

Version published
Weekly downloads
15
decreased by-11.76%
Maintainers
1
Weekly downloads
 
Created
Source

jsexpr

JSON Expressions!

Build Status

String and JSON expression interpolator and evaluator. Interpolates or evaluates a string against a json object, or transforms an object into another based on a json template.

Installation

npm install jsexpr

String Evaluation

const expression = require("jsexpr");

var fn = expression.fn("(${host}=='mymachine' || ${host}=='yourmachine') && ${appName}=='su'");

// Result: false
var result = fn({host:"mymachine",appName:23});

String Interpolation

const expression = require("jsexpr");

var expr = expression.expr("/var/${date}/${client.address}/file.log");

// Result: /var/2017-01-01/localhost/file.log
var result = expr({date:"2017-01-01",client:{address:"localhost"}});

Object Interpolation

const expression = require("jsexpr");

var jsexpr = expression.expr({
	time : "${client}/${address.host}:${address.port}",
	data : {
		request : {
			headers : "${headers}"
		}
	}
});

var result = jsexpr({
	client : "HOST001",
	address : {
		host : "localhost",
		port : 8080
	},
	headers : "Content-Type: application/json"
});

Object Interpolation Result

{
	time: 'HOST001/localhost:8080',
	data: {
		request: {
			headers: 'Content-Type: application/json'
		}
	}
}

Keywords

FAQs

Package last updated on 29 Mar 2019

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc