docs

Zakary Timson 2024-09-22 03:11:09 -04:00
parent 394b9b0bf7
commit 9851a2bdd6
16 changed files with 8742 additions and 0 deletions

19
Home.md Normal file

@ -0,0 +1,19 @@
# @ztimson/utils
## Modules
- [array](array.md)
- [aset](aset.md)
- [emitter](emitter.md)
- [errors](errors.md)
- [files](files.md)
- [http](http.md)
- [index](index.md)
- [logger](logger.md)
- [math](math.md)
- [misc](misc.md)
- [objects](objects.md)
- [promise-progress](promise-progress.md)
- [string](string.md)
- [time](time.md)
- [types](types.md)

315
array.md Normal file

@ -0,0 +1,315 @@
[@ztimson/utils](Home.md) / array
# array
## Functions
### ~~addUnique()~~
> **addUnique**\<`T`\>(`array`, `el`): `T`[]
Only add element to array if it isn't already included
#### Type Parameters
• **T**
#### Parameters
**array**: `T`[]
Target array element will be added to
**el**: `T`
Unique element to add
#### Returns
`T`[]
Array with element if it was unique
#### Example
```js
const arr = addUnique([1, 2, 3], 3);
console.log(arr); // Output: [1, 2, 3]
```
#### Deprecated
Use ASet to create unique arrays
#### Defined in
src/array.ts:17
***
### ~~arrayDiff()~~
> **arrayDiff**(`a`, `b`): `any`[]
Find all unique elements in arrays
#### Parameters
**a**: `any`[]
First array to compare
**b**: `any`[]
Second array to compare
#### Returns
`any`[]
Unique elements
#### Deprecated
Use ASet to perform Set operations on arrays
#### Defined in
src/array.ts:30
***
### caseInsensitiveSort()
> **caseInsensitiveSort**(`prop`): (`a`, `b`) => `number`
Provides a shorthand for sorting arrays of complex objects by a string property
#### Parameters
**prop**: `string`
Name of property to use, supports dot notation
#### Returns
`Function`
- Function to handle sort (Meant to be passed to Array.prototype.sort or used in sortFn)
##### Parameters
**a**: `any`
**b**: `any`
##### Returns
`number`
#### Example
```ts
let arr = [{a: 'Apple', b: 123}, {a: 'Carrot', b: 789}, {a: 'banana', b: 456}];
arr.sort(caseInsensitiveSort('a'));
```
#### Defined in
src/array.ts:49
***
### findByProp()
> **findByProp**(`prop`, `value`): (`v`) => `boolean`
Shorthand to find objects with a property value
#### Parameters
**prop**: `string`
Property to compare (Dot nation supported)
**value**: `any`
Value property must have
#### Returns
`Function`
Function used by `filter` or `find`
##### Parameters
**v**: `any`
##### Returns
`boolean`
#### Example
```js
const found = [
{name: 'Batman'},
{name: 'Superman'},
].filter(findByProp('name', 'Batman'));
```
#### Defined in
src/array.ts:73
***
### flattenArr()
> **flattenArr**(`arr`, `result`): `any`[]
Recursively flatten nested arrays
#### Parameters
**arr**: `any`[]
n-dimensional array
**result**: `any`[] = `[]`
Internal use only -- Keeps track of recursion
#### Returns
`any`[]
- Flattened array
#### Example
```ts
const arr = [
{label: null, url: '/'},
{label: 'Model Admin', url: '/model-admin'},
[
{label: 'Elements', url: '/model-admin/elements'},
{label: 'Example', url: null}
]
];
console.log(flattenArr(arr));
// Output:
[
{label: null, url: '/'},
{label: 'Model Admin', url: '/model-admin'},
{label: 'Elements', url: '/model-admin/elements'},
{label: 'Example', url: null}
]
```
#### Defined in
src/array.ts:105
***
### makeArray()
> **makeArray**\<`T`\>(`value`): `T`[]
Make sure value is an array, if it isn't wrap it in one
#### Type Parameters
• **T**
#### Parameters
**value**: `T` \| `T`[]
Value that should be an array
#### Returns
`T`[]
Value in an array
#### Defined in
src/array.ts:155
***
### ~~makeUnique()~~
> **makeUnique**(`arr`): `any`[]
Make sure every element in array is unique
#### Parameters
**arr**: `any`[]
Array that will be filtered in place
#### Returns
`any`[]
Original array
#### Deprecated
Please use ASet to create a guaranteed unique array
#### Defined in
src/array.ts:142
***
### sortByProp()
> **sortByProp**(`prop`, `reverse`): (`a`, `b`) => `number`
Provides a shorthand for sorting arrays of complex objects
#### Parameters
**prop**: `string`
Name of property to use, supports dot notation
**reverse**: `boolean` = `false`
Reverse the order of the sort
#### Returns
`Function`
- Function to handle sort (Meant to be passed to Array.prototype.sort)
##### Parameters
**a**: `any`
**b**: `any`
##### Returns
`number`
#### Example
```ts
let arr = [{a: {b: 2}}, {a: {b: 3}}, {a: {b: 1}}];
arr.sort(sortByProp('a.b'));
```
#### Defined in
src/array.ts:123

2048
aset.md Normal file

File diff suppressed because it is too large Load Diff

239
emitter.md Normal file

@ -0,0 +1,239 @@
[@ztimson/utils](Home.md) / emitter
# emitter
## Classes
### TypedEmitter\<T\>
#### Extended by
- [`Logger`](logger.md#logger)
#### Type Parameters
**T** *extends* [`TypedEvents`](emitter.md#typedevents) = [`TypedEvents`](emitter.md#typedevents)
#### Constructors
##### new TypedEmitter()
> **new TypedEmitter**\<`T`\>(): [`TypedEmitter`](emitter.md#typedemittert)\<`T`\>
###### Returns
[`TypedEmitter`](emitter.md#typedemittert)\<`T`\>
#### Methods
##### emit()
> **emit**\<`K`\>(`event`, ...`args`): `void`
###### Type Parameters
**K** *extends* `string` \| `number` \| `symbol`
###### Parameters
**event**: `K`
• ...**args**: `Parameters`\<`T`\[`K`\]\>
###### Returns
`void`
###### Defined in
src/emitter.ts:36
##### off()
> **off**\<`K`\>(`event`, `listener`): `void`
###### Type Parameters
**K** *extends* `string` \| `number` \| `symbol` = `string`
###### Parameters
**event**: `K`
**listener**: `T`\[`K`\]
###### Returns
`void`
###### Defined in
src/emitter.ts:41
##### on()
> **on**\<`K`\>(`event`, `listener`): () => `void`
###### Type Parameters
**K** *extends* `string` \| `number` \| `symbol` = `string`
###### Parameters
**event**: `K`
**listener**: `T`\[`K`\]
###### Returns
`Function`
###### Returns
`void`
###### Defined in
src/emitter.ts:45
##### once()
> **once**\<`K`\>(`event`, `listener`?): `Promise`\<`any`\>
###### Type Parameters
**K** *extends* `string` \| `number` \| `symbol` = `string`
###### Parameters
**event**: `K`
**listener?**: `T`\[`K`\]
###### Returns
`Promise`\<`any`\>
###### Defined in
src/emitter.ts:51
##### emit()
> `static` **emit**(`event`, ...`args`): `void`
###### Parameters
**event**: `any`
• ...**args**: `any`[]
###### Returns
`void`
###### Defined in
src/emitter.ts:9
##### off()
> `static` **off**(`event`, `listener`): `void`
###### Parameters
**event**: `any`
**listener**: [`Listener`](emitter.md#listener)
###### Returns
`void`
###### Defined in
src/emitter.ts:14
##### on()
> `static` **on**(`event`, `listener`): () => `void`
###### Parameters
**event**: `any`
**listener**: [`Listener`](emitter.md#listener)
###### Returns
`Function`
###### Returns
`void`
###### Defined in
src/emitter.ts:19
##### once()
> `static` **once**(`event`, `listener`?): `Promise`\<`any`\>
###### Parameters
**event**: `any`
**listener?**: [`Listener`](emitter.md#listener)
###### Returns
`Promise`\<`any`\>
###### Defined in
src/emitter.ts:26
## Type Aliases
### Listener()
> **Listener**: (...`args`) => `any`
#### Parameters
• ...**args**: `any`[]
#### Returns
`any`
#### Defined in
src/emitter.ts:1
***
### TypedEvents
> **TypedEvents**: \{ \[k in string \| symbol\]: Listener \} & `object`
#### Type declaration
##### \*()
> **\***: (`event`, ...`args`) => `any`
###### Parameters
**event**: `string`
• ...**args**: `any`[]
###### Returns
`any`
#### Defined in
src/emitter.ts:2

3148
errors.md Normal file

File diff suppressed because it is too large Load Diff

145
files.md Normal file

@ -0,0 +1,145 @@
[@ztimson/utils](Home.md) / files
# files
## Functions
### download()
> **download**(`href`, `name`?): `void`
Download a file from a URL
#### Parameters
**href**: `any`
URL that will be downloaded
**name?**: `string`
Override download name
#### Returns
`void`
#### Defined in
src/files.ts:10
***
### downloadBlob()
> **downloadBlob**(`blob`, `name`): `void`
Download blob as a file
#### Parameters
**blob**: `Blob`
File as a blob
**name**: `string`
Name blob will be downloaded as
#### Returns
`void`
#### Defined in
src/files.ts:25
***
### fileBrowser()
> **fileBrowser**(`options`): `Promise`\<`File`[]\>
Open filebrowser & return selected file
#### Parameters
**options** = `{}`
accept - selectable mimetypes, multiple - Allow selecting more than 1 file
**options.accept?**: `string`
**options.multiple?**: `boolean`
#### Returns
`Promise`\<`File`[]\>
Array of selected files
#### Defined in
src/files.ts:37
***
### timestampFilename()
> **timestampFilename**(`name`?, `date`?): `string`
Create timestamp intended for filenames from a date
#### Parameters
**name?**: `string`
Name of file, `{{TIMESTAMP}}` will be replaced
**date?**: `string` \| `number` \| `Date` = `...`
Date to use for timestamp
#### Returns
`string`
Interpolated filename, or the raw timestamp if name was omitted
#### Defined in
src/files.ts:60
***
### uploadWithProgress()
> **uploadWithProgress**\<`T`\>(`options`): [`PromiseProgress`](promise-progress.md#promiseprogresst)\<`T`\>
Upload file to URL with progress callback using PromiseProgress
#### Type Parameters
• **T**
#### Parameters
• **options**
**options.files**: `File`[]
• **options.headers?**
**options.url**: `string`
**options.withCredentials?**: `boolean`
#### Returns
[`PromiseProgress`](promise-progress.md#promiseprogresst)\<`T`\>
Promise of request with `onProgress` callback
#### Defined in
src/files.ts:72

237
http.md Normal file

@ -0,0 +1,237 @@
[@ztimson/utils](Home.md) / http
# http
## Classes
### Http
#### Constructors
##### new Http()
> **new Http**(`defaults`): [`Http`](http.md#http)
###### Parameters
**defaults**: [`HttpDefaults`](http.md#httpdefaults) = `{}`
###### Returns
[`Http`](http.md#http)
###### Defined in
src/http.ts:35
#### Properties
##### headers
> **headers**: `object` = `{}`
###### Index Signature
\[`key`: `string`\]: `string` \| `null` \| `undefined`
###### Defined in
src/http.ts:32
##### url
> **url**: `null` \| `string`
###### Defined in
src/http.ts:33
##### headers
> `static` **headers**: `object` = `{}`
###### Index Signature
\[`key`: `string`\]: `string` \| `null` \| `undefined`
###### Defined in
src/http.ts:28
#### Methods
##### addInterceptor()
> **addInterceptor**(`fn`): () => `void`
###### Parameters
**fn**: [`HttpInterceptor`](http.md#httpinterceptor)
###### Returns
`Function`
###### Returns
`void`
###### Defined in
src/http.ts:49
##### request()
> **request**\<`T`\>(`opts`): [`PromiseProgress`](promise-progress.md#promiseprogresst)\<[`DecodedResponse`](http.md#decodedresponset)\<`T`\>\>
###### Type Parameters
• **T**
###### Parameters
**opts**: [`HttpRequestOptions`](http.md#httprequestoptions) = `{}`
###### Returns
[`PromiseProgress`](promise-progress.md#promiseprogresst)\<[`DecodedResponse`](http.md#decodedresponset)\<`T`\>\>
###### Defined in
src/http.ts:55
##### addInterceptor()
> `static` **addInterceptor**(`fn`): () => `void`
###### Parameters
**fn**: [`HttpInterceptor`](http.md#httpinterceptor)
###### Returns
`Function`
###### Returns
`void`
###### Defined in
src/http.ts:43
## Type Aliases
### DecodedResponse\<T\>
> **DecodedResponse**\<`T`\>: `Response` & `object`
#### Type declaration
##### data
> **data**: `T` \| `null`
#### Type Parameters
• **T**
#### Defined in
src/http.ts:4
***
### HttpDefaults
> **HttpDefaults**: `object`
#### Type declaration
##### headers?
> `optional` **headers**: `object`
###### Index Signature
\[`key`: `string` \| `symbol`\]: `string` \| `null` \| `undefined`
##### interceptors?
> `optional` **interceptors**: [`HttpInterceptor`](http.md#httpinterceptor)[]
##### url?
> `optional` **url**: `string`
#### Defined in
src/http.ts:19
***
### HttpInterceptor()
> **HttpInterceptor**: (`response`, `next`) => `void`
#### Parameters
**response**: `Response`
• **next**
#### Returns
`void`
#### Defined in
src/http.ts:6
***
### HttpRequestOptions
> **HttpRequestOptions**: `object`
#### Index Signature
\[`key`: `string`\]: `any`
#### Type declaration
##### body?
> `optional` **body**: `any`
##### decode?
> `optional` **decode**: `boolean`
##### fragment?
> `optional` **fragment**: `string`
##### headers?
> `optional` **headers**: `object`
###### Index Signature
\[`key`: `string` \| `symbol`\]: `string` \| `null` \| `undefined`
##### method?
> `optional` **method**: `"GET"` \| `"POST"` \| `"PATCH"` \| `"PUT"` \| `"DELETE"`
##### query?
> `optional` **query**: `object`[] \| `object`
##### url?
> `optional` **url**: `string`
#### Defined in
src/http.ts:8

309
index.md Normal file

@ -0,0 +1,309 @@
[@ztimson/utils](Home.md) / index
# index
## References
### addUnique
Re-exports [addUnique](array.md#addunique)
### arrayDiff
Re-exports [arrayDiff](array.md#arraydiff)
### ASet
Re-exports [ASet](aset.md#asett)
### BadGatewayError
Re-exports [BadGatewayError](errors.md#badgatewayerror)
### BadRequestError
Re-exports [BadRequestError](errors.md#badrequesterror)
### caseInsensitiveSort
Re-exports [caseInsensitiveSort](array.md#caseinsensitivesort)
### clean
Re-exports [clean](objects.md#clean)
### CliBackground
Re-exports [CliBackground](logger.md#clibackground)
### CliEffects
Re-exports [CliEffects](logger.md#clieffects)
### CliForeground
Re-exports [CliForeground](logger.md#cliforeground)
### CustomError
Re-exports [CustomError](errors.md#customerror)
### dec2Frac
Re-exports [dec2Frac](math.md#dec2frac)
### DecodedResponse
Re-exports [DecodedResponse](http.md#decodedresponset)
### deepCopy
Re-exports [deepCopy](objects.md#deepcopy)
### deepMerge
Re-exports [deepMerge](objects.md#deepmerge)
### dotNotation
Re-exports [dotNotation](objects.md#dotnotation)
### download
Re-exports [download](files.md#download)
### downloadBlob
Re-exports [downloadBlob](files.md#downloadblob)
### encodeQuery
Re-exports [encodeQuery](objects.md#encodequery)
### errorFromCode
Re-exports [errorFromCode](errors.md#errorfromcode)
### fileBrowser
Re-exports [fileBrowser](files.md#filebrowser)
### findByProp
Re-exports [findByProp](array.md#findbyprop)
### flattenArr
Re-exports [flattenArr](array.md#flattenarr)
### flattenObj
Re-exports [flattenObj](objects.md#flattenobj)
### ForbiddenError
Re-exports [ForbiddenError](errors.md#forbiddenerror)
### formatBytes
Re-exports [formatBytes](string.md#formatbytes)
### formatDate
Re-exports [formatDate](time.md#formatdate)
### formatPhoneNumber
Re-exports [formatPhoneNumber](string.md#formatphonenumber)
### formData
Re-exports [formData](objects.md#formdata)
### fracToDec
Re-exports [fracToDec](math.md#fractodec)
### GatewayTimeoutError
Re-exports [GatewayTimeoutError](errors.md#gatewaytimeouterror)
### gravatar
Re-exports [gravatar](misc.md#gravatar)
### Http
Re-exports [Http](http.md#http)
### HttpDefaults
Re-exports [HttpDefaults](http.md#httpdefaults)
### HttpInterceptor
Re-exports [HttpInterceptor](http.md#httpinterceptor)
### HttpRequestOptions
Re-exports [HttpRequestOptions](http.md#httprequestoptions)
### includes
Re-exports [includes](objects.md#includes)
### insertAt
Re-exports [insertAt](string.md#insertat)
### InternalServerError
Re-exports [InternalServerError](errors.md#internalservererror)
### isEqual
Re-exports [isEqual](objects.md#isequal)
### JSONAttemptParse
Re-exports [JSONAttemptParse](objects.md#jsonattemptparse)
### JSONSanitize
Re-exports [JSONSanitize](objects.md#jsonsanitize)
### Listener
Re-exports [Listener](emitter.md#listener)
### LOG\_LEVEL
Re-exports [LOG_LEVEL](logger.md#log_level)
### Logger
Re-exports [Logger](logger.md#logger)
### LoggerEvents
Re-exports [LoggerEvents](logger.md#loggerevents)
### makeArray
Re-exports [makeArray](array.md#makearray)
### makeUnique
Re-exports [makeUnique](array.md#makeunique)
### matchAll
Re-exports [matchAll](string.md#matchall)
### md5
Re-exports [md5](string.md#md5)
### MethodNotAllowedError
Re-exports [MethodNotAllowedError](errors.md#methodnotallowederror)
### mixin
Re-exports [mixin](objects.md#mixin)
### NotAcceptableError
Re-exports [NotAcceptableError](errors.md#notacceptableerror)
### NotFoundError
Re-exports [NotFoundError](errors.md#notfounderror)
### NotImplementedError
Re-exports [NotImplementedError](errors.md#notimplementederror)
### pad
Re-exports [pad](string.md#pad)
### ParsedUrl
Re-exports [ParsedUrl](string.md#parsedurl)
### parseUrl
Re-exports [parseUrl](string.md#parseurl)
### PaymentRequiredError
Re-exports [PaymentRequiredError](errors.md#paymentrequirederror)
### ProgressCallback
Re-exports [ProgressCallback](promise-progress.md#progresscallback)
### PromiseProgress
Re-exports [PromiseProgress](promise-progress.md#promiseprogresst)
### randomHex
Re-exports [randomHex](string.md#randomhex)
### randomString
Re-exports [randomString](string.md#randomstring)
### randomStringBuilder
Re-exports [randomStringBuilder](string.md#randomstringbuilder)
### ServiceUnavailableError
Re-exports [ServiceUnavailableError](errors.md#serviceunavailableerror)
### sleep
Re-exports [sleep](time.md#sleep)
### sleepUntil
Re-exports [sleepUntil](time.md#sleepuntil)
### sortByProp
Re-exports [sortByProp](array.md#sortbyprop)
### timestampFilename
Re-exports [timestampFilename](files.md#timestampfilename)
### timeUntil
Re-exports [timeUntil](time.md#timeuntil)
### tyoeKeys
Re-exports [tyoeKeys](types.md#tyoekeys)
### TypedEmitter
Re-exports [TypedEmitter](emitter.md#typedemittert)
### TypedEvents
Re-exports [TypedEvents](emitter.md#typedevents)
### UnauthorizedError
Re-exports [UnauthorizedError](errors.md#unauthorizederror)
### uploadWithProgress
Re-exports [uploadWithProgress](files.md#uploadwithprogress)
### validateEmail
Re-exports [validateEmail](string.md#validateemail)

615
logger.md Normal file

@ -0,0 +1,615 @@
[@ztimson/utils](Home.md) / logger
# logger
## Enumerations
### LOG\_LEVEL
#### Enumeration Members
##### DEBUG
> **DEBUG**: `4`
###### Defined in
src/logger.ts:49
##### ERROR
> **ERROR**: `0`
###### Defined in
src/logger.ts:45
##### INFO
> **INFO**: `2`
###### Defined in
src/logger.ts:47
##### LOG
> **LOG**: `3`
###### Defined in
src/logger.ts:48
##### WARN
> **WARN**: `1`
###### Defined in
src/logger.ts:46
## Classes
### Logger
#### Extends
- [`TypedEmitter`](emitter.md#typedemittert)\<[`LoggerEvents`](logger.md#loggerevents)\>
#### Constructors
##### new Logger()
> **new Logger**(`namespace`?): [`Logger`](logger.md#logger)
###### Parameters
**namespace?**: `string`
###### Returns
[`Logger`](logger.md#logger)
###### Overrides
[`TypedEmitter`](emitter.md#typedemittert).[`constructor`](emitter.md#constructors)
###### Defined in
src/logger.ts:63
#### Properties
##### namespace?
> `readonly` `optional` **namespace**: `string`
###### Defined in
src/logger.ts:63
##### LOG\_LEVEL
> `static` **LOG\_LEVEL**: [`LOG_LEVEL`](logger.md#log_level) = `LOG_LEVEL.DEBUG`
###### Defined in
src/logger.ts:61
#### Methods
##### debug()
> **debug**(...`args`): `void`
###### Parameters
• ...**args**: `string`[]
###### Returns
`void`
###### Defined in
src/logger.ts:81
##### emit()
> **emit**\<`K`\>(`event`, ...`args`): `void`
###### Type Parameters
**K** *extends* `string` \| `symbol`
###### Parameters
**event**: `K`
• ...**args**: `Parameters`\<[`LoggerEvents`](logger.md#loggerevents)\[`K`\]\>
###### Returns
`void`
###### Inherited from
[`TypedEmitter`](emitter.md#typedemittert).[`emit`](emitter.md#emit)
###### Defined in
src/emitter.ts:36
##### error()
> **error**(...`args`): `void`
###### Parameters
• ...**args**: `string`[]
###### Returns
`void`
###### Defined in
src/logger.ts:109
##### info()
> **info**(...`args`): `void`
###### Parameters
• ...**args**: `string`[]
###### Returns
`void`
###### Defined in
src/logger.ts:95
##### log()
> **log**(...`args`): `void`
###### Parameters
• ...**args**: `string`[]
###### Returns
`void`
###### Defined in
src/logger.ts:88
##### off()
> **off**\<`K`\>(`event`, `listener`): `void`
###### Type Parameters
**K** *extends* `string` \| `symbol` = `string`
###### Parameters
**event**: `K`
**listener**: [`LoggerEvents`](logger.md#loggerevents)\[`K`\]
###### Returns
`void`
###### Inherited from
[`TypedEmitter`](emitter.md#typedemittert).[`off`](emitter.md#off)
###### Defined in
src/emitter.ts:41
##### on()
> **on**\<`K`\>(`event`, `listener`): () => `void`
###### Type Parameters
**K** *extends* `string` \| `symbol` = `string`
###### Parameters
**event**: `K`
**listener**: [`LoggerEvents`](logger.md#loggerevents)\[`K`\]
###### Returns
`Function`
###### Returns
`void`
###### Inherited from
[`TypedEmitter`](emitter.md#typedemittert).[`on`](emitter.md#on)
###### Defined in
src/emitter.ts:45
##### once()
> **once**\<`K`\>(`event`, `listener`?): `Promise`\<`any`\>
###### Type Parameters
**K** *extends* `string` \| `symbol` = `string`
###### Parameters
**event**: `K`
**listener?**: [`LoggerEvents`](logger.md#loggerevents)\[`K`\]
###### Returns
`Promise`\<`any`\>
###### Inherited from
[`TypedEmitter`](emitter.md#typedemittert).[`once`](emitter.md#once)
###### Defined in
src/emitter.ts:51
##### warn()
> **warn**(...`args`): `void`
###### Parameters
• ...**args**: `string`[]
###### Returns
`void`
###### Defined in
src/logger.ts:102
##### emit()
> `static` **emit**(`event`, ...`args`): `void`
###### Parameters
**event**: `any`
• ...**args**: `any`[]
###### Returns
`void`
###### Inherited from
[`TypedEmitter`](emitter.md#typedemittert).[`emit`](emitter.md#emit-1)
###### Defined in
src/emitter.ts:9
##### off()
> `static` **off**(`event`, `listener`): `void`
###### Parameters
**event**: `any`
**listener**: [`Listener`](emitter.md#listener)
###### Returns
`void`
###### Inherited from
[`TypedEmitter`](emitter.md#typedemittert).[`off`](emitter.md#off-1)
###### Defined in
src/emitter.ts:14
##### on()
> `static` **on**(`event`, `listener`): () => `void`
###### Parameters
**event**: `any`
**listener**: [`Listener`](emitter.md#listener)
###### Returns
`Function`
###### Returns
`void`
###### Inherited from
[`TypedEmitter`](emitter.md#typedemittert).[`on`](emitter.md#on-1)
###### Defined in
src/emitter.ts:19
##### once()
> `static` **once**(`event`, `listener`?): `Promise`\<`any`\>
###### Parameters
**event**: `any`
**listener?**: [`Listener`](emitter.md#listener)
###### Returns
`Promise`\<`any`\>
###### Inherited from
[`TypedEmitter`](emitter.md#typedemittert).[`once`](emitter.md#once-1)
###### Defined in
src/emitter.ts:26
## Type Aliases
### LoggerEvents
> **LoggerEvents**: [`TypedEvents`](emitter.md#typedevents) & `object`
#### Type declaration
##### DEBUG()
> **DEBUG**: (...`args`) => `any`
###### Parameters
• ...**args**: `any`[]
###### Returns
`any`
##### ERROR()
> **ERROR**: (...`args`) => `any`
###### Parameters
• ...**args**: `any`[]
###### Returns
`any`
##### INFO()
> **INFO**: (...`args`) => `any`
###### Parameters
• ...**args**: `any`[]
###### Returns
`any`
##### LOG()
> **LOG**: (...`args`) => `any`
###### Parameters
• ...**args**: `any`[]
###### Returns
`any`
##### WARN()
> **WARN**: (...`args`) => `any`
###### Parameters
• ...**args**: `any`[]
###### Returns
`any`
#### Defined in
src/logger.ts:52
## Variables
### CliBackground
> `const` **CliBackground**: `object`
#### Type declaration
##### BLACK
> **BLACK**: `string` = `"\x1b[40m"`
##### BLUE
> **BLUE**: `string` = `"\x1b[44m"`
##### CYAN
> **CYAN**: `string` = `"\x1b[46m"`
##### GREEN
> **GREEN**: `string` = `"\x1b[42m"`
##### GREY
> **GREY**: `string` = `"\x1b[100m"`
##### MAGENTA
> **MAGENTA**: `string` = `"\x1b[45m"`
##### RED
> **RED**: `string` = `"\x1b[41m"`
##### WHITE
> **WHITE**: `string` = `"\x1b[47m"`
##### YELLOW
> **YELLOW**: `string` = `"\x1b[43m"`
#### Defined in
src/logger.ts:32
***
### CliEffects
> `const` **CliEffects**: `object`
#### Type declaration
##### BLINK
> **BLINK**: `string` = `"\x1b[5m"`
##### BRIGHT
> **BRIGHT**: `string` = `"\x1b[1m"`
##### CLEAR
> **CLEAR**: `string` = `"\x1b[0m"`
##### DIM
> **DIM**: `string` = `"\x1b[2m"`
##### HIDDEN
> **HIDDEN**: `string` = `"\x1b[8m"`
##### REVERSE
> **REVERSE**: `string` = `"\x1b[7m"`
##### UNDERSCORE
> **UNDERSCORE**: `string` = `"\x1b[4m"`
#### Defined in
src/logger.ts:3
***
### CliForeground
> `const` **CliForeground**: `object`
#### Type declaration
##### BLACK
> **BLACK**: `string` = `'\x1b[30m'`
##### BLUE
> **BLUE**: `string` = `'\x1b[34m'`
##### CYAN
> **CYAN**: `string` = `'\x1b[36m'`
##### GREEN
> **GREEN**: `string` = `'\x1b[32m'`
##### GREY
> **GREY**: `string` = `'\x1b[90m'`
##### LIGHT\_BLUE
> **LIGHT\_BLUE**: `string` = `'\x1b[94m'`
##### LIGHT\_CYAN
> **LIGHT\_CYAN**: `string` = `'\x1b[96m'`
##### LIGHT\_GREEN
> **LIGHT\_GREEN**: `string` = `'\x1b[92m'`
##### LIGHT\_GREY
> **LIGHT\_GREY**: `string` = `'\x1b[37m'`
##### LIGHT\_MAGENTA
> **LIGHT\_MAGENTA**: `string` = `'\x1b[95m'`
##### LIGHT\_RED
> **LIGHT\_RED**: `string` = `'\x1b[91m'`
##### LIGHT\_YELLOW
> **LIGHT\_YELLOW**: `string` = `'\x1b[93m'`
##### MAGENTA
> **MAGENTA**: `string` = `'\x1b[35m'`
##### RED
> **RED**: `string` = `'\x1b[31m'`
##### WHITE
> **WHITE**: `string` = `'\x1b[97m'`
##### YELLOW
> **YELLOW**: `string` = `'\x1b[33m'`
#### Defined in
src/logger.ts:13

63
math.md Normal file

@ -0,0 +1,63 @@
[@ztimson/utils](Home.md) / math
# math
## Functions
### dec2Frac()
> **dec2Frac**(`num`): `string`
Convert decimal number to fraction
#### Parameters
**num**: `number`
Number to convert
#### Returns
`string`
Fraction with remainder
#### Example
```js
dec2Frac(1.25) // Outputs: "1 1/4"
```
#### Defined in
src/math.ts:12
***
### fracToDec()
> **fracToDec**(`frac`): `number`
Convert fraction to decimal number
#### Parameters
**frac**: `string`
Fraction to convert
#### Returns
`number`
Faction as a decimal
#### Example
```js
fracToDec('1 1/4') // Outputs: 1.25
```
#### Defined in
src/math.ts:40

31
misc.md Normal file

@ -0,0 +1,31 @@
[@ztimson/utils](Home.md) / misc
# misc
## Functions
### gravatar()
> **gravatar**(`email`, `def`): `string`
Get profile image from Gravatar
#### Parameters
**email**: `string`
Account email address
**def**: `string` = `'mp'`
Default image, can be a link or '404', see: https://docs.gravatar.com/general/images/
#### Returns
`string`
Gravatar URL
#### Defined in
src/misc.ts:10

422
objects.md Normal file

@ -0,0 +1,422 @@
[@ztimson/utils](Home.md) / objects
# objects
## Functions
### clean()
> **clean**\<`T`\>(`obj`, `undefinedOnly`): `Partial`\<`T`\>
Removes any null values from an object in-place
#### Type Parameters
• **T**
#### Parameters
**obj**: `T`
Object reference that will be cleaned
**undefinedOnly**: `boolean` = `false`
Ignore null values
#### Returns
`Partial`\<`T`\>
Cleaned object
#### Example
```ts
let test = {a: 0, b: false, c: null, d: 'abc'}
console.log(clean(test)); // Output: {a: 0, b: false, d: 'abc'}
```
#### Defined in
src/objects.ts:14
***
### ~~deepCopy()~~
> **deepCopy**\<`T`\>(`value`): `T`
Create a deep copy of an object (vs. a shallow copy of references)
Should be replaced by `structuredClone` once released.
#### Type Parameters
• **T**
#### Parameters
**value**: `T`
Object to copy
#### Returns
`T`
Type
#### Deprecated
Please use `structuredClone`
#### Defined in
src/objects.ts:34
***
### deepMerge()
> **deepMerge**\<`T`\>(`target`, ...`sources`): `T`
Merge any number of objects into the target
#### Type Parameters
• **T**
#### Parameters
**target**: `any`
Destination of all properties
• ...**sources**: `any`[]
Objects that will copied into target
#### Returns
`T`
The des
#### Defined in
src/objects.ts:45
***
### dotNotation()
#### dotNotation(obj, prop, set)
> **dotNotation**\<`T`\>(`obj`, `prop`, `set`): `T`
Get/set a property of an object using dot notation
##### Type Parameters
• **T**
##### Parameters
**obj**: `any`
source object to search
**prop**: `string`
property name (Dot notation & indexing allowed)
**set**: `T`
Set object property to value, omit to fetch value instead
##### Returns
`T`
property value
##### Example
```ts
// Get a value
const name = dotNotation<string>(person, 'firstName');
const familyCarMake = dotNotation(family, 'cars[0].make');
// Set a value
dotNotation(family, 'cars[0].make', 'toyota');
```
##### Defined in
src/objects.ts:77
#### dotNotation(obj, prop)
> **dotNotation**\<`T`\>(`obj`, `prop`): `T` \| `undefined`
##### Type Parameters
• **T**
##### Parameters
**obj**: `any`
**prop**: `string`
##### Returns
`T` \| `undefined`
##### Defined in
src/objects.ts:78
***
### encodeQuery()
> **encodeQuery**(`data`): `string`
Convert object into URL encoded query string
#### Parameters
**data**: `any`
data to convert
#### Returns
`string`
- Encoded form data
#### Example
```js
const query = encodeQuery({page: 1, size: 20});
console.log(query); // Output: "page=1&size=20"
```
#### Defined in
src/objects.ts:107
***
### flattenObj()
> **flattenObj**(`obj`, `parent`?, `result`?): `any`
Recursively flatten a nested object, while maintaining key structure
#### Parameters
**obj**: `any`
Object to flatten
**parent?**: `any`
Recursively check if key is a parent key or not
**result?**: `any` = `{}`
Result
#### Returns
`any`
- Flattened object
#### Example
```ts
const car = {honda: {model: "Civic"}};
console.log(flattenObj(car)); //Output {honda.model: "Civic"}
```
#### Defined in
src/objects.ts:128
***
### formData()
> **formData**(`target`): `FormData`
Convert object to FormData
#### Parameters
**target**: `any`
Object to convert
#### Returns
`FormData`
- Form object
#### Defined in
src/objects.ts:148
***
### includes()
> **includes**(`target`, `values`, `allowMissing`): `boolean`
Check that an object has the following values
#### Parameters
**target**: `any`
Object to search
**values**: `any`
Criteria to check against
**allowMissing**: `boolean` = `false`
Only check the keys that are available on the target
#### Returns
`boolean`
Does target include all the values
#### Example
```ts
const test = {a: 2, b: 2};
includes(test, {a: 1}); // true
includes(test, {b: 1, c: 3}); // false
```
#### Defined in
src/objects.ts:169
***
### isEqual()
> **isEqual**(`a`, `b`): `boolean`
Deep check if two objects are equal
#### Parameters
**a**: `any`
first item to compare
**b**: `any`
second item to compare
#### Returns
`boolean`
True if they match
#### Defined in
src/objects.ts:188
***
### JSONAttemptParse()
> **JSONAttemptParse**\<`T`\>(`json`): `T` \| `string`
Parse JSON but return the original string if it fails
#### Type Parameters
• **T**
#### Parameters
**json**: `string`
JSON string to parse
#### Returns
`T` \| `string`
Object if successful, original string otherwise
#### Defined in
src/objects.ts:222
***
### JSONSanitize()
> **JSONSanitize**(`obj`, `space`?): `string`
Convert an object to a JSON string avoiding any circular references.
#### Parameters
**obj**: `any`
Object to convert to JSON
**space?**: `number`
Format the JSON with spaces
#### Returns
`string`
JSON string
#### Defined in
src/objects.ts:234
***
### mixin()
> **mixin**(`target`, `constructors`): `void`
Experimental: Combine multiple object prototypes into one
#### Parameters
**target**: `any`
Object that will have prototypes added
**constructors**: `any`[]
Additionally prototypes that should be merged into target
#### Returns
`void`
#### Defined in
src/objects.ts:203

600
promise-progress.md Normal file

@ -0,0 +1,600 @@
[@ztimson/utils](Home.md) / promise-progress
# promise-progress
## Classes
### PromiseProgress\<T\>
A promise that fires the `onProgress` callback on incremental progress
#### Example
```js
const promise = new Promise((resolve, reject, progress) => {
const max = 10;
for(let i = 0; i < max; i++) progress(i / max);
resolve(1);
});
console.log(promise.progress);
promise.onProgress(console.log)
.then(console.log)
.catch(console.error)
.finally(...);
```
#### Extends
- `Promise`\<`T`\>
#### Type Parameters
• **T**
#### Constructors
##### new PromiseProgress()
> **new PromiseProgress**\<`T`\>(`executor`): [`PromiseProgress`](promise-progress.md#promiseprogresst)\<`T`\>
###### Parameters
• **executor**
###### Returns
[`PromiseProgress`](promise-progress.md#promiseprogresst)\<`T`\>
###### Overrides
`Promise<T>.constructor`
###### Defined in
src/promise-progress.ts:34
#### Properties
##### \[toStringTag\]
> `readonly` **\[toStringTag\]**: `string`
###### Inherited from
`Promise.[toStringTag]`
###### Defined in
node\_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts:176
##### \[species\]
> `readonly` `static` **\[species\]**: `PromiseConstructor`
###### Inherited from
`Promise.[species]`
###### Defined in
node\_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts:180
#### Accessors
##### progress
> `get` **progress**(): `number`
> `set` **progress**(`p`): `void`
###### Parameters
**p**: `number`
###### Returns
`number`
###### Defined in
src/promise-progress.ts:27
#### Methods
##### catch()
> **catch**(`rej`?): [`PromiseProgress`](promise-progress.md#promiseprogresst)\<`any`\>
Attaches a callback for only the rejection of the Promise.
###### Parameters
• **rej?**
###### Returns
[`PromiseProgress`](promise-progress.md#promiseprogresst)\<`any`\>
A Promise for the completion of the callback.
###### Overrides
`Promise.catch`
###### Defined in
src/promise-progress.ts:65
##### finally()
> **finally**(`res`?): [`PromiseProgress`](promise-progress.md#promiseprogresst)\<`any`\>
Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
resolved value cannot be modified from the callback.
###### Parameters
• **res?**
###### Returns
[`PromiseProgress`](promise-progress.md#promiseprogresst)\<`any`\>
A Promise for the completion of the callback.
###### Overrides
`Promise.finally`
###### Defined in
src/promise-progress.ts:69
##### onProgress()
> **onProgress**(`callback`): [`PromiseProgress`](promise-progress.md#promiseprogresst)\<`T`\>
###### Parameters
**callback**: [`ProgressCallback`](promise-progress.md#progresscallback)
###### Returns
[`PromiseProgress`](promise-progress.md#promiseprogresst)\<`T`\>
###### Defined in
src/promise-progress.ts:55
##### then()
> **then**(`res`?, `rej`?): [`PromiseProgress`](promise-progress.md#promiseprogresst)\<`any`\>
Attaches callbacks for the resolution and/or rejection of the Promise.
###### Parameters
• **res?**
• **rej?**
###### Returns
[`PromiseProgress`](promise-progress.md#promiseprogresst)\<`any`\>
A Promise for the completion of which ever callback is executed.
###### Overrides
`Promise.then`
###### Defined in
src/promise-progress.ts:60
##### all()
###### all(values)
> `static` **all**\<`T`\>(`values`): `Promise`\<`Awaited`\<`T`\>[]\>
Creates a Promise that is resolved with an array of results when all of the provided Promises
resolve, or rejected when any Promise is rejected.
###### Type Parameters
• **T**
###### Parameters
**values**: `Iterable`\<`T` \| `PromiseLike`\<`T`\>\>
An iterable of Promises.
###### Returns
`Promise`\<`Awaited`\<`T`\>[]\>
A new Promise.
###### Inherited from
`Promise.all`
###### Defined in
node\_modules/typescript/lib/lib.es2015.iterable.d.ts:225
###### all(values)
> `static` **all**\<`T`\>(`values`): `Promise`\<\{ -readonly \[P in string \| number \| symbol\]: Awaited\<T\[P\<P\>\]\> \}\>
Creates a Promise that is resolved with an array of results when all of the provided Promises
resolve, or rejected when any Promise is rejected.
###### Type Parameters
**T** *extends* readonly `unknown`[] \| []
###### Parameters
**values**: `T`
An array of Promises.
###### Returns
`Promise`\<\{ -readonly \[P in string \| number \| symbol\]: Awaited\<T\[P\<P\>\]\> \}\>
A new Promise.
###### Inherited from
`Promise.all`
###### Defined in
node\_modules/typescript/lib/lib.es2015.promise.d.ts:39
##### allSettled()
###### allSettled(values)
> `static` **allSettled**\<`T`\>(`values`): `Promise`\<\{ -readonly \[P in string \| number \| symbol\]: PromiseSettledResult\<Awaited\<T\[P\<P\>\]\>\> \}\>
Creates a Promise that is resolved with an array of results when all
of the provided Promises resolve or reject.
###### Type Parameters
**T** *extends* readonly `unknown`[] \| []
###### Parameters
**values**: `T`
An array of Promises.
###### Returns
`Promise`\<\{ -readonly \[P in string \| number \| symbol\]: PromiseSettledResult\<Awaited\<T\[P\<P\>\]\>\> \}\>
A new Promise.
###### Inherited from
`Promise.allSettled`
###### Defined in
node\_modules/typescript/lib/lib.es2020.promise.d.ts:38
###### allSettled(values)
> `static` **allSettled**\<`T`\>(`values`): `Promise`\<`PromiseSettledResult`\<`Awaited`\<`T`\>\>[]\>
Creates a Promise that is resolved with an array of results when all
of the provided Promises resolve or reject.
###### Type Parameters
• **T**
###### Parameters
**values**: `Iterable`\<`T` \| `PromiseLike`\<`T`\>\>
An array of Promises.
###### Returns
`Promise`\<`PromiseSettledResult`\<`Awaited`\<`T`\>\>[]\>
A new Promise.
###### Inherited from
`Promise.allSettled`
###### Defined in
node\_modules/typescript/lib/lib.es2020.promise.d.ts:46
##### any()
###### any(values)
> `static` **any**\<`T`\>(`values`): `Promise`\<`Awaited`\<`T`\[`number`\]\>\>
The any function returns a promise that is fulfilled by the first given promise to be fulfilled, or rejected with an AggregateError containing an array of rejection reasons if all of the given promises are rejected. It resolves all elements of the passed iterable to promises as it runs this algorithm.
###### Type Parameters
**T** *extends* readonly `unknown`[] \| []
###### Parameters
**values**: `T`
An array or iterable of Promises.
###### Returns
`Promise`\<`Awaited`\<`T`\[`number`\]\>\>
A new Promise.
###### Inherited from
`Promise.any`
###### Defined in
node\_modules/typescript/lib/lib.es2021.promise.d.ts:40
###### any(values)
> `static` **any**\<`T`\>(`values`): `Promise`\<`Awaited`\<`T`\>\>
The any function returns a promise that is fulfilled by the first given promise to be fulfilled, or rejected with an AggregateError containing an array of rejection reasons if all of the given promises are rejected. It resolves all elements of the passed iterable to promises as it runs this algorithm.
###### Type Parameters
• **T**
###### Parameters
**values**: `Iterable`\<`T` \| `PromiseLike`\<`T`\>\>
An array or iterable of Promises.
###### Returns
`Promise`\<`Awaited`\<`T`\>\>
A new Promise.
###### Inherited from
`Promise.any`
###### Defined in
node\_modules/typescript/lib/lib.es2021.promise.d.ts:47
##### from()
> `static` **from**\<`T`\>(`promise`): [`PromiseProgress`](promise-progress.md#promiseprogresst)\<`T`\>
###### Type Parameters
• **T**
###### Parameters
**promise**: `Promise`\<`T`\>
###### Returns
[`PromiseProgress`](promise-progress.md#promiseprogresst)\<`T`\>
###### Defined in
src/promise-progress.ts:42
##### race()
###### race(values)
> `static` **race**\<`T`\>(`values`): `Promise`\<`Awaited`\<`T`\>\>
Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
or rejected.
###### Type Parameters
• **T**
###### Parameters
**values**: `Iterable`\<`T` \| `PromiseLike`\<`T`\>\>
An iterable of Promises.
###### Returns
`Promise`\<`Awaited`\<`T`\>\>
A new Promise.
###### Inherited from
`Promise.race`
###### Defined in
node\_modules/typescript/lib/lib.es2015.iterable.d.ts:233
###### race(values)
> `static` **race**\<`T`\>(`values`): `Promise`\<`Awaited`\<`T`\[`number`\]\>\>
Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
or rejected.
###### Type Parameters
**T** *extends* readonly `unknown`[] \| []
###### Parameters
**values**: `T`
An array of Promises.
###### Returns
`Promise`\<`Awaited`\<`T`\[`number`\]\>\>
A new Promise.
###### Inherited from
`Promise.race`
###### Defined in
node\_modules/typescript/lib/lib.es2015.promise.d.ts:50
##### reject()
> `static` **reject**\<`T`\>(`reason`?): `Promise`\<`T`\>
Creates a new rejected promise for the provided reason.
###### Type Parameters
**T** = `never`
###### Parameters
**reason?**: `any`
The reason the promise was rejected.
###### Returns
`Promise`\<`T`\>
A new rejected Promise.
###### Inherited from
`Promise.reject`
###### Defined in
node\_modules/typescript/lib/lib.es2015.promise.d.ts:60
##### resolve()
###### resolve()
> `static` **resolve**(): `Promise`\<`void`\>
Creates a new resolved promise.
###### Returns
`Promise`\<`void`\>
A resolved promise.
###### Inherited from
`Promise.resolve`
###### Defined in
node\_modules/typescript/lib/lib.es2015.promise.d.ts:66
###### resolve(value)
> `static` **resolve**\<`T`\>(`value`): `Promise`\<`Awaited`\<`T`\>\>
Creates a new resolved promise for the provided value.
###### Type Parameters
• **T**
###### Parameters
**value**: `T`
A promise.
###### Returns
`Promise`\<`Awaited`\<`T`\>\>
A promise whose internal state matches the provided promise.
###### Inherited from
`Promise.resolve`
###### Defined in
node\_modules/typescript/lib/lib.es2015.promise.d.ts:72
###### resolve(value)
> `static` **resolve**\<`T`\>(`value`): `Promise`\<`Awaited`\<`T`\>\>
Creates a new resolved promise for the provided value.
###### Type Parameters
• **T**
###### Parameters
**value**: `T` \| `PromiseLike`\<`T`\>
A promise.
###### Returns
`Promise`\<`Awaited`\<`T`\>\>
A promise whose internal state matches the provided promise.
###### Inherited from
`Promise.resolve`
###### Defined in
node\_modules/typescript/lib/lib.es2015.promise.d.ts:78
## Type Aliases
### ProgressCallback()
> **ProgressCallback**: (`progress`) => `any`
#### Parameters
**progress**: `number`
#### Returns
`any`
#### Defined in
src/promise-progress.ts:1

396
string.md Normal file

@ -0,0 +1,396 @@
[@ztimson/utils](Home.md) / string
# string
## Type Aliases
### ParsedUrl
> **ParsedUrl**: `object`
Parts of a URL
#### Type declaration
##### domain
> **domain**: `string`
##### fragment?
> `optional` **fragment**: `string`
##### host
> **host**: `string`
##### path?
> `optional` **path**: `string`
##### port?
> `optional` **port**: `number`
##### protocol?
> `optional` **protocol**: `string`
##### query?
> `optional` **query**: `object`
###### Index Signature
\[`name`: `string`\]: `string`
##### subdomain?
> `optional` **subdomain**: `string`
#### Defined in
src/string.ts:180
## Functions
### formatBytes()
> **formatBytes**(`bytes`, `decimals`): `string`
Convert number of bytes into a human-readable size
#### Parameters
**bytes**: `number`
Number of bytes
**decimals**: `number` = `2`
Decimal places to preserve
#### Returns
`string`
Formated size
#### Defined in
src/string.ts:38
***
### formatPhoneNumber()
> **formatPhoneNumber**(`number`): `string`
Extract numbers from a string & create a formated phone number: +1 (123) 456-7890
#### Parameters
**number**: `string`
String that will be parsed for numbers
#### Returns
`string`
Formated phone number
#### Defined in
src/string.ts:52
***
### insertAt()
> **insertAt**(`target`, `str`, `index`): `String`
Insert a string into another string at a given position
#### Parameters
**target**: `string`
Parent string you want to modify
**str**: `string`
Value that will be injected to parent
**index**: `number`
Position to inject string at
#### Returns
`String`
- New string
#### Example
```js
console.log(insertAt('Hello world!', ' glorious', 5);
// Output: Hello glorious world!
```
#### Defined in
src/string.ts:72
***
### matchAll()
> **matchAll**(`value`, `regex`): `RegExpExecArray`[]
Find all substrings that match a given pattern.
Roughly based on `String.prototype.matchAll`.
#### Parameters
**value**: `string`
String to search.
**regex**: `string` \| `RegExp`
Regular expression to match.
#### Returns
`RegExpExecArray`[]
Found matches.
#### Defined in
src/string.ts:160
***
### md5()
> **md5**(`d`): `string`
Create MD5 hash using native javascript
#### Parameters
**d**: `string`
String to hash
#### Returns
`string`
Hashed string
#### Defined in
src/string.ts:226
***
### ~~pad()~~
> **pad**(`text`, `length`, `char`, `start`): `any`
Add padding to string
#### Parameters
**text**: `any`
Text that will be padded
**length**: `number`
Target length
**char**: `string` = `' '`
Character to use as padding, defaults to space
**start**: `boolean` = `true`
Will pad start of text if true, or the end if false
#### Returns
`any`
Padded string
#### Example
```js
const now = new Date();
const padded = now.getHours() + ':' + pad(now.getMinutes(), 2, '0');
console.log(padded); // Output: "2:05"
```
#### Deprecated
Please use `String.padStart` & `String.padEnd`
#### Defined in
src/string.ts:93
***
### parseUrl()
> **parseUrl**(`url`): [`ParsedUrl`](string.md#parsedurl)
Break a URL string into its parts for easy parsing
#### Parameters
**url**: `string`
URL string that will be parsed
#### Returns
[`ParsedUrl`](string.md#parsedurl)
Parts of URL
#### Defined in
src/string.ts:197
***
### randomHex()
> **randomHex**(`length`): `string`
Generate a random hexadecimal value
#### Parameters
**length**: `number`
Number of hexadecimal place values
#### Returns
`string`
Hexadecimal number as a string
#### Defined in
src/string.ts:27
***
### randomString()
> **randomString**(`length`, `pool`): `string`
Generate a string of random characters.
#### Parameters
**length**: `number`
length of generated string
**pool**: `string` = `CHAR_LIST`
character pool to generate string from
#### Returns
`string`
generated string
#### Example
```ts
const random = randomString();
const randomByte = randomString(8, "01")
```
#### Defined in
src/string.ts:111
***
### randomStringBuilder()
> **randomStringBuilder**(`length`, `letters`, `numbers`, `symbols`): `string`
Generate a random string with fine control over letters, numbers & symbols
#### Parameters
**length**: `number`
length of generated string
**letters**: `boolean` = `false`
Add letters to pool
**numbers**: `boolean` = `false`
Add numbers to pool
**symbols**: `boolean` = `false`
Add symbols to pool
#### Returns
`string`
generated string
#### Example
```ts
const randomLetter = randomString(1, true);
const randomChar = randomString(1, true, true, true);
```
#### Defined in
src/string.ts:133
***
### validateEmail()
> **validateEmail**(`email`): `boolean`
Check if email is valid
#### Parameters
**email**: `string`
Target
#### Returns
`boolean`
- Follows format
#### Defined in
src/string.ts:247

117
time.md Normal file

@ -0,0 +1,117 @@
[@ztimson/utils](Home.md) / time
# time
## Functions
### formatDate()
> **formatDate**(`date`): `string`
Return date formated highest to lowest: YYYY-MM-DD H:mm AM
#### Parameters
**date**: `string` \| `number` \| `Date`
Date or timestamp to convert to string
#### Returns
`string`
Formated date
#### Defined in
src/time.ts:7
***
### sleep()
> **sleep**(`ms`): `Promise`\<`void`\>
Use in conjunction with `await` to pause an async script
#### Parameters
**ms**: `number`
Time to pause for in milliseconds
#### Returns
`Promise`\<`void`\>
- Resolves promise when it's time to resume
#### Example
```js
await sleep(1000) // Pause for 1 second
```
#### Defined in
src/time.ts:28
***
### sleepUntil()
> **sleepUntil**(`fn`, `checkInterval`): `Promise`\<`void`\>
Sleep while function returns true
#### Parameters
• **fn**
Return true to continue
**checkInterval**: `number` = `100`
Run function ever x milliseconds
#### Returns
`Promise`\<`void`\>
Callback when sleep is over
#### Example
```js
let loading = true;
setTimeout(() => wait = false, 1000);
await sleepUntil(() => loading); // Won't continue until loading flag is false
```
#### Defined in
src/time.ts:46
***
### timeUntil()
> **timeUntil**(`date`): `number`
Calculate the number of milliseconds until date/time
#### Parameters
**date**: `number` \| `Date`
Target
#### Returns
`number`
- Number of milliseconds until target
#### Defined in
src/time.ts:56

38
types.md Normal file

@ -0,0 +1,38 @@
[@ztimson/utils](Home.md) / types
# types
## Functions
### tyoeKeys()
> **tyoeKeys**\<`T`\>(): keyof `T`[]
Return keys on a type as an array of strings
#### Type Parameters
**T** *extends* `object`
#### Returns
keyof `T`[]
Available keys
#### Example
```ts
type Person = {
firstName: string;
lastName: string;
age: number;
}
const keys = typeKeys<Person>();
console.log(keys); // Output: ["firstName", "lastName", "age"]
```
#### Defined in
src/types.ts:18