npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@oqton/utils-core

v1.0.6

Published

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

Downloads

210

Readme

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

  • periods Array<Period> {Array} An array of periods [{ startTime: '2019-01-07T01:00:00.000Z', endTime: '2019-01-07T02:00:00.000Z' }] (optional, default [])

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