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

fwsp-jsutils

v1.0.10

Published

JavaScript Utils - useful dev utils

Downloads

594

Readme

JS Utils

Flywheel JS utils is a library of useful JavaScript utilities.

Install

You can install it via NPM:

$ npm -i fwsp-jsutils

Usage

const Utils = require('fwsp-jsutils');
let hash = Utils.stringHash('This is a test');

Tests

Tests can be found in the specs folder.

$ npm test

API

strip - strips white space characters - except for spaces

 /**
  * @name strip
  * @summary strips white space characters - except for spaces
  * @param {string} str - string to strip characters from
  * @return {string} string - without white space characters
  */
  static strip(str)

zeroPad - add preceeding zeros to maintain desired places

  /**
  * @name zeroPad
  * @summary add preceeding zeros to maintain desired places
  * @param {number} num - number to zero pad
  * @param {number} places - place digits (length)
  * @return {string} string with preceeding zeros
  */
  static zeroPad(num, places)

stringHash - returns a hash value for a supplied string

 /**
   * @name stringHash
   * @summary returns a hash value for a supplied string
   * @see https://github.com/darkskyapp/string-hash
   * @private
   * @param {object} str - string to hash
   * @return {number} hash - hash value
   */
  static stringHash(str)

shortID - generate a random id composed of alphanumeric characters

  /**
  * @name shortID
  * @summary generate a random id composed of alphanumeric characters
  * @see https://en.wikipedia.org/wiki/Base36
  * @return {string} random string id
  */
  static shortID()

UUID - Pseudo UUID

  /**
  * @name UUID
  * @summary Pseudo UUID
  * @return {string} uuid - unique string
  */
  static UUID()

UUID - Test

  /**
  * @name isUUID4
  * @summary determine whether a string is a valid UUID
  * @param {string} str - possible UUID
  * @return {undefined}
  */
  static isUUID(str)

isObject - Determines whether a variable is an object

  /**
  * @name isObject
  * @summary Determines whether a variable is an object
  * @param {object} obj - variable being tested
  * @return {boolean} - true if object else false
  */
  static isObject(obj)

isArray - Determines whether a variable is an array

  /**
  * @name isArray
  * @summary Determines whether a variable is an array
  * @param {object} obj - variable being tested
  * @return {boolean} - true if array else false
  */
  static isArray(obj)

safeJSONStringify - Safe JSON stringify

/**
 * @name safeJSONParse
 * @summary Safe JSON parse
 * @private
 * @param {string} str - string which will be parsed
 * @return {object} obj - parsed object
 *   Returns undefined if string can't be parsed into an object
 */
  static safeJSONStringify(obj)

safeJSONParse - Safe JSON parse

  /**
   * @name safeJSONParse
   * @summary Safe JSON parse
   * @private
   * @param {string} str - string which will be parsed
   * @return {object} obj - parsed object
   *   Returns undefined if string can't be parsed into an object
   */
  static safeJSONParse(str)

shuffleArray - Uses the Durstenfeld shuffle algorithm

  /**
  * @name shuffleArray
  * @summary Shuffles and array
  * @description Uses the Durstenfeld shuffle algorithm
  * @param {array} array - to shuffle
  * @return {array} array - shuffled array
  */
  static shuffleArray(array)

htmlEncode - Encode HTML text by converting characters to html codes

  /**
  * @name htmlEncode
  * @summary Encode HTML text by converting characters to html codes
  * @param {string} text - html text to encode
  * @return {string} text - encoded html text
  */
  static htmlEncode(text)

htmlDecode - Decode HTML text to original form

  /**
  * @name htmlDecode
  * @summary Decode HTML text to original form
  * @param {string} text - html text to encode
  * @return {string} text - decoded html text
  */
  static htmlDecode(text)

md5Hash - Hashes a key to produce an MD5 hash

  /**
  * @name md5Hash
  * @summary Hashes a key to produce an MD5 hash
  * @param {string} key - input key to hash
  * @return {string} hash - hashed value
  */
  static md5Hash(key)

getGeoDistance - Get the distance between to lat/lngs


  /**
  * @name getGeoDistance
  * @summary Get the distance between to lat/lngs
  * @notes http://stackoverflow.com/questions/27928/how-do-i-calculate-distance-between-two-latitude-longitude-points
  * @param {number} lat1 - from lat
  * @param {number} lng1 - from lng
  * @param {number} lat2 - to lat
  * @param {number} lng2 - to lng
  * @return {number} value - distance in miles
  */
  static getGeoDistance(lat1, lng1, lat2, lng2) {

getRandom - Returns a random number between 0 (inclusive) and 1 (exclusive)

  /**
  * @name getRandom
  * @summary Returns a random number between 0 (inclusive) and 1 (exclusive)
  * @return {number} num - number
  */
  static getRandom()

getRandomArbitrary - Returns a random number between min (inclusive) and max (exclusive)

  /**
  * @name getRandomArbitrary
  * @summary Returns a random number between min (inclusive) and max (exclusive)
  * @return {number} num - number
  */
  static getRandomArbitrary(min, max)

getRandomInt - Returns a random integer between min (included) and max (excluded)

  /**
  * @name getRandomInt
  * @summary Returns a random integer between min (included) and max (excluded)
  * @return {number} num - number
  */
  static getRandomInt(min, max)

getRandomIntInclusive - Returns a random integer between min (included) and max (included)

  /**
  * @name getRandomIntInclusive
  * @summary Returns a random integer between min (included) and max (included)
  * @return {number} num - number
  */
  static getRandomIntInclusive(min, max)