1.5.0 • Published 2 years ago

js-helpertools v1.5.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

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
ParameterTypeDescription
lengthnumberRequired. Length of the key
includeSCbooleanWhether to include special characters in the key
  • Get a random number within a limit

  Tools.random(300);
  // returns a number ebtween 0 - 300
ParameterTypeDescription
limitnumberRequired. Limit
  • Get a random element from an array

 let array = [23,45,87,90];
 Tools.sampleOne(array);
 // returns 87
ParameterTypeDescription
arrayarray<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]
ParameterTypeDescription
arrayarray<any>Required. Array to get an element from
amountnumberRequired. amount of random elements you want
  • Check accuracy. Useful during building games

 Tools.isLucky(60);
 // returns true or false
ParameterTypeDescription
Accuracy %numberRequired. Check the luckiness
  • Deeply shuffles an array

 Tools.shuffle(array);
 // returns a shuffled array
ParameterTypeDescription
ArrayarrayRequired. Array to shuffle
  • Compares two arrays.

 Tools.compareArrays(array1,array2);
 // returns true if elements of both arrays are same and in same order.
ParameterTypeDescription
Array 1array<any>Required. First array
Array 2array<any>Required. Second array
  • Removes the element of given index in array and returns new array

 Tools.removeElement(array,index);
 // returns updated array
ParameterTypeDescription
Array %array<any>Required. Array to remove element from
IndexnumberRequired. 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"
ParameterTypeDescription
textStringRequired. Text to convert into alphanumeric
  • Returns "1st, 2nd... nth" type string. depends on the number order

 Tools.toNumberOrderString(21);
 // returns "21st"
ParameterTypeDescription
NumbernumberRequired.
  • Escapes HTML characters

 Tools.escapeHTML(html);
 // returns escaped HTML
ParameterTypeDescription
HTMLstringRequired. A HTML String
  • Unescapes HTML characters

 Tools.unescapeHTML(html);
 // returns unescaped HTML
ParameterTypeDescription
HTMLstringRequired. 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"
ParameterTypeDescription
dateObject<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
ParameterTypeDescription
dateObject<Date>Required. Date object
  • Returns all the possible permutations of given array elements

 Tools.getPermutations(elements,min,max);
 // returns an array
ParameterTypeDescription
elementsarray<any>Required. Array of elements to get permutations
minstringRequired. Minimum length of the permutations
maxstringRequired. Maximum length of the permutations
  • Returns all the possible combinations of given arrays elements

 Tools.getCombinations(arr1,arr2,...,arrn);
 // returns an array
ParameterTypeDescription
arr1array<any>Required. A normal array
arr2array<any>Required. A normal array
arrnarray<any>A normal array
  • Calculate the execution time of a function

 Tools.getRunTime(func,arg1,arg2);
 // returns the execution time in milliseconds
ParameterTypeDescription
functionfunctionRequired. The function of which the execution time is calculated
arg1anyA argument of the function
arg2anyA argument of the function
  • Deeply clone an object

 Tools.deepClone(obj);
 // returns an object
ParameterTypeDescription
objObject<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

1.4.6

2 years ago

1.4.5

2 years ago

1.4.4

2 years ago

1.3.3

2 years ago

1.5.0

2 years ago

1.2.3

2 years ago

1.4.9

2 years ago

1.4.7

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago