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

js-helpertools

v1.5.0

Published

Easy Tools for developers. It includes many useful javascript function for developers

Downloads

5

Readme

js-helpertools

A npm package which can be useful while building a node application. It contains some minor and major functions which developers often search for on google or stackoverflow.

For Example

  • A Function to generate a random key
  • A Function to deeply sort an array
  • A Function to get one or more random element/s from an array
  • A Function to encrypt/decrypt a text

Github Repository

How To Use

Install js-helpertools with npm

  npm install js-helpertools

Basic Example

 let Tools = require("js-helpertools");

 let randomKey = Tools.generateKey(16);
 //result : 5YzDqOfcT30EEqrr 

List Of Functions

  • Generate a key

 Tools.generateKey(length,includeSC);
 // returns a string

| Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | length | number | Required. Length of the key | | includeSC | boolean | Whether to include special characters in the key |

  • Get a random number within a limit

  Tools.random(300);
  // returns a number ebtween 0 - 300

| Parameter | Type | Description | | :-------- | :------- | :------------------------- | | limit | number | Required. Limit |

  • Get a random element from an array

 let array = [23,45,87,90];
 Tools.sampleOne(array);
 // returns 87

| Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | array | array<any> | Required. Array to get an element from |

  • Get 2 or more random elements from an array

 let array = [23,45,87,90];
 Tools.sampleMany(array,2);
 // returns [45,90]

| Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | array | array<any> | Required. Array to get an element from | | amount | number | Required. amount of random elements you want |

  • Check accuracy. Useful during building games

 Tools.isLucky(60);
 // returns true or false

| Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | Accuracy % | number | Required. Check the luckiness |

  • Deeply shuffles an array

 Tools.shuffle(array);
 // returns a shuffled array

| Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | Array | array | Required. Array to shuffle |

  • Compares two arrays.

 Tools.compareArrays(array1,array2);
 // returns true if elements of both arrays are same and in same order.

| Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | Array 1 | array<any> | Required. First array | | Array 2 | array<any> | Required. Second array |

  • Removes the element of given index in array and returns new array

 Tools.removeElement(array,index);
 // returns updated array

| Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | Array % | array<any> | Required. Array to remove element from | | Index | number | Required. Index of the element |

  • Removes all characters,spaces, whitespaces from string and returns a lower case alphanumeric string.

 Tools.toId("Hello Guys!~ Sup?? 123!!!");
 // returns "helloguyssup123"

| Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | text | String | Required. Text to convert into alphanumeric |

  • Returns "1st, 2nd... nth" type string. depends on the number order

 Tools.toNumberOrderString(21);
 // returns "21st"

| Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | Number | number | Required. |

  • Escapes HTML characters

 Tools.escapeHTML(html);
 // returns escaped HTML

| Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | HTML | string | Required. A HTML String |

  • Unescapes HTML characters

 Tools.unescapeHTML(html);
 // returns unescaped HTML

| Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | HTML | string | Required. A HTML String |

  • Takes Date object and returns a time stamp string. example "2022-04-11 22:55:45"

 Tools.toTimestampString(date);
 // returns "2022-04-11 22:55:45"

| Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | date | Object<Date> | Required. Date object |

  • Takes Date object and returns a duration string. example '52 years, 3 months, 10 days, 17 hours, 28 minutes, and 37 seconds'

 Tools.toDurationString(date)
 // returns a duration string

| Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | date | Object<Date> | Required. Date object |

  • Returns all the possible permutations of given array elements

 Tools.getPermutations(elements,min,max);
 // returns an array

| Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | elements | array<any> | Required. Array of elements to get permutations | | min | string | Required. Minimum length of the permutations | | max | string | Required. Maximum length of the permutations |

  • Returns all the possible combinations of given arrays elements

 Tools.getCombinations(arr1,arr2,...,arrn);
 // returns an array

| Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | arr1 | array<any> | Required. A normal array | | arr2 | array<any> | Required. A normal array | | arrn | array<any> | A normal array |

  • Calculate the execution time of a function


 Tools.getRunTime(func,arg1,arg2);
 // returns the execution time in milliseconds

| Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | function | function | Required. The function of which the execution time is calculated | | arg1 | any | A argument of the function | | arg2 | any | A argument of the function |

  • Deeply clone an object

 Tools.deepClone(obj);
 // returns an object

| Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | obj | Object<any> | Required. An Object to clone |

Contributing

Contributions are always welcome!

You can help us add more functions that can be useful for developers. Visit this project's Github Repository and start a PR.

While adding more functions to this package try to -

  • Not include any dependancy unless it's necessary
  • Make a clean code
  • Check the code for errors before submitting a PR
  • Add comments wherever necessary to explain whats happening
  • Drink caffeine that helps us keep up the good work ;)

Authors