Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/totigm/js-utils
This is a collection of JS snippets
https://github.com/totigm/js-utils
javascript js node node-js nodejs snippets utils utils-repo
Last synced: 20 days ago
JSON representation
This is a collection of JS snippets
- Host: GitHub
- URL: https://github.com/totigm/js-utils
- Owner: totigm
- Created: 2021-05-28T03:05:23.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-11-04T00:13:05.000Z (about 1 year ago)
- Last Synced: 2023-11-04T01:23:28.236Z (about 1 year ago)
- Topics: javascript, js, node, node-js, nodejs, snippets, utils, utils-repo
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JS utils
This is a collection of JavaScript snippets.
## [camelCase](./utils/camelCase.js)
This snippet converts a string to its camelCase notation.\
For example, `This is not camel case, but it will` will return `thisIsNotCamelCaseButItWill`## [PascalCase](./utils/PascalCase.js)
This snippet converts a string to its PascalCase notation.\
For example, `This is not pascal case, but it will` will return `ThisIsNotPascalCaseButItWill`## [kebab-case](./utils/kebab-case.js)
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`## [Capitalize](./utils/capitalize.js)
This snippet capitalizes a string.\
For example, `toti muñoz` will return `Toti Muñoz`## [Create fake email](./utils/createFakeEmail.js)
This snippet uses puppeteer to create fake emails. You don't have to provide any parameter.
## [Filter from object](./utils/filterFromObject.js)
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.## [Format nested object](./utils/formatNestedObject.js)
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.## [Join names](./utils/joinNames.js)
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`## [Time options](./utils/timeOptions.js)
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']`## [Unique values](./utils/uniqueValues.js)
This snippet will return an array without repeating its values.\
For example, `[1, 2, 2, 1, 3]` will return `[1, 2, 3]`## [Hide email](./utils/hideEmail.js)
This snippet will hide the half of the email.\
For example, `[email protected]` will return `test*****@gmail.com`## [Hash string](./utils/hashString.js)
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...`## [Hours diff](./utils/hoursDiff.js)
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`.## [Dates utils](./utils/dates.js)
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`.## [Custom timer](./utils/customTimer.js)
This utils class is a wrapper around `setInterval` and `setTimeout`. It allows you to start a timer, pause it, resume it, and stop it.