0.7.0 • Published 8 months ago

@teteu/utils v0.7.0

Weekly downloads
-
License
-
Repository
-
Last release
8 months ago

@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

MethodWhat It DoesParametersReturnExample
uniqueElementsreturns an array with unique elements(array)array with unique elementshere
groupByreceives an array of objects and returns a grouped by object(array of literal object, key)object with keys being the values of arrayihere
randomizeArrayrecieves an array and returns a randomized version of it(array to randomize)randomized arrayhere

Promises

MethodWhat It DoesParametersReturnExample
sleeppretty much sleeps until the specified time passes(time in milliseconds)Promisehere

Strings

MethodWhat It DoesParametersReturnExample
replaceTokensreplace tokens in a string based on a custom regular expression(string, tokens and regex)new string with tokens replacedhere
isEmailvalidates if the input string is a valid email(string)True if the string is a valid email, false otherwise.here

Phone Numbers

MethodWhat It DoesParametersReturnExample
validBrazilianPhoneNumberChecks 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 otherwisehere

Numbers

MethodWhat It DoesParametersReturnExample
randomreceives a min and max number and returns a random number between them(min, max)random number between min-maxhere

Date And Time

MethodWhat It DoesParametersReturnExample
getGreetingReturns a greeting based on the current hour of the dayvoidgreeting stringhere
getCurrentDateReturns the current date in the format "YYYY-MM-DD"voidcurrent datehere
getCurrentTimeReturns the current time in the format "HH:MM:SS"voidcurrent timehere
getDaysBetweenDatesCalculates the number of days between two given dates(date1, date2)number of days between the two dateshere
formatDateToBrazilianDateFormats a given date to the Brazilian date format "DD/MM/YYYY"(date)formatted date stringhere

Databases

MethodWhat It DoesParametersReturnExample
sanitizeThis 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 stringhere

Calculations

MethodWhat It DoesParametersReturnExample
getDiscountedValueCalculate the discount amount based on the original price and discount percentage(price, discount percentage 0 - 100)discounted valuehere
applyDiscountCalculates the discounted price based on the original price and discount percentage(price, discount percentage)result of price after discounthere

Objects

MethodWhat It DoesParametersReturnExample
deepClonerecieves an object and returns a deep clone of it(object to clone)cloned objecthere
pickreceives 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 specifiedhere
omitreceives 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 specifiedhere
isObjectreceives a value and checks if it is a javascript object literal(value to check)booleanhere

Contribute

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

0.5.0

8 months ago

0.4.1

8 months ago

0.4.0

8 months ago

0.7.0

8 months ago

0.6.1

8 months ago

0.5.2

8 months ago

0.6.0

8 months ago

0.5.1

8 months ago

0.4.2

8 months ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago

0.0.1

1 year ago