New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

formula-machine

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formula-machine

Formula machine =============

latest
Source
npmnpm
Version
1.1.1
Version published
Maintainers
1
Created
Source

Formula machine

A formula machine for JS

example

var formula = require('formula-machine');

var src = {
  operator: '+',
  operands: [2, {
    operator: 'sqrt',
    operands: [
      { number: 4 }, // like a just number
      {
        operator: '/',
        operands: [2, 2]
      }
    ]
  }]
};

// will convert to
(2 + Math.sqrt(4 * (2/2)))

console.log(formula.toFunction(src)()); // 4

With variables

var formula = require('formula-machine');

var src = {
  operator: '+',
  operands: [2, { variable: 'name' }]
};

var fn = formula.toFunction(src);

console.log(fn({ name: 4 })); // 2 + 4 = 6

Multiple operands

var formula = require('formula-machine');

var src = {
  operator: '+',
  operands: [2, 3, 4, 5, { operator: '+', operands: [6, 7] }]
};

var fn = formula.toFunction(src);

console.log(fn()); // 2 + 3 + 4 + 5 + (6 + 7) = 27

operators

Formula machine has some binary operators:

  • 1 + 2: simple "plus" (+)
  • 1 - 2: simple "minus" (-)
  • 1 * 2: simple "multiply" (*)
  • 1 / 2: simple "division" (/)
  • Math.pow(1, 2): exponentiation (pow)

Formula machine has some unary operators:

  • Math.sqrt(4): calculating the root (sqrt)

install

With npm do:

npm install formula-machine

test

With npm do:

npm test

FAQs

Package last updated on 06 Dec 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