4.10.0 • Published 1 year ago

@execonline-inc/numbers v4.10.0

Weekly downloads
288
License
ISC
Repository
github
Last release
1 year ago

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%"
4.9.0

1 year ago

4.8.0

2 years ago

4.7.0

2 years ago

4.6.1

2 years ago

4.10.0

1 year ago

4.6.0

2 years ago

4.5.0

2 years ago

4.4.0

2 years ago

4.3.0

3 years ago

4.2.0

3 years ago

4.1.0

3 years ago

4.1.1

3 years ago

4.0.0

3 years ago

3.0.0

3 years ago

2.0.0

3 years ago

1.0.1

4 years ago