4.9 KiB
@resultium/utils / Exports
@resultium/utils
Table of contents
Functions
- SplitIntoChunks
- capitalizeFirstChar
- classNames
- conditionalJoin
- isDeepWeakEqual
- randomInRange
- removeFromArrayByKeyValue
- removeObjectProperty
- replaceFromArrayByKeyValue
Functions
SplitIntoChunks
▸ SplitIntoChunks<T>(array, chunkSize): T[][]
Splits an array into chunks
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type | Description |
|---|---|---|
array |
T[] |
array which shall be split into chunks |
chunkSize |
number |
size of a single chunk |
Returns
T[][]
array of chunks
Defined in
functions/splitIntoChuks.ts:8
capitalizeFirstChar
▸ capitalizeFirstChar(string): string
Capitalizes first character of the given string
Parameters
| Name | Type | Description |
|---|---|---|
string |
string |
string to modify |
Returns
string
new string
Defined in
functions/capitalizeFirstChar.ts:7
classNames
▸ classNames(...classes): string
Conditionally joins given class strings
Parameters
| Name | Type | Description |
|---|---|---|
...classes |
string[] |
class strings to join |
Returns
string
new string
Defined in
functions/classNames.ts:7
conditionalJoin
▸ conditionalJoin(array, joinChar): string
Conditionally joins given strings
Parameters
| Name | Type | Description |
|---|---|---|
array |
string[] |
strings to join |
joinChar |
string |
character used to join strings |
Returns
string
new string
Defined in
functions/conditionalJoin.ts:8
isDeepWeakEqual
▸ isDeepWeakEqual(obj1, obj2): boolean
Weakly compares two objects
Parameters
| Name | Type | Description |
|---|---|---|
obj1 |
object |
first object to compare with second |
obj2 |
object |
second object to compare with first |
Returns
boolean
true if equal
Remarks
uses JSON.stringify()
Defined in
functions/isDeepWeakEqual.ts:10
randomInRange
▸ randomInRange(min, max): number
Returns a pseudo-random number in given range
Parameters
| Name | Type | Description |
|---|---|---|
min |
number |
minimum acceptable value |
max |
number |
maximum acceptable value |
Returns
number
number [min; max]
Remarks
Uses Math.random(), which is not cryptographically secure Returns only integers
Defined in
functions/randomInRange.ts:12
removeFromArrayByKeyValue
▸ removeFromArrayByKeyValue<T>(array, keyValue): T[]
Removes an object from an array by key value object.
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type | Description |
|---|---|---|
array |
T[] |
array which shall be manipulated with |
keyValue |
Partial<{ [K in string | number | symbol]: T[K] }> |
key-value object which defines which object shall be removed from the array |
Returns
T[]
modified array
Remarks
This method doesn't support deep comparements.
Defined in
functions/removeFromArrayByKeyValue.ts:11
removeObjectProperty
▸ removeObjectProperty<T>(object, key): T
Removes an object property by provided key
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type | Description |
|---|---|---|
object |
T |
object which shall be manipulated |
key |
keyof T |
key which should be used to remove a property from object |
Returns
T
new object
Defined in
functions/removeObjectProperty.ts:9
replaceFromArrayByKeyValue
▸ replaceFromArrayByKeyValue<T>(array, keyValue, newObject): T[]
Replaces an object from an array with key value object search
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type | Description |
|---|---|---|
array |
T[] |
array which shall be manipulated with |
keyValue |
Partial<{ [K in string | number | symbol]: T[K] }> |
key-value object which defines which object shall be removed from the array |
newObject |
Partial<{ [K in string | number | symbol]: T[K] }> |
object or values to replace within the searched object |
Returns
T[]
modified array
Remarks
This method doesn't support deep comparements.
Defined in
functions/replaceFromArrayByKeyValue.ts:12