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

dynamic-rules

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dynamic-rules

evaluate javascript code according conditions and formulas

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Dynamic Rules

the most fun and fast way to eval javascript objects

Usage

  1. Passing an object and rules, getting the result.
const dynamicRules = require('dynamic-rules');

// This can be any javascript object
const myModel = {
	amount: 118,
	subtotal: 100,
	taxes: 18,
	typeDocument: {
		name: 'INVOICE',
	},
};

// This is the config dynamic-rules needs.
// model represents the parent of the object
const config = {
	condition: 'model.typeDocument.name === "INVOICE"',
	formula: '(model.subtotal * model.amount) + 10',
};

const result = dynamicRules.execute(myModel, config);

console.log(result);

/*
	{
		meetCondition: true,
		formula: 11790
	}
*/
  1. Merging the result into your object
const dynamicRules = require('dynamic-rules');

// This can be any javascript object
const myModel = {
	amount: 118,
	subtotal: 100,
	taxes: 18,
	typeDocument: {
		name: 'INVOICE',
	},
};

// This is the config dynamic-rules needs.
// model represents the parent of the object
const config = {
	merge: true, // make a copy of your model and return the result on it.
	condition: 'model.typeDocument.name === "INVOICE"',
	formula: '(model.subtotal * model.amount) + 10',
};

const result = dynamicRules.execute(myModel, config);

console.log(result);

/*
	{
		model: {
			amount: 118,
			subtotal: 100,
			taxes: 18,
			typeDocument: {
				name: 'INVOICE',
			},
		}
		condition: true,
		formula: 11790
	}
*/

FAQs

Package last updated on 11 Feb 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