npm package: @hexxag0nal/utils
Description: A handy collection of utilities.
Author: hexxag0n
Latest version: 0.6.0

# Utils

A handy collection of utilities.

# Module: "utils"

## Index

### Classes

* [Utils](#class-utils)

### Type aliases

* [Constructable](#constructable)
* [Percentage](#percentage)

## Type aliases

###  Constructable

Ƭ **Constructable**: *object*

Defined in utils.ts:303

Basically telling that an object can be constructed via the 'new' keyword

#### Type declaration:

___

###  Percentage

Ƭ **Percentage**: *number*

Defined in utils.ts:296

Basically telling that the number is expected to resemble some kind of percentage

# Class: Utils

## Hierarchy

* **Utils**

## Index

### Methods

* [areSimilarArrays](#static-aresimilararrays)
* [binaryImageDataToDataUrl](#static-binaryimagedatatodataurl)
* [binaryToImageData](#static-binarytoimagedata)
* [isInArray](#static-isinarray)
* [isNullOrUndefined](#static-isnullorundefined)
* [readBlobAsDataUrl](#static-readblobasdataurl)
* [readFileAsDataUrl](#static-readfileasdataurl)
* [safeUnsubscribe](#static-safeunsubscribe)
* [saveAs](#static-saveas)
* [setOnlyOnce](#static-setonlyonce)
* [thisOrNull](#static-thisornull)

## Methods

### `Static` areSimilarArrays

▸ **areSimilarArrays**‹**T**›(`array1`: ArrayLike‹T›, `array2`: ArrayLike‹T›, ...`moreArrays`: Array‹ArrayLike‹T››): *boolean*

Defined in utils.ts:74

Checks two or more given array for equality regarding their values

**Type parameters:**

▪ **T**

**Parameters:**

Name | Type |
------ | ------ |
`array1` | ArrayLike‹T› |
`array2` | ArrayLike‹T› |
`...moreArrays` | Array‹ArrayLike‹T›› |

**Returns:** *boolean*

___

### `Static` binaryImageDataToDataUrl

▸ **binaryImageDataToDataUrl**(`imageData`: Uint8ClampedArray, `width`: number, `height`: number, `format`: "RGBA" | "RGB" | "AUTODETECT"): *DataUrl*

Defined in utils.ts:148

Turns a Uint8ClampedArray containing an image's pixel data into a DataUrl object

**Parameters:**

Name | Type | Default | Description |
------ | ------ | ------ | ------ |
`imageData` | Uint8ClampedArray | - | Uint8ClampedArray containing an image's pixel data in either RGBA or RGB |
`width` | number | - | The width of the image |
`height` | number | - | The height of the image |
`format` | "RGBA" &#124; "RGB" &#124; "AUTODETECT" | "AUTODETECT" | The format the binary data is provided. Can autodetect between RGB and RGBA, but will try RGBA first  |

**Returns:** *DataUrl*

___

### `Static` binaryToImageData

▸ **binaryToImageData**(`imageData`: Uint8ClampedArray, `width`: number, `height`: number, `format`: "RGBA" | "RGB" | "AUTODETECT"): *ImageData*

Defined in utils.ts:172

Turns a Uint8ClampedArray containing an image's pixel data into an object of type ImageData

**Parameters:**

Name | Type | Default | Description |
------ | ------ | ------ | ------ |
`imageData` | Uint8ClampedArray | - | Uint8ClampedArray containing an image's pixel data in either RGBA or RGB |
`width` | number | - | The width of the image |
`height` | number | - | The height of the image |
`format` | "RGBA" &#124; "RGB" &#124; "AUTODETECT" | "AUTODETECT" | The format the binary data is provided. Can autodetect between RGB and RGBA, but will try RGBA first  |

**Returns:** *ImageData*

___

### `Static` isInArray

▸ **isInArray**‹**T**›(`outerArray`: Array‹T›, `innerArray`: Array‹T›): *number*

Defined in utils.ts:115

Checks whether the inner array is completely contained within the outer array. If it is, it returns the index where
the inner array starts in the outer one. If it is NOT contained, it return -1

**Type parameters:**

▪ **T**

**Parameters:**

Name | Type | Description |
------ | ------ | ------ |
`outerArray` | Array‹T› | The array that is tested if it contains the other one |
`innerArray` | Array‹T› | The array that is tested if it is contained within the other one |

**Returns:** *number*

If inner is in outer, it returns the index where the inner array starts in the outer one. If it is NOT contained, it returns -1

___

### `Static` isNullOrUndefined

▸ **isNullOrUndefined**(...`values`: any[]): *boolean*

Defined in utils.ts:23

Checks if a value is null or undefined

**Parameters:**

Name | Type |
------ | ------ |
`...values` | any[] |

**Returns:** *boolean*

___

### `Static` readBlobAsDataUrl

▸ **readBlobAsDataUrl**(`blob`: Blob): *Promise‹DataUrl›*

Defined in utils.ts:48

This function wraps the file reader into a promise such that it can be used with async/await

**Parameters:**

Name | Type | Description |
------ | ------ | ------ |
`blob` | Blob | The blob that shall be read as a data url  |

**Returns:** *Promise‹DataUrl›*

___

### `Static` readFileAsDataUrl

▸ **readFileAsDataUrl**(`file`: Blob): *Promise‹DataUrl›*

Defined in utils.ts:67

Just an alias for readBlobAsDataUrl()

**Parameters:**

Name | Type |
------ | ------ |
`file` | Blob |

**Returns:** *Promise‹DataUrl›*

___

### `Static` safeUnsubscribe

▸ **safeUnsubscribe**(...`subscriptions`: Subscription[]): *void*

Defined in utils.ts:281

Safely unsubscribe from rxjs' Subscriptions. If it is not set, the unsubscribe() method will not be called.
Supports array of subscriptions or infinitely many subscriptions as direct arguments

**Parameters:**

Name | Type | Description |
------ | ------ | ------ |
`...subscriptions` | Subscription[] | The subscription(s) that are/is to be unsubscribed from  |

**Returns:** *void*

___

### `Static` saveAs

▸ **saveAs**(`data`: Blob | string, `filename?`: string, `options?`: FileSaverOptions): *Promise‹void›*

Defined in utils.ts:272

Open the browser's save file dialog

**Parameters:**

Name | Type | Description |
------ | ------ | ------ |
`data` | Blob &#124; string | The file that is being saved |
`filename?` | string | The name if the file |
`options?` | FileSaverOptions | Some further options  |

**Returns:** *Promise‹void›*

___

### `Static` setOnlyOnce

▸ **setOnlyOnce**‹**S**›(`variable`: S, `value`: S, `errorMessage?`: string): *void*

Defined in utils.ts:12

Set variable. If already set, an error is thrown.

**Type parameters:**

▪ **S**

**Parameters:**

Name | Type |
------ | ------ |
`variable` | S |
`value` | S |
`errorMessage?` | string |

**Returns:** *void*

___

### `Static` thisOrNull

▸ **thisOrNull**‹**T**›(`value`: T): *T | null*

Defined in utils.ts:36

If the given value is not null or undefined, it will be returned without modification. If it is null or undefined, null is returned

**Type parameters:**

▪ **T**

**Parameters:**

Name | Type | Description |
------ | ------ | ------ |
`value` | T | The value that shall be checked  |

**Returns:** *T | null*