@zerodep/utils v0.9.2
@zerodep/utils
This is a library of commonly used utilities, formatters, tests, and guards that help developers be more productive. This is a barrel package of all @zerodep.*
utility packages.
Works in the browser and on the server. Includes typescript definitions as well as tree-shakable CJS and ESM exports. Works out-of-the-box; may be configured as required.
Table of Contents
- Installation Instructions
- Included Packages
- Related Packages
- ZeroDep Advantages
- Support
- Semver
- Resources
- License
Install
npm install @zerodep/utils
Of course, you may use yarn
, pnpm
, or the package manager of your choice. Only npm
examples are shown for brevity.
Included Packages
The @zerodep/utils
package is a tree-shakable collection of utility-related packages in the @zerodep ecosystem.
Base Error
Method Name | Package | Purpose | Size |
---|---|---|---|
ZeroDepError | errors | A namespaced subclass of the Error object with additional properties, used by all @zerodep methods |
Can
A set of functions that test for specific language construct capabilities or features.
Method Name | Package | Purpose | Size |
---|---|---|---|
canIterate | can.iterate | Determine if a value is iterable in a for...of loop (with opinionated safeguards) |
Format
A set of locale-aware, configurable functions that format a value for a specific use case.
Method Name | Package | Purpose | Size |
---|---|---|---|
formatCurrency | format.currency | A configurable, locale-aware utility to format a value to a currency |
Guard
A collection of configurable defensive programming utilities that guard for specific data types.
Method Name | Package | Purpose | Size |
---|---|---|---|
guardArray | guard.array | A configurable defensive programming utility to guard against non-array values | |
guardBigInt | guard.bigint | A configurable defensive programming utility to guard against non-BigInt values | |
guardBoolean | guard.boolean | A configurable defensive programming utility to guard against non-boolean values | |
guardDate | guard.date | A configurable defensive programming utility to guard against non-Date values | |
guardFloat | guard.float | A configurable defensive programming utility to guard against non-float values | |
guardFunction | guard.function | A configurable defensive programming utility to guard against non-function values | |
guardInteger | guard.integer | A configurable defensive programming utility to guard against non-integer values | |
guardJSON | guard.json | A configurable defensive programming utility to guard against non-JSON object values | |
guardNumber | guard.number | A configurable defensive programming utility to guard against non-float/non-integer values | |
guardObject | guard.object | A configurable defensive programming utility to guard against non-plain JavaScript object values | |
guardString | guard.string | A configurable defensive programming utility to guard against non-string values |
Is
A collection of utility methods to determine the classification or equality of a value.
Method Name | Package | Purpose | Size |
---|---|---|---|
isArray | is.array | A utility to determine if a value is an array | |
isBigInt | is.bigint | A utility to determine if a value is a BigInt | |
isBoolean | is.boolean | A utility to determine if a value is a boolean | |
isDate | is.date | A utility to determine if a value is a Date | |
isEqual | is.equal | A utility to deeply compare two values of any type for equality | |
isFloat | is.float | A utility to determine if a value is a non-infinite float | |
isFunction | is.function | A utility to determine if a value is a function | |
isInteger | is.integer | A utility to determine if a value is a non-infinite integer | |
isJSON | is.json | A utility to determine if a value is a serializable JSON object | |
isMap | is.map | A utility to determine if a value is a Map | |
isNil | is.nil | A utility to determine if a value is null or undefined | |
isNull | is.null | A utility to determine if a value is null | |
isNumber | is.number | A utility to determine if a value is a non-infinite float or integer | |
isObject | is.object | A utility to determine if a value is a plain JavaScript object | |
isPromise | is.promise | A utility to determine if a value is a Promise | |
isRegex | is.regex | A utility to determine if a value is a regular expression | |
isSet | is.set | A utility to determine if a value is a Set | |
isString | is.string | A utility to determine if a value is a string | |
isSymbol | is.symbol | A utility to determine if a value is a Symbol | |
isTypedArray | is.typedarray | A utility to determine if a value is a Typed Array | |
isUndefined | is.undefined | A utility to determine if a value is undefined | |
isWeakMap | is.weakmap | A utility to determine if a value is a WeakMap | |
isWeakSet | is.weakset | A utility to determine if a value is a WeakSet |
Locale
A collection of helpers to appropriately work with locales.
Method Name | Package | Purpose | Size |
---|---|---|---|
localeGet | locale.get | A helper to get the locales of the environment (server or browser) | |
localeSettings | locale.settings | The locale configuration getter and setter |
To
A collection of utility methods to convert a value to a specific data type.
Method Name | Package | Purpose | Size |
---|---|---|---|
toJSON | to.json | A configurable function that converts a value to a JSON object | |
toNumber | to.number | A configurable utility to convert a value (string, boolean, date, or BigInt) to a number | |
toString | to.string | A configurable utility to convert a value (number, boolean, array, object, more...) to a locale-appropriate string |
Types
Some useful typescript type
declarations.
Type Name | Package | Purpose | Size |
---|---|---|---|
TypesCurrencies &TypesCurrenciesCrypto | types.currencies | Typescript type declaration of currencies and crypto-currencies | N/A |
TypesLocales | types.locales | Typescript type declaration of locales | N/A |
TypesTimeZones | types.timezones | Typescript type declaration of time zones | N/A |
TypesUnits | types.units | Typescript type declaration of supported units of measure | N/A |
Related Packages
The following @zerodep packages may be helpful or more appropriate for your specific case:
- @zerodep/app - a barrel package of all
@zerodep/*
capabilities - @zerodep/can - a barrel package of
@zerodep/can.*
detectors - @zerodep/format - a barrel package of
@zerodep/format.*
formatters - @zerodep/guard - a barrel package of
@zerodep/guard.*
defensive guards - @zerodep/is - a barrel package of
@zerodep/is.*
utilities - @zerodep/locale - a barrel package of
@zerodep/locale.*
tools - @zerodep/to - a barrel package of
@zerodep/to.*
converters - @zerodep/types - a barrel package of
@zerodep/types.*
declarations
Advantages of @zerodep Packages
We help make source code more readable, more secure, faster to craft, less likely to have hidden defects, and easier to maintain.
- Zero npm dependencies - completely eliminates all risk of supply-chain attacks, decreases
node_modules
folder size - Fully typed - typescript definitions are provided for every package for a better developer experience
- Semantically named - package and method names are easy to grok, remember, use, and read
- Documented - actually useful documentation with examples and helpful tips
- Intelligently Packaged - multiple npm packages of different sizes available allowing a menu or a-la-carte composition of capabilities
- 100% Tested - all methods and packages are fully unit tested
- ESM & CJS - has both ecmascript modules and common javascript exports, both are fully tree-shakable
- CDN Available - available on fast content delivery networks in UMD, CJS and ESM formats
- FP Inspired - gently opinionated to encourage functional programming style for cleaner and more maintainable software
- Predictably Versioned - semantically versioned for peace-of-mind upgrading, this includes changelogs
- MIT Licensed - permissively licensed for maximum usability
Support
All @zerodep packages are built for the ES2020 specification. Should you need to support older environments you will need to add appropriate polyfills. All packages are tested on the following platforms/browsers:
Browsers
- Chrome - last 2 major versions
- Firefox - last 2 major versions
- Safari - last 2 major versions
- Edge - last 2 major versions
- Android - last 2 major versions
- iOS - last 2 major versions
Node
- v16.x - Gallium LTS
- v14.x - Fermium LTS
It is likely the package will work on other technologies and version, however development and testing effort is only spent on the above.
Semver
All @zerodep packages, including this one, adhere to Semantic Versioning practices:
- major versions: correlates with breaking changes to one or more method signatures
- minor versions: includes addition of new functionality or backwards-compatible software improvements
- patch versions: are reserved for copy changes, documentation enhancements and bug fixes
The above said, a security best practice is to pin your software packages to specific versions and only upgrade to more recent releases after careful inspection of any CHANGELOG, release notes and all software changes.