1.0.11 • Published 3 years ago

@known-as-dan/calculator v1.0.11

Weekly downloads
6
License
MIT
Repository
github
Last release
3 years ago

About

A modular text-parsing calculator that enables the creation of custom operators, functions and constants with ease.

Usage

Parsing and calculating a simple math statement:

import { parse, calculate } from "@known-as-dan/calculator";

const math: string = "1 + 5 * 2";
const answer: Array<number> = calculate(parse(math));

console.log(`${math} = ${answer[0]}`);

// Output: 
// 1 + 5 * 2 = 11

Implementing a random number function that takes in two inputs(min & max):

import { addFunction, fetchValue } from "@known-as-dan/calculator";

addFunction("Random", "rand", "rand(min, max)", (values: Array<number>) => {
	const min: number = fetchValue(values, 0);
	const max: number = fetchValue(values, 1);
	return Math.floor(Math.random() * (max - min)) + min;
});
1.0.9

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago