Giter Site home page Giter Site logo

utils's Introduction

@teteu/utils

npm (scoped)

✨ Library to commonly used cross-projects utilities methods ✨

Run

npm install @teteu/utils --save

Usage

const utils = require('@teteu/utils');

utils.random(10, 20); // should return a random number between 10 and 20

Methods Docs

Arrays

Method What It Does Parameters Return Example
uniqueElements returns an array with unique elements (array) array with unique elements here
groupBy receives an array of objects and returns a grouped by object (array of literal object, key) object with keys being the values of array[i][key] here
randomizeArray recieves an array and returns a randomized version of it (array to randomize) randomized array here

Promises

Method What It Does Parameters Return Example
sleep pretty much sleeps until the specified time passes (time in milliseconds) Promise here

Strings

Method What It Does Parameters Return Example
replaceTokens replace tokens in a string based on a custom regular expression (string, tokens and regex) new string with tokens replaced here
isEmail validates if the input string is a valid email (string) True if the string is a valid email, false otherwise. here

Phone Numbers

Method What It Does Parameters Return Example
validBrazilianPhoneNumber Checks if a string phone number has valid brazilian phone number format (string phone number) True if the string is a valid brazilian phone number, false otherwise here

Numbers

Method What It Does Parameters Return Example
random receives a min and max number and returns a random number between them (min, max) random number between min-max here

Date And Time

Method What It Does Parameters Return Example
getGreeting Returns a greeting based on the current hour of the day void greeting string here
getCurrentDate Returns the current date in the format "YYYY-MM-DD" void current date here
getCurrentTime Returns the current time in the format "HH:MM:SS" void current time here
getDaysBetweenDates Calculates the number of days between two given dates (date1, date2) number of days between the two dates here
formatDateToBrazilianDate Formats a given date to the Brazilian date format "DD/MM/YYYY" (date) formatted date string here

Databases

Method What It Does Parameters Return Example
sanitize This method recieves an string input and sanitizes removing all SQL injection (string to sanitize and optionally an object containing the options for sanitization, check Example for better understanding) sanitized string here

Calculations

Method What It Does Parameters Return Example
getDiscountedValue Calculate the discount amount based on the original price and discount percentage (price, discount percentage [0 - 100]) discounted value here
applyDiscount Calculates the discounted price based on the original price and discount percentage (price, discount percentage) result of price after discount here

Objects

Method What It Does Parameters Return Example
deepClone recieves an object and returns a deep clone of it (object to clone) cloned object here
pick receives an object and an array of keys and returns a new object with only the keys specified (source object and array of keys to pick from the source object) new object with only the keys specified here
omit receives an object and an array of keys and returns a new object without the keys specified (source object and array of keys to omit from the source object) new object without the keys specified here

Contribute

Feel free to contribute. Check if we have open issues or request your utility method. Your code here is very welcome 🤝🤝

utils's People

Contributors

matheus-rodrigues00 avatar ahn0min avatar giri-madhan avatar nullsploit01 avatar gustavohbo avatar marcosviniciuscl avatar ycarooliveira avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.