public bytes(precision?: number, limit?: number): string
Returns an abbreviated form of the number, considered to be "Bytes".
extra
[precision] will round to the given precision.
[limit] is the upper limit for the units.
The default is %4%, which is "terabytes" (TB).
If [limit] is %false%, the upper limit will be "exa".
Returns an array containing numbers from the number down to .
extra
Optionally calls [fn] callback for each number in that array.
[step] allows multiples greater than 1.
example
(8).downto(3) -> [8, 7, 6, 5, 4, 3]
(8).downto(3, function(n) {
// This function is called 6 times receiving n as the value.
});
(8).downto(2, null, 2) -> [8, 6, 4, 2]
Parameters
num: number
Number to count down to.
fn?: (n: number) => voidoptional
Callback function to call for each number.
step?: numberoptional
Number to subtract each iteration, default = 1.
Returns
Array<number>
number[] containing numbers from number down to .
public duration(locale?: string): string
Takes the number as milliseconds and returns a unit-adjusted localized string.
extra
This method is the same as %Date#relative% without
the localized equivalent of "from now" or "ago".
[locale] can be passed as the first (and only) parameter.
Note that this method is only available when the dates
package is included.
If [place] is %undefined%, will automatically determine the place.
[thousands] is the character used for the thousands separator.
[decimal] is the character used for the decimal point.
public metric(precision?: number, limit?: number): string
Returns the number as a string in metric notation.
method
metric([precision] = 0, [limit] = 1)
extra
[precision] will round to the given precision.
Both very large numbers and very small numbers are supported.
[limit] is the upper limit for the units.
The default is %1%, which is "kilo".
If [limit] is %false%, the upper limit will be "exa".
The lower limit is "nano", and cannot be changed.
Method names can be both singular and plural.
Note that as "a month" is ambiguous as a unit of time,
%months% will be equivalent to 30.4375 days, the average
number in a month. Be careful using %months% if you need
exact precision.
set
millisecond
milliseconds
second
seconds
minute
minutes
hour
hours
day
days
week
weeks
month
months
year
years
public millisecondAfter(d: string, locale?: string): Date
Returns a date units after , where is the number.
method
[unit]After([d], [locale] = currentLocale)
extra
[d] will accept a date object, timestamp, or text format.
Note that "months" is ambiguous as a unit of time. If the
target date falls on a day that does not exist
(ie. August 31 -> February 31), the date will be shifted
to the last day of the month. Be careful using %monthsAfter%
if you need exact precision. See @date_format for more.
(5).daysAfter('tuesday') -> 5 days after tuesday of this week
(1).yearAfter('January 23, 1997') -> January 23, 1998
Parameters
d: string
Date to start from.
locale?: stringoptional
Locale for return Date, default = currentLocale.
Returns
Date
Date units after .
public millisecondAfter(d: Date, locale?: string): Date
see
millisecondAfter
Parameters
d: Date
locale?: stringoptional
Returns
Date
public millisecondAgo(): Date
Returns a date that is units ago.
method
[unit]Ago()
extra
Note that "months" is ambiguous as a unit of time.
If the target date falls on a day that does not exist
(ie. August 31 -> February 31), the date will be shifted
to the last day of the month. Be careful using %monthsAgo%
if you need exact precision.
(5).weeksAgo() -> 5 weeks ago
(1).yearAgo() -> January 23, 1996
Returns
Date
Date
public millisecondBefore(d: string, locale?: string): Date
Returns a date that is units before , where is the number.
method
[unit]Before([d], [locale] = currentLocale)
extra
[d] will accept a date object, timestamp, or text format.
Note that "months" is ambiguous as a unit of time. If the
target date falls on a day that does not exist
(ie. August 31 -> February 31), the date will be shifted to
the last day of the month. Be careful using %monthsBefore%
if you need exact precision. See @date_format for more.
(5).daysBefore('tuesday') -> 5 days before tuesday of this week
(1).yearBefore('January 23, 1997') -> January 23, 1996
Parameters
d: string
Date to start from.
locale?: stringoptional
Locale for return Date, default = currentLocale.
Returns
Date
Date units before .
public millisecondBefore(d: Date, locale?: string): Date
see
millisecondBefore
Parameters
d: Date
locale?: stringoptional
Returns
Date
public millisecondFromNow(): Date
Returns a date units from now.
method
[unit]FromNow()
extra
Note that "months" is ambiguous as a unit of time.
If the target date falls on a day that does not exist
(ie. August 31 -> February 31), the date will be shifted
to the last day of the month. Be careful using %monthsFromNow%
if you need exact precision.
public secondAfter(d: string, locale?: string): Date
see
millisecondAfter
Parameters
d: string
locale?: stringoptional
Returns
Date
public secondAfter(d: Date, locale?: string): Date
see
millisecondAfter
Parameters
d: Date
locale?: stringoptional
Returns
Date
public secondAgo(): Date
see
millisecondAgo
Returns
Date
public secondBefore(d: string, locale?: string): Date
see
millisecondBefore
Parameters
d: string
locale?: stringoptional
Returns
Date
public secondBefore(d: Date, locale?: string): Date
see
millisecondBefore
Parameters
d: Date
locale?: stringoptional
Returns
Date
public secondFromNow(): Date
see
millisecondFromNow
Returns
Date
public seconds(): number
see
millisecond
Returns
number
public secondsAfter(d: string, locale?: string): Date
see
millisecondAfter
Parameters
d: string
locale?: stringoptional
Returns
Date
public secondsAfter(d: Date, locale?: string): Date
see
millisecondAfter
Parameters
d: Date
locale?: stringoptional
Returns
Date
public secondsAgo(): Date
see
millisecondAgo
Returns
Date
public secondsBefore(d: string, locale?: string): Date
see
millisecondBefore
Parameters
d: string
locale?: stringoptional
Returns
Date
public secondsBefore(d: Date, locale?: string): Date
see
millisecondBefore
Parameters
d: Date
locale?: stringoptional
Returns
Date
public secondsFromNow(): Date
see
millisecondFromNow
Returns
Date
public sin(): number
sine
Returns
number
public sqrt(): number
example
(1024).sqrt() -> 32
Returns
number
public tan(): number
tangent
Returns
number
public times(fn: (i: number) => void): number
Calls a number of times equivalent to the number.
example
(8).times(function(i) {
// This function is called 8 times.
});
Parameters
fn: (i: number) => void
Callback function to call n times.
Returns
number
The original number.
public toNumber(): number
Returns a number. This is mostly for compatibility reasons.
example
(420).toNumber() -> 420
Returns
number
The original number.
public upto(num: number, fn?: Function, step?: number): Array<number>
Returns an array containing numbers from the number up to .
extra
Optionally calls [fn] callback for each number in that array.
[step] allows multiples greater than 1.
example
(2).upto(6) -> [2, 3, 4, 5, 6]
(2).upto(6, function(n) {
// This function is called 5 times receiving n as the value.
});
(2).upto(8, null, 2) -> [2, 4, 6, 8]
Parameters
num: number
Number to count down to.
fn?: Functionoptional
Callback function to call for each number.
step?: numberoptional
Number to add each iteration, default = 1.
Returns
Array<number>
number[] containing numbers from number up to .
public week(): number
see
millisecond
Returns
number
public weekAfter(d: string, locale?: string): Date
see
millisecondAfter
Parameters
d: string
locale?: stringoptional
Returns
Date
public weekAfter(d: Date, locale?: string): Date
see
millisecondAfter
Parameters
d: Date
locale?: stringoptional
Returns
Date
public weekAgo(): Date
see
millisecondAgo
Returns
Date
public weekBefore(d: string, locale?: string): Date
see
millisecondBefore
Parameters
d: string
locale?: stringoptional
Returns
Date
public weekBefore(d: Date, locale?: string): Date
see
millisecondBefore
Parameters
d: Date
locale?: stringoptional
Returns
Date
public weekFromNow(): Date
see
millisecondFromNow
Returns
Date
public weeks(): number
see
millisecond
Returns
number
public weeksAfter(d: string, locale?: string): Date
see
millisecondAfter
Parameters
d: string
locale?: stringoptional
Returns
Date
public weeksAfter(d: Date, locale?: string): Date
see
millisecondAfter
Parameters
d: Date
locale?: stringoptional
Returns
Date
public weeksAgo(): Date
see
millisecondAgo
Returns
Date
public weeksBefore(d: string, locale?: string): Date
see
millisecondBefore
Parameters
d: string
locale?: stringoptional
Returns
Date
public weeksBefore(d: Date, locale?: string): Date
see
millisecondBefore
Parameters
d: Date
locale?: stringoptional
Returns
Date
public weeksFromNow(): Date
see
millisecondFromNow
Returns
Date
public year(): number
see
millisecond
Returns
number
public yearAfter(d: string, locale?: string): Date
see
millisecondAfter
Parameters
d: string
locale?: stringoptional
Returns
Date
public yearAfter(d: Date, locale?: string): Date
see
millisecondAfter
Parameters
d: Date
locale?: stringoptional
Returns
Date
public yearAgo(): Date
see
millisecondAgo
Returns
Date
public yearBefore(d: string, locale?: string): Date
see
millisecondBefore
Parameters
d: string
locale?: stringoptional
Returns
Date
public yearBefore(d: Date, locale?: string): Date
see
millisecondBefore
Parameters
d: Date
locale?: stringoptional
Returns
Date
public yearFromNow(): Date
see
millisecondFromNow
Returns
Date
public years(): number
see
millisecond
Returns
number
public yearsAfter(d: string, locale?: string): Date
see
millisecondAfter
Parameters
d: string
locale?: stringoptional
Returns
Date
public yearsAfter(d: Date, locale?: string): Date
see
millisecondAfter
Parameters
d: Date
locale?: stringoptional
Returns
Date
public yearsAgo(): Date
see
millisecondAgo
Returns
Date
public yearsBefore(d: string, locale?: string): Date
see
millisecondBefore
Parameters
d: string
locale?: stringoptional
Returns
Date
public yearsBefore(d: Date, locale?: string): Date