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

mrules-engine

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mrules-engine

A package for generating objects via a set of rules.

  • 1.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by300%
Maintainers
1
Weekly downloads
 
Created
Source

MRulesEngine

A package for generating objects via a set of rules.

Please use version 1.3.2 and above as below will be unstable

Installation

npm install mrules-engine

Standard Example:

const engine = require('mrules-engine');

const exampleRules1 = [{
    pathTo: 'data.name',
    pathFor: 'name'
}];

const example1 = engine({ data: { name: 'Name' } }, exampleRules1);
console.log(example1);

> { name: 'Name' };


selectorFn example

const engine = require('mrules-engine');

const exampleRules2 = [{
    pathTo: 'data.name',
    pathFor: 'name'
    selectorFn: (name) => `My Name: ${name}`
}];

const example2 = engine({ data: { name: 'Name' } }, exampleRules2);
console.log(example2);

> { name: 'My Name: Name' };

Fallback example

const engine = require('mrules-engine');

const exampleRules3 = [{
    pathTo: 'data.nameDoesNotExist',
    pathFor: 'name',
    fallback: 'Fallback Name'
}];

const example3 = engine({ data: { name: 'Name' } }, exampleRules3);
console.log(example3);

> { name: 'Fallback Name' };

Fallback with selectorFn example

const engine = require('mrules-engine');

const exampleRules4 = [{
    pathTo: 'data.nameDoesNotExist',
    pathFor: 'name',
    selectorFn: (name) => `Your Fallback Name: ${name}`,
    fallback: 'Fallback Name'
}];

const example4 = engine({ data: { name: 'Name' } }, exampleRules4);
console.log(example4);

> { name: 'Your Fallback Name: Fallback Name' };

Multiple Rules with selectorFn

const engine = require('mrules-engine');

const exampleRules5 = [{
    pathTo: 'data.name',
    pathFor: 'name',
    selectorFn: (name) => `Forename: ${name}`
}, {
    pathTo: 'data.surname',
    pathFor: 'surname',
    selectorFn: (name) => `Surname: ${name}`
}];

const example5 = engine({ data: { name: 'Foo', surname: 'Bar' } }, exampleRules5);
console.log(example5);

> { name: 'Forename: Foo', surname: 'Surname: Bar'  };

FAQs

Package last updated on 18 Aug 2021

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