@techmmunity/utils
v1.10.1
Published
Lightweight utils for every project
Downloads
213
Maintainers
Readme
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
| function | description |
| ---------- | ----------------------------------------------- |
| chunk
| Chunks an array |
| cleanObj
| Remove undefined and null values from an object |
| sleep
| Await the amount of time specified (in seconds) |
| nest
| Nest objects that have been unnested |
| unnest
| Plain objects and arrays |
get*
| function | description |
| ---------------------- | ---------------------------------------------------------------------- |
| getArrayUniqueValues
| Remove duplicated values of an array (only work with primitive values) |
| getAspectRatio
| Gets the aspect ratio (like 16:9, 4:3) |
| getEnumValues
| Return the enum values |
| getGCD
| Gets the Greatest Common Divisor (GCD) |
| getHexColorLuma
| Return the color luma of a hex color |
| getRootPath
| Get root path to something from the root folder of the process |
| getTypeof
| Fix native "typeof" |
has*
| function | description |
| -------------------- | ---------------------------------- |
| hasEmojis
| Return true if value has emojis |
| hasHtmlTags
| Return true if value has html tags |
| hasRequiredEnvVars
| Verify if all env vars are defined |
| hasUrl
| Return true if value has a url |
is*
| function | description |
| -------------------- | ----------------------------------------------------------------- |
| isAlphanumeric
| Return true if value is a number or a letter |
| isBetween
| Return true if value is a number between 2 values |
| isBrazilianPhone
| Return true if value is a brazilian phone |
| isClassInstance
| Return true if value is a class instance |
| isCnpj
| Return true if value is a CNPJ |
| isCpf
| Return true if value is a CPF |
| isDarkHexColor
| Return true if value is a dark hex color |
| isDate
| Return true if value is a valid date in the specified format |
| isDateDMY
| Return true if value is a valid date DD-MM-YYY |
| isDateDMYS
| Return true if value is a valid date DD/MM/YYY |
| isDateMDY
| Return true if value is a valid date MM-DD-YYY |
| isDateMDYS
| Return true if value is a valid date MM/DD/YYY |
| isDateYMD
| Return true if value is a valid date YYYY-MM-DD |
| isDateYMDS
| Return true if value is a valid date YYYY/MM/DD |
| isDivisibleByTen
| Return true if value is divisible by ten |
| isEmail
| Return true if value is a valid email |
| isEmoji
| Return true if value is an emoji (has some false-positives!) |
| isEmptyArray
| Checks if is an array and it's empty |
| isEmptyObject
| Checks if is an object and it's empty |
| isEven
| Return true if value is a even number |
| isFloat
| Return true if value is a float number (.0 numbers doesn't count) |
| isHerokuApiKey
| Return true if value is a heroku api key |
| isHexColor
| Return true if value is a valid hex color |
| isInt
| Return true if value is a float number |
| isIpv4
| Return true if value is a valid ipv4 |
| isIpv4WithMask
| Return true if value is a valid ipv4 with mask |
| isIsoDate
| Return true if value is a ISO Date |
| isLeap
| Return true if value is a leap year |
| isLightHexColor
| Return true if value is a light hex color |
| isMaskedCnpj
| Return true if value is a masked CNPJ |
| isMaskedCpf
| Return true if value is a masked CPF |
| isNumeric
| Return true if value is a numeric string |
| isOdd
| Return true if value is a odd number |
| isPackageInstalled
| Return true if the package is installed |
| isStrongPassword
| Return true if value is a strong password |
| isTimeWithFraction
| Return true if value is a time in the format hh:mm:ss.s
|
| isTimezone
| Return true if value is a time zone (Ex: +01:00, UTC, -12:00) |
| isUrl
| Return true if value is a valid url |
| isUsername
| Return true if value is a valid username |
| isUuidV4
| Return true if value is a valid uuid (v4) |
isNot*
| function | description |
| ------------------ | ----------------------------------------- |
| isNotEmptyArray
| Checks if is an array and it's NOT empty |
| isNotEmptyObject
| Checks if is an object and it's NOT empty |