Appearance
Class: Numberable
Defined in: src/number.ts:4
Fluent number manipulation class inspired by Laravel's Number and modern utilities.
Constructors
Constructor
new Numberable(
value):Numberable
Defined in: src/number.ts:12
Create a new Numberable instance.
Parameters
value
unknown
The initial value
Returns
Numberable
Methods
toNumber()
toNumber():
number
Defined in: src/number.ts:24
Get the raw number value.
Returns
number
The raw value
get()
get():
number
Defined in: src/number.ts:33
Alias for toNumber().
Returns
number
The raw value
format()
format(
decimals?,locale?):string
Defined in: src/number.ts:44
Format the number with locale-specific formatting.
Parameters
decimals?
number = 0
The number of decimal points
locale?
string = 'en-US'
The locale to use for formatting
Returns
string
The formatted number
currency()
currency(
currency?,locale?):string
Defined in: src/number.ts:58
Format the number as currency.
Parameters
currency?
string = 'USD'
The currency code (e.g., 'USD', 'EUR')
locale?
string = 'en-US'
The locale to use for formatting
Returns
string
The formatted currency string
percentage()
percentage(
decimals?,locale?):string
Defined in: src/number.ts:72
Format the number as a percentage.
Parameters
decimals?
number = 0
The number of decimal points
locale?
string = 'en-US'
The locale to use for formatting
Returns
string
The formatted percentage string
fileSize()
fileSize(
precision?):string
Defined in: src/number.ts:86
Format the number as a human-readable file size.
Parameters
precision?
number = 2
The number of decimal points
Returns
string
The formatted file size (e.g., "1.50 MB")
abbreviate()
abbreviate(
precision?):string
Defined in: src/number.ts:101
Abbreviate the number (e.g., 1K, 1M, 1B).
Parameters
precision?
number = 1
The number of decimal points
Returns
string
The abbreviated number
ordinal()
ordinal():
string
Defined in: src/number.ts:115
Add an ordinal suffix to the number (e.g., 1st, 2nd, 3rd).
Returns
string
The number with its ordinal suffix
clamp()
clamp(
min,max):this
Defined in: src/number.ts:128
Clamp the number between a minimum and maximum value.
Parameters
min
number
The minimum value
max
number
The maximum value
Returns
this
The Numberable instance
isBetween()
isBetween(
min,max,inclusive?):boolean
Defined in: src/number.ts:141
Check if the number is between a minimum and maximum value.
Parameters
min
number
The minimum value
max
number
The maximum value
inclusive?
boolean = true
Whether to include the boundaries
Returns
boolean
True if the number is between min and max
add()
add(
value):this
Defined in: src/number.ts:151
Add a value to the current number.
Parameters
value
number
The value to add
Returns
this
The Numberable instance
sub()
sub(
value):this
Defined in: src/number.ts:162
Subtract a value from the current number.
Parameters
value
number
The value to subtract
Returns
this
The Numberable instance
mul()
mul(
value):this
Defined in: src/number.ts:173
Multiply the current number by a value.
Parameters
value
number
The value to multiply by
Returns
this
The Numberable instance
div()
div(
value):this
Defined in: src/number.ts:184
Divide the current number by a value.
Parameters
value
number
The value to divide by
Returns
this
The Numberable instance
round()
round(
precision?):this
Defined in: src/number.ts:197
Round the number to a specified precision.
Parameters
precision?
number = 0
The number of decimal points
Returns
this
The Numberable instance
ceil()
ceil(
precision?):this
Defined in: src/number.ts:209
Round the number up to a specified precision.
Parameters
precision?
number = 0
The number of decimal points
Returns
this
The Numberable instance
floor()
floor(
precision?):this
Defined in: src/number.ts:221
Round the number down to a specified precision.
Parameters
precision?
number = 0
The number of decimal points
Returns
this
The Numberable instance
pipe()
pipe<
U>(callback):U
Defined in: src/number.ts:233
Pipe the current Numberable instance to a callback.
Type Parameters
U
U
Parameters
callback
(num) => U
The callback to execute
Returns
U
The result of the callback
when()
when(
condition,callback):this
Defined in: src/number.ts:244
Execute a callback if a condition is met.
Parameters
condition
boolean | (() => boolean)
The condition to check
callback
(num) => void
The callback to execute if condition is true
Returns
this
The Numberable instance