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

jshelper

v1.0.22

Published

Some helper functions

Downloads

9

Readme

JsHelpers

Just some JsHelpers I made for myself.

npm install jshelper

Example

ES6

import JsHelper              = 'jshelper';
import Objects               = 'jshelper/Objects';
import { find }   = 'jshelper/Objects';

var data = {
    person: {
        name: 'Ray Davis',
        age: 23,
    },
    job: 'idk',
};

const _jsHelper         = JsHelper.Objects.find(data, 'person.name');
const _objects          = Objects.find(data, 'person.name');
const _valueFromObject  = find(data, 'person.name');

console.log(`JsHelper Output:           ${_jsHelper}`);
console.log(`Objects Output:            ${_objects}`);
console.log(`valueFromObject Output:    ${_valueFromObject}`);

Non ES6

const JsHelper              = require('jshelper').default;

API

JsHelper

JsHelper imports everything

Objects

find

This function search the item using a nexted string path

Parameters

  • item Object The object you want to search in
  • propertyName String The path to the value seperated by dots (.). (optional, default '')

Returns (any | undefined) The found value or nothing

Arrays

removeDupilcates

This function will remove all dupilcates from a array

Parameters

  • array Array The array to remove dupilcates from.

Returns Array The new array

sortObjects

This function will sort an array of objects no matter the depth

Parameters

  • array Array The array to sort
  • propertyName String The path to the value seperated by dots (.) (optional, default '')
  • config Object An object containing additional setting for the function (optional, default {})
    • config.caseSen string The type of case sensitive to use when sorting (optional, default 'lower')
    • config.asc boolean True for ascending and false for descending (optional, default true)

Returns Array The sorted array

filterObjects

This function will folter an array of objects no matter the depth

Parameters

  • array Array The array to filter
  • match string What you want to find (Currently only support string) Need support for number boolean and custom match function
  • propertyName string The path to the value seperate by dotes (.) (optional, default '')
  • config Object An object containing additional setting for the function (optional, default {})
    • config.caseSen string The type of case sensitive to use when sorting (optional, default 'lower')

Returns Array The flitered array

find

This function search the item using a nexted string path

Parameters

  • item Object The object you want to search in
  • propertyName String The path to the value seperated by dots (.). (optional, default '')

Returns (any | undefined) The found value or nothing

Dates

isValid

This function returns true if date is an instanceof Date

Parameters

  • date Date any object that is an instanceof Date

Returns boolean if the date is an instanceof Date

daysInMonth

This function returns the number of days in a month

Parameters

  • date Date any object that is an instanceof Date (optional, default new Date())

Returns (number | undefined) The number of days in month or undefined if date is no valid

getMonthBounds

This function returns the start and end dates of the month

Parameters

  • date Date any object that is an instanceof Date (optional, default new Date())

Returns (Object | undefined) A object containing the start and end dates or nothing

getWeekBounds

This function returns the start and end dates of the week

Parameters

  • date Date any object that is an instanceof Date (optional, default new Date())

Returns (Object | undefined) A object containing the start and end dates or nothing

getWeekBoundsCentered

This function returns the start and end dates of the week centered around the date

Parameters

  • date Date any object that is an instanceof Date (optional, default new Date())

Returns (Object | undefined) A object containing the start and end dates or nothing

getDayBounds

This function returns the start and end dates of the day

Parameters

  • date Date any object that is an instanceof Date (optional, default new Date())

Returns (Object | undefined) A object containing the start and end dates or nothing

addToDate

This function returns a new date with the additions

Parameters

  • config Object An object containing the fields and how much to add
    • config.years number The number of years to add (optional, default 0)
    • config.months number The number of months to add (optional, default 0)
    • config.days number The number of days to add (optional, default 0)
    • config.hours number The number of hours to add (optional, default 0)
    • config.minutes number The number of minutes to add (optional, default 0)
    • config.seconds number The number of seconds to add (optional, default 0)
    • config.milliseconds number The number of milliseconds to add (optional, default 0)
  • date Date any object that is an instanceof Date (optional, default new Date())

Returns (Date | undefined) A Date with the additions or nothing

addYears

This function returns a new Date with the added years

Parameters

  • years (optional, default 0)
  • date Date any object that is an instanceof Date (optional, default new Date())

Returns (Date | undefined) A new Date with the addition or nothing

addMonths

This function returns a new Date with the added months

Parameters

  • months (optional, default 0)
  • date Date any object that is an instanceof Date (optional, default new Date())

Returns (Date | undefined) A new Date with the addition or nothing

addWeeks

This function returns a new Date with the added weeks

Parameters

  • weeks (optional, default 0)
  • date Date any object that is an instanceof Date (optional, default new Date())

Returns (Date | undefined) A new Date with the addition or nothing

addDays

This function returns a new Date with the added days

Parameters

  • days (optional, default 0)
  • date Date any object that is an instanceof Date (optional, default new Date())

Returns (Date | undefined) A new Date with the addition or nothing

addHours

This function returns a new Date with the added hours

Parameters

  • hours (optional, default 0)
  • date Date any object that is an instanceof Date (optional, default new Date())

Returns (Date | undefined) A new Date with the addition or nothing

addMinutes

This function returns a new Date with the added minutes

Parameters

  • minutes (optional, default 0)
  • date Date any object that is an instanceof Date (optional, default new Date())

Returns (Date | undefined) A new Date with the addition or nothing

addSeconds

This function returns a new Date with the added seconds

Parameters

  • seconds (optional, default 0)
  • date Date any object that is an instanceof Date (optional, default new Date())

Returns (Date | undefined) A new Date with the addition or nothing

addMilliseconds

This function returns a new Date with the added milliseconds

Parameters

  • milliseconds (optional, default 0)
  • date Date any object that is an instanceof Date (optional, default new Date())

Returns (Date | undefined) A new Date with the addition or nothing