Everything you constantly need for development (and probably still copy-pasting from other projects)
The promise:
- β 1 package: say goodbye to lodash, faker, this and that and the other package.
- β 0 dependencies: keep it simple and lightweight.
- π Pick the best: the code is minimal and uses the best current practices and is optimized for max performance.
- πͺπΌ Typescript: use it, support it and export it.
- π Intuitive: favour always the most intuitive API and common usage, never throw errors unless asked.
- π Semantic: use simple function names that are easy to remember, no complicated options.
Contributions always welcome!
isArray()
isBoolean()
isBrowser()
to detect if you are on the browserisClient()
to detect if you are ont the browser/clientisEmail()
this is a relaxed check, use your own validation if you need to be strict- β
isEmpty()
to check for empty object, empty array, empty string, null or undefinedisEmptyString()
trims the string and checks if something is leftisEmptyArray()
isEmptyObject()
isFunction()
isJsDate()
if it's a valid javascript's DateisFutureDate()
isPastDate()
isStringDate()
also checks if the string passed is a valid date
isKey()
is a real key of an objectisLastIndex()
is the index is the last item of arrayisNumber()
if the arg is number, and also usable (no infinity)isInt()
isEven()
isOdd()
isPositive()
isNegative()
isNumeric()
- β
isObject()
if it's a js plain Object isPromise()
isPWA()
isReactElement()
isRegExp()
- β
isSame()
Compare if dates, functions, arrays, objects or anything else are the same isServer()
if you are on the serverisString()
isURL()
isUUID()
average()
max()
min()
sum()
array()
create an arbitrary array based on a functionarrayDiff()
arrayIntersection()
capitalize()
word => WordcleanSpaces()
trims and turns double spaces into single spaceclamp()
clamp number in a rangefirst()
get the first element of an arraygetKeys()
get the keys of an object, includes symbolslast()
get the last element of an array- β
merge()
deep merge objects moveToFirst()
move array element to firstmoveToIndex()
move array element to desired indexmoveToLast()
move array element to lastnormalizeNumber()
normalizes between 0 and 1objectDiff()
- β
parseDate()
pass anything Date-Like, and get a JS Date back pretty()
stringify anything, without breaking on circular dependenciespromiseWithTimeout()
takes a promise, a timeoutMs, and an option error as arguments. Returns a new Promise that either resolves with the value of the input promise or rejects with the provided error or a default error message if the input promise does not resolve or reject within the specified timeoutMs.sleep()
promise-based sleepshuffle()
shuffles elements in an arraytoggleArrayValue()
remove/add value in arraytruncate()
truncate text, does not break emojisuniqueValues()
gets unique values in an array
These functions are optimized for low entropy random data generation useful for Unit Testing, Storybook, Pass real validations, Reverse hacking, Penetration testing...
randomAddress()
randomAlphaNumericCode()
- β
randomArrayItem()
randomBankAccount()
randomBool()
randomCompany()
- β
randomCoords()
randomLat()
randomLng()
randomDate()
a safe range in decaderandomMaxDate()
a range in the Max dates allowed by JSrandomFutureDate()
randomPastDate()
randomDateRange()
=> { startDate, endDate }
randomEmail()
randomEmoji()
randomEnumKey()
enum FRUIT { APPLE, PEAR } => APPLErandomEnumValue()
enum FRUIT { APPLE = 1, PEAR = 3 } => 3randomFile()
randomFloat()
randomHandle()
useful for social identifiers, or slugsrandomHexColor()
randomHexValue()
randomHtmlColorName()
randomIBAN()
randomInt()
randomPositiveInt()
> 0randomNegativeInt()
< 0randomMaxSafeInt()
Range of very BIG integers, which are still safe to use thorandomMaxInt()
Range within the Maximum integer supported by js
randomIP()
randomName()
randomFirstName()
randomLastName()
randomFullName()
randomNumericCode()
randomNumericId()
autoincremental process-unique idrandomParagraph()
randomPassword()
randomPhoneNumber()
randomUUID()
lightweight uuid generation, passing UUID validationrandomWord()
Checks are functions that throw an error, if the validation fails
- β
checkEnvVars()
Make sure env vars are set per-environment
Coords
DateLike
Dimensions
Maybe<>
MaybePromise<>
MaybePromiseOrValue<>
MaybePromiseOrValueArray<>
NonUndefined
ObjectKey<>
ObjectValue<>
PlainObject
Point
PrismaSelect<>
After changes, run
pnpm bump
To bump the version. CI will take care of publishing the package when merged.