V2.0.22 added mergeWithoutNulls, minuteFloor, kebabCase

This commit is contained in:
Martin Donnelly 2023-10-03 12:25:22 +01:00
parent db49633a1c
commit 8bdb4a5c6d
13 changed files with 4890 additions and 1828 deletions

View File

@ -26,10 +26,14 @@
- [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
@ -50,23 +54,23 @@ LocalStorage.ts:44
Create an array from an Object using specified fields
**`Example`**
```ts
U.arrayFromObj({ a: 1, b: 2 }, ['a', 'b']) // => [1, 2]
```
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `jsonObj` | `Object` | The Original object |
| `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
@ -79,10 +83,6 @@ ___
Debounce the calling of a function
**`Signature`**
U.debounce(fn, time)
#### Parameters
| Name | Type | Description |
@ -94,6 +94,10 @@ U.debounce(fn, time)
`Function`
**`Signature`**
U.debounce(fn, time)
#### Defined in
debounce.ts:12
@ -106,16 +110,6 @@ ___
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 |
@ -129,6 +123,16 @@ distance(1, 1, 2, 2) // => 157.22543203805722;
`number`
**`Signature`**
U.distance(lat1, long1, lat2, long2)
**`Example`**
```ts
distance(1, 1, 2, 2) // => 157.22543203805722;
```
#### Defined in
distance.ts:16
@ -137,6 +141,17 @@ 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)
@ -149,17 +164,6 @@ 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
@ -168,10 +172,21 @@ ___
### 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)
@ -182,17 +197,6 @@ 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
@ -201,28 +205,28 @@ ___
### get
**get**(`obj`, `path`, `defaultValue?`): `any`
**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
```
#### 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
@ -258,23 +262,23 @@ ___
Check if an object has an property
**`Example`**
```ts
U.hasOwn({bob:'1'}, 'bob') // => true
```
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `obj` | `Object` | The source object |
| `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
@ -287,12 +291,6 @@ ___
Get the hour floor as a Base 32 string
**`Example`**
```ts
U.hourFloor(1605532173) // => '1fnp540'
```
#### Parameters
| Name | Type | Description |
@ -303,6 +301,12 @@ U.hourFloor(1605532173) // => '1fnp540'
`string`
**`Example`**
```ts
U.hourFloor(1605532173) // => '1fnp540'
```
#### Defined in
hourFloor.ts:10
@ -315,6 +319,16 @@ ___
Check if an object is empty
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `obj` | `object` | The object being checked |
#### Returns
`boolean`
**`Example`**
```ts
@ -322,39 +336,48 @@ U.isEmpty({}) // => true
U.isEmpty({ bob: true }) // => false
```
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `obj` | `Object` | The object being checked |
#### Returns
`boolean`
#### 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:
**`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 |
@ -367,22 +390,90 @@ U.maybePluralize(1, 'Bag', 's') // => 1 Bag
`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 |
@ -393,6 +484,10 @@ U.once(fn)
`Function`
**`Signature`**
U.once(fn)
#### Defined in
once.ts:9
@ -405,16 +500,6 @@ ___
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 |
@ -426,6 +511,16 @@ U.partOfDay('13:00') // => 'Afternoon'
`string`
**`Signature`**
U.partOfDay(timeString, today)
**`Example`**
```ts
U.partOfDay('13:00') // => 'Afternoon'
```
#### Defined in
partOfDay.ts:11
@ -438,10 +533,6 @@ ___
Throttle the calling of a function
**`Signature`**
U.throttle(callback, limit)
#### Parameters
| Name | Type |
@ -453,28 +544,58 @@ U.throttle(callback, limit)
`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 |
@ -488,6 +609,16 @@ U.toHour('13:00') // => 1605532173
*
**`Signature`**
U.toHour(currentTimsestamp, extra)
**`Example`**
```ts
U.toHour('13:00') // => 1605532173
```
#### Defined in
toHour.ts:12

View File

@ -45,7 +45,7 @@ limitedArray.ts:10
### \_array
**\_array**: `any`[]
**\_array**: `unknown`[]
#### Defined in
@ -73,7 +73,7 @@ Bulk add an array to the array
| Name | Type |
| :------ | :------ |
| `items` | `any`[] |
| `items` | `unknown`[] |
#### Returns
@ -87,13 +87,13 @@ ___
### get
**get**(): `any`[]
**get**(): `unknown`[]
Return the items within the array
#### Returns
`any`[]
`unknown`[]
#### Defined in
@ -149,7 +149,7 @@ Add items to the end of an array
| Name | Type |
| :------ | :------ |
| `item` | `any` |
| `item` | `unknown` |
#### Returns
@ -163,13 +163,13 @@ ___
### shift
**shift**(): `any`
**shift**(): `unknown`
Remove an item from the beginning of an array
#### Returns
`any`
`unknown`
#### Defined in

View File

@ -24,10 +24,14 @@
- [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
@ -48,23 +52,23 @@ LocalStorage.ts:44
Create an array from an Object using specified fields
**`Example`**
```ts
U.arrayFromObj({ a: 1, b: 2 }, ['a', 'b']) // => [1, 2]
```
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `jsonObj` | `Object` | The Original object |
| `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
@ -77,10 +81,6 @@ ___
Debounce the calling of a function
**`Signature`**
U.debounce(fn, time)
#### Parameters
| Name | Type | Description |
@ -92,6 +92,10 @@ U.debounce(fn, time)
`Function`
**`Signature`**
U.debounce(fn, time)
#### Defined in
debounce.ts:12
@ -104,16 +108,6 @@ ___
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 |
@ -127,6 +121,16 @@ distance(1, 1, 2, 2) // => 157.22543203805722;
`number`
**`Signature`**
U.distance(lat1, long1, lat2, long2)
**`Example`**
```ts
distance(1, 1, 2, 2) // => 157.22543203805722;
```
#### Defined in
distance.ts:16
@ -135,6 +139,17 @@ 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)
@ -147,17 +162,6 @@ 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
@ -166,10 +170,21 @@ ___
### 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)
@ -180,17 +195,6 @@ 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
@ -199,28 +203,28 @@ ___
### get
**get**(`obj`, `path`, `defaultValue?`): `any`
**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
```
#### 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
@ -256,23 +260,23 @@ ___
Check if an object has an property
**`Example`**
```ts
U.hasOwn({bob:'1'}, 'bob') // => true
```
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `obj` | `Object` | The source object |
| `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
@ -285,12 +289,6 @@ ___
Get the hour floor as a Base 32 string
**`Example`**
```ts
U.hourFloor(1605532173) // => '1fnp540'
```
#### Parameters
| Name | Type | Description |
@ -301,6 +299,12 @@ U.hourFloor(1605532173) // => '1fnp540'
`string`
**`Example`**
```ts
U.hourFloor(1605532173) // => '1fnp540'
```
#### Defined in
hourFloor.ts:10
@ -313,6 +317,16 @@ ___
Check if an object is empty
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `obj` | `object` | The object being checked |
#### Returns
`boolean`
**`Example`**
```ts
@ -320,39 +334,48 @@ U.isEmpty({}) // => true
U.isEmpty({ bob: true }) // => false
```
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `obj` | `Object` | The object being checked |
#### Returns
`boolean`
#### 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:
**`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 |
@ -365,22 +388,90 @@ U.maybePluralize(1, 'Bag', 's') // => 1 Bag
`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 |
@ -391,6 +482,10 @@ U.once(fn)
`Function`
**`Signature`**
U.once(fn)
#### Defined in
once.ts:9
@ -403,16 +498,6 @@ ___
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 |
@ -424,6 +509,16 @@ U.partOfDay('13:00') // => 'Afternoon'
`string`
**`Signature`**
U.partOfDay(timeString, today)
**`Example`**
```ts
U.partOfDay('13:00') // => 'Afternoon'
```
#### Defined in
partOfDay.ts:11
@ -436,10 +531,6 @@ ___
Throttle the calling of a function
**`Signature`**
U.throttle(callback, limit)
#### Parameters
| Name | Type |
@ -451,28 +542,58 @@ U.throttle(callback, limit)
`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 |
@ -486,6 +607,16 @@ U.toHour('13:00') // => 1605532173
*
**`Signature`**
U.toHour(currentTimsestamp, extra)
**`Example`**
```ts
U.toHour('13:00') // => 1605532173
```
#### Defined in
toHour.ts:12

5440
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@rakh/utils",
"version": "2.0.16",
"version": "2.0.22",
"main": "dist/commonjs/index.js",
"types": "dist/commonjs/index.d.ts",
"module": "dist/es/index.js",
@ -35,22 +35,22 @@
"author": "Martin Donnelly",
"license": "ISC",
"devDependencies": {
"@types/jest": "^29.5.0",
"@types/sinon": "^10.0.13",
"@typescript-eslint/eslint-plugin": "^5.59.1",
"@typescript-eslint/parser": "^5.59.1",
"@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.5.0",
"marked": "^4.3.0",
"prettier": "^2.8.7",
"jest": "^29.7.0",
"marked": "^9.0.3",
"prettier": "^3.0.3",
"save": "^2.9.0",
"sinon": "^15.0.3",
"ts-jest": "^29.1.0",
"sinon": "^16.0.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typedoc": "^0.23.28",
"typedoc-plugin-markdown": "^3.14.0",
"typescript": "^5.0.3",
"typedoc": "^0.25.1",
"typedoc-plugin-markdown": "^3.16.0",
"typescript": "^5.2.2",
"vik": "^0.4.0"
},
"description": "",

369
readme.MD
View File

@ -24,10 +24,14 @@
- [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
@ -48,23 +52,23 @@ LocalStorage.ts:44
Create an array from an Object using specified fields
**`Example`**
```ts
U.arrayFromObj({ a: 1, b: 2 }, ['a', 'b']) // => [1, 2]
```
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `jsonObj` | `Object` | The Original object |
| `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
@ -77,10 +81,6 @@ ___
Debounce the calling of a function
**`Signature`**
U.debounce(fn, time)
#### Parameters
| Name | Type | Description |
@ -92,6 +92,10 @@ U.debounce(fn, time)
`Function`
**`Signature`**
U.debounce(fn, time)
#### Defined in
debounce.ts:12
@ -104,16 +108,6 @@ ___
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 |
@ -127,6 +121,16 @@ distance(1, 1, 2, 2) // => 157.22543203805722;
`number`
**`Signature`**
U.distance(lat1, long1, lat2, long2)
**`Example`**
```ts
distance(1, 1, 2, 2) // => 157.22543203805722;
```
#### Defined in
distance.ts:16
@ -135,6 +139,17 @@ 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)
@ -147,17 +162,6 @@ 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
@ -166,10 +170,21 @@ ___
### 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)
@ -180,17 +195,6 @@ 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
@ -199,28 +203,28 @@ ___
### get
▸ **get**(`obj`, `path`, `defaultValue?`): `any`
▸ **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
```
#### 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
@ -256,23 +260,23 @@ ___
Check if an object has an property
**`Example`**
```ts
U.hasOwn({bob:'1'}, 'bob') // => true
```
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `obj` | `Object` | The source object |
| `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
@ -285,12 +289,6 @@ ___
Get the hour floor as a Base 32 string
**`Example`**
```ts
U.hourFloor(1605532173) // => '1fnp540'
```
#### Parameters
| Name | Type | Description |
@ -301,6 +299,12 @@ U.hourFloor(1605532173) // => '1fnp540'
`string`
**`Example`**
```ts
U.hourFloor(1605532173) // => '1fnp540'
```
#### Defined in
hourFloor.ts:10
@ -313,6 +317,16 @@ ___
Check if an object is empty
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `obj` | `object` | The object being checked |
#### Returns
`boolean`
**`Example`**
```ts
@ -320,39 +334,48 @@ U.isEmpty({}) // => true
U.isEmpty({ bob: true }) // => false
```
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `obj` | `Object` | The object being checked |
#### Returns
`boolean`
#### 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:
**`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 |
@ -365,22 +388,90 @@ U.maybePluralize(1, 'Bag', 's') // => 1 Bag
`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 |
@ -391,6 +482,10 @@ U.once(fn)
`Function`
**`Signature`**
U.once(fn)
#### Defined in
once.ts:9
@ -403,16 +498,6 @@ ___
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 |
@ -424,6 +509,16 @@ U.partOfDay('13:00') // => 'Afternoon'
`string`
**`Signature`**
U.partOfDay(timeString, today)
**`Example`**
```ts
U.partOfDay('13:00') // => 'Afternoon'
```
#### Defined in
partOfDay.ts:11
@ -436,10 +531,6 @@ ___
Throttle the calling of a function
**`Signature`**
U.throttle(callback, limit)
#### Parameters
| Name | Type |
@ -451,28 +542,58 @@ U.throttle(callback, limit)
`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 |
@ -486,6 +607,16 @@ U.toHour('13:00') // => 1605532173
*
**`Signature`**
U.toHour(currentTimsestamp, extra)
**`Example`**
```ts
U.toHour('13:00') // => 1605532173
```
#### Defined in
toHour.ts:12

View File

@ -8,9 +8,12 @@ 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';

25
ts-src/kebabCase.test.ts Normal file
View File

@ -0,0 +1,25 @@
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');
});

23
ts-src/kebabCase.ts Normal file
View File

@ -0,0 +1,23 @@
/**
* 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;
}

View File

@ -0,0 +1,25 @@
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}));
});

View File

@ -0,0 +1,26 @@
/**
* 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;
}

View File

@ -0,0 +1,14 @@
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();
});

15
ts-src/minuteFloor.ts Normal file
View File

@ -0,0 +1,15 @@
/**
* 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);
}