@rakh/utils
TypeScript icon, indicating that this package has built-in type declarations

2.0.26 • Public • Published

@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

Name Type Description
jsonObj object The Original object
wantedFields string[] 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

Name Type Description
fn Function The function to be debounced
time number How long to wait

Returns

Function

Signature

U.debounce(fn, time)

Defined in

debounce.ts:12


distance

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

Calculate the distance between two lat long points

Parameters

Name Type
lat1 number
lon1 number
lat2 number
lon2 number

Returns

number

Signature

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

Example

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

Defined in

distance.ts:16

distance(latLong1, latLong2): number

Calculate the distance between two lat long points

Parameters

Name Type
latLong1 LatLong
latLong2 LatLong

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

Name Type Description
jsonObj object The source object
wantedFields string[] 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

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

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

Name Type
startdate Date
enddate Date

Returns

number

Defined in

getDays.ts:7


hasOwn

hasOwn(obj, prop): boolean

Check if an object has an property

Parameters

Name Type Description
obj object The source object
prop string The required property

Returns

boolean

Example

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

Defined in

hasOwn.ts:12


hourFloor

hourFloor(timestamp): string

Get the hour floor as a Base 32 string

Parameters

Name Type Description
timestamp number The timestamp as a number

Returns

string

Example

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

Defined in

hourFloor.ts:10


isEmpty

isEmpty(obj): boolean

Check if an object is empty

Parameters

Name Type Description
obj object The object being checked

Returns

boolean

Example

U.isEmpty({}) // => true
   U.isEmpty({ bob: true }) // => false

Defined in

isEmpty.ts:9


kebabCase

kebabCase(inval): string

Turn a string into a kebab-case string

Parameters

Name Type
inval null | string

Returns

string

Example

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

Name Type Default value Description
count number undefined the value counting
noun string undefined the name of the value
suffix string 's' the suffix

Returns

string

Signature

U.maybePluralize(number, noun, suffix)

Example

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

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

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

Defined in

minuteFloor.ts:10


once

once(fn): Function

Trigger a function once and then prevent it from triggering again

Parameters

Name Type
fn Function

Returns

Function

Signature

U.once(fn)

Defined in

once.ts:9


partOfDay

partOfDay(timeString, today?): string

Get a string phrase for the current time of day

Parameters

Name Type Default value
timeString string undefined
today boolean false

Returns

string

Signature

U.partOfDay(timeString, today)

Example

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

Defined in

partOfDay.ts:11


throttle

throttle(callback, limit): Function

Throttle the calling of a function

Parameters

Name Type
callback Function
limit number

Returns

Function

Signature

U.throttle(callback, limit)

Defined in

throttle.ts:10


timeToMilliseconds

timeToMilliseconds(inTime?): number

Get milliseconds from a string of time sections

Parameters

Name Type Default value Description
inTime string '' *

Returns

number

Signature

U.timeToMilliseconds(inTime)

Example

U.timeToMilliseconds('1s')  // => 1000
   U.timeToMilliseconds('1min') // => 60000
   U.timeToMilliseconds('1 weeks') // => 604800000
   U.timeToMilliseconds('5y2w30d14h30m10s') // => 161641810000
   U.timeToMilliseconds('1 hour and 5 seconds') // => 3605000

Defined in

timeToMilliseconds.ts:31


toHour

toHour(currentTimsestamp, extra?): number

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

Parameters

Name Type Default value
currentTimsestamp number undefined
extra number 0

Returns

number

Signature

U.toHour(currentTimsestamp, extra)

Example

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

Defined in

toHour.ts:12

Readme

Keywords

none

Package Sidebar

Install

npm i @rakh/utils

Weekly Downloads

7

Version

2.0.26

License

ISC

Unpacked Size

98.3 kB

Total Files

145

Last publish

Collaborators

  • rakh