0.10.6 • Published 1 year ago

jsexpr v0.10.6

Weekly downloads
262
License
MIT
Repository
-
Last release
1 year ago

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

JSON Stringify

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

let jxpr1 = expr.expr("${JSON}");
let jxpr2 = expr.expr("${JSON:address}");
let jxpr3 = expr.expr("${JSON:address:0}");
let jxpr4 = expr.expr("${JSON:0}");

// =>

{
  "client": "HOST001",
  "address": {
    "host": "localhost",
    "port": 8080
  },
  "headers": "Content-Type: application/json"
}

{
  "host": "localhost",
  "port": 8080
}

{"host":"localhost","port":8080}

{"client":"HOST001","address":{"host":"localhost","port":8080},"headers":"Content-Type: application/json"}
0.10.4

1 year ago

0.10.5

1 year ago

0.10.6

1 year ago

0.10.3

2 years ago

0.10.2

3 years ago

0.10.1

3 years ago

0.10.0

3 years ago

0.9.4

3 years ago

0.9.3

3 years ago

0.9.2

3 years ago

0.9.1

3 years ago

0.9.0

4 years ago

0.8.0

4 years ago

0.7.5

4 years ago

0.7.4

4 years ago

0.7.3

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.16

5 years ago

0.5.15

5 years ago

0.5.14

5 years ago

0.5.13

5 years ago

0.5.12

5 years ago

0.5.11

5 years ago

0.5.10

5 years ago

0.5.9

5 years ago

0.5.8

6 years ago

0.5.7

6 years ago

0.5.6

6 years ago

0.5.5

6 years ago

0.5.4

6 years ago

0.5.3

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago