utils
@hashml/hashml › Globals › "utils"
Index
Array Functions
Other Functions
RegExp Functions
Array Functions
countOccurrences
▸ countOccurrences<T>(seq: Iterable‹T›): Map‹T, number›
Defined in utils.ts:67
Returns a map of items to their occurrence count.
Type parameters:
▪ T
Type of the items in the sequence
Parameters:
| Name | Type | Description |
|---|---|---|
seq | Iterable‹T› | Sequence items, potentially with duplicates. |
Returns: Map‹T, number›
findDuplicates
▸ findDuplicates<T>(seq: Iterable‹T›): Array‹[T, number]›
Defined in utils.ts:56
Returns the duplicates in a sequence of items, and their count
Type parameters:
▪ T
Type of the items in the sequence
Parameters:
| Name | Type | Description |
|---|---|---|
seq | Iterable‹T› | Sequence of items, potentially with duplicates. |
Returns: Array‹[T, number]›
hasDuplicates
▸ hasDuplicates<T>(arr: T[]): boolean
Defined in utils.ts:45
Returns whether an array has duplicate items
Type parameters:
▪ T
Parameters:
| Name | Type | Description |
|---|---|---|
arr | T[] | Array of items, potentially with duplicates. |
Returns: boolean
last
▸ last<T>(seq: ArrayLike‹T›): T
Defined in utils.ts:88
Returns the last item in a sequence.
remarks
If the last item does not exist, this function will return undefined.
This is coherent with the behavior of arrays in TS, but means that this function should only
be called when we know that a last item exists.
Type parameters:
▪ T
Type of the items in the sequence
Parameters:
| Name | Type | Description |
|---|---|---|
seq | ArrayLike‹T› | String, array, or other array-like sequence |
Returns: T
unique
▸ unique<T>(seq: Iterable‹T›): T[]
Defined in utils.ts:35
Returns a copy of a sequence with duplicates removed.
remarks
Order of the first occurrences is preserved.
To see how this implementation respects that, see the MDN documentation for Set.
Type parameters:
▪ T
Parameters:
| Name | Type | Description |
|---|---|---|
seq | Iterable‹T› | Sequence of items, potentially with duplicates. |
Returns: T[]
Other Functions
capitalize
▸ capitalize(s: string): string
Defined in utils.ts:111
Parameters:
| Name | Type |
|---|---|
s | string |
Returns: string
ordinal
▸ ordinal(i: number): string
Defined in utils.ts:98
Returns the ordinal form of a number. For example, the ordinal of 1 is "1st".
Parameters:
| Name | Type | Description |
|---|---|---|
i | number | Number to convert to an ordinal. |
Returns: string
RegExp Functions
regexpUnion
▸ regexpUnion(...regExps: RegExp[]): RegExp
Defined in utils.ts:19
Returns a union of regular expressions, in the given order.
Parameters:
| Name | Type | Description |
|---|---|---|
...regExps | RegExp[] | Array of regular expressions to produce the union of |
Returns: RegExp
stringToRegexp
▸ stringToRegexp(regexp: string): RegExp
Defined in utils.ts:9
Convert a string to a regexp, escaping any special characters.
From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping
Parameters:
| Name | Type | Description |
|---|---|---|
regexp | string | String that the regex will match. |
Returns: RegExp