Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
@ezez/utils
Advanced tools
Formerly: bottom-line-utils, but I never liked the name
A tiny and fast utils library.
Documentation can be found here: documentation.
npm install @ezez/utils
Lodash complexity that causes big bundle sizes just for using single function (even with tree shaking!).
Lodash is trying to cover each possible use case, even very rare while typical observed use case of lodash is basic
methods used on basic data. As an example, let's take a _.pick
method that simply returns an object, based on source
object, with just some properties copied. Easy, right? Few lines of code? Lodash makes that 114 imports!
@ezez/utils
aims to:
map
/forEach
functions etc.),addPrefix
- add prefix to a string if not already presentaddSuffix
- add suffix to a string if not already presentcapitalize
- capitalize a string, optionally lower casing the restisNumericString
- check if given value is a numeric string, features configurableoccurrences
- count occurrences of a substring in a string, optionally allow overlappingreplace
- replace all occurrences of a substring using a map of replacementsstripPrefix
- strip prefix from a stringstripSuffix
- strip suffix from a stringcap
- cap a value between lower and upper boundround
- round a value to given precisionscale
- scale given value from old range to new rangecompareArrays
- compare two arraysensureArray
- ensure that given value is an arrayinsertSeparator
- insert a separator between every character in an arraylast
- get last element of an arraymatch
- split your array into two groups - one that matches given predicate, and one that doesn'tmostFrequent
- find most frequent value in an arraypull
- remove values from an array (by mutating)remove
- remove values from an array (by mutating) using predicate function and return removed valuessortBy
- sort an array by given property (create callback function for Array.prototype.sort
)unique
- get unique values from an arraycompareProps
- compare two objects and return list of different propertiesdeserialize
- deserialize values serialized with serialize
isPlainObject
- check if given value is a plain objectmapValues
- map values of an objectmerge
- merge two objects shallowly, allowing to remove properties while doing soomit
- omit properties from an objectpick
- pick some properties from an objectreplaceDeep
- recursively replace all occurrences of a value in an object/arraysortProps
- sort object properties by keyserialize
- like JSON.stringify but any data type is allowedensureDate
- ensure that given value is a Date instanceensureTimestamp
- ensure that given value is a numeric timestampformatDate
- format a date using a format string, syntax from PHPcoalesce
- return first non-nullish valueensureError
- ensure that given value is an errorescapeRegExp
- escape a string to be used in a regular expressionsafe
- runs function and returns its result or default value if function throws an errorlater
- create a promise you can resolve later, outside of Promise constructormapAsync
- map an array asynchronously if sync version blocks your event loop for too longnoop
- do nothingrethrow
- throw given valueseq
- sequentially execute Promise-returning functions until one returns a valuewait
- wait given amount of time (async)waitSync
- wait given amount of time (sync)waitFor
- wait for a condition to be true, checking every given amount of timeget
- extract a value from a deep object using specified path, optionally with a default valuegetMultiple
- same as above, but test multiple pathsset
- set a value in a deep object using specified pathsetImmutable
- set a value in a deep object using specified path, but return a new objectisEmpty
- check if given value is emptythrottle
- throttle a function, very configurabletruthy
- is value truthy? (useful for filtering with more correct TypeScript support than filter(Boolean)
)Methods will be added as I need them. I am open for suggestions and PRs. See next heading for list of methods that I want to add.
(TODO)
This library is fully unit tested and can be used on production. See License.
MIT
FAQs
> Formerly: bottom-line-utils, but I never liked the name
We found that @ezez/utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.