Skip to content

totigm/JS-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 

Repository files navigation

JS utils

This is a collection of JavaScript snippets.

This snippet converts a string to its camelCase notation.
For example, This is not camel case, but it will will return thisIsNotCamelCaseButItWill

This snippet converts a string to its PascalCase notation.
For example, This is not pascal case, but it will will return ThisIsNotPascalCaseButItWill

This snippet converts a string to its kebab-case notation.
For example, This is not kebab case, but it will will return this-is-not-kebab-case-but-it-will

This snippet capitalizes a string.
For example, toti muñoz will return Toti Muñoz

This snippet uses puppeteer to create fake emails. You don't have to provide any parameter.

This snippet filters objects of an array that matches every field of a given query object.
For example, if you want to look for people whose last name is Smith and also are 22 years old, you could use filterFromObject(peopleArray, { last: "Smith", age: 22 }) and get an array of them.

This snippet executes a given callback for every element of an object, no matter how nested it is. For example, let's say that you have an object full of numbers (some of them are deeply nested) and you want to fix them all to two decimals, running formatNestedObject(object, (number) => number.toFixed(2)) will do it for you.

This snippet joins names' array based on its length.
For example,

  • ["Toti"] will return Toti
  • ["Toti", "John"] will return Toti and John
  • ["Toti", "John", "Mike"] will return Toti, John and Mike

This snippet will return an array with every time option for a given interval in minutes. This can be useful for dropdowns options.
For example, getTimeOptions(45) will return ['00:00', '00:45', '01:30', '02:15', '03:00', '03:45', '04:30', '05:15','06:00', '06:45', '07:30', '08:15', '09:00', '09:45', '10:30', '11:15', '12:00', '12:45', '13:30', '14:15', '15:00', '15:45', '16:30', '17:15', '18:00', '18:45', '19:30', '20:15', '21:00', '21:45', '22:30', '23:15']

This snippet will return an array without repeating its values.
For example, [1, 2, 2, 1, 3] will return [1, 2, 3]

This snippet will hide the half of the email.
For example, testemail@gmail.com will return test*****@gmail.com

This snippet will hash a string using a given hashing algorithm (sha512 by default). This is useful for storing sensitive data securely. For example, 123456 will return ba3253876aed6bc22d4a6ff...

This snippet will return the hours difference between two Dates objects. For example, getting the diff from 2022-03-27 to 2022-03-30 will return 72.

This group of snippets will return the date and time in a more human friendly format. For example, running getDateAndTime(new Date()) will return Today at hh:mm. If ran with a date from the previous day, it will return Yesterday at hh:mm. In any other case, it will return dd/mm/yyyy at hh:mm.

This utils class is a wrapper around setInterval and setTimeout. It allows you to start a timer, pause it, resume it, and stop it.

Releases

No releases published

Packages

No packages published