ts-utily v1.2.1
ts-utily / Exports
ts-utily
Table of contents
Functions
- addDays
- arrayBufferToBase64
- at
- capitalize
- capitalizeFully
- compare
- convertArrayBufferToUint8Array
- convertArrayToRecord
- convertIndexSignaturesToMap
- convertMapToIndexSignatures
- convertRecordToArray
- createArrayBufferFromString
- createBlobFromBase64AndMimeType
- createBlobFromSourceAndMimeType
- createFileFromBase64AndMimeType
- createUint8ArrayFromBase64
- dateWith00Mins
- dayBetween
- deleteElementCollection
- equalsCollection
- fileIs
- findOrDefault
- get
- getDeltaTimeFromTwoDates
- getExtensionFromFileName
- getExtensionFromMimeType
- getHoursAndMinutesFromDateAsString
- getMimeTypeFromExtension
- getNextDayOfWeekFromDate
- getOrDefault
- getOrDefaultCollection
- getOrDefaultString
- getTomorrow
- hoursBetween
- includes
- instantToDate
- isAfter
- isBefore
- isBetween
- isEmptyCollection
- isEmptyString
- isEqual
- isNotEmptyCollection
- isNotEmptyString
- isNumber
- isString
- monthFromDate
- notPresent
- parzializeArray
- parzializeArrayByKeys
- percentage
- populateTemplate
- present
- removeDays
- removeDuplicateByKey
- removeDuplicateByKeys
- removeNullOrUndefinedFieldsFromObject
- removeWhiteSpace
- replaceAll
- sameDate
- setTime
- sortByObjectValues
- sortNumericString
- ternaryOperator
- toBoolean
- toLocalDate
- toLocalDateTime
- toNumber
- typizeBlobFromFileName
Functions
addDays
▸ addDays(d
, days?
): Date
Adds specified number of days to a given Date object.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
d | Date | undefined | The Date object to which days are to be added. |
days | number | 1 | The number of days to be added. Defaults to 1 if not provided. |
Returns
Date
- The updated Date object with additional days.
Defined in
arrayBufferToBase64
▸ arrayBufferToBase64(buffer
): string
Converts an ArrayBuffer to a Base64 string.
Parameters
Name | Type | Description |
---|---|---|
buffer | Uint8Array | The ArrayBuffer to convert. |
Returns
string
- The Base64 string representation of the ArrayBuffer.
Defined in
at
▸ at\<T
>(collection
, index
): undefined
| T
The function at
returns the element at the specified index in a collection, or undefined if the collection is empty or the index is out of bounds.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
collection | undefined | null | T [] | The collection parameter is an array of type T[] , or it can be undefined or null . It represents the collection of elements from which we want to retrieve an element at a specific index. |
index | number | The index parameter is the position of the element you want to retrieve from the collection . It is a number that represents the index of the element in the array. |
Returns
undefined
| T
the element at the specified index in the collection. If the collection is empty or the index is out of range, it will return undefined.
Defined in
capitalize
▸ capitalize(str
): string
The capitalize
function takes a string as input and returns the same string with the first letter of each word capitalized.
Parameters
Name | Type | Description |
---|---|---|
str | undefined | null | string | The str parameter is a string that may be undefined or null . |
Returns
string
The capitalize
function returns a string.
Defined in
capitalizeFully
▸ capitalizeFully(str
): string
The capitalizeFully
function takes a string as input and returns a new string with each word capitalized.
Parameters
Name | Type | Description |
---|---|---|
str | undefined | null | string | The str parameter is a string that can also be undefined or null . |
Returns
string
The function capitalizeFully
returns a string.
Defined in
compare
▸ compare(s1
, s2
): number
The function "compare" compares two strings case-insensitively and returns -1 if the first string is smaller, 1 if the second string is smaller.
Parameters
Name | Type | Description |
---|---|---|
s1 | string | The parameter s1 is a string that represents the first string to be compared. |
s2 | string | The parameter s2 is a string that represents the second string to be compared. |
Returns
number
a number. If s1
is lexicographically less than s2
(ignoring case), it returns -1. Otherwise, it returns 1.
Defined in
convertArrayBufferToUint8Array
▸ convertArrayBufferToUint8Array(arrayBuffer
): Uint8Array
Converts an ArrayBuffer to a Uint8Array.
Parameters
Name | Type | Description |
---|---|---|
arrayBuffer | ArrayBuffer | The ArrayBuffer to be converted. |
Returns
Uint8Array
- The converted Uint8Array.
Defined in
convertArrayToRecord
▸ convertArrayToRecord\<T
>(array
, key
): Record
\<string
, T
>
Converts an array to a record by using the specified key from each element.
Type parameters
Name | Description |
---|---|
T | The type of array elements. |
Parameters
Name | Type | Description |
---|---|---|
array | T [] | The array to convert. |
key | keyof T | The key to use from each element. |
Returns
Record
\<string
, T
>
- The record with keys as the values of the specified key and values as the corresponding elements.
Defined in
convertIndexSignaturesToMap
▸ convertIndexSignaturesToMap\<V
>(indexSignatures
): undefined
| Map
\<string
, V
>
The function converts an object with index signatures to a Map.
Type parameters
Name |
---|
V |
Parameters
Name | Type | Description |
---|---|---|
indexSignatures | undefined | { [p: string] : V ; } | An object that contains index signatures, where the keys are strings and the values can be of any type. |
Returns
undefined
| Map
\<string
, V
>
a Map<string, V>
or undefined
.
Defined in
convertMapToIndexSignatures
▸ convertMapToIndexSignatures\<V
>(map
): undefined
| { [p: string]
: V
; }
The function converts a Map object to an object with index signatures in TypeScript.
Type parameters
Name |
---|
V |
Parameters
Name | Type | Description |
---|---|---|
map | undefined | Map \<string , V > | A Map object that contains key-value pairs. |
Returns
undefined
| { [p: string]
: V
; }
an object with index signatures, where the keys are strings and the values are of type V. If the input map is undefined, the function returns undefined.
Defined in
convertRecordToArray
▸ convertRecordToArray\<T
, K
>(record
): T
[]
Converts a record to an array of its values.
Type parameters
Name | Type | Description |
---|---|---|
T | T | The type of the record values. |
K | extends PropertyKey | The type of the record keys. |
Parameters
Name | Type | Description |
---|---|---|
record | Record \<K , T > | The record to convert. |
Returns
T
[]
- The array containing the values of the record.
Defined in
createArrayBufferFromString
▸ createArrayBufferFromString(string
): ArrayBuffer
Converts a string into an ArrayBuffer.
Parameters
Name | Type | Description |
---|---|---|
string | string | The string to be converted. |
Returns
ArrayBuffer
- The converted ArrayBuffer.
Defined in
createBlobFromBase64AndMimeType
▸ createBlobFromBase64AndMimeType(base64
, MIME_Type
): Blob
Create a Blob object from the given base64 string and MIME type.
Parameters
Name | Type | Description |
---|---|---|
base64 | string | The base64 string. |
MIME_Type | MimeTypeEnum | The MIME type of the Blob. |
Returns
Blob
- The Blob object.
Defined in
createBlobFromSourceAndMimeType
▸ createBlobFromSourceAndMimeType(blobParts
, MIME_Type
): Blob
Creates a Blob object from an array of blob parts and the MIME type.
Parameters
Name | Type | Description |
---|---|---|
blobParts | BlobPart [] | The array of blob parts to be combined into a Blob object. |
MIME_Type | MimeTypeEnum | The MIME type for the Blob object. |
Returns
Blob
- The Blob object created from the provided blob parts and MIME type.
Defined in
createFileFromBase64AndMimeType
▸ createFileFromBase64AndMimeType(base64
, MIME_Type
, fileName
): File
Creates a file from a base64 encoded string and MIME type.
Parameters
Name | Type | Description |
---|---|---|
base64 | string | The base64 encoded string representing the file. |
MIME_Type | MimeTypeEnum | The MIME type of the file. |
fileName | string | The name of the file. |
Returns
File
- The created file object.
Defined in
createUint8ArrayFromBase64
▸ createUint8ArrayFromBase64(base64
): Uint8Array
Converts a base64 string to a Uint8Array.
Parameters
Name | Type | Description |
---|---|---|
base64 | string | The base64 string to convert. |
Returns
Uint8Array
The Uint8Array representing the base64 string.
Defined in
dateWith00Mins
▸ dateWith00Mins(date?
): Date
Sets the minutes, seconds, and milliseconds of the given date to 0. If no date is provided, the current date and time will be used.
Parameters
Name | Type | Description |
---|---|---|
date? | number | Date | The date to modify. If not provided, the current date and time will be used. |
Returns
Date
The modified date.
Defined in
dayBetween
▸ dayBetween(d1
, d2
): number
Calculates the number of days between two dates.
Parameters
Name | Type | Description |
---|---|---|
d1 | Date | The first date. |
d2 | Date | The second date. |
Returns
number
The number of days between the two dates.
Defined in
deleteElementCollection
▸ deleteElementCollection\<T
>(collection
, element
): T
[]
The deleteElementCollection
function removes an element from a collection if it exists, otherwise it returns the original collection.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
collection | undefined | null | T [] | The collection parameter is an array of elements of type T , or it can be undefined or null . |
element | T | Readonly \<T > | The element parameter represents the element that you want to delete from the collection . |
Returns
T
[]
an array of type T.
Defined in
equalsCollection
▸ equalsCollection\<T
>(collection1
, collection2
): boolean
The function checks if two collections are equal by comparing their lengths and elements.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
collection1 | undefined | null | T [] | The collection1 parameter is an array of type T , or it can be undefined or null . |
collection2 | undefined | null | T [] | The collection2 parameter is a generic array (T[] ) or can be undefined or null . It represents the second collection that you want to compare with collection1 . |
Returns
boolean
a boolean value.
Defined in
fileIs
▸ fileIs(filename
, mimeType
): boolean
Checks if a file matches the specified filename and mimeType.
Parameters
Name | Type | Description |
---|---|---|
filename | string | The name of the file. |
mimeType | MimeTypeEnum | The MIME type to match. |
Returns
boolean
Returns true
if the filename matches the MIME type, otherwise false
.
Defined in
findOrDefault
▸ findOrDefault\<T
>(collection
, element
, defaultElement
): T
The findOrDefault
function searches for an element in a collection and returns it if found, otherwise it returns a default element.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
collection | undefined | null | T [] | The collection parameter is an array of elements of type T , or it can be undefined or null . It represents the collection of elements in which we want to find a specific element. |
element | T | Readonly \<T > | The element parameter represents the element that you want to find in the collection . |
defaultElement | T | Readonly \<T > | The defaultElement parameter is the value that will be returned if the element is not found in the collection . |
Returns
T
a value of type T.
Defined in
get
▸ get\<T
>(collection
): T
[]
The get
function returns the input collection if it is not empty, otherwise it returns an empty array.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
collection | undefined | null | T [] | The collection parameter is of type T[] \| undefined \| null . This means it can accept an array of type T , or it can be undefined or null . |
Returns
T
[]
an array of type T.
Defined in
getDeltaTimeFromTwoDates
▸ getDeltaTimeFromTwoDates(date1
, date2
): DeltaDateResult
Calculates the time difference between two dates and returns the result as an object containing the number of years, months, days, hours, minutes, and seconds.
Parameters
Name | Type | Description |
---|---|---|
date1 | number | Date | The first date. |
date2 | number | Date | The second date. |
Returns
DeltaDateResult
- The result object containing the time difference in years, months, days, hours, minutes, and seconds.
Defined in
getExtensionFromFileName
▸ getExtensionFromFileName(fileName
): undefined
| string
Retrieves the file extension from a file name.
Parameters
Name | Type | Description |
---|---|---|
fileName | string | The file name. |
Returns
undefined
| string
- The corresponding file extension.
Defined in
getExtensionFromMimeType
▸ getExtensionFromMimeType(mimeType
): string
Retrieves file extension from given MIME type
Parameters
Name | Type | Description |
---|---|---|
mimeType | MimeTypeEnum | The MIME type of the file |
Returns
string
- The file extension
Defined in
getHoursAndMinutesFromDateAsString
▸ getHoursAndMinutesFromDateAsString(d
, locales
, hour?
, minute?
): null
| string
Converts a given date or number into a string representation of hours and minutes.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
d | undefined | null | number | Date | undefined | The date or number to convert. |
locales | LocalesArgument | undefined | The locales argument for the toLocaleTimeString method. |
hour? | "numeric" | "2-digit" | "2-digit" | The format of the hour: "numeric" for a single digit, "2-digit" for a double digit. Default is "2-digit". |
minute? | "numeric" | "2-digit" | "2-digit" | The format of the minute: "numeric" for a single digit, "2-digit" for a double digit. Default is "2-digit". |
Returns
null
| string
The string representation of the hours and minutes, or null if the input is null or undefined.
Defined in
getMimeTypeFromExtension
▸ getMimeTypeFromExtension(extension
): string
Retrieves the MIME type from a file extension.
Parameters
Name | Type | Description |
---|---|---|
extension | string | The file extension. |
Returns
string
- The corresponding MIME type.
Defined in
getNextDayOfWeekFromDate
▸ getNextDayOfWeekFromDate(date
, dayOfWeek
): Date
Gets the next occurrence of a specified day of the week from a given date.
Parameters
Name | Type | Description |
---|---|---|
date | undefined | null | number | Date | The date from which to start searching. If not provided or invalid, the current date will be used. |
dayOfWeek | DayOfWeek | The day of the week to find the next occurrence of. |
Returns
Date
- The next occurrence of the specified day of the week.
Defined in
getOrDefault
▸ getOrDefault\<T
>(data
, defaultValue
): T
The getOrDefault
function returns the provided data if it is not null or undefined, otherwise it returns the provided default value.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
data | T | The data parameter is the value that you want to check if it is null or undefined. |
defaultValue | T | The defaultValue parameter is the value that will be returned if the data parameter is null or undefined . |
Returns
T
The function getOrDefault
returns the value of data
if it is not null or undefined, otherwise it returns the value of defaultValue
.
Defined in
getOrDefaultCollection
▸ getOrDefaultCollection\<T
>(collection
, defaultList
): T
[]
The getOrDefaultCollection
function returns the provided collection if it is not empty, otherwise it returns the default list.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
collection | undefined | null | T [] | The collection parameter is a variable that represents an array of elements of type T , or it can be undefined or null . |
defaultList | T [] | The defaultList parameter is an array of type T[] . It is the list that will be returned if the collection parameter is empty or undefined. |
Returns
T
[]
an array of type T.
Defined in
getOrDefaultString
▸ getOrDefaultString(string
, defaultValue?
): string
The getOrDefaultString
function returns a string value if it is not empty, otherwise it returns a default value.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
string | undefined | null | string | undefined | The string parameter is a string value that can be either a valid string, undefined , or null . |
defaultValue? | string | '' | The defaultValue parameter is a string that specifies the value to return if the string parameter is empty, undefined, or null. If no defaultValue is provided, it defaults to an empty string (''). |
Returns
string
The function getOrDefault
returns a string value.
Defined in
getTomorrow
▸ getTomorrow(d?
): Date
Returns tomorrow's date.
Parameters
Name | Type | Description |
---|---|---|
d? | number | Date | Optional date to be used as the base. |
Returns
Date
- Tomorrow's date.
Defined in
hoursBetween
▸ hoursBetween(d1
, d2
, withAbs?
): number
Calculates the number of hours between two given dates.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
d1 | Date | undefined | The first date. |
d2 | Date | undefined | The second date. |
withAbs? | boolean | true | Whether to return the absolute difference or not. |
Returns
number
The number of hours between the two dates.
Defined in
includes
▸ includes(string1
, string2
): boolean
The function checks if a given string contains another given string, ignoring case sensitivity.
Parameters
Name | Type | Description |
---|---|---|
string1 | undefined | null | string | A string that can be undefined or null. |
string2 | undefined | null | string | The string2 parameter is a string that represents the substring that we want to check if it is present in string1 . |
Returns
boolean
The function includes
returns a boolean value.
Defined in
instantToDate
▸ instantToDate(instant?
): Date
Converts the given instant to a Date object.
Parameters
Name | Type | Description |
---|---|---|
instant? | string | Date | The instant to convert. If not provided, the current date and time is used. |
Returns
Date
- The converted Date object.
Example
use for convert Instant(like as java object) to javascript date
Defined in
isAfter
▸ isAfter(d1
, d2
, matchOnlyForYearMonthDay?
): boolean
Checks if a given date is after another date.
Parameters
Name | Type | Description |
---|---|---|
d1 | Date | The first date. |
d2 | Date | The second date. |
matchOnlyForYearMonthDay? | boolean | Optional parameter to match only up to year, month, and day. |
Returns
boolean
- Returns true if d1 is after d2, otherwise returns false.
Defined in
isBefore
▸ isBefore(d1
, d2
, matchOnlyForYearMonthDay?
): boolean
Determines if the given date is before the reference date.
Parameters
Name | Type | Description |
---|---|---|
d1 | Date | The date to compare. |
d2 | Date | The reference date. |
matchOnlyForYearMonthDay? | boolean | Optional flag to indicate if the dates should only match for year, month, and day. Defaults to false. |
Returns
boolean
- True if d1 is before d2 (or matches only for year, month, and day if specified), otherwise false.
Defined in
isBetween
▸ isBetween(dateToMatch
, start
, end
, matchOnlyForYearMonthDay?
): boolean
Checks if a given date falls between a start and end date.
Parameters
Name | Type | Description |
---|---|---|
dateToMatch | Date | The date to check. |
start | Date | The start date. |
end | Date | The end date. |
matchOnlyForYearMonthDay? | boolean | (Optional) Specifies whether to only consider the year, month, and day when checking the date. Default is false. |
Returns
boolean
- True if the date falls between the start and end dates, false otherwise.
Defined in
isEmptyCollection
▸ isEmptyCollection\<T
>(collection
): boolean
The function isEmptyCollection
checks if a collection is empty or not.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
collection | undefined | null | T [] | The collection parameter is a generic type T[] which represents an array of elements of type T . It can also be undefined or null . |
Returns
boolean
a boolean value indicating whether the collection is empty or not.
Defined in
isEmptyString
▸ isEmptyString(string
): boolean
The function checks if a string is empty, including cases where the string is undefined or null.
Parameters
Name | Type | Description |
---|---|---|
string | undefined | null | string | The string parameter is of type string \| undefined \| null , which means it can accept a value of type string , undefined , or null . |
Returns
boolean
The function isEmpty
returns a boolean value.
Defined in
isEqual
▸ isEqual\<T
>(...objects
): boolean
The isEqual
function checks if all the given objects are equal by comparing their JSON representations.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
...objects | T [] | The objects parameter is a rest parameter that allows you to pass in multiple objects of type T . The rest parameter syntax (...objects ) allows you to pass any number of arguments, which will be collected into an array called objects . |
Returns
boolean
The function isEqual
returns a boolean value.
Defined in
isNotEmptyCollection
▸ isNotEmptyCollection\<T
>(collection
): boolean
The function isNotEmptyCollection
checks if a collection is not empty.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
collection | undefined | null | T [] | The collection parameter is of type T[] \| undefined \| null . This means it can accept an array of type T , or it can be undefined or null . |
Returns
boolean
The function isNotEmpty is returning a boolean value.
Defined in
isNotEmptyString
▸ isNotEmptyString(string
): boolean
The function isNotEmptyString
checks if a string is not empty.
Parameters
Name | Type | Description |
---|---|---|
string | undefined | null | string | The parameter "string" is of type string and can also be undefined or null. |
Returns
boolean
The function isNotEmpty is returning a boolean value.
Defined in
isNumber
▸ isNumber\<T
>(value
): boolean
The function isNumber
checks if a value is a number in TypeScript.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
value | T | The value parameter is the value that you want to check if it is a number. It can be of any type T . |
Returns
boolean
a boolean value.
Defined in
isString
▸ isString\<T
>(obj
): boolean
The function isString
checks if an object is a string or an instance of the String class.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
obj | T | The obj parameter is a generic type T , which means it can be any type. |
Returns
boolean
a boolean value indicating whether the input object is a string or not.
Defined in
monthFromDate
▸ monthFromDate(date
, locales?
, month?
): string
Returns the month from a given date in the specified format.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
date | Date | undefined | The date from which to extract the month. |
locales? | LocalesArgument | 'default' | A string representing a BCP 47 language tag, or an array of such strings. |
month? | "numeric" | "2-digit" | "long" | "short" | "narrow" | "long" | The format in which to return the month. Possible values are: - "numeric": Returns the month as a digit (e.g. 1, 2, 3, ... 12). - "2-digit": Returns the month as a two-digit number with leading zero (e.g. 01, 02, 03, ... 12). - "long": Returns the full name of the month (e.g. January, February, ... December). - "short": Returns the abbreviated name of the month (e.g. Jan, Feb, ... Dec). - "narrow": Returns the narrow name of the month (e.g. J, F, ... D). - undefined or not provided: Returns the default long format. |
Returns
string
The month from the given date in the specified format.
Defined in
notPresent
▸ notPresent\<T
>(...args
): boolean
The function notPresent
checks if any of the arguments passed to it are not present.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
...args | T [] | The args parameter is a rest parameter of type T[] , which means it can accept any number of arguments of type T . |
Returns
boolean
a boolean value.
Defined in
parzializeArray
▸ parzializeArray\<T
>(array
, section
): undefined
| T
The function parzializeArray
takes an array and a section size as input and returns an array of arrays, where each subarray contains a section of the original array.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
array | undefined | null | T [] | The array parameter is an array of elements of type T , or it can be undefined or null . |
section | number | The parameter "section" represents the size of each section or chunk that the array will be divided into. |
Returns
an array of arrays of type T, or undefined.
Defined in
parzializeArrayByKeys
▸ parzializeArrayByKeys\<T
>(array
, keys
): undefined
| T
The function parzializeArrayByKeys
takes an array of objects and an array of keys, and returns a partially grouped array based on the specified keys.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
array | undefined | null | T [] | The array parameter is an array of objects of type T , or it can be undefined or null . |
keys | keyof T [] | An array of keys that represent the properties of the objects in the array. |
Returns
The function parzializeArrayByKeys
returns an array of arrays of type T
, or undefined
.
Defined in
percentage
▸ percentage(value
, totalValue
): number
The function calculates the percentage of a value in relation to a total value.
Parameters
Name | Type | Description |
---|---|---|
value | number | The value parameter represents the specific value that you want to calculate the percentage of. It is a number that you want to find the percentage of in relation to the totalValue. |
totalValue | number | The total value represents the maximum value or the total amount that you want to calculate the percentage of. |
Returns
number
a number, which is the calculated percentage value.
Defined in
populateTemplate
▸ populateTemplate(string
, placeholders
): undefined
| string
Replaces placeholders in a string with corresponding values from an array.
Parameters
Name | Type | Description |
---|---|---|
string | undefined | string | The string containing placeholders. |
placeholders | any [] | An array of objects containing key-value pairs, where the key represents a placeholder and the value is the replacement value. |
Returns
undefined
| string
- The resulting string with replaced placeholders, or undefined if the input string is undefined.
Example
populateTemplate('Replace my text {myReplacePlaceholder}', [{name: 'Valery', age: 20, myReplacePlaceholder: 'test this'}, {name: 'Marcus', age: 21}]) => Replace my text test this
Defined in
present
▸ present\<T
>(...args
): boolean
The present
function checks if all the arguments passed to it are not null or undefined.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
...args | T [] | args is a rest parameter of type T[]. It allows the function to accept any number of arguments of type T. |
Returns
boolean
a boolean value.
Defined in
removeDays
▸ removeDays(d
, days?
): Date
Removes the specified number of days from a given date.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
d | Date | undefined | The date to remove days from. |
days | number | 1 | The number of days to remove. Defaults to 1 if not provided. |
Returns
Date
- The new date after removing the specified number of days.
Defined in
removeDuplicateByKey
▸ removeDuplicateByKey\<T
>(collection
, key?
): T
[]
The function removeDuplicatesByKey
removes duplicate elements from a collection based on a specified key.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
collection | undefined | null | T [] | The collection parameter is an array of objects of type T . It can also be undefined or null . |
key? | keyof T | The key parameter is an optional parameter that specifies the property of the objects in the collection array that should be used as the key for removing duplicates. If key is not provided, the entire objects in the collection array will be compared for duplicates. |
Returns
T
[]
The function rimuoviDuplicatiByKey
returns an array of type T[]
.
Defined in
removeDuplicateByKeys
▸ removeDuplicateByKeys\<T
>(collection
, keys
): T
[]
The removeDuplicateByKeys
function removes duplicate elements from a collection based on specified keys.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
collection | undefined | null | T [] | The collection parameter is an array of objects of type T . It can also be undefined or null . |
keys | keyof T [] | The keys parameter is an array of keys that are used to determine uniqueness in the collection. Each element in the array represents a key in the objects of the collection. |
Returns
T
[]
an array of type T, which is the collection with duplicate elements removed based on the specified keys.
Defined in
removeNullOrUndefinedFieldsFromObject
▸ removeNullOrUndefinedFieldsFromObject\<T
>(value
): undefined
| T
The function removes fields with null or undefined values from an object.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
value | T | The value parameter is the object from which you want to remove fields that have null or undefined values. |
Returns
undefined
| T
either the input value T
or undefined
.
Example
example of usage: cleaning object before store into DB(JSON type colum)
Defined in
removeWhiteSpace
▸ removeWhiteSpace(str
): string
The removeWhiteSpace
function removes all white spaces from a given string.
Parameters
Name | Type | Description |
---|---|---|
str | undefined | null | string | The str parameter is a string that can be either a valid string value, undefined , or null . |
Returns
string
a string with all whitespace characters removed.
Defined in
replaceAll
▸ replaceAll(originalString
, occurrenceToReplace
, replaceWith
): string
The replaceAll
function replaces all occurrences of a specified string in a given string with another specified string.
Parameters
Name | Type | Description |
---|---|---|
originalString | string | The original string that you want to perform the replacement on. |
occurrenceToReplace | string | The occurrenceToReplace parameter is a string that represents the occurrence or pattern that you want to replace in the originalString . |
replaceWith | string | The replaceWith parameter is the string that will replace all occurrences of occurrenceToReplace in the originalString . |
Returns
string
The function replaceAll
returns a string.
Defined in
sameDate
▸ sameDate(d1
, d2
): boolean
Checks if two dates are the same (year, month, and day).
Parameters
Name | Type | Description |
---|---|---|
d1 | Date | The first date to compare. |
d2 | Date | The second date to compare. |
Returns
boolean
- True if the two dates are the same, false otherwise.
Defined in
setTime
▸ setTime(date
, time
): undefined
| Date
Sets the time portion of a given date.
Parameters
Name | Type | Description |
---|---|---|
date | undefined | null | number | Date | The date object or timestamp to modify. |
time | string | The time string to set in the format 'HH:MM'. |
Returns
undefined
| Date
- The modified date object or null if the input date is not present.
Throws
- Throws an error if the given date or time is not valid.
Defined in
sortByObjectValues
▸ sortByObjectValues\<T
>(keys
, isAsc
): (a
: T
, b
: T
) => number
The function sortByObjectValues
sorts an array of objects based on the values of specified nested keys in ascending or descending order.
Type parameters
Name | Type |
---|---|
T | extends object |
Parameters
Name | Type | Description |
---|---|---|
keys | NestedKeyOf \<T >[] | An array of keys that represent the nested properties of the objects being sorted. |
isAsc | boolean | The isAsc parameter is a boolean value that determines whether the sorting order should be ascending (true ) or descending (false ). |
Returns
fn
The function sortByObjectValues
returns a function that takes two objects a
and b
of type T
and returns a number.
▸ (a
, b
): number
Parameters
Name | Type |
---|---|
a | T |
b | T |
Returns
number
Example
example of usage: [{name: 'Amanda', age:18}, {name: 'Victor', age:18}].sort(sortByObjectValues(['name', 'age'], true))
Example
array.sort(sortByObjectValues(['ele1', 'ele2' 'eleN',...], false))
Defined in
sortNumericString
▸ sortNumericString(a
, b
): number
The function sortNumericString
compares two numeric strings and returns a number indicating their relative order.
Parameters
Name | Type | Description |
---|---|---|
a | string | The parameter "a" is a string representing the first numeric string to be compared. |
b | string | The parameter "b" is a string representing the second value to be compared. |
Returns
number
a number.
Defined in
ternaryOperator
▸ ternaryOperator(condition
, s1
, s2
): string
The ternaryOperator
function returns s1
if condition
is true, otherwise it returns s2
.
Parameters
Name | Type | Description |
---|---|---|
condition | boolean | A boolean value that represents the condition to be evaluated. If the condition is true, the function will return s1. If the condition is false, the function will return s2. |
s1 | string | The parameter s1 is a string that represents the value to be returned if the condition is true. |
s2 | string | The parameter s2 is a string that represents the value to be returned if the condition is false. |
Returns
string
The ternaryOperator function returns either s2 or s1 based on the value of the condition. If the condition is false, it returns s2. Otherwise, it returns s1.
Defined in
toBoolean
▸ toBoolean(value
): boolean
The function toBoolean
converts a string value to a boolean value, considering various possible representations of true like as 'true', '1' or 'y'.
Parameters
Name | Type | Description |
---|---|---|
value | string | The value parameter is a string that represents a boolean value. |
Returns
boolean
a boolean value.
Defined in
toLocalDate
▸ toLocalDate(date
): string
Converts a Date object to a string representation of the local date. If the input date is null or undefined, an empty string is returned.
Parameters
Name | Type | Description |
---|---|---|
date | undefined | null | Date | The date object to convert. |
Returns
string
The string representation of the local date.
Defined in
toLocalDateTime
▸ toLocalDateTime(date
, nowAsDefault?
): string
Converts a given Date
, number
, null
, or undefined
value to a localized string representation of the date and time in "YYYY-MM-DDTHH:MM" format.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
date | undefined | null | number | Date | undefined | The value to be converted. |
nowAsDefault? | boolean | false | If true and date is not provided, the current date and time will be used as the default value. |
Returns
string
The localized string representation of the date and time. Returns 'N.d.' if date
is null
and nowAsDefault
is false
.
Defined in
toNumber
▸ toNumber\<T
>(value
): number
The toNumber
function converts a value to a number, returning 0 if the value is not a valid number.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
value | T | The value parameter is of type T , which means it can be any type. It represents the value that needs to be converted to a number. |
Returns
number
a number.
Defined in
typizeBlobFromFileName
▸ typizeBlobFromFileName(blob
, fileName
): undefined
| Blob
Converts a Blob to a specific Blob type based on the file name extension.
Parameters
Name | Type | Description |
---|---|---|
blob | Blob | The Blob instance to be typed. |
fileName | string | The name of the file associated with the Blob. |
Returns
undefined
| Blob
- A new Blob instance of the specified type, or undefined if unsupported extension or invalid filename.
Defined in
13 days ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago