npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sylver

v1.0.2

Published

A lightweight math library for JavaScript

Downloads

9

Readme

Sylver

npm version

❄️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 sylver
var sylver = require('sylver');

// basic
sylver("(3*2)+6")           // 12
sylver("~16")               // -16
sylver("7!")                // 5040

// compare (0 = false; 1 = true)
sylver("32<>32")            // 0
sylver("(10*2)<=(40+3)")    // 1
sylver("11 eq 11")          // 1
sylver("4<=9")              // 1

// conditions
sylver("if(3+8<=23)12:3")   // 12

// intervals
sylver("2 to 8")            // [2, 3, 4, 5, 6, 7, 8]
sylver("(4*PI) to (23/2)")  // [11.5, 12.5]
sylver("2 * (6 to 10)")     // [ 12, 14, 16, 18, 20 ]

// list
sylver("[2, 3, 5, 1] * [6, 3, 5, 4, 102]")     // [ 12, 9, 25, 4, 102 ]

// algebra
sylver("cos(4)")            // -0.6536436208636119
sylver("atan(7)")           // 1.4288992721907328
sylver("atanh(-0.4)")       // -0.4236489301936018
// See: test/algebra1.js

// Other
sylver("abs(ln(2)*(4^3))*(if(3<>6) 2:5)")  // 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:

sylver("1 to 7")                  // [ 1, 2, 3, 4, 5, 6, 7 ]
sylver("2 * (6 to 10)")           // [12, 14, 16, 18, 20]
sylver("(1 to 4) * [2, 4, 6, 7]") // [ 2, 8, 18, 28 ]
sylver("(1 to 4) * 3")            // [ 3, 6, 9, 12 ]
sylver("1 to (10/2) + 10")        // [11, 12, 13, 14, 15]

The order of the operators is important:

sylver("10 / [2, 5, 4]")          // [5, 2, 2.5]

// This is different from:
sylver("[2, 5, 4] / 10")          // [0.2, 0.5, 0.4]

Conditions

Evaluate expressions and returns a decision:

sylver(`if((5*2)>(6*2)) 80 : 35 `)    // 35

You can use the returned result to operate with other expressions:

sylver("(if(3>0)1:2)*5)")            // 5

Constants

Currently there are two constants available: PI, E

sylver("PI")        // 3.141592653589793
sylver("E")         // 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.git
cd 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

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