docs | ||
scripts | ||
src | ||
ts-src | ||
.editorconfig | ||
.eslintrc.json | ||
.gitignore | ||
.prettierrc | ||
.travis.yml | ||
out.json | ||
package-lock.json | ||
package.json | ||
readme.MD | ||
rollup.config.js | ||
tsconfig.json |
@rakh/utils / Exports
@rakh/utils
Table of contents
Classes
Variables
Functions
- arrayFromObj
- debounce
- distance
- extractFromObj
- get
- getDays
- hasOwn
- hourFloor
- isEmpty
- maybePluralize
- once
- partOfDay
- throttle
- toHour
Variables
LocalStorage
• LocalStorage: Object
= _LocalStorage
Defined in
LocalStorage.ts:44
Functions
arrayFromObj
▸ arrayFromObj(jsonObj
, wantedFields
): any
[]
Create an array from an Object using specified fields
Example
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
debounce
▸ debounce(fn
, time
): Function
Debounce the calling of a function
Signature
U.debounce(fn, time)
Parameters
Name | Type | Description |
---|---|---|
fn |
Function |
The function to be debounced |
time |
number |
How long to wait |
Returns
Function
Defined in
debounce.ts:12
distance
▸ distance(lat1
, lon1
, lat2
, lon2
): number
Calculate the distance between two lat long points
Signature
U.distance(lat1, long1, lat2, long2)
Example
distance(1, 1, 2, 2) // => 157.22543203805722;
Parameters
Name | Type |
---|---|
lat1 |
number |
lon1 |
number |
lat2 |
number |
lon2 |
number |
Returns
number
Defined in
distance.ts:16
▸ distance(latLong1
, latLong2
): number
Calculate the distance between two lat long points
Signature
U.distance(latLong1, latLong2)
Example
const a: U.LatLong = new LatLong(1, 1);
const b: U.LatLong = new LatLong(2, 2);
U.distance(a, b) // => 157.22543203805722
Parameters
Name | Type |
---|---|
latLong1 |
LatLong |
latLong2 |
LatLong |
Returns
number
Defined in
distance.ts:33
extractFromObj
▸ extractFromObj(jsonObj
, wantedFields
): Object
Extract an object from another object using specific fields
Signature
U.extractFromObj(jsonObj, wantedFields)
Example
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
get
▸ get(obj
, path
, defaultValue?
): any
Get the value of an item inside an object
Example
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
getDays
▸ getDays(startdate
, enddate
): number
Get number of days between two Date objects
Parameters
Name | Type |
---|---|
startdate |
Date |
enddate |
Date |
Returns
number
Defined in
getDays.ts:7
hasOwn
▸ hasOwn(obj
, prop
): boolean
Check if an object has an property
Example
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
hourFloor
▸ hourFloor(timestamp
): string
Get the hour floor as a Base 32 string
Example
U.hourFloor(1605532173) // => '1fnp540'
Parameters
Name | Type | Description |
---|---|---|
timestamp |
number |
The timestamp as a number |
Returns
string
Defined in
hourFloor.ts:10
isEmpty
▸ isEmpty(obj
): boolean
Check if an object is empty
Example
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
maybePluralize
▸ maybePluralize(count
, noun
, suffix?
): string
Maybe pluralize a count:
Signature
U.maybePluralize(number, noun, suffix)
Example
U.maybePluralize(1, 'Bag', 's') // => 1 Bag
U.maybePluralize(5, 'Bag', 's') // => 5 Bags
Parameters
Name | Type | Default value | Description |
---|---|---|---|
count |
number |
undefined |
the value counting |
noun |
string |
undefined |
the name of the value |
suffix |
string |
's' |
the suffix |
Returns
string
Defined in
maybePluralize.ts:16
once
▸ once(fn
): Function
Trigger a function once and then prevent it from triggering again
Signature
U.once(fn)
Parameters
Name | Type |
---|---|
fn |
Function |
Returns
Function
Defined in
once.ts:9
partOfDay
▸ partOfDay(timeString
, today?
): string
Get a string phrase for the current time of day
Signature
U.partOfDay(timeString, today)
Example
U.partOfDay('13:00') // => 'Afternoon'
Parameters
Name | Type | Default value |
---|---|---|
timeString |
string |
undefined |
today |
boolean |
false |
Returns
string
Defined in
partOfDay.ts:11
throttle
▸ throttle(callback
, limit
): Function
Throttle the calling of a function
Signature
U.throttle(callback, limit)
Parameters
Name | Type |
---|---|
callback |
Function |
limit |
number |
Returns
Function
Defined in
throttle.ts:10
toHour
▸ toHour(currentTimsestamp
, extra?
): number
Return the number of Milliseconds to the hour for the supplied timestamp
Signature
U.toHour(currentTimsestamp, extra)
Example
U.toHour('13:00') // => 1605532173
Parameters
Name | Type | Default value |
---|---|---|
currentTimsestamp |
number |
undefined |
extra |
number |
0 |
Returns
number
Defined in
toHour.ts:12