npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ts-utily

v1.2.4

Published

Typescript utils library

Downloads

28

Readme


ts-utily / Exports

ts-utily

Table of contents

Functions

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

utils/date-utils.ts:89


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

utils/file-utils.ts:122


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

utils/collection-utils.ts:29


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

utils/string-utils.ts:55


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

utils/string-utils.ts:68


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

utils/string-utils.ts:83


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

utils/file-utils.ts:148


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

utils/conversion-utils.ts:33


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

utils/conversion-utils.ts:8


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

utils/conversion-utils.ts:20


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

utils/conversion-utils.ts:51


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

utils/file-utils.ts:138


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

utils/file-utils.ts:65


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

utils/file-utils.ts:76


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

utils/file-utils.ts:88


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

utils/file-utils.ts:48


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

utils/date-utils.ts:223


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

utils/date-utils.ts:115


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

utils/collection-utils.ts:62


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

utils/collection-utils.ts:76


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

utils/file-utils.ts:110


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

utils/collection-utils.ts:91


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

utils/collection-utils.ts:40


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

utils/date-utils.ts:261


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

utils/file-utils.ts:20


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

utils/file-utils.ts:99


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

utils/date-utils.ts:172


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

utils/file-utils.ts:10


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

utils/date-utils.ts:141


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

utils/common-utils.ts:36


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

utils/collection-utils.ts:51


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

utils/string-utils.ts:40


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

utils/date-utils.ts:157


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

utils/date-utils.ts:128


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

utils/string-utils.ts:10


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

utils/date-utils.ts:185


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

utils/date-utils.ts:37


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

utils/date-utils.ts:24


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

utils/date-utils.ts:49


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

utils/collection-utils.ts:9


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

utils/string-utils.ts:20


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

utils/common-utils.ts:46


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

utils/collection-utils.ts:19


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

utils/string-utils.ts:30


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

utils/number-utils.ts:19


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

utils/string-utils.ts:93


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

utils/date-utils.ts:212


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

utils/common-utils.ts:26


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

undefined | T[][]

an array of arrays of type T, or undefined.

Defined in

utils/collection-utils.ts:133


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

undefined | T[][]

The function parzializeArrayByKeys returns an array of arrays of type T, or undefined.

Defined in

utils/collection-utils.ts:150


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

utils/number-utils.ts:33


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

utils/string-utils.ts:153


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

utils/common-utils.ts:15


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

utils/date-utils.ts:102


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

utils/collection-utils.ts:103


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

utils/collection-utils.ts:115


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

utils/object-utils.ts:9


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

utils/string-utils.ts:102


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

utils/string-utils.ts:125


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

utils/date-utils.ts:12


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

[utils/date-utils.ts:241](https://github.com/kemotx90/ts-utily/blob/38d9efc3ccfe9be06d9eeb3f51836fc950c38af5/src/utils/date-util