1.10.1 • Published 2 years ago

@techmmunity/utils v1.10.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

Techmmunity - Utils

Package of utils, make in a way to let you import only the functions that you really need, so it doesn't make your project heavier than it needs to be.

Every util is optimized to only contain the necessary code, so even if this package have 1M utils, if you are using babel, webpack or @vercel/ncc, the compiled code will only contain the utils that you are using.

We also have zero external dependencies, so everything that can cause trouble to your project is inside this repository! It makes easier to check and validate if the code match your expectations and is good enough for your project.

:warning: WARNING :warning:

The package may not be updated so often, but it not means that it has been abandoned. We do the utils in a way to (almost) never have to touch it again, and we only update the package to add new features, what may don't need to happen so often.

You can safely use this package, even if it don't receive updates in a year, and if you find any bug, you can report it by creating a issue in the GitHub repository, or create a PR to fix it! We will always give it special attention.

Install

With Yarn:

yarn add @techmmunity/utils

With NPM:

npm i @techmmunity/utils

Docs

Miscellaneous

functiondescription
chunkChunks an array
cleanObjRemove undefined and null values from an object
sleepAwait the amount of time specified (in seconds)
nestNest objects that have been unnested
unnestPlain objects and arrays

get*

functiondescription
getArrayUniqueValuesRemove duplicated values of an array (only work with primitive values)
getAspectRatioGets the aspect ratio (like 16:9, 4:3)
getEnumValuesReturn the enum values
getGCDGets the Greatest Common Divisor (GCD)
getHexColorLumaReturn the color luma of a hex color
getRootPathGet root path to something from the root folder of the process
getTypeofFix native "typeof"

has*

functiondescription
hasEmojisReturn true if value has emojis
hasHtmlTagsReturn true if value has html tags
hasRequiredEnvVarsVerify if all env vars are defined
hasUrlReturn true if value has a url

is*

functiondescription
isAlphanumericReturn true if value is a number or a letter
isBetweenReturn true if value is a number between 2 values
isBrazilianPhoneReturn true if value is a brazilian phone
isClassInstanceReturn true if value is a class instance
isCnpjReturn true if value is a CNPJ
isCpfReturn true if value is a CPF
isDarkHexColorReturn true if value is a dark hex color
isDateReturn true if value is a valid date in the specified format
isDateDMYReturn true if value is a valid date DD-MM-YYY
isDateDMYSReturn true if value is a valid date DD/MM/YYY
isDateMDYReturn true if value is a valid date MM-DD-YYY
isDateMDYSReturn true if value is a valid date MM/DD/YYY
isDateYMDReturn true if value is a valid date YYYY-MM-DD
isDateYMDSReturn true if value is a valid date YYYY/MM/DD
isDivisibleByTenReturn true if value is divisible by ten
isEmailReturn true if value is a valid email
isEmojiReturn true if value is an emoji (has some false-positives!)
isEmptyArrayChecks if is an array and it's empty
isEmptyObjectChecks if is an object and it's empty
isEvenReturn true if value is a even number
isFloatReturn true if value is a float number (.0 numbers doesn't count)
isHerokuApiKeyReturn true if value is a heroku api key
isHexColorReturn true if value is a valid hex color
isIntReturn true if value is a float number
isIpv4Return true if value is a valid ipv4
isIpv4WithMaskReturn true if value is a valid ipv4 with mask
isIsoDateReturn true if value is a ISO Date
isLeapReturn true if value is a leap year
isLightHexColorReturn true if value is a light hex color
isMaskedCnpjReturn true if value is a masked CNPJ
isMaskedCpfReturn true if value is a masked CPF
isNumericReturn true if value is a numeric string
isOddReturn true if value is a odd number
isPackageInstalledReturn true if the package is installed
isStrongPasswordReturn true if value is a strong password
isTimeWithFractionReturn true if value is a time in the format hh:mm:ss.s
isTimezoneReturn true if value is a time zone (Ex: +01:00, UTC, -12:00)
isUrlReturn true if value is a valid url
isUsernameReturn true if value is a valid username
isUuidV4Return true if value is a valid uuid (v4)

isNot*

functiondescription
isNotEmptyArrayChecks if is an array and it's NOT empty
isNotEmptyObjectChecks if is an object and it's NOT empty