2.0.26 • Published 8 months ago

@rakh/utils v2.0.26

Weekly downloads
1
License
ISC
Repository
-
Last release
8 months ago

@rakh/utils / Exports

@rakh/utils

Table of contents

Classes

Variables

Functions

Variables

LocalStorage

LocalStorage: Object = _LocalStorage

Defined in

LocalStorage.ts:44

Functions

arrayFromObj

arrayFromObj(jsonObj, wantedFields): any[]

Create an array from an Object using specified fields

Parameters

NameTypeDescription
jsonObjobjectThe Original object
wantedFieldsstring[]The required fields

Returns

any[]

Example

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

Defined in

arrayFromObj.ts:9


debounce

debounce(fn, time): Function

Debounce the calling of a function

Parameters

NameTypeDescription
fnFunctionThe function to be debounced
timenumberHow long to wait

Returns

Function

Signature

U.debounce(fn, time)

Defined in

debounce.ts:12


distance

distance(lat1, lon1, lat2, lon2): number

Calculate the distance between two lat long points

Parameters

NameType
lat1number
lon1number
lat2number
lon2number

Returns

number

Signature

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

Example

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

Defined in

distance.ts:16

distance(latLong1, latLong2): number

Calculate the distance between two lat long points

Parameters

NameType
latLong1LatLong
latLong2LatLong

Returns

number

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

Defined in

distance.ts:33


extractFromObj

extractFromObj(jsonObj, wantedFields): object

Extract an object from another object using specific fields

Parameters

NameTypeDescription
jsonObjobjectThe source object
wantedFieldsstring[]The required fields

Returns

object

Signature

U.extractFromObj(jsonObj, wantedFields)

Example

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

Defined in

extractFromObj.ts:12


get

get(obj, path, defaultValue?): any

Get the value of an item inside an object

Parameters

NameTypeDefault valueDescription
objobjectundefinedThe source object
pathstringundefinedThe path to the object
defaultValueanyundefinedA default value to be returned

Returns

any

Example

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

Defined in

get.ts:10


getDays

getDays(startdate, enddate): number

Get number of days between two Date objects

Parameters

NameType
startdateDate
enddateDate

Returns

number

Defined in

getDays.ts:7


hasOwn

hasOwn(obj, prop): boolean

Check if an object has an property

Parameters

NameTypeDescription
objobjectThe source object
propstringThe required property

Returns

boolean

Example

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

Defined in

hasOwn.ts:12


hourFloor

hourFloor(timestamp): string

Get the hour floor as a Base 32 string

Parameters

NameTypeDescription
timestampnumberThe timestamp as a number

Returns

string

Example

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

Defined in

hourFloor.ts:10


isEmpty

isEmpty(obj): boolean

Check if an object is empty

Parameters

NameTypeDescription
objobjectThe object being checked

Returns

boolean

Example

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

NameType
invalnull | string

Returns

string

Example

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

Defined in

kebabCase.ts:10


linuxTimestamp

linuxTimestamp(): number

Get the current timestamp in linux ( seconds ) format

Returns

number

Defined in

linuxTimestamp.ts:4


maybePluralize

maybePluralize(count, noun, suffix?): string

Maybe pluralize a count:

Parameters

NameTypeDefault valueDescription
countnumberundefinedthe value counting
nounstringundefinedthe name of the value
suffixstring's'the suffix

Returns

string

Signature

U.maybePluralize(number, noun, suffix)

Example

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

NameTypeDescription
startingObjobjectThe original source object to be merged into
newObjobjectThe new incoming data

Returns

object

Signature

U.mergeWithoutNulls(startingObj, newObj)

Example

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

NameTypeDescription
timestamp?null | numberThe timestamp as a number

Returns

string

Example

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

Defined in

minuteFloor.ts:10


once

once(fn): Function

Trigger a function once and then prevent it from triggering again

Parameters

NameType
fnFunction

Returns

Function

Signature

U.once(fn)

Defined in

once.ts:9


partOfDay

partOfDay(timeString, today?): string

Get a string phrase for the current time of day

Parameters

NameTypeDefault value
timeStringstringundefined
todaybooleanfalse

Returns

string

Signature

U.partOfDay(timeString, today)

Example

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

Defined in

partOfDay.ts:11


throttle

throttle(callback, limit): Function

Throttle the calling of a function

Parameters

NameType
callbackFunction
limitnumber

Returns

Function

Signature

U.throttle(callback, limit)

Defined in

throttle.ts:10


timeToMilliseconds

timeToMilliseconds(inTime?): number

Get milliseconds from a string of time sections

Parameters

NameTypeDefault valueDescription
inTimestring''*

Returns

number

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

Defined in

timeToMilliseconds.ts:31


toHour

toHour(currentTimsestamp, extra?): number

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

Parameters

NameTypeDefault value
currentTimsestampnumberundefined
extranumber0

Returns

number

*

Signature

U.toHour(currentTimsestamp, extra)

Example

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

Defined in

toHour.ts:12

2.0.26

8 months ago

2.0.24

8 months ago

2.0.25

8 months ago

2.0.22

8 months ago

2.0.23

8 months ago

2.0.18

1 year ago

2.0.16

1 year ago

2.0.20

1 year ago

2.0.14

1 year ago

2.0.12

1 year ago

2.0.10

1 year ago

2.0.8

2 years ago

2.0.7

2 years ago

2.0.6

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

1.0.0

4 years ago