1.0.6 • Published 1 year ago

@oqton/utils-core v1.0.6

Weekly downloads
-
License
Copyright Oqton
Repository
-
Last release
1 year ago

utils-core

A collection of standard helpers: like lodash, nothing specific for Oqton

Modules

  • Date
  • Json
  • Math
  • Object
  • String

Scripts

"test"

Run the tests

yarn test

"lint"

Run lint

yarn lint

"fix-lint"

Run lint and attempt to automatically fix issues

yarn fix-lint

"check-formatting"

Run formatting check

yarn check-formatting

"fix-formatting"

Run formatter

yarn fix-formatting

Docs

Table of Contents

toBitMask

Return an array of ids into a bitmask. Each id has to be > 0 and <= maxValue

Parameters

Returns Int32Array

MS

File with helper functions to deal with datetime/date/time objects. E.g. calculate duration between datetimes, calculate end of day, ... Not to be used to define formatting of datetime objects.

Type: number

MS

1 millisecond

Type: number

SECOND_MS

1 second in milliseconds

Type: number

MINUTE_MS

1 minute in milliseconds

Type: number

HOUR_MS

1 hour in milliseconds

Type: number

DAY_MS

1 day in milliseconds

Type: number

toDateInputValue

Given date, return as RFC3339 valid date like 2011-09-29 Only used for html form date input

Parameters

  • date (string | Date | Milliseconds) or now (optional, default Date.now())

Returns string the given date (or now) as RFC3339 valid date like 2011-09-29

getTimeDurationInMs

Get the time duration in milliseconds

Parameters

Returns number

toEndOfTime

Get the ISO string of the end time based on type.

Parameters

Returns string

toStartOfTime

Get the ISO string of the start time based on type.

Parameters

Returns string

toStartOfTheDay

get the ISO string of the start time of the day

Parameters

Returns string

addDaysToNow

Add number of days to date

Parameters

Returns Date

addHoursToNow

Add number of hours to date

Parameters

Returns Date

getDaysArray

Get an array of dates between 2 dates

Parameters

Returns Array<Date>

getMinutesArray

Get all the hours between 2 dates

Parameters

Returns Array<Date>

getHoursArray

Get all the hours between 2 dates

Parameters

Returns Array<Date>

dateAndTimeToDate

Turn a date object and a time string ('01:23:45') into a single date object

Parameters

Returns (Date | undefined)

dateAndTimeToDateIgnoreTimezone

Turn a date object and a time string ('01:23:45') into a single date object

Parameters

Returns (Date | undefined)

isIntervalOverlapping

Given 2 intervals in milliseconds { startMillis, endMillis } compare to see if they overlap

Parameters

  • a Interval
  • b Interval

Returns boolean

convertToInterval

Converts { startTime: '2019-01-07T01:00:00.000Z', endTime: '2019-01-07T02:00:00.000Z' } to { startMillis:1546822800000, endMillis:1546826400000 }

Parameters

  • period Period

Returns Interval

splitOverlapping

Given a list of periods, split them in to arrays, pushing any overlapping periods down to the next level

Parameters

Returns Array<Array>

debugMode

Check if user has appended #debug to the url Or if server was started with DEBUG=true as command line variable

Returns boolean Returns true if user appended #debug to the url

shallowEqual

Check if two objects or arrays have the same keys and values.

Parameters

Returns boolean

isEqualIgnoringNull

Check if two objects or arrays are equal, but treat null values the same as undefined or not defined

Parameters

  • v any
  • o any

objectFromEntries

The inverse of Object.entries({a: 1, b: 2}). objectFromEntries(['a', 1, 'b', 2]) = {a: 1, b: 2}.

Parameters

recursiveObjectMap

Create a clone of an object tree and apply a function to each leaf.

Parameters

Returns Object

throwUndefinedProperties

Wraps an object so that accessing a non-existing property throws an error. ({a:1, b:2}).c returns undefined but throwUndefinedProperties({a:1, b:2}).c throws an error.

Parameters

  • object Object the object to wrap

Returns T

isAncestorOf

Check if one object (obj2) is nested in an other (obj1)

Parameters

Returns boolean

stripRootDot

A collection of functions that help with working with immutable JSON data.

Parameters

  • path Path

Returns Path

unify

Unify: accepts two jsons, and returns a json that is deepequal to the first, and shares as many objects as possible with the second.

Parameters

Returns M

allEqual

Check if all values in an array are the same

Parameters

traverse

Object tree traversal, execute fn on leaves https://gist.github.com/tushariscoolster/567c1d22ca8d5498cbc0

Parameters

  • obj object
  • fn function function that gets executed on leaf nodes of your object

pickDeep

Maintain the object structure but remove anything that does not include the given keys Similar to lodash pick https://lodash.com/docs/4.17.15#pick but for deep objects

Parameters

Returns object

isExternalLink

File with helper functions to deal with urls. E.g. check if a url is external.

Parameters

isExternalLink

Check if the given url is external

Parameters