Monkey service

Service useMonkey permet de bénéficier du Monkey Patching d'Orion pour les prototypes comme Array, Number, Date, ou String mais sans vraiment l'utiliser.
C'est utile pour les personnes qui ne veulent pas ajouter des méthodes aux prototypes natifs.
Le type de paramètre sera automatiquement déduit pour fournir les méthodes disponibles.

Astuce

Rendez-vous sur notre guide du Monkey Patching pour plus d'informations.

Exemple

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

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

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

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

Méthodes disponibles

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 = '...'