[@rakh/utils](./docs/README.md) / Exports

# @rakh/utils

## Table of contents

### Classes

- [LatLong](./docs/classes/LatLong.md)
- [limitedArray](./docs/classes/limitedArray.md)

### Variables

- [LocalStorage](./docs/modules.md#localstorage)

### Functions

- [arrayFromObj](./docs/modules.md#arrayfromobj)
- [debounce](./docs/modules.md#debounce)
- [distance](./docs/modules.md#distance)
- [extractFromObj](./docs/modules.md#extractfromobj)
- [get](./docs/modules.md#get)
- [getDays](./docs/modules.md#getdays)
- [hasOwn](./docs/modules.md#hasown)
- [hourFloor](./docs/modules.md#hourfloor)
- [isEmpty](./docs/modules.md#isempty)
- [kebabCase](./docs/modules.md#kebabcase)
- [linuxTimestamp](./docs/modules.md#linuxtimestamp)
- [maybePluralize](./docs/modules.md#maybepluralize)
- [mergeWithoutNulls](./docs/modules.md#mergewithoutnulls)
- [minuteFloor](./docs/modules.md#minutefloor)
- [once](./docs/modules.md#once)
- [partOfDay](./docs/modules.md#partofday)
- [throttle](./docs/modules.md#throttle)
- [timeToMilliseconds](./docs/modules.md#timetomilliseconds)
- [toHour](./docs/modules.md#tohour)

## Variables

### LocalStorage

• **LocalStorage**: `Object` = `_LocalStorage`

#### Defined in

LocalStorage.ts:44

## Functions

### arrayFromObj

▸ **arrayFromObj**(`jsonObj`, `wantedFields`): `any`[]

Create an array from an Object using specified fields

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `jsonObj` | `object` | The Original object |
| `wantedFields` | `string`[] | The required fields |

#### Returns

`any`[]

**`Example`**

```ts
U.arrayFromObj({ a: 1, b: 2 }, ['a', 'b']) // => [1, 2]
```

#### Defined in

arrayFromObj.ts:9

___

### debounce

▸ **debounce**(`fn`, `time`): `Function`

Debounce the calling of a function

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `fn` | `Function` | The function to be debounced |
| `time` | `number` | How long to wait |

#### Returns

`Function`

**`Signature`**

U.debounce(fn, time)

#### Defined in

debounce.ts:12

___

### distance

▸ **distance**(`lat1`, `lon1`, `lat2`, `lon2`): `number`

Calculate the distance between two lat long points

#### Parameters

| Name | Type |
| :------ | :------ |
| `lat1` | `number` |
| `lon1` | `number` |
| `lat2` | `number` |
| `lon2` | `number` |

#### Returns

`number`

**`Signature`**

U.distance(lat1, long1, lat2, long2)

**`Example`**

```ts
distance(1, 1, 2, 2) // => 157.22543203805722;
```

#### Defined in

distance.ts:16

▸ **distance**(`latLong1`, `latLong2`): `number`

Calculate the distance between two lat long points

#### Parameters

| Name | Type |
| :------ | :------ |
| `latLong1` | [`LatLong`](./docs/classes/LatLong.md) |
| `latLong2` | [`LatLong`](./docs/classes/LatLong.md) |

#### Returns

`number`

**`Signature`**

U.distance(latLong1, latLong2)

**`Example`**

```ts
const a: U.LatLong = new LatLong(1, 1);
   const b: U.LatLong = new LatLong(2, 2);
   U.distance(a, b) // => 157.22543203805722
```

#### Defined in

distance.ts:33

___

### extractFromObj

▸ **extractFromObj**(`jsonObj`, `wantedFields`): `object`

Extract an object from another object using specific fields

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `jsonObj` | `object` | The source object |
| `wantedFields` | `string`[] | The required fields |

#### Returns

`object`

**`Signature`**

U.extractFromObj(jsonObj, wantedFields)

**`Example`**

```ts
U.extractFromObj({ a: 1, b: 2 }, ['a']) // => { a: 1 }
```

#### Defined in

extractFromObj.ts:12

___

### get

▸ **get**(`obj`, `path`, `defaultValue?`): `any`

Get the value of an item inside an object

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `obj` | `object` | `undefined` | The source object |
| `path` | `string` | `undefined` | The path to the object |
| `defaultValue` | `any` | `undefined` | A default value to be returned |

#### Returns

`any`

**`Example`**

```ts
U.get({ a: 1, b: 2 }, 'b') // => 2
```

#### Defined in

get.ts:10

___

### getDays

▸ **getDays**(`startdate`, `enddate`): `number`

Get number of days between two Date objects

#### Parameters

| Name | Type |
| :------ | :------ |
| `startdate` | `Date` |
| `enddate` | `Date` |

#### Returns

`number`

#### Defined in

getDays.ts:7

___

### hasOwn

▸ **hasOwn**(`obj`, `prop`): `boolean`

Check if an object has an property

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `obj` | `object` | The source object |
| `prop` | `string` | The required property |

#### Returns

`boolean`

**`Example`**

```ts
U.hasOwn({bob:'1'}, 'bob') // => true
```

#### Defined in

hasOwn.ts:12

___

### hourFloor

▸ **hourFloor**(`timestamp`): `string`

Get the hour floor as a Base 32 string

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `timestamp` | `number` | The timestamp as a number |

#### Returns

`string`

**`Example`**

```ts
U.hourFloor(1605532173) // => '1fnp540'
```

#### Defined in

hourFloor.ts:10

___

### isEmpty

▸ **isEmpty**(`obj`): `boolean`

Check if an object is empty

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `obj` | `object` | The object being checked |

#### Returns

`boolean`

**`Example`**

```ts
U.isEmpty({}) // => true
   U.isEmpty({ bob: true }) // => false
```

#### Defined in

isEmpty.ts:9

___

### kebabCase

▸ **kebabCase**(`inval`): `string`

Turn a string into a kebab-case string

#### Parameters

| Name | Type |
| :------ | :------ |
| `inval` | ``null`` \| `string` |

#### Returns

`string`

**`Example`**

```ts
U.kebabCase('test string') // => 'test-string'
   U.kebabCase('testString') // => 'test-string'
   U.kebabCase('test_string') // => 'test-string'
```

#### Defined in

kebabCase.ts:10

___

### linuxTimestamp

▸ **linuxTimestamp**(): `number`

Get the current timestamp in linux ( seconds ) format

#### Returns

`number`

#### Defined in

linuxTimestamp.ts:4

___

### maybePluralize

▸ **maybePluralize**(`count`, `noun`, `suffix?`): `string`

Maybe pluralize a count:

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `count` | `number` | `undefined` | the value counting |
| `noun` | `string` | `undefined` | the name of the value |
| `suffix` | `string` | `'s'` | the suffix |

#### Returns

`string`

**`Signature`**

U.maybePluralize(number, noun, suffix)

**`Example`**

```ts
U.maybePluralize(1, 'Bag', 's') // => 1 Bag
   U.maybePluralize(5, 'Bag', 's') // => 5 Bags
```

#### Defined in

maybePluralize.ts:16

___

### mergeWithoutNulls

▸ **mergeWithoutNulls**(`startingObj`, `newObj`): `object`

Merge two objects together ignoring null values in the incoming data

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `startingObj` | `object` | The original source object to be merged into |
| `newObj` | `object` | The new incoming data |

#### Returns

`object`

**`Signature`**

U.mergeWithoutNulls(startingObj, newObj)

**`Example`**

```ts
U.mergeWithoutNulls({a:1, b:2}, {c:null, d:4}) // => { a:1, b:2, d:4}
```

#### Defined in

mergeWithoutNulls.ts:11

___

### minuteFloor

▸ **minuteFloor**(`timestamp?`): `string`

Get the minute floor as a Base 32 string

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `timestamp?` | ``null`` \| `number` | The timestamp as a number |

#### Returns

`string`

**`Example`**

```ts
U.minuteFloor(1605532173) // => '1fnp540'
```

#### Defined in

minuteFloor.ts:10

___

### once

▸ **once**(`fn`): `Function`

Trigger a function once and then prevent it from triggering again

#### Parameters

| Name | Type |
| :------ | :------ |
| `fn` | `Function` |

#### Returns

`Function`

**`Signature`**

U.once(fn)

#### Defined in

once.ts:9

___

### partOfDay

▸ **partOfDay**(`timeString`, `today?`): `string`

Get a string phrase for the current time of day

#### Parameters

| Name | Type | Default value |
| :------ | :------ | :------ |
| `timeString` | `string` | `undefined` |
| `today` | `boolean` | `false` |

#### Returns

`string`

**`Signature`**

U.partOfDay(timeString, today)

**`Example`**

```ts
U.partOfDay('13:00') // => 'Afternoon'
```

#### Defined in

partOfDay.ts:11

___

### throttle

▸ **throttle**(`callback`, `limit`): `Function`

Throttle the calling of a function

#### Parameters

| Name | Type |
| :------ | :------ |
| `callback` | `Function` |
| `limit` | `number` |

#### Returns

`Function`

**`Signature`**

U.throttle(callback, limit)

#### Defined in

throttle.ts:10

___

### timeToMilliseconds

▸ **timeToMilliseconds**(`inTime?`): `number`

Get milliseconds from a string of time sections

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `inTime` | `string` | `''` | * |

#### Returns

`number`

**`Signature`**

U.timeToMilliseconds(inTime)

**`Example`**

```ts
U.timeToMilliseconds('1s')  // => 1000
   U.timeToMilliseconds('1min') // => 60000
   U.timeToMilliseconds('1 weeks') // => 604800000
   U.timeToMilliseconds('5y2w30d14h30m10s') // => 161641810000
   U.timeToMilliseconds('1 hour and 5 seconds') // => 3605000
```

#### Defined in

timeToMilliseconds.ts:31

___

### toHour

▸ **toHour**(`currentTimsestamp`, `extra?`): `number`

Return the number of Milliseconds to the hour for the supplied timestamp

#### Parameters

| Name | Type | Default value |
| :------ | :------ | :------ |
| `currentTimsestamp` | `number` | `undefined` |
| `extra` | `number` | `0` |

#### Returns

`number`

*

**`Signature`**

U.toHour(currentTimsestamp, extra)

**`Example`**

```ts
U.toHour('13:00') // => 1605532173
```

#### Defined in

toHour.ts:12
