Giter VIP home page Giter VIP logo

integer.flow's Introduction

integer.flow

travis package downloads styled with prettier

Library provides integer opquae type alias for number and set of functions to work with integer type values with guarantees that any integer returned is not a floating point number, NaN or (-)Infinity.

API

Import

import * as Integer from "integer.flow"

Integer.integer:number

Library exposes integer, a subtype of a number that is guranteed to not be a floating point number, NaN or (-)Infinity.

Integer.parseInteger(string):?integer

Try to turn given string into an intgere, unlike built-in parseInt this function never returns NaN or an Infinity, but rather retuns null (? portion of ?integer). It also unlike built-in parseInt fails (returns null) on strings than aren't numbers like "0what?".

Integer.parseInteger("123") //> 123
Integer.parseInteger("+1234") //> 1234
Integer.parseInteger("-1234") //> -1234
Integer.parseInteger("0x001A") //> 26
Integer.parseInteger("0xBEEF") //> 48879
Integer.parseInteger("3.14") //> null
Integer.parseInteger("3.14") //> null
Integer.parseInteger("+3.14") //> null
Integer.parseInteger("-3.14") //> null
Integer.parseInteger("0") //> 0
Integer.parseInteger(".0") // > null
Integer.parseInteger("NaN") //> null
Integer.parseInteger("-Infinity") //> null
Integer.parseInteger("Infinity") //> null
Integer.parseInteger("0xFF") //> null
Integer.parseInteger("0what?") //> null

Integer.div(integer, integer):integer

Integer division. The remainder is discarded.

Integer.rem(integer, integer):integer

Find the remainder after dividing one number by another.

Integer.rem(11, 4) //> 3
Integer.rem(12, 4) //> 0
Integer.rem(13, 4) //> 1
Integer.rem(-1, 4) //> -1

Integer.mod(integer, integer):integer

Perform modular arithmetic.

Integer.mod(7, 2) //> 1
Integer.mod(-1, 4) //> 3

Integer.round(number):integer

Round a number to the nearest integer.

Integer.floor(number):integer

Floor function, rounding down.

Integer.ceiling(number):integer

Ceiling function, rounding up.

Integer.truncate(number):integer

Truncate a number, rounding towards zero.

Install

npm install integer.flow

integer.flow's People

Contributors

gozala avatar

Stargazers

Michael Curry avatar  avatar Athan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.