Monkey service

The useMonkey service allows you to benefit from Orion Monkey Patching for prototypes like Array, Number, Date, or String but without actually using it.

This is useful for people who don't want to add methods to the native prototypes.
Parameter type will be automatically inferred to provide the available methods.

TIP

Please head to our Monkey Patching guide page for further informations.

Example

useMonkey(['a', 'b', 'c']).delete('b');
// returns -> "['a', 'c']"

useMonkey(new Date(2022, 8, 5)).toReadable('$dddd, $YYYY-$MM-$DD');
// returns -> "Wednesday, 2022-09-05"

useMonkey(1.5).toHoursMinutes();
// returns -> "01:30"

useMonkey('Hello world').insert(' tiny', 5);
// returns -> "Hello tiny world"

Available methods

Array

distinct(distinctBy)T[]
distinctBy keyof T
last()T | undefined
first()T | undefined
delete(target, key, deleteCount)T[]
target any
key keyof T = 'id'
deleteCount number = 1
deleteWhere(keyValue, key)T[]
keyValue any
key K | ((x: T) => boolean)
empty()Array
toggle(target, key)T[]
target T
key keyof T = 'id'
mapKey()T[K][]
findByKey(keyValue, key)T | undefined
keyValue T[K]
key K = 'id'
pushUniq(item)Array
item any
filterNil(){*} {T[]}

Date

toPost(withTime)string
withTime boolean = false
toOffset()string
isBissextile()boolean
getOrdinalDate()number
getTimeBetween(pattern, date)string
pattern string
date date
getWeekNumber()number
getWeekDays()object
getWeekDates()object
hasFiftyThreeWeeks()boolean
setDateToFirstDow()Date
setDateToLastDow()Date
toReadable(pattern)string
pattern string = language.DATE_PATTERN
Example
PatternKeywords
toMidnight()Date
toEndOfDay()Date

Number

toHoursMinutes(separator)string
separator string = ':'
withDelimiters(thousands, decimal)string
thousands string = ' '
decimal string = ','
toCurrency(currency)string
currency string = ' €'
decimal(precision)number
precision number = 2

String

toPost()string
toReadableDate(pattern)string
pattern string
MoreInfos
insert(string, index, replace)string
string string
index number = 0
replace boolean = false
pluralize(quantity, quantityIncluded)string
quantity number
quantityIncluded boolean = true
hashCode()number
mark(valueToMark)string
valueToMark string
preview(charLength, ellipsis)string
charLength number
ellipsis string = '...'