@execonline-inc/numbers
TypeScript icon, indicating that this package has built-in type declarations

4.10.0 • Public • Published

numbers

Safely parse numbers from strings

Functions

parseIntM

Attempts to parse an integer from a string, using Maybe<number> to wrap the success or failure of the parse.

import { parseIntM } from '@execonline-inc/numbers';

parseIntM('123').getOrElseValue(0) // returns `123`
parseIntM('123.42').getOrElseValue(0) // returns `123`
parseIntM('Hello World!').getOrElseValue(0) // returns `0`

parseIntR

Attempts to parse an integer from a string, using Result<NumberParseFailure, number> to wrap the success or failure of the parse.

import { parseIntR } from '@execonline-inc/numbers';

parseIntR('123').getOrElseValue(0) // returns `123`
parseIntR('123.42').getOrElseValue(0) // returns `123`

parseIntR('Hello World').elseDo(console.warn).getOrElseValue(0)
// Prints object: { kind: 'number-parse-failure', message: `Couldn't parse string into a number` }
// Returns 0

parseIntT

Attempts to parse an integer from a string, using Task<NumberParseFailure, number> to wrap the success or failure of the parse.

import { parseIntT } from '@execonline-inc/numbers';

parseIntT('123').fork(() => {}, console.log); // Prints the integer 123
parseIntT('123.42').fork(() => {}, console.log); // Prints the integer 123

parseIntT('Hello World').fork(console.warn, () => {});
// Prints object: { kind: 'number-parse-failure', message: `Couldn't parse string into a number` }

percentage

Display a number as a percentage.

import { percentage } from '@execonline-inc/numbers';

percentage(42.22) // returns the string "42%"

Readme

Keywords

none

Package Sidebar

Install

npm i @execonline-inc/numbers

Weekly Downloads

8

Version

4.10.0

License

ISC

Unpacked Size

5.65 kB

Total Files

5

Last publish

Collaborators

  • kofno