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

node-js-utilities

v2.0.0

Published

Node.js module exposing some of the basic utils that helps in basic development

Downloads

5

Readme

node-utils

Node.js module exposing some of the basic utils that helps in basic development which I came across during development

Author: Gaurav Joshi

Start

const Utils = require('node-utils');

Methods

beautifyDate(date, [format, seperator])

Generates a decorated date object where:

  • date - date.
  • format - optional format. Available formats are yyyy, mm, yyyy-mm-dd, yyyy-mm-dd h:i, mm-dd-yyyy hh:ss .
  • seperator - optional Date sepeartor default "-".
Utils.beautifyDate('01/16/2016', 'YYYY');

Returns following result:

2017

beautifyNumber(number, [decPlaces])

Generates a decorated Number where:

  • number - number.
  • decPlaces - optional format. Decimal place to round of number .
Utils.beautifyNumber(1050000, 2);

Returns following result:

1.05M

beautifyMoney(amount, [currency, raw])

Generates a decorated amount where:

  • amount - amount.
  • currency - optional currency. Available currency format USD,EUR,CRC,GBP,ILS,INR,JPY,KRW,NGN,PHP,PLN,PYG,THB,UAH,VND. Default USD
  • raw - optional raw. {boolean}
Utils.beautifyMoney(1545, 'GBP')

Returns following result:

£1.55K

getDaysDiff(date)

Returns days diff from current date

  • date - date.
Utils.getDaysDiff('01/01/2017')

Returns following result:

16

stripHtml(html, [all])

Strips HTML content from HTML string. (Returns a promise)

  • html - HTML string.
  • all - Boolean If true strips all HTML content otherwise strips only script tag and its content
	Utils.stripHtml('<script>alert(1);</script><p>HI GAURAV JOSHI</p><script>alert(1);</script>', true)
	.then( str => {
		console.log(str);
	});

Returns following result:

HI GAURAV JOSHI

containsWord(string, word)

Checks word exists in the string and return true or false accordingly. (*NOTE: check existence of complete word not sub string)

  • string - string - string in which to check
  • word - word - word to check
	Utils.containsWord('Hi I am a MEAN stack developer', 'MEAN');
	 AND
	Utils.containsWord('Hi I am a MEAN stack developer', 'velop');

Returns following result:

true

AND

false

getRandomNumber(min, max)

Returns random number between passed range

  • min - number - min range default 0
  • max - number - max range default 1
	Utils.getRandomNumber(1, 5);

Returns number


isUrlValid(url)

Returns random number between passed range

  • url - string - URL string
	Utils.isUrlValid('https://☺.damowmow.com/');

Returns boolean

true

getPathFromUrl(url)

Returns path from url skipping query parameters

  • url - string - URL string
	Utils.getPathFromUrl('https://☺.damowmow.com?a=3');

Returns string

https://☺.damowmow.com

getQueryString(url)

Returns query string parameters as an javascript oblect

  • url - string - URL string
	Utils.getQueryString('https://☺.damowmow.com?a=3&b=4');

Returns object

{"a": 3, "b": 4}

getQueryParamByName(param, url)

Returns query string values

  • param - string - Param name
  • url - string - URL string
	Utils.getQueryParamByName('a', 'https://☺.damowmow.com?a=3&b=4');

Returns value or null

3

startsWith(string, searchString, [position])

Determines whether the beginning of searchString instance matches the specified string when compared using the position.

  • string - string - The string from compare.
  • searchString - string - The string to compare.
  • position - number - position
	Utils.startsWith('Hello MEAN developers', 'EAN', 7);

Returns boolean

true

getRandomString(len, charStr)

Returns random string of passed length

  • len - number - length of random string default 4
  • charStr - string - charcters list to create random string default aplha numeric
	Utils.getRandomString(4);

Returns string