deverything
v4.5.0
Published
Everything you need for Dev
Maintainers
Readme
Everything you constantly need for development (and probably still copy-pasting from other projects)
The promise:
- ✅ 1 package: say goodbye to lodash, faker, and the other package you don't recall the name of.
- ⭕ 0 dependencies: keep it simple and lightweight.
- 🏆 Pick the best: the code is minimal and uses the best practices for max performance.
- 🤖 AI: Functions are reviewed by AI to make sure all corner cases are covered.
- 👪🏼 Typescript: use it, support it and export it.
- 🌊 Intuitive: favour always the most intuitive API and common usage, never throw error unless asked to.
- 🙈 Semantic: use simple function names that are easy to remember, no complicated options.
Contributions always welcome!
Validators
isArray()isArrayIncluded()isBoolean()isBrowser()to detect if you are on the browserisBuffer()if it's a bufferisClient()same as isBrowserisEmail()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()checks if the array has no itemsisEmptyObject()checks if the object has no keys
isFile()if it's a fileisFunction()isJsDate()if it's a valid javascript's DateisBetweenDates()check if date falls between two other dates (left inclusive: includes start, excludes end)isFutureDate()check if date is in the future, optionally against a reference dateisPastDate()check if date is in the past, optionally against a reference dateisStringDate()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 arrayisNotEmptyString()must have some text, checks for spaces-onlyisNumber()if the arg is number, and also usable (no infinity)isInt()if it's an integerisEven()isOdd()isPositiveInt()isNegativeInt()
isNumeric()if string is representing a numberisNumericId()if it's a valid numeric ID- ⭐
isObject()if it's a js plain Object isPromise()if it's a promiseisPWA()to detect if you are on a PWAisReactElement()if it's a valid React ElementisRegExp()if it's a valid RegExp- ⭐
isSame()Compare if dates, functions, arrays, objects or anything else are the same isSequence()if the array is a perfect sequenceisServer()if you are on the serverisSpacedString()if string contains spacesisString()isURL()isUUID()if it's a valid UUIDisValue()if it's a defined value (not null, undefined, or empty string)
Dates
getDateRangeSeries()generate a series of dates within a rangegetDateSeriesRange()get the smallest and biggest dates from an array of datesgroupByDateBucket()group items into date buckets based on their dates and specified time intervalsisOver18()check if someone is over 18 years oldstartOfDay()get the start of a specific daystartOfNextMonth()startOfNextWeek()startOfThisWeek()startOfToday()startOfTomorrow()startOfUTCDay()get the start of a specific day in UTCstartOfUTCTomorrow()get the start of tomorrow in UTC
Math
average()isBetween()isOutside()isStrictlyBetween()max()min()multiply()normaliseArray()normaliseNumber()percentageChange()sum()
Helpers
array()create an arbitrary array based on a functionarrayDiff()get the difference of two arraysarrayIntersection()get the intersection of two arrays
capitalize()word => WordchunkArray()split array into chunkschunkedAll()process all items in chunkschunkedAsync()process async operations in chunkschunkedDynamic()process with dynamic chunk sizesclamp()clamp number in a rangecleanSpaces()trims and turns double spaces into single spacecyclicalItem()get item from array with cyclical indexingdir()get directory listingenumKeys()enum FRUIT { APPLE, PEAR } => ["APPLE", "PEAR"]enumValues()enum FRUIT { APPLE = 1, PEAR = 3 } => [1, 3]filterAlphanumeric()remove non-alphanumeric charactersfirst()get the first element of an arrayfirstKey()get the first key of an objectfirstValue()get the first value of an objectgetCookieByName()get cookie value by namegetKeys()get all keys from an objectgetUrlSearchParam()get URL search paramgetUrlSearchParams()get URL search paramsgroupByKey()incrementalId()autoincremental SQL-like, process-unique numeric idkeysLength()get the length of keys in an objectlast()get the last element of an arraylastIndex()get the last index of an arraymapByKey()- ⭐
merge()deep merge objects mergeArrays()merge multiple arraysmoveToFirst()move array element to firstmoveToIndex()move array element to desired indexmoveToLast()move array element to lastnormalizeNumber()normalizes between 0 and 1objectDiff()get the difference between two objectsomit()omit properties from object- ⭐
parseDate()pass anything Date-Like, and get a JS Date back pickObjectKeys()pick specific keys from objectpickObjectValues()pick specific values from objectpluck()make array of value from object keyspromiseWithTimeout()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.removeUndefinedValues()remove undefined values from objectscrambleText()replace alpha chars with random charsserialize()serialize object to stringseriesAsync()executes promises in series, and returns all resultssetObjectPath()set a value in an object by pathsetUrlSearchParams()set URL search paramsshuffle()shuffles elements in an arraysleep()promise-based sleepstringify()stringify anything, without breaking on circular dependenciestoggleArrayValue()remove/add value in arraytruncate()truncate text, does not break emojisuniqueValues()gets unique values in an array
Formatters
formatCamelCase()formatCookies(){ cookie1: "1", cookie2: "2" } => "cookie1=1; cookie2=2"formatNumber()1000 => "1,000" or "1K" or 0.112 => "11.2%"formatPercentage()0.11 => "11%"formatIndexProgress()=> "[2/10]"stringToCSSUnicode()"hello" => "\000068\000065\00006c\00006c\00006f" use this for CSSstringToUnicode()"hello" => "\u0068\u0065\u006c\u006c\u006f"
Random data generators
These functions are optimized for low entropy random data generation useful for Unit Testing, Storybook, Pass real validations, Reverse hacking, Penetration testing...
randomAddress()randomAlphaNumericCode()randomArray()- ⭐
randomArrayItem()now supporting non-uniform distribution randomBankAccount()randomBool()randomChar()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()randomEmptyValue()random empty value (null, undefined, empty string)randomEnumKey()enum FRUIT { APPLE, PEAR } => APPLErandomEnumValue()enum FRUIT { APPLE = 1, PEAR = 3 } => 3randomFile()randomFloat()randomObject()randomHandle()useful for social identifiers, or slugsrandomHexColor()randomHexValue()randomHtmlColorName()randomIBAN()randomInt()randomBigInt()randomMaxInt()Range within the Maximum integer supported by jsrandomMaxSafeInt()Range of very BIG integers, which are still safe to use thorandomNegativeInt()< 0randomPositiveInt()> 0
randomIP()randomName()randomFirstName()randomLastName()randomFullName()
randomNumericCode()randomObject()randomParagraph()randomPassword()randomPath()/path/to/somethingrandomPhoneNumber()randomString()randomSymbol()randomUUID()lightweight uuid generation, passing UUID validationrandomValue()randomWord()
TypeScript Helpers & Generics
CoordsDateLikeDefined<T>DimensionsFunctionHashMap<>BoolMapNumberMapStringMapTrueMap
KeyMatrixMaybe<>MaybePromise<>MaybePromiseOrValue<>MaybePromiseOrValueArray<>
NonUndefinedObjectPickDefined<T, K>PickRequired<T, K>PlainKeyPointPrismaSelectSerializedTuple
Development
After changes, run
pnpm releaseTo bump the version. CI will take care of publishing the package when merged.
