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 🙏

© 2025 – Pkg Stats / Ryan Hefner

silveress_custom

v3.0.20

Published

Custom functions that I have found useful

Downloads

234

Readme

Intro

pipeline status coverage report

My package for custom functions

Functions

Table of Contents

moduleTest

Testing if the module is working as planned

Returns string This is a successful test

cleanQuery

Cleans up a query object to work with my apis

Parameters

Returns object cleaned query

convertDate

Converts date to another format

Parameters

  • inputFormat string ISO date format
  • format string what you want (european/american)

Returns string converted date

IsJsonString

Checks if a particular string is json or not

Parameters

  • item object that you want to test

Returns boolean if the input is json or not

bumpRequests

Just capitalises the first letter of a string

Parameters

  • type string category that the particular request belongs to
  • requestsObject object input object

Returns object same format as the input object

capitalize

Just capitalises the first letter of a string

Parameters

Returns string capitalised string.

createRandomString

Creates a random string of specified length

Parameters

  • length number Input number (optional, default 50)

Returns string random string.

convertToGold

Converts a number to g/s/c format

Mostly used for GuildWars2

Parameters

  • number number Input number
  • shorten boolean cut off the trailing currency or not

Returns string formatted g/s/c.

beautifyJSON

This beautifies json depending on teh flag

Parameters

  • json string Input json
  • flag string Flag to expand it out or not (min/human)

Returns string Resulting json.

sorter

Function to sort array, need to pass in the strings directly

Parameters

Returns number Resulting order.

stringToNumber

Returns a number from a string

Strips out any non number characters and forces conversion

Parameters

Returns number Resulting number.

uniq

Returns an array of unique objects

Parameters

  • array array of the account

Returns array Unique items.

getNextUpdate

For Datawars2

Gets the next update based on the users level

Parameters

  • level string of the account
  • newAccount boolean is it a new account
  • mapping object an object mapping times to levels

Returns string ISO datestamp.

filterGeneralNumber

This function is a filter function for all numbers

Strips all non number characters

Parameters

  • item string item being filtered
  • filter string what the item is being filtered by
  • multiplier number what to multiply the filter quanty by

Returns boolean returns true or false.

filterGeneralText

This function is a filter function text

Converts all inputs to lowercase

Parameters

  • item string item being filtered
  • filter string what the item is being filtered by

Returns boolean returns true or false.

getURL

This function gets the specified url with options

Requires:

  • request-promise-native

Parameters

  • rp object request-promise-native object
  • url string url ye are requesting
  • options object? optional options

Returns object with headers, body and errors.

verifySession

Verifies sessionKey

Requires:

  • mongodb

Parameters

  • db object Mongodb instance
  • collection string Collection that you want to store the session data in (optional, default accounts_sessions)
  • session string user that the key is being generated for
  • req object request object

Returns string sessionKey.

createUniqueSession

Creates a sessionKey

Requires:

  • mongodb

Parameters

  • db object Mongodb instance
  • collection string Collection that you want to store the session data in (optional, default accounts_sessions)
  • user string user that the key is being generated for
  • req object request object
  • sessionKey string? sessionKey override used for testing

Returns string sessionKey.

sendPageView

This function gets sends a page view to google analytics

Requires:

  • universal-analytics
  • uuid-by-string

Parameters

Returns boolean

logToDB

Logs the specified message into the DB

Requires:

  • mongodb

Parameters

  • db object mongodb object
  • logCollection string? collection to put it into
  • type string category
  • location string subcategory
  • message string main message
  • misc object? object that contains other messages
  • consoleFlag boolean? log to console
  • maxSize number? size of collection

Returns null

dataToDbArray

Takes an array of objects and returns an object to insert them into a database

Parameters

  • data array array of objects
  • limit number? maximum amount to insert in one go
  • accessor string? accessor for the find query
  • setOnInsert object? accessor for the find query

Returns object

Functions_ext

Table of Contents

getURL

This function gets the specified url with options

Requires:

  • request-promise-native

Parameters

  • rp object request-promise-native object
  • url string url ye are requesting
  • options object optional options

Returns object with headers, body and errors.

verifySession

Verifies sessionKey

Requires:

  • mongodb

Parameters

  • db object Mongodb instance
  • collection string Collection that you want to store the session data in (optional, default accounts_sessions)
  • session string user that the key is being generated for
  • req object request object

Returns string sessionKey.

createUniqueSession

Creates a sessionKey

Requires:

  • mongodb

Parameters

  • db object Mongodb instance
  • collection string Collection that you want to store the session data in (optional, default accounts_sessions)
  • user string user that the key is being generated for
  • req object request object

Returns string sessionKey.

sendPageView

This function gets sends a page view to google analytics

Requires:

  • universal-analytics
  • uuid-by-string

Parameters

Returns null

moduleTest

Testing if the module is working as planned

Returns string This is a successful test

cleanQuery

Cleans up a query object to work with my apis

Parameters

Returns object cleaned query

convertDate

Converts date to another format

Parameters

  • inputFormat string ISO date format
  • format string what you want (european/american)

Returns string converted date

IsJsonString

Checks if a particular string is json or not

Parameters

  • item object that you want to test

Returns boolean if the input is json or not

bumpRequests

Just capitalises the first letter of a string

Parameters

  • type string category that the particular request belongs to
  • requestsObject object input object

Returns object same format as the input object

capitalize

Just capitalises the first letter of a string

Parameters

Returns string capitalised string.

createRandomString

Creates a random string of specified length

Parameters

  • length number Input number (optional, default 50)

Returns string random string.

convertToGold

Converts a number to g/s/c format

Mostly used for GuildWars2

Parameters

  • number number Input number
  • shorten boolean cut off the trailing currency or not

Returns string formatted g/s/c.

beautifyJSON

This beautifies json depending on teh flag

Parameters

  • json string Input json
  • flag string Flag to expand it out or not (min/human)

Returns string Resulting json.

sorter

Function to sort array, need to pass in the strings directly

Parameters

Returns number Resulting order.

stringToNumber

Returns a number from a string

Strips out any non number characters and forces conversion

Parameters

Returns number Resulting number.

uniq

Returns an array of unique objects

Parameters

  • array array of the account

Returns array Unique items.

getNextUpdate

For Datawars2

Gets the next update based on the users level

Parameters

  • level string of the account
  • newAccount boolean is it a new account
  • mapping object an object mapping times to levels

Returns string ISO datestamp.

filterGeneralNumber

This function is a filter function for all numbers

Strips all non number characters

Parameters

  • item string item being filtered
  • filter string what the item is being filtered by
  • multiplier number what to multiply the filter quanty by

Returns boolean returns true or false.

filterGeneralText

This function is a filter function text

Converts all inputs to lowercase

Parameters

  • item string item being filtered
  • filter string what the item is being filtered by

Returns boolean returns true or false.