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

ax-calculator

v2.4.2

Published

Complex Math Calculator

Downloads

175

Readme

Last added feature

RegexValidator, you can use for validate inputs or form

const form = {
  name: RegexValidator.onlyLetters({ capitalize: true, length: { minvalue: 5, maxvalue: 30 } }),
  lastname: RegexValidator.onlyLetters({ capitalize: true, length: { minvalue: 5, maxvalue: 30 } }),
  phone: RegexValidator.onlyNumbers(),
  // if the email doesn't contains '@gmail.com' returns false
  email: RegexValidator.coincidence("@gmail.com", "@outlook.com"),
  address: RegexValidator.onlyLettersAndNumbers({ capitalize: true, allowSpacing: true }),
  // is obligatory to have only 2 values, 3 or 1 returns false
  age: RegexValidator.implicitLength(2) 
}

Instalation

npm

npm i ax-calculator

yarn

yarn add ax-calculator
  • Import / Require
//esm
import * as ax from 'ax-calculator'
import { ... } from 'ax-calculator

//cjs
const ax = require('ax-calculator')
const { ... } = require('ax-calculator')

Objects and their operations

Please be informed of every change that is made to this calculator, many more operations are being added that can help you and an example of use is given.

Basic Operations

  • Sum, substract, product, division, module, root, raise to, Chaining class
BasicOperations.sum(2, 5, 8, 4, 11) // { result: 30, toNegative: [Function: toNegative] }
BasicOperations.substract(304, 20, 51) // { result: 233, toNegative: [Function: toNegative] }
BasicOperations.product(35, 1, 9) // { result: 315, toNegative: [Function: toNegative] }
BasicOperations.division(25, 5) // 5.00
BasicOperations.module(40, 4) // 0
BasicOperations.root(1296, 4) // 6
BasicOperations.raiseTo(3, 5) // 243

const chaining = new BasicOperations.Chaining()

console.log(chaining.baseNumber(5).multiply(4).divide(2).value); // 10

Base

  • binary to base 10, to base
Base.toBase(20, 4) // -> 110
Base.binaryToBase10(1001) // -> 9

Fractions

  • Sum, substract, product, division, simplify, destructure
Fractions.sum(1,2,-4,6) // 1/2 + (-4/6) -> -1/6
Fractions.substract(-5,2,4,7) // -5/2 - 4/7 -> -43/14
Fractions.product(10,2,-5,4) // 10/2 * (-5/4) -> -25/4
Fractions.division(5,3,7,2) // (5/3)/(7/2) ->10/21
Fractions.simplify(154, 6) // 77/3
Fractions.destructure("12/5") // { top: '12', bottom: '5' }

Equations

  • Secoond degree
// 2x² - 3x + 3 = 0
Equations.secondDegree(2, -3, 3) // { x1: '3/4 + 𝓲√15/4' , x2: '3/4 - 𝓲√15/4'  }

Percentage

  • What percentage is, percentage of, percent from percent, total from percent
// What percentaje is 12 out of 30?
Percentage.whatPercentageIs(12, 30) // 40.00%

// How much is 7% of 39?
Percentage.percentageOf(7, 39) // 2.73

// If 30% is 10, then 60% is...
Percentage.percentFromPercent(30, 10, 60) // 20

// If 10% is 20, the total is...
Percentage.totalFromPercent(10, 20) // 200

Rule of three

  • Simple
RuleOfThree.simple("direct", 10, undefined, 60, 90) // 15

Triangles

  • Functions return information about triangles
Triangles.angle14_76()

/*
{
  hypotenuse: 'k√17',
  opposite: 'k',
  adjacent: '4k',
  sin: 'k/k√17',
  cos: '4k/k√17',
  tan: 'k/4k'
}
*/

Linear Regression

  • Simple
var array_x = [100, 90, 80, 45, 50, 50, 60, 40, 25, 20];
var array_y = [3, 5, 9, 10, 20, 21, 24, 24, 27, 35];

console.log(LinearRegression.simple(array_x, array_y));

//
/*
{
  a: -0.34788,
  b: 37.28128,
  equation: '-0.34788x + 37.28128',
  coefficient: [Function: coefficient]
}
*/

Area

  • Triangle, rectangle, circle, square, square2, trapeze
// ...
Area.triangle(4, 3) // 6
Area.circle(5) // 25π
// ...

Operations

  • Hypotenuse, to roman, log, factorial, double factorial, combinatorial, fibonacci, divisors
Operations.hypotenuse(7, 9) // -> √11.40
Operations.toRoman(420); // CDXX

// log5x = 4
Operations.log(5, null, 4) // 625

// 4!
Operations.factorial(4); // 24

// 10!!
Operations.doubleFactorial(10); // 3840
Operations.combinatorial(7, 3); // 35

Operations.divisors(25); // [ 1, 5, 25 ]

Operations.fibonacci(13)

/*
Output:

[
    0,  1,  1,  2,  3,  5,
    8, 13, 21, 34, 55, 89,
    144
]
*/

Vectors

  • Sum, Substract, Product, unit vector
// (3, 6) + (2, -7)
var vector_a = [3, 6];
var vector_b = [2, -7];

// Sum or sustract returns object
Vectors.sum(vector_a, vector_b)

/*
  {
    x: 5,
    y: -1,
    expression: '5i - 1j',
    cartesian: [ 5, -1 ],
    unit_vector: [ 0.98, -0.19 ]
  }
*/

// (2i - j) • (5i + 2j)
Vectors.product( [2, -1], [5, 2] ) // 8

// (-3, 5)
Vector.unitVector(-3, 5);

System of equations

  • Double
var equation1 = [1, 2, 10];
var equation2 = [2, -1, 5]

console.log(SystemEquation.double(equation1, equation2))
// { x: 4, y: 3 }

Chemical elements

  • Show, obtain by group, obtain by family
ChemicalElements.show("H")

/*
  {
    simbol: 'H',
    atomic_number: 1,
    atomic_mass: 1,
    name: 'Hydrogen',
    group: 'I A',
    type: 'Non-metal',
    electroegativity: 2.2
  }
*/

//  I A, II A, III A, ...
ChemicalElements.obtainByGroup("I B") // object

// You will place the family of the elements you want to obtain
ChemicalElements.obtainByFamily("Halogen") // object

Angle measurements system

  • Radian, Centesimal, Sexasegimal (toRadian, toCentesimal, toSexagesimal)
...

// 2π/5
AngleMeasurements.radian("2/5").toCentesimal() // 80

// 40ᵍ
AngleMeasurements.centesimal(40).toRadian() // π/5

// 45°
AngleMeasurements.sexagesimal(45).toCentesimal() // 50

...

Validator

  • isNumber, isString, isObject, isUndefined, containsString, containsNumber ...
...

Validator.isNumber("2") // false
Validator.isString("test") // true

Validator.containsString([1,2,3,4]) // false
Validator.containsNumber(["1", "2", "3", 4]) // true

...

Clock

  • date, time
Clock.time() // Sample: 23:10

// the default format is US
Clock.date() // month/day/year

Browser

  • setCSSVariable, getCSSVariable, getBrowserDetails, isMobile, getComputedStyleById
...

Browser.isMobile() // false

Browser.getComputedStyleById('main', 'margin-top') // 0px
Browser.getComputedStyleById('nav', 'border') // 2px solid rgb(123, 123, 123)

Browser.setCSSVariable('--myvariable', '4px')
Browser.getCSSVariable('--myvariable') // '4px'

...