Compare commits
No commits in common. "development" and "fixing-packages" have entirely different histories.
developmen
...
fixing-pac
@ -1,60 +0,0 @@
|
||||
module.exports = {
|
||||
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: ['@typescript-eslint'],
|
||||
root: true,
|
||||
env: {
|
||||
'node': true,
|
||||
'es2018': true,
|
||||
},
|
||||
rules: {
|
||||
'no-shadow': ['error', { 'hoist': 'all' }],
|
||||
'@typescript-eslint/no-shadow': ['error'],
|
||||
'no-multi-spaces': 'error',
|
||||
'no-multiple-empty-lines': ['error', { 'max': 1, 'maxEOF': 1 }],
|
||||
'spaced-comment': ['error', 'always', { 'markers': ['/'] }],
|
||||
'semi': 'error',
|
||||
'arrow-spacing': 'error',
|
||||
'block-scoped-var': 'error',
|
||||
'block-spacing': 'error',
|
||||
'brace-style': ['error', '1tbs', {}],
|
||||
'camelcase': 'error',
|
||||
'comma-spacing': ['error', { 'before': false, 'after': true }],
|
||||
'comma-style': ['error', 'last'],
|
||||
'consistent-this': ['error', '_this'],
|
||||
'curly': ['error', 'multi'],
|
||||
'eol-last': ['error', 'always'],
|
||||
'eqeqeq': ['error', 'always'],
|
||||
'func-names': ['error', 'as-needed'],
|
||||
'indent': ['error', 2, { 'SwitchCase': 1 }],
|
||||
'max-len': [
|
||||
'error',
|
||||
{
|
||||
'code': 160,
|
||||
'tabWidth': 2,
|
||||
'ignoreComments': true,
|
||||
'ignoreTrailingComments': true,
|
||||
'ignoreUrls': true,
|
||||
'ignoreStrings': true,
|
||||
'ignoreTemplateLiterals': true,
|
||||
'ignoreRegExpLiterals': true,
|
||||
},
|
||||
],
|
||||
'new-cap': 'error',
|
||||
'newline-before-return': 'error',
|
||||
'no-array-constructor': 'error',
|
||||
'no-inner-declarations': ['error', 'both'],
|
||||
'no-new-object': 'error',
|
||||
'no-shadow-restricted-names': 'error',
|
||||
'object-curly-spacing': ['error', 'always'],
|
||||
'prefer-const': 'error',
|
||||
'prefer-template': 'error',
|
||||
'one-var': ['error', { 'initialized': 'never' }],
|
||||
'quote-props': ['error', 'always'],
|
||||
'quotes': ['error', 'single'],
|
||||
'radix': 'error',
|
||||
'space-before-blocks': ['error', 'always'],
|
||||
'space-infix-ops': 'error',
|
||||
'vars-on-top': 'error',
|
||||
},
|
||||
};
|
@ -1 +0,0 @@
|
||||
TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.
|
624
docs/README.md
624
docs/README.md
@ -1,624 +0,0 @@
|
||||
@rakh/utils / [Exports](./docs/modules.md)
|
||||
|
||||
[@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)
|
||||
- [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?`): `unknown`
|
||||
|
||||
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` | `unknown` | `undefined` | A default value to be returned |
|
||||
|
||||
#### Returns
|
||||
|
||||
`unknown`
|
||||
|
||||
**`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
|
||||
|
||||
___
|
||||
|
||||
### 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
|
@ -1,61 +0,0 @@
|
||||
[@rakh/utils](./docs/README.md) / [Exports](./docs/modules.md) / LatLong
|
||||
|
||||
# Class: LatLong
|
||||
|
||||
Calculate the distance between two latLongs
|
||||
|
||||
**`Param`**
|
||||
|
||||
**`Param`**
|
||||
|
||||
**`Param`**
|
||||
|
||||
**`Param`**
|
||||
|
||||
## Table of contents
|
||||
|
||||
### Constructors
|
||||
|
||||
- [constructor](./docs/classes/LatLong.md#constructor)
|
||||
|
||||
### Properties
|
||||
|
||||
- [lat](./docs/classes/LatLong.md#lat)
|
||||
- [long](./docs/classes/LatLong.md#long)
|
||||
|
||||
## Constructors
|
||||
|
||||
### constructor
|
||||
|
||||
• **new LatLong**(`lat`, `long`)
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `lat` | `number` |
|
||||
| `long` | `number` |
|
||||
|
||||
#### Defined in
|
||||
|
||||
latLong.ts:12
|
||||
|
||||
## Properties
|
||||
|
||||
### lat
|
||||
|
||||
• **lat**: `number`
|
||||
|
||||
#### Defined in
|
||||
|
||||
latLong.ts:10
|
||||
|
||||
___
|
||||
|
||||
### long
|
||||
|
||||
• **long**: `number`
|
||||
|
||||
#### Defined in
|
||||
|
||||
latLong.ts:11
|
@ -1,176 +0,0 @@
|
||||
[@rakh/utils](./docs/README.md) / [Exports](./docs/modules.md) / limitedArray
|
||||
|
||||
# Class: limitedArray
|
||||
|
||||
## Table of contents
|
||||
|
||||
### Constructors
|
||||
|
||||
- [constructor](./docs/classes/limitedArray.md#constructor)
|
||||
|
||||
### Properties
|
||||
|
||||
- [\_array](./docs/classes/limitedArray.md#_array)
|
||||
- [\_limit](./docs/classes/limitedArray.md#_limit)
|
||||
|
||||
### Methods
|
||||
|
||||
- [add](./docs/classes/limitedArray.md#add)
|
||||
- [get](./docs/classes/limitedArray.md#get)
|
||||
- [length](./docs/classes/limitedArray.md#length)
|
||||
- [limit](./docs/classes/limitedArray.md#limit)
|
||||
- [push](./docs/classes/limitedArray.md#push)
|
||||
- [shift](./docs/classes/limitedArray.md#shift)
|
||||
|
||||
## Constructors
|
||||
|
||||
### constructor
|
||||
|
||||
• **new limitedArray**(`size?`)
|
||||
|
||||
Used to construct the LimitedArray
|
||||
Defaults to 100 when no size is passed in
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Default value |
|
||||
| :------ | :------ | :------ |
|
||||
| `size` | `number` | `100` |
|
||||
|
||||
#### Defined in
|
||||
|
||||
limitedArray.ts:10
|
||||
|
||||
## Properties
|
||||
|
||||
### \_array
|
||||
|
||||
• **\_array**: `unknown`[]
|
||||
|
||||
#### Defined in
|
||||
|
||||
limitedArray.ts:2
|
||||
|
||||
___
|
||||
|
||||
### \_limit
|
||||
|
||||
• **\_limit**: `number`
|
||||
|
||||
#### Defined in
|
||||
|
||||
limitedArray.ts:3
|
||||
|
||||
## Methods
|
||||
|
||||
### add
|
||||
|
||||
▸ **add**(`items`): `void`
|
||||
|
||||
Bulk add an array to the array
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `items` | `unknown`[] |
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Defined in
|
||||
|
||||
limitedArray.ts:54
|
||||
|
||||
___
|
||||
|
||||
### get
|
||||
|
||||
▸ **get**(): `unknown`[]
|
||||
|
||||
Return the items within the array
|
||||
|
||||
#### Returns
|
||||
|
||||
`unknown`[]
|
||||
|
||||
#### Defined in
|
||||
|
||||
limitedArray.ts:29
|
||||
|
||||
___
|
||||
|
||||
### length
|
||||
|
||||
▸ **length**(): `number`
|
||||
|
||||
Returns the length of the array
|
||||
|
||||
#### Returns
|
||||
|
||||
`number`
|
||||
|
||||
#### Defined in
|
||||
|
||||
limitedArray.ts:46
|
||||
|
||||
___
|
||||
|
||||
### limit
|
||||
|
||||
▸ **limit**(`size`): `void`
|
||||
|
||||
Limits the size of the array
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `size` | `number` |
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Defined in
|
||||
|
||||
limitedArray.ts:37
|
||||
|
||||
___
|
||||
|
||||
### push
|
||||
|
||||
▸ **push**(`item`): `void`
|
||||
|
||||
Add items to the end of an array
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `item` | `unknown` |
|
||||
|
||||
#### Returns
|
||||
|
||||
`void`
|
||||
|
||||
#### Defined in
|
||||
|
||||
limitedArray.ts:20
|
||||
|
||||
___
|
||||
|
||||
### shift
|
||||
|
||||
▸ **shift**(): `unknown`
|
||||
|
||||
Remove an item from the beginning of an array
|
||||
|
||||
#### Returns
|
||||
|
||||
`unknown`
|
||||
|
||||
#### Defined in
|
||||
|
||||
limitedArray.ts:64
|
622
docs/modules.md
622
docs/modules.md
@ -1,622 +0,0 @@
|
||||
[@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)
|
||||
- [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?`): `unknown`
|
||||
|
||||
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` | `unknown` | `undefined` | A default value to be returned |
|
||||
|
||||
#### Returns
|
||||
|
||||
`unknown`
|
||||
|
||||
**`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
|
||||
|
||||
___
|
||||
|
||||
### 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
|
6995
package-lock.json
generated
6995
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
53
package.json
53
package.json
@ -1,27 +1,9 @@
|
||||
{
|
||||
"name": "@rakh/utils",
|
||||
"version": "2.0.22",
|
||||
"version": "2.0.5",
|
||||
"main": "dist/commonjs/index.js",
|
||||
"types": "dist/commonjs/index.d.ts",
|
||||
"module": "dist/es/index.js",
|
||||
"jsnext:main": "dist/es/index.js",
|
||||
"files": [
|
||||
"dist/**/*",
|
||||
"docs/**/*",
|
||||
"readme.MD"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"import": {
|
||||
"types": "./dist/es/index.d.ts",
|
||||
"default": "./dist/es/index.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"default": "./dist/commonjs/index.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"release": "node ./scripts/create-index.js && vik patch -t",
|
||||
"clean": "rm -rf dist",
|
||||
@ -29,28 +11,25 @@
|
||||
"test": "jest --coverage && npm run compile",
|
||||
"compile:es": "tsc --declaration true --declarationMap true --module esnext --outDir './dist/es'",
|
||||
"compile:commonjs": "tsc --declaration true --declarationMap true --module commonjs --outDir './dist/commonjs'",
|
||||
"compile": "npm run clean && npm run compile:es && npm run compile:commonjs && npm run document",
|
||||
"document": "./node_modules/.bin/typedoc --plugin typedoc-plugin-markdown --publicPath ./docs/ --out docs ./ts-src && cp ./docs/modules.md ./readme.MD"
|
||||
"compile": "npm run clean && npm run compile:es && npm run compile:commonjs"
|
||||
},
|
||||
"author": "Martin Donnelly",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"save": "^2.4.0",
|
||||
"typedoc": "^0.23.15"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.5.5",
|
||||
"@types/sinon": "^10.0.18",
|
||||
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
||||
"@typescript-eslint/parser": "^6.7.4",
|
||||
"eslint": "^8.39.0",
|
||||
"grunt": "^1.6.1",
|
||||
"jest": "^29.7.0",
|
||||
"marked": "^9.0.3",
|
||||
"prettier": "^3.0.3",
|
||||
"save": "^2.9.0",
|
||||
"sinon": "^16.0.0",
|
||||
"ts-jest": "^29.1.1",
|
||||
"@types/jest": "^29.0.3",
|
||||
"@types/sinon": "^10.0.0",
|
||||
"grunt": "^1.3.0",
|
||||
"jest": "^29.0.3",
|
||||
"marked": "^4.1.0",
|
||||
"prettier": "^2.3.0",
|
||||
"sinon": "^14.0.0",
|
||||
"ts-jest": "^29.0.2",
|
||||
"ts-node": "^10.9.1",
|
||||
"typedoc": "^0.25.1",
|
||||
"typedoc-plugin-markdown": "^3.16.0",
|
||||
"typescript": "^5.2.2",
|
||||
"typescript": "^4.2.4",
|
||||
"vik": "^0.4.0"
|
||||
},
|
||||
"description": "",
|
||||
@ -76,4 +55,4 @@
|
||||
"node"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
3817
pnpm-lock.yaml
3817
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
622
readme.MD
622
readme.MD
@ -1,622 +1,4 @@
|
||||
[@rakh/utils](./docs/README.md) / Exports
|
||||
# Rakh/utils
|
||||
|
||||
# @rakh/utils
|
||||
![Build status](https://travis-ci.org/martind2000/utils.svg?branch=main)
|
||||
|
||||
## 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)
|
||||
- [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?`): `unknown`
|
||||
|
||||
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` | `unknown` | `undefined` | A default value to be returned |
|
||||
|
||||
#### Returns
|
||||
|
||||
`unknown`
|
||||
|
||||
**`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
|
||||
|
||||
___
|
||||
|
||||
### 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
|
||||
|
@ -6,11 +6,10 @@
|
||||
* @example
|
||||
* U.arrayFromObj({ a: 1, b: 2 }, ['a', 'b']) // => [1, 2]
|
||||
*/
|
||||
export function arrayFromObj(jsonObj: object, wantedFields: string[]): any[] {
|
||||
export function arrayFromObj(jsonObj: Object, wantedFields: string[]): any[] {
|
||||
return wantedFields.map((key) => {
|
||||
if (jsonObj.hasOwnProperty(key)) {
|
||||
const { value }: any = Object.getOwnPropertyDescriptor(jsonObj, key);
|
||||
|
||||
return value;
|
||||
}
|
||||
});
|
||||
|
@ -36,16 +36,16 @@ export function distance(latLong1: LatLong, latLong2: LatLong): number;
|
||||
* Calculate the Distance between two lat long points
|
||||
*/
|
||||
export function distance(): number {
|
||||
if (arguments.length === 4)
|
||||
if (arguments.length === 4) {
|
||||
return _distance(arguments[0], arguments[1], arguments[2], arguments[3]);
|
||||
else if (arguments.length === 2)
|
||||
} else if (arguments.length === 2) {
|
||||
return _distance(
|
||||
<number>arguments[0].lat,
|
||||
<number>arguments[0].long,
|
||||
<number>arguments[1].lat,
|
||||
<number>arguments[1].long
|
||||
);
|
||||
else return 0;
|
||||
} else return 0;
|
||||
}
|
||||
|
||||
function _distance(lat1: number, lon1: number, lat2: number, lon2: number): number {
|
||||
|
@ -9,16 +9,16 @@
|
||||
* U.extractFromObj({ a: 1, b: 2 }, ['a']) // => { a: 1 }
|
||||
*
|
||||
*/
|
||||
export function extractFromObj(jsonObj: object, wantedFields: string[]): object {
|
||||
export function extractFromObj(jsonObj: Object, wantedFields: string[]): {} {
|
||||
return Object.keys(jsonObj).reduce((obj, key) => {
|
||||
if (wantedFields.includes(key)) {
|
||||
const { value }: any = Object.getOwnPropertyDescriptor(jsonObj, key);
|
||||
|
||||
Object.defineProperty(obj, key, {
|
||||
'value': value,
|
||||
'writable': true,
|
||||
'enumerable': true,
|
||||
'configurable': true
|
||||
value: value,
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -7,19 +7,18 @@
|
||||
* @example
|
||||
* U.get({ a: 1, b: 2 }, 'b') // => 2
|
||||
*/
|
||||
export function get(obj: object, path: string, defaultValue: unknown = undefined): unknown {
|
||||
const travel = (regexp: RegExp) => {
|
||||
export function get(obj: Object, path: string, defaultValue: any = undefined): any {
|
||||
const travel = (regexp: any) => {
|
||||
return String.prototype.split
|
||||
.call(path, regexp)
|
||||
.filter(Boolean)
|
||||
.reduce((res, key) => {
|
||||
if (res !== null && res !== undefined && res.hasOwnProperty(key)) {
|
||||
const { value }: any = Object.getOwnPropertyDescriptor(res, key);
|
||||
|
||||
return value;
|
||||
} else
|
||||
} else {
|
||||
return res;
|
||||
|
||||
}
|
||||
}, obj);
|
||||
};
|
||||
const result = travel(/[,[\].]+?/);
|
||||
|
@ -5,8 +5,10 @@
|
||||
*/
|
||||
|
||||
export function getDays(startdate: Date, enddate: Date): number {
|
||||
const startMS = startdate.getTime();
|
||||
const endMS = enddate.getTime();
|
||||
let result, startMS, endMS;
|
||||
startMS = startdate.getTime();
|
||||
endMS = enddate.getTime();
|
||||
result = Math.ceil((endMS - startMS) / (24 * 60 * 60 * 1000));
|
||||
|
||||
return Math.ceil((endMS - startMS) / (24 * 60 * 60 * 1000));
|
||||
return result;
|
||||
}
|
||||
|
@ -9,6 +9,6 @@ const hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
* @example
|
||||
* U.hasOwn({bob:'1'}, 'bob') // => true
|
||||
*/
|
||||
export function hasOwn(obj: object, prop: string): boolean {
|
||||
export function hasOwn(obj: Object, prop: string): boolean {
|
||||
return hasOwnProperty.call(obj, prop);
|
||||
}
|
||||
|
@ -8,14 +8,10 @@ export * from './getDays';
|
||||
export * from './hasOwn';
|
||||
export * from './hourFloor';
|
||||
export * from './isEmpty';
|
||||
export * from './kebabCase';
|
||||
export * from './latLong';
|
||||
export * from './limitedArray';
|
||||
export * from './maybePluralize';
|
||||
export * from './mergeWithoutNulls';
|
||||
export * from './minuteFloor';
|
||||
export * from './once';
|
||||
export * from './partOfDay';
|
||||
export * from './throttle';
|
||||
export * from './timeToMilliseconds';
|
||||
export * from './toHour';
|
@ -6,7 +6,7 @@
|
||||
* U.isEmpty({}) // => true
|
||||
* U.isEmpty({ bob: true }) // => false
|
||||
*/
|
||||
export function isEmpty(obj: object): boolean {
|
||||
export function isEmpty(obj: Object): boolean {
|
||||
// @ts-ignore
|
||||
return [Object, Array].includes((obj || {}).constructor) && !Object.entries(obj || {}).length;
|
||||
}
|
||||
|
@ -1,25 +0,0 @@
|
||||
import { kebabCase } from './kebabCase';
|
||||
|
||||
test('Null instead of string', function() {
|
||||
expect(kebabCase(null)).toBe('');
|
||||
});
|
||||
|
||||
test('Empty string', function() {
|
||||
expect(kebabCase('')).toBe('');
|
||||
});
|
||||
|
||||
test('String with spaces', function() {
|
||||
expect(kebabCase('test string')).toBe('test-string');
|
||||
});
|
||||
|
||||
test('String with Capitals', function() {
|
||||
expect(kebabCase('testString')).toBe('test-string');
|
||||
});
|
||||
|
||||
test('String with underscores', function() {
|
||||
expect(kebabCase('test_string')).toBe('test-string');
|
||||
});
|
||||
|
||||
test('String with spaces, underscores and capitals', function() {
|
||||
expect(kebabCase('this is a_complexTest_String')).toBe('this-is-a-complex-test-string');
|
||||
});
|
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Turn a string into a kebab-case string
|
||||
* @param inval
|
||||
*
|
||||
* @example
|
||||
* U.kebabCase('test string') // => 'test-string'
|
||||
* U.kebabCase('testString') // => 'test-string'
|
||||
* U.kebabCase('test_string') // => 'test-string'
|
||||
*/
|
||||
export function kebabCase(inval: string | null): string {
|
||||
|
||||
const tempString = (inval) ? inval : '';
|
||||
|
||||
const workArray = tempString.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g);
|
||||
|
||||
let workString: string = '';
|
||||
|
||||
if (workArray && workArray.length > 0) {
|
||||
workString = workArray!.join('-').toLowerCase();
|
||||
}
|
||||
|
||||
return workString;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
export class limitedArray {
|
||||
_array: unknown[];
|
||||
_array: any[];
|
||||
_limit: number;
|
||||
|
||||
/**
|
||||
@ -17,7 +17,7 @@ export class limitedArray {
|
||||
* @param item
|
||||
*/
|
||||
|
||||
push(item: unknown): void {
|
||||
push(item: any): void {
|
||||
this._array.push(item);
|
||||
if (this._array.length > this._limit) this._array.shift();
|
||||
}
|
||||
@ -26,7 +26,7 @@ export class limitedArray {
|
||||
* Return the items within the array
|
||||
* @returns {[]}
|
||||
*/
|
||||
get(): unknown[] {
|
||||
get(): any[] {
|
||||
return this._array;
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ export class limitedArray {
|
||||
* Bulk add an array to the array
|
||||
* @param items
|
||||
*/
|
||||
add(items: unknown[]): void {
|
||||
add(items: any[]): void {
|
||||
this._array = this._array.concat(items);
|
||||
|
||||
if (this._array.length > this._limit) this._array = this._array.slice(this._array.length - this._limit);
|
||||
@ -61,7 +61,7 @@ export class limitedArray {
|
||||
* Remove an item from the beginning of an array
|
||||
* @returns {*}
|
||||
*/
|
||||
shift(): unknown {
|
||||
shift(): any {
|
||||
return this._array.shift();
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +0,0 @@
|
||||
import { mergeWithoutNulls} from "./mergeWithoutNulls";
|
||||
|
||||
|
||||
|
||||
test('It should merge object correctly', function () {
|
||||
|
||||
const a = {a:1,b:2};
|
||||
const b = {c:3,d:4};
|
||||
|
||||
expect(mergeWithoutNulls(a,b)).toEqual(({a:1,b:2, c:3, d:4}));
|
||||
|
||||
});
|
||||
|
||||
test('It should merge an object with nulls correctly', function () {
|
||||
|
||||
const a = {a:1,b:2};
|
||||
const b = {c:3,d:4, e:null, f:null};
|
||||
|
||||
expect(mergeWithoutNulls(a,b)).toEqual(({a:1,b:2, c:3, d:4}));
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
@ -1,26 +0,0 @@
|
||||
/**
|
||||
* Merge two objects together ignoring null values in the incoming data
|
||||
* @param startingObj The original source object to be merged into
|
||||
* @param newObj The new incoming data
|
||||
* @signature
|
||||
* U.mergeWithoutNulls(startingObj, newObj)
|
||||
*
|
||||
* @example
|
||||
* U.mergeWithoutNulls({a:1, b:2}, {c:null, d:4}) // => { a:1, b:2, d:4}
|
||||
*/
|
||||
export function mergeWithoutNulls(startingObj: object, newObj: object) : object {
|
||||
|
||||
const _cloneObj = Object.assign({}, startingObj);
|
||||
|
||||
for (const key of Object.keys(newObj)) {
|
||||
|
||||
const properties = Object.getOwnPropertyDescriptor(newObj, key);
|
||||
|
||||
if (properties?.value !== null)
|
||||
|
||||
Object.defineProperty(_cloneObj, key, { ...properties });
|
||||
|
||||
}
|
||||
|
||||
return _cloneObj;
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
import { minuteFloor } from './minuteFloor';
|
||||
|
||||
test('Should return the correct Base32 value', () => {
|
||||
expect(minuteFloor(1605532173)).toEqual('1fr3bi0');
|
||||
});
|
||||
|
||||
test('Should return something for a null value', () => {
|
||||
expect(minuteFloor(null)).toBeDefined();
|
||||
});
|
||||
|
||||
test('Should return something for an empty value', () => {
|
||||
expect(minuteFloor()).toBeDefined();
|
||||
});
|
||||
|
@ -1,15 +0,0 @@
|
||||
/**
|
||||
* Get the minute floor as a Base 32 string
|
||||
* @param timestamp The timestamp as a number
|
||||
* @returns {string}
|
||||
*
|
||||
* @example
|
||||
* U.minuteFloor(1605532173) // => '1fnp540'
|
||||
*/
|
||||
|
||||
export function minuteFloor(timestamp?: number|null): string {
|
||||
|
||||
const _timestamp = (timestamp) ? timestamp : Date.now();
|
||||
|
||||
return (Math.floor(_timestamp / 60000) * 60000).toString(32);
|
||||
}
|
@ -7,7 +7,7 @@
|
||||
* U.once(fn)
|
||||
*/
|
||||
export function once(fn: Function): Function {
|
||||
let alreadyCalled = false;
|
||||
let alreadyCalled: boolean = false;
|
||||
let result: Function;
|
||||
|
||||
return function (...args: any): any {
|
||||
|
@ -8,7 +8,7 @@
|
||||
* @example
|
||||
* U.partOfDay('13:00') // => 'Afternoon'
|
||||
*/
|
||||
export function partOfDay(timeString: string, today = false): string {
|
||||
export function partOfDay(timeString: string, today: boolean = false): string {
|
||||
if (timeString === undefined || timeString === null) timeString = new Date().getHours().toString();
|
||||
|
||||
if (today === undefined) today = false;
|
||||
|
@ -8,7 +8,7 @@
|
||||
* U.throttle(callback, limit)
|
||||
*/
|
||||
export function throttle(callback: Function, limit: number): Function {
|
||||
let wait = false;
|
||||
var wait: boolean = false;
|
||||
|
||||
return function (...args: any): any {
|
||||
if (!wait) {
|
||||
|
@ -1,65 +0,0 @@
|
||||
import { timeToMilliseconds } from './timeToMilliseconds';
|
||||
describe('Should convert strings into milliseconds', () => {
|
||||
describe('Handle individual strings', () => {
|
||||
test('Should handle seconds', () => {
|
||||
expect(timeToMilliseconds('1s')).toEqual(1000);
|
||||
expect(timeToMilliseconds('1sec')).toEqual(1000);
|
||||
expect(timeToMilliseconds('1 second')).toEqual(1000);
|
||||
|
||||
});
|
||||
|
||||
test('Should handle minutes', () => {
|
||||
expect(timeToMilliseconds('1m')).toEqual(60000);
|
||||
expect(timeToMilliseconds('1min')).toEqual(60000);
|
||||
expect(timeToMilliseconds('1 minutes')).toEqual(60000);
|
||||
|
||||
});
|
||||
|
||||
test('Should handle hours', () => {
|
||||
expect(timeToMilliseconds('1h')).toEqual(3600000);
|
||||
expect(timeToMilliseconds('1 hours')).toEqual(3600000);
|
||||
|
||||
});
|
||||
|
||||
test('Should handle days', () => {
|
||||
expect(timeToMilliseconds('1d')).toEqual(86400000);
|
||||
expect(timeToMilliseconds('1 days')).toEqual(86400000);
|
||||
|
||||
});
|
||||
|
||||
test('Should handle weeks', () => {
|
||||
expect(timeToMilliseconds('1w')).toEqual(604800000);
|
||||
expect(timeToMilliseconds('1 weeks')).toEqual(604800000);
|
||||
|
||||
});
|
||||
|
||||
test('Should handle years', () => {
|
||||
expect(timeToMilliseconds('1y')).toEqual(31557600000);
|
||||
expect(timeToMilliseconds('1 years')).toEqual(31557600000);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Handle complex strings', () => {
|
||||
|
||||
test('Should handle 5y2w30d14h30m10s', () => {
|
||||
expect(timeToMilliseconds('5y2w30d14h30m10s')).toEqual(161641810000);
|
||||
|
||||
});
|
||||
|
||||
test('1 hour and 5 seconds', () => {
|
||||
expect(timeToMilliseconds('1 hour and 5 seconds')).toEqual(3605000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Handle complex strings', () => {
|
||||
|
||||
test('Should handle empty', () => {
|
||||
expect(timeToMilliseconds('')).toEqual(0);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -1,44 +0,0 @@
|
||||
/**
|
||||
* perform the regEx to number conversion
|
||||
* @param reg
|
||||
* @param timeCheck
|
||||
*/
|
||||
function doRegEx(reg : RegExp, timeCheck: string) : number {
|
||||
|
||||
if (!timeCheck || timeCheck.length === 0) return 0;
|
||||
|
||||
const result = reg.exec(timeCheck);
|
||||
|
||||
if (result && result.length > 0)
|
||||
return parseInt(result[1], 10);
|
||||
else return 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get milliseconds from a string of time sections
|
||||
* @param inTime *
|
||||
* @signature
|
||||
* U.timeToMilliseconds(inTime)
|
||||
* @example
|
||||
* 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
|
||||
*/
|
||||
|
||||
export function timeToMilliseconds(inTime = '') : number {
|
||||
|
||||
const workTime = inTime || '';
|
||||
|
||||
const years = doRegEx(/(\d+)(?:\s*(?:year[s]?|y))+/gi, workTime) * 31557600000;
|
||||
const weeks = doRegEx(/(\d+)(?:\s*(?:week[s]?|w))+/gi, workTime) * 604800000;
|
||||
const days = doRegEx(/(\d+)(?:\s*(?:day[s]?|d))+/gi, workTime) * 86400000;
|
||||
const hours = doRegEx(/(\d+)(?:\s*(?:hour[s]?|h))+/gi, workTime) * 3600000;
|
||||
const minutes = doRegEx(/(\d+)(?:\s*(?:minutes[s]?|min[s]?|m))+/gi, workTime) * 60000;
|
||||
const seconds = doRegEx(/(\d+)(?:\s*(?:second[s]?|sec[s]?|s))+/gi, workTime) * 1000;
|
||||
|
||||
return years + weeks + days + hours + minutes + seconds;
|
||||
|
||||
}
|
@ -9,6 +9,6 @@
|
||||
* @example
|
||||
* U.toHour('13:00') // => 1605532173
|
||||
*/
|
||||
export function toHour(currentTimsestamp: number, extra = 0): number {
|
||||
export function toHour(currentTimsestamp: number, extra: number = 0): number {
|
||||
return 3600000 - (currentTimsestamp % 3600000) + extra;
|
||||
}
|
||||
|
@ -66,5 +66,5 @@
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": ["ts-src"],
|
||||
"exclude": ["node_modules", "**/*.test.ts"]
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user