Compare commits
No commits in common. "development" and "update-build-packages" have entirely different histories.
developmen
...
update-bui
@ -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',
|
||||
},
|
||||
};
|
375
docs/README.md
375
docs/README.md
@ -26,14 +26,10 @@
|
||||
- [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
|
||||
@ -54,23 +50,23 @@ LocalStorage.ts:44
|
||||
|
||||
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]
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `jsonObj` | `Object` | The Original object |
|
||||
| `wantedFields` | `string`[] | The required fields |
|
||||
|
||||
#### Returns
|
||||
|
||||
`any`[]
|
||||
|
||||
#### Defined in
|
||||
|
||||
arrayFromObj.ts:9
|
||||
@ -83,6 +79,10 @@ ___
|
||||
|
||||
Debounce the calling of a function
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.debounce(fn, time)
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
@ -94,10 +94,6 @@ Debounce the calling of a function
|
||||
|
||||
`Function`
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.debounce(fn, time)
|
||||
|
||||
#### Defined in
|
||||
|
||||
debounce.ts:12
|
||||
@ -110,6 +106,16 @@ ___
|
||||
|
||||
Calculate the distance between two lat long points
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.distance(lat1, long1, lat2, long2)
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
distance(1, 1, 2, 2) // => 157.22543203805722;
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
@ -123,16 +129,6 @@ Calculate the distance between two lat long points
|
||||
|
||||
`number`
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.distance(lat1, long1, lat2, long2)
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
distance(1, 1, 2, 2) // => 157.22543203805722;
|
||||
```
|
||||
|
||||
#### Defined in
|
||||
|
||||
distance.ts:16
|
||||
@ -141,17 +137,6 @@ distance.ts:16
|
||||
|
||||
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)
|
||||
@ -164,6 +149,17 @@ const a: U.LatLong = new LatLong(1, 1);
|
||||
U.distance(a, b) // => 157.22543203805722
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `latLong1` | [`LatLong`](./docs/classes/LatLong.md) |
|
||||
| `latLong2` | [`LatLong`](./docs/classes/LatLong.md) |
|
||||
|
||||
#### Returns
|
||||
|
||||
`number`
|
||||
|
||||
#### Defined in
|
||||
|
||||
distance.ts:33
|
||||
@ -172,21 +168,10 @@ ___
|
||||
|
||||
### extractFromObj
|
||||
|
||||
▸ **extractFromObj**(`jsonObj`, `wantedFields`): `object`
|
||||
▸ **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)
|
||||
@ -197,6 +182,17 @@ U.extractFromObj(jsonObj, wantedFields)
|
||||
U.extractFromObj({ a: 1, b: 2 }, ['a']) // => { a: 1 }
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `jsonObj` | `Object` | The source object |
|
||||
| `wantedFields` | `string`[] | The required fields |
|
||||
|
||||
#### Returns
|
||||
|
||||
`Object`
|
||||
|
||||
#### Defined in
|
||||
|
||||
extractFromObj.ts:12
|
||||
@ -205,28 +201,28 @@ ___
|
||||
|
||||
### get
|
||||
|
||||
▸ **get**(`obj`, `path`, `defaultValue?`): `unknown`
|
||||
▸ **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` | `unknown` | `undefined` | A default value to be returned |
|
||||
|
||||
#### Returns
|
||||
|
||||
`unknown`
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.get({ a: 1, b: 2 }, 'b') // => 2
|
||||
```
|
||||
|
||||
#### 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`
|
||||
|
||||
#### Defined in
|
||||
|
||||
get.ts:10
|
||||
@ -262,23 +258,23 @@ ___
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `obj` | `Object` | The source object |
|
||||
| `prop` | `string` | The required property |
|
||||
|
||||
#### Returns
|
||||
|
||||
`boolean`
|
||||
|
||||
#### Defined in
|
||||
|
||||
hasOwn.ts:12
|
||||
@ -291,6 +287,12 @@ ___
|
||||
|
||||
Get the hour floor as a Base 32 string
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.hourFloor(1605532173) // => '1fnp540'
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
@ -301,12 +303,6 @@ Get the hour floor as a Base 32 string
|
||||
|
||||
`string`
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.hourFloor(1605532173) // => '1fnp540'
|
||||
```
|
||||
|
||||
#### Defined in
|
||||
|
||||
hourFloor.ts:10
|
||||
@ -319,16 +315,6 @@ ___
|
||||
|
||||
Check if an object is empty
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `obj` | `object` | The object being checked |
|
||||
|
||||
#### Returns
|
||||
|
||||
`boolean`
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
@ -336,39 +322,19 @@ 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` |
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `obj` | `Object` | The object being checked |
|
||||
|
||||
#### Returns
|
||||
|
||||
`string`
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.kebabCase('test string') // => 'test-string'
|
||||
U.kebabCase('testString') // => 'test-string'
|
||||
U.kebabCase('test_string') // => 'test-string'
|
||||
```
|
||||
`boolean`
|
||||
|
||||
#### Defined in
|
||||
|
||||
kebabCase.ts:10
|
||||
isEmpty.ts:9
|
||||
|
||||
___
|
||||
|
||||
@ -378,6 +344,17 @@ ___
|
||||
|
||||
Maybe pluralize a count:
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.maybePluralize(number, noun, suffix)
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.maybePluralize(1, 'Bag', 's') // => 1 Bag
|
||||
U.maybePluralize(5, 'Bag', 's') // => 5 Bags
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Default value | Description |
|
||||
@ -390,90 +367,22 @@ Maybe pluralize a count:
|
||||
|
||||
`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
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.once(fn)
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
@ -484,10 +393,6 @@ Trigger a function once and then prevent it from triggering again
|
||||
|
||||
`Function`
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.once(fn)
|
||||
|
||||
#### Defined in
|
||||
|
||||
once.ts:9
|
||||
@ -500,6 +405,16 @@ ___
|
||||
|
||||
Get a string phrase for the current time of day
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.partOfDay(timeString, today)
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.partOfDay('13:00') // => 'Afternoon'
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Default value |
|
||||
@ -511,16 +426,6 @@ Get a string phrase for the current time of day
|
||||
|
||||
`string`
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.partOfDay(timeString, today)
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.partOfDay('13:00') // => 'Afternoon'
|
||||
```
|
||||
|
||||
#### Defined in
|
||||
|
||||
partOfDay.ts:11
|
||||
@ -533,6 +438,10 @@ ___
|
||||
|
||||
Throttle the calling of a function
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.throttle(callback, limit)
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
@ -544,58 +453,28 @@ Throttle the calling of a function
|
||||
|
||||
`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
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.toHour(currentTimsestamp, extra)
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.toHour('13:00') // => 1605532173
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Default value |
|
||||
@ -609,16 +488,6 @@ Return the number of Milliseconds to the hour for the supplied timestamp
|
||||
|
||||
*
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.toHour(currentTimsestamp, extra)
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.toHour('13:00') // => 1605532173
|
||||
```
|
||||
|
||||
#### Defined in
|
||||
|
||||
toHour.ts:12
|
||||
|
@ -45,7 +45,7 @@ limitedArray.ts:10
|
||||
|
||||
### \_array
|
||||
|
||||
• **\_array**: `unknown`[]
|
||||
• **\_array**: `any`[]
|
||||
|
||||
#### Defined in
|
||||
|
||||
@ -73,7 +73,7 @@ Bulk add an array to the array
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `items` | `unknown`[] |
|
||||
| `items` | `any`[] |
|
||||
|
||||
#### Returns
|
||||
|
||||
@ -87,13 +87,13 @@ ___
|
||||
|
||||
### get
|
||||
|
||||
▸ **get**(): `unknown`[]
|
||||
▸ **get**(): `any`[]
|
||||
|
||||
Return the items within the array
|
||||
|
||||
#### Returns
|
||||
|
||||
`unknown`[]
|
||||
`any`[]
|
||||
|
||||
#### Defined in
|
||||
|
||||
@ -149,7 +149,7 @@ Add items to the end of an array
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `item` | `unknown` |
|
||||
| `item` | `any` |
|
||||
|
||||
#### Returns
|
||||
|
||||
@ -163,13 +163,13 @@ ___
|
||||
|
||||
### shift
|
||||
|
||||
▸ **shift**(): `unknown`
|
||||
▸ **shift**(): `any`
|
||||
|
||||
Remove an item from the beginning of an array
|
||||
|
||||
#### Returns
|
||||
|
||||
`unknown`
|
||||
`any`
|
||||
|
||||
#### Defined in
|
||||
|
||||
|
375
docs/modules.md
375
docs/modules.md
@ -24,14 +24,10 @@
|
||||
- [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
|
||||
@ -52,23 +48,23 @@ LocalStorage.ts:44
|
||||
|
||||
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]
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `jsonObj` | `Object` | The Original object |
|
||||
| `wantedFields` | `string`[] | The required fields |
|
||||
|
||||
#### Returns
|
||||
|
||||
`any`[]
|
||||
|
||||
#### Defined in
|
||||
|
||||
arrayFromObj.ts:9
|
||||
@ -81,6 +77,10 @@ ___
|
||||
|
||||
Debounce the calling of a function
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.debounce(fn, time)
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
@ -92,10 +92,6 @@ Debounce the calling of a function
|
||||
|
||||
`Function`
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.debounce(fn, time)
|
||||
|
||||
#### Defined in
|
||||
|
||||
debounce.ts:12
|
||||
@ -108,6 +104,16 @@ ___
|
||||
|
||||
Calculate the distance between two lat long points
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.distance(lat1, long1, lat2, long2)
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
distance(1, 1, 2, 2) // => 157.22543203805722;
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
@ -121,16 +127,6 @@ Calculate the distance between two lat long points
|
||||
|
||||
`number`
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.distance(lat1, long1, lat2, long2)
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
distance(1, 1, 2, 2) // => 157.22543203805722;
|
||||
```
|
||||
|
||||
#### Defined in
|
||||
|
||||
distance.ts:16
|
||||
@ -139,17 +135,6 @@ distance.ts:16
|
||||
|
||||
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)
|
||||
@ -162,6 +147,17 @@ const a: U.LatLong = new LatLong(1, 1);
|
||||
U.distance(a, b) // => 157.22543203805722
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `latLong1` | [`LatLong`](./docs/classes/LatLong.md) |
|
||||
| `latLong2` | [`LatLong`](./docs/classes/LatLong.md) |
|
||||
|
||||
#### Returns
|
||||
|
||||
`number`
|
||||
|
||||
#### Defined in
|
||||
|
||||
distance.ts:33
|
||||
@ -170,21 +166,10 @@ ___
|
||||
|
||||
### extractFromObj
|
||||
|
||||
▸ **extractFromObj**(`jsonObj`, `wantedFields`): `object`
|
||||
▸ **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)
|
||||
@ -195,6 +180,17 @@ U.extractFromObj(jsonObj, wantedFields)
|
||||
U.extractFromObj({ a: 1, b: 2 }, ['a']) // => { a: 1 }
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `jsonObj` | `Object` | The source object |
|
||||
| `wantedFields` | `string`[] | The required fields |
|
||||
|
||||
#### Returns
|
||||
|
||||
`Object`
|
||||
|
||||
#### Defined in
|
||||
|
||||
extractFromObj.ts:12
|
||||
@ -203,28 +199,28 @@ ___
|
||||
|
||||
### get
|
||||
|
||||
▸ **get**(`obj`, `path`, `defaultValue?`): `unknown`
|
||||
▸ **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` | `unknown` | `undefined` | A default value to be returned |
|
||||
|
||||
#### Returns
|
||||
|
||||
`unknown`
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.get({ a: 1, b: 2 }, 'b') // => 2
|
||||
```
|
||||
|
||||
#### 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`
|
||||
|
||||
#### Defined in
|
||||
|
||||
get.ts:10
|
||||
@ -260,23 +256,23 @@ ___
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `obj` | `Object` | The source object |
|
||||
| `prop` | `string` | The required property |
|
||||
|
||||
#### Returns
|
||||
|
||||
`boolean`
|
||||
|
||||
#### Defined in
|
||||
|
||||
hasOwn.ts:12
|
||||
@ -289,6 +285,12 @@ ___
|
||||
|
||||
Get the hour floor as a Base 32 string
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.hourFloor(1605532173) // => '1fnp540'
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
@ -299,12 +301,6 @@ Get the hour floor as a Base 32 string
|
||||
|
||||
`string`
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.hourFloor(1605532173) // => '1fnp540'
|
||||
```
|
||||
|
||||
#### Defined in
|
||||
|
||||
hourFloor.ts:10
|
||||
@ -317,16 +313,6 @@ ___
|
||||
|
||||
Check if an object is empty
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `obj` | `object` | The object being checked |
|
||||
|
||||
#### Returns
|
||||
|
||||
`boolean`
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
@ -334,39 +320,19 @@ 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` |
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `obj` | `Object` | The object being checked |
|
||||
|
||||
#### Returns
|
||||
|
||||
`string`
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.kebabCase('test string') // => 'test-string'
|
||||
U.kebabCase('testString') // => 'test-string'
|
||||
U.kebabCase('test_string') // => 'test-string'
|
||||
```
|
||||
`boolean`
|
||||
|
||||
#### Defined in
|
||||
|
||||
kebabCase.ts:10
|
||||
isEmpty.ts:9
|
||||
|
||||
___
|
||||
|
||||
@ -376,6 +342,17 @@ ___
|
||||
|
||||
Maybe pluralize a count:
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.maybePluralize(number, noun, suffix)
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.maybePluralize(1, 'Bag', 's') // => 1 Bag
|
||||
U.maybePluralize(5, 'Bag', 's') // => 5 Bags
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Default value | Description |
|
||||
@ -388,90 +365,22 @@ Maybe pluralize a count:
|
||||
|
||||
`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
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.once(fn)
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
@ -482,10 +391,6 @@ Trigger a function once and then prevent it from triggering again
|
||||
|
||||
`Function`
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.once(fn)
|
||||
|
||||
#### Defined in
|
||||
|
||||
once.ts:9
|
||||
@ -498,6 +403,16 @@ ___
|
||||
|
||||
Get a string phrase for the current time of day
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.partOfDay(timeString, today)
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.partOfDay('13:00') // => 'Afternoon'
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Default value |
|
||||
@ -509,16 +424,6 @@ Get a string phrase for the current time of day
|
||||
|
||||
`string`
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.partOfDay(timeString, today)
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.partOfDay('13:00') // => 'Afternoon'
|
||||
```
|
||||
|
||||
#### Defined in
|
||||
|
||||
partOfDay.ts:11
|
||||
@ -531,6 +436,10 @@ ___
|
||||
|
||||
Throttle the calling of a function
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.throttle(callback, limit)
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
@ -542,58 +451,28 @@ Throttle the calling of a function
|
||||
|
||||
`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
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.toHour(currentTimsestamp, extra)
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.toHour('13:00') // => 1605532173
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Default value |
|
||||
@ -607,16 +486,6 @@ Return the number of Milliseconds to the hour for the supplied timestamp
|
||||
|
||||
*
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.toHour(currentTimsestamp, extra)
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.toHour('13:00') // => 1605532173
|
||||
```
|
||||
|
||||
#### Defined in
|
||||
|
||||
toHour.ts:12
|
||||
|
5378
package-lock.json
generated
5378
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
25
package.json
25
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@rakh/utils",
|
||||
"version": "2.0.22",
|
||||
"version": "2.0.14",
|
||||
"main": "dist/commonjs/index.js",
|
||||
"types": "dist/commonjs/index.d.ts",
|
||||
"module": "dist/es/index.js",
|
||||
@ -35,22 +35,19 @@
|
||||
"author": "Martin Donnelly",
|
||||
"license": "ISC",
|
||||
"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",
|
||||
"@types/jest": "^29.5.0",
|
||||
"@types/sinon": "^10.0.13",
|
||||
"grunt": "^1.6.1",
|
||||
"jest": "^29.7.0",
|
||||
"marked": "^9.0.3",
|
||||
"prettier": "^3.0.3",
|
||||
"jest": "^29.5.0",
|
||||
"marked": "^4.3.0",
|
||||
"prettier": "^2.8.7",
|
||||
"save": "^2.9.0",
|
||||
"sinon": "^16.0.0",
|
||||
"ts-jest": "^29.1.1",
|
||||
"sinon": "^15.0.3",
|
||||
"ts-jest": "^29.1.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"typedoc": "^0.25.1",
|
||||
"typedoc-plugin-markdown": "^3.16.0",
|
||||
"typescript": "^5.2.2",
|
||||
"typedoc": "^0.23.28",
|
||||
"typedoc-plugin-markdown": "^3.14.0",
|
||||
"typescript": "^5.0.3",
|
||||
"vik": "^0.4.0"
|
||||
},
|
||||
"description": "",
|
||||
|
3817
pnpm-lock.yaml
3817
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
375
readme.MD
375
readme.MD
@ -24,14 +24,10 @@
|
||||
- [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
|
||||
@ -52,23 +48,23 @@ LocalStorage.ts:44
|
||||
|
||||
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]
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `jsonObj` | `Object` | The Original object |
|
||||
| `wantedFields` | `string`[] | The required fields |
|
||||
|
||||
#### Returns
|
||||
|
||||
`any`[]
|
||||
|
||||
#### Defined in
|
||||
|
||||
arrayFromObj.ts:9
|
||||
@ -81,6 +77,10 @@ ___
|
||||
|
||||
Debounce the calling of a function
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.debounce(fn, time)
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
@ -92,10 +92,6 @@ Debounce the calling of a function
|
||||
|
||||
`Function`
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.debounce(fn, time)
|
||||
|
||||
#### Defined in
|
||||
|
||||
debounce.ts:12
|
||||
@ -108,6 +104,16 @@ ___
|
||||
|
||||
Calculate the distance between two lat long points
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.distance(lat1, long1, lat2, long2)
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
distance(1, 1, 2, 2) // => 157.22543203805722;
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
@ -121,16 +127,6 @@ Calculate the distance between two lat long points
|
||||
|
||||
`number`
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.distance(lat1, long1, lat2, long2)
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
distance(1, 1, 2, 2) // => 157.22543203805722;
|
||||
```
|
||||
|
||||
#### Defined in
|
||||
|
||||
distance.ts:16
|
||||
@ -139,17 +135,6 @@ distance.ts:16
|
||||
|
||||
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)
|
||||
@ -162,6 +147,17 @@ const a: U.LatLong = new LatLong(1, 1);
|
||||
U.distance(a, b) // => 157.22543203805722
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `latLong1` | [`LatLong`](./docs/classes/LatLong.md) |
|
||||
| `latLong2` | [`LatLong`](./docs/classes/LatLong.md) |
|
||||
|
||||
#### Returns
|
||||
|
||||
`number`
|
||||
|
||||
#### Defined in
|
||||
|
||||
distance.ts:33
|
||||
@ -170,21 +166,10 @@ ___
|
||||
|
||||
### extractFromObj
|
||||
|
||||
▸ **extractFromObj**(`jsonObj`, `wantedFields`): `object`
|
||||
▸ **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)
|
||||
@ -195,6 +180,17 @@ U.extractFromObj(jsonObj, wantedFields)
|
||||
U.extractFromObj({ a: 1, b: 2 }, ['a']) // => { a: 1 }
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `jsonObj` | `Object` | The source object |
|
||||
| `wantedFields` | `string`[] | The required fields |
|
||||
|
||||
#### Returns
|
||||
|
||||
`Object`
|
||||
|
||||
#### Defined in
|
||||
|
||||
extractFromObj.ts:12
|
||||
@ -203,28 +199,28 @@ ___
|
||||
|
||||
### get
|
||||
|
||||
▸ **get**(`obj`, `path`, `defaultValue?`): `unknown`
|
||||
▸ **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` | `unknown` | `undefined` | A default value to be returned |
|
||||
|
||||
#### Returns
|
||||
|
||||
`unknown`
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.get({ a: 1, b: 2 }, 'b') // => 2
|
||||
```
|
||||
|
||||
#### 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`
|
||||
|
||||
#### Defined in
|
||||
|
||||
get.ts:10
|
||||
@ -260,23 +256,23 @@ ___
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `obj` | `Object` | The source object |
|
||||
| `prop` | `string` | The required property |
|
||||
|
||||
#### Returns
|
||||
|
||||
`boolean`
|
||||
|
||||
#### Defined in
|
||||
|
||||
hasOwn.ts:12
|
||||
@ -289,6 +285,12 @@ ___
|
||||
|
||||
Get the hour floor as a Base 32 string
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.hourFloor(1605532173) // => '1fnp540'
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
@ -299,12 +301,6 @@ Get the hour floor as a Base 32 string
|
||||
|
||||
`string`
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.hourFloor(1605532173) // => '1fnp540'
|
||||
```
|
||||
|
||||
#### Defined in
|
||||
|
||||
hourFloor.ts:10
|
||||
@ -317,16 +313,6 @@ ___
|
||||
|
||||
Check if an object is empty
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `obj` | `object` | The object being checked |
|
||||
|
||||
#### Returns
|
||||
|
||||
`boolean`
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
@ -334,39 +320,19 @@ 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` |
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `obj` | `Object` | The object being checked |
|
||||
|
||||
#### Returns
|
||||
|
||||
`string`
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.kebabCase('test string') // => 'test-string'
|
||||
U.kebabCase('testString') // => 'test-string'
|
||||
U.kebabCase('test_string') // => 'test-string'
|
||||
```
|
||||
`boolean`
|
||||
|
||||
#### Defined in
|
||||
|
||||
kebabCase.ts:10
|
||||
isEmpty.ts:9
|
||||
|
||||
___
|
||||
|
||||
@ -376,6 +342,17 @@ ___
|
||||
|
||||
Maybe pluralize a count:
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.maybePluralize(number, noun, suffix)
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.maybePluralize(1, 'Bag', 's') // => 1 Bag
|
||||
U.maybePluralize(5, 'Bag', 's') // => 5 Bags
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Default value | Description |
|
||||
@ -388,90 +365,22 @@ Maybe pluralize a count:
|
||||
|
||||
`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
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.once(fn)
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
@ -482,10 +391,6 @@ Trigger a function once and then prevent it from triggering again
|
||||
|
||||
`Function`
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.once(fn)
|
||||
|
||||
#### Defined in
|
||||
|
||||
once.ts:9
|
||||
@ -498,6 +403,16 @@ ___
|
||||
|
||||
Get a string phrase for the current time of day
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.partOfDay(timeString, today)
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.partOfDay('13:00') // => 'Afternoon'
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Default value |
|
||||
@ -509,16 +424,6 @@ Get a string phrase for the current time of day
|
||||
|
||||
`string`
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.partOfDay(timeString, today)
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.partOfDay('13:00') // => 'Afternoon'
|
||||
```
|
||||
|
||||
#### Defined in
|
||||
|
||||
partOfDay.ts:11
|
||||
@ -531,6 +436,10 @@ ___
|
||||
|
||||
Throttle the calling of a function
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.throttle(callback, limit)
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
@ -542,58 +451,28 @@ Throttle the calling of a function
|
||||
|
||||
`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
|
||||
|
||||
**`Signature`**
|
||||
|
||||
U.toHour(currentTimsestamp, extra)
|
||||
|
||||
**`Example`**
|
||||
|
||||
```ts
|
||||
U.toHour('13:00') // => 1605532173
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Default value |
|
||||
@ -607,16 +486,6 @@ Return the number of Milliseconds to the hour for the supplied timestamp
|
||||
|
||||
*
|
||||
|
||||
**`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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user