Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-js-utilities

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-js-utilities

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

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

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


Keywords

FAQs

Package last updated on 24 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc