The tiny utility library for JavaScript/TypeScript project.
This library is intentionally minimalist, designed to handle most cases.
It's deliberately not built to handle rare cases to keep its size from becoming bloated.
Basically it is the improved version & unnecessary-utilities-removed version of my previous libraries:
Also, Dev Disk supports ESM & CommonJS โ
You can check it out at https://www.npmjs.com/package/dev-disk.
- Vanilla JS ๐
import { ... } from "dev-disk"
- React JS ๐
import { ... } from "dev-disk/react"
If you're interested in diving deeper, feel free to check out the source code.
noop
- Empty functionidentity
- Identity functionhasValue
- Check if a value is notundefined
and notnull
isObject
- Check if a value is object (Record<string, any>
)getValue
- If the value is a function, it will get the returned value, otherwise it will get the valuegetHash
- Get stable hash (string) from object/arrayswapKeyValue
- Get a swaped key-value objectsleep
- Delay the next operation for a specific durationsplit2
- Split string into 2 partscn
- A minimalistclassName
utilityshallow
- Shallow compare
createError
- Create an Error instance with custom propsnoThrow
- Higher-order function to prevent a function throwing error when invokednoReject
- Higher-order function to prevent an async function throwing promise-rejection error when invoked
objectToQueryString
- Convert object to search param (string)queryStringToObject
- Convert search param (string) to objecthttp
- Minimalist abstraction forfetch
APIhttp.get
http.post
http.put
http.delete
http.gql
initStore
- Create vanilla JS store that can be subscribedinitStores
- Same asinitStore
but for multiple stores, publish/subscribe/access the value using a store-key (that will be serialized into a string).
useIsomorphicLayoutEffect
- Basically justuseLayoutEffect
without warninguseBoolean
- Handle boolean state with useful utility functionsuseDebounceFn
- Debounces a functionuseThrottleFn
- Throttles a functionuseIntersectionObserver
- Track intersection of a DOM element
createStore
- Just like Zustand's, but with store event & auto shallow compare (see vanillainitStore
)createStores
- React implementation for vanillainitStores
createQuery
- Just like react-query'suseQuery
, but using Zustand's pattern.createAsyncAction
- Just like react-query'suseMutation
, but using Zustand's pattern