Sylver
❄️A lightweight math library for JavaScript. It features a flexible expression parser comes with a large set of built-in functions and constants. Powerful and easy to use.
In active development, any pull request will be welcome :)
Features
- Minimal and fast
- Supports numbers, complex numbers, fractions, conditions.
- Compatible with JavaScript.
- Contains a flexible expression parser.
- Comes with a large set of built-in functions and constants.
- Has no dependencies. Runs on any JavaScript engine.
- Can be used as a command line application as well.
- Open source.
Usage
npm install --save sylver # or yarn add sylver
// load sylvervar sylver = ; // basic // 12 // -16 // 5040 // compare (0 = false; 1 = true) // 0 // 1 // 1 // 1 // conditions // 12 // intervals // [2, 3, 4, 5, 6, 7, 8] // [11.5, 12.5] // [ 12, 14, 16, 18, 20 ] // list // [ 12, 9, 25, 4, 102 ] // algebra // -0.6536436208636119 // 1.4288992721907328 // -0.4236489301936018// See: test/algebra1.js // Other // 88.722839111673
Usage globally (Available in the next versions)
npm i -g sylver # or yarn global add sylver
Enter from the command terminal:
sylver --help
Documentation
Mathematical operators
Operator | Description |
---|---|
+ | addition |
- | subtraction |
∗ | multiplication |
/ | right division, i.e. x/y |
ˆ | power, i.e. x^y |
Mathematical functions: trigonometry
functions |
---|
log log10 log1p log2 sqrt, cos, tan, sin, atan, asin, acos, atanh, acosh, asinh |
Intervals
Sylver is able to generate lists of numbers from a range:
// [ 1, 2, 3, 4, 5, 6, 7 ] // [12, 14, 16, 18, 20] // [ 2, 8, 18, 28 ] // [ 3, 6, 9, 12 ] // [11, 12, 13, 14, 15]
The order of the operators is important:
// [5, 2, 2.5] // This is different from: // [0.2, 0.5, 0.4]
Conditions
Evaluate expressions and returns a decision:
// 35
You can use the returned result to operate with other expressions:
// 5
Constants
Currently there are two constants available: PI
, E
// 3.141592653589793 // 2.718281828459045
Browser support
// TODO: Version for browsers in development Sylver works on any ES5 compatible JavaScript engine: node.js 0.10, and Internet Explorer 9 and newer, and all other browsers (Chrome, Firefox, Safari). If support for old browsers like Internet Explorer 8 is required, the es5-shim library has to be loaded. Use function parser from parser.js file.
Build
First clone the project from github:
git clone https://github.com/juliandavidmr/sylver.gitcd sylver
Install the project dependencies:
npm install# or yarn
Test
To execute tests for the library, install the project dependencies once:
npm install
Then, the tests can be executed:
npm test
The tests are run with ava
Built With
- jison - Bison in JavaScript
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
Versioning
We use SemVer for versioning.
Authors
- Julian David - Initial work - @juliandavidmr
See also the list of contributors who participated in this project.
See changelog
License
This project is licensed under the MIT License - see the LICENSE file for details