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.
Tips
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 Tlast()
T | undefinedfirst()
T | undefineddelete(target, key, deleteCount)
T[] target
any key
keyof T = 'id' deleteCount
number = 1deleteWhere(keyValue, key)
T[] keyValue
any key
K | ((x: T) => boolean)empty()
Arraytoggle(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
anyfilterNil()
{*} {T[]}Date
toPost(withTime)
string withTime
boolean = falsetoOffset()
stringisBissextile()
booleangetOrdinalDate()
numbergetTimeBetween(pattern, date)
string pattern
string date
dategetWeekNumber()
numbergetWeekDays()
objectgetWeekDates()
objecthasFiftyThreeWeeks()
booleansetDateToFirstDow()
DatesetDateToLastDow()
DatetoReadable(pattern)
string pattern
string = language.DATE_PATTERN Example
PatternKeywords
toMidnight()
DatetoEndOfDay()
DateNumber
toHoursMinutes(separator)
string separator
string = ':'withDelimiters(thousands, decimal)
string thousands
string = ' ' decimal
string = ','toCurrency(currency)
string currency
string = ' €'decimal(precision)
number precision
number = 2String
toPost()
stringtoReadableDate(pattern)
string pattern
string MoreInfos
insert(string, index, replace)
string string
string index
number = 0 replace
boolean = falsepluralize(quantity, quantityIncluded)
string quantity
number quantityIncluded
boolean = truehashCode()
numbermark(valueToMark)
string valueToMark
stringpreview(charLength, ellipsis)
string charLength
number ellipsis
string = '...'