Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@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
[4.0.0] - 2024-05-16
replaceDeep
will not mutate anything by default anymore — previously it was wrongly documented as always mutating,
but it was not mutating objects. Mutating behavior can now be enabled and additionally controlled by defining if
instances properties are allowed to be mutated.serialize
] to avoid excessive calls to serializer functions - they are now only called with non-plain objects or
unknown data types, this breaks some rare use casesserialize
custom serializers now allow things like Date
(that defines .toJSON) to be supported as the user would
expectreplaceDeepByFn
method for more granular control over replacing values. replaceDeep
is a simplified wrapper over
the new functiontrim
, trimStart
, and trimEnd
methodsFAQs
> Formerly: bottom-line-utils, but I never liked the name
The npm package @ezez/utils receives a total of 593 weekly downloads. As such, @ezez/utils popularity was classified as not popular.
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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.