ModernDash
ModernDash is a TypeScript-first utility library designed as a performant and lightweight alternative to Lodash, optimized for modern browsers and enhanced developer experience. Currently stable at version 4.0.2, it follows a release cadence driven by feature additions, bug fixes, and security patches, with major versions tied to breaking changes like Node.js version bumps. Key differentiators include its strict TypeScript adherence (no `any` types), ESM-only distribution, tree-shakable design, and a strong focus on outperforming Lodash in most benchmarks while maintaining zero runtime dependencies. It selectively implements only essential utility functions, encouraging the use of native JavaScript alternatives where available, contrasting with Lodash's more comprehensive API surface.
Common errors
-
SyntaxError: Named export 'chunk' not found. The requested module 'moderndash' does not provide an export named 'chunk'
cause Attempting to import ModernDash functions using CommonJS `require()` syntax in an ESM-only environment.fixRefactor your import statements to use ES Module syntax: `import { chunk } from 'moderndash';` and ensure your project is configured for ESM. -
Error: The 'moderndash' package requires Node.js version >=20.x. You are running Node.js version X.
cause Using ModernDash v4.x or later with an unsupported Node.js version.fixUpdate your Node.js environment to version 20 or higher. You can use a tool like `nvm` to manage Node.js versions. -
TypeError: (0 , _moderndash.merge) is not a function
cause A bundler or transpiler might be incorrectly transforming ESM imports to CommonJS, or a CommonJS context is trying to use an ESM-only library.fixEnsure your build setup (e.g., Babel, Webpack, Vite) is correctly configured for ES Modules, allowing `import` statements to resolve `moderndash` properly. Verify `"type": "module"` in your `package.json` if running in Node.js, or adjust bundler configurations.
Warnings
- breaking ModernDash v4.0.0 and later require Node.js version 20.x or higher. Projects running on older Node.js versions will encounter errors.
- breaking Functions `merge` and `set` in versions prior to v4.0.1 were vulnerable to prototype pollution. This could allow attackers to inject arbitrary properties into `Object.prototype`, potentially leading to denial-of-service or remote code execution.
- deprecated Several utility functions including `difference`, `intersection`, `isUrl`, and `groupBy` have been deprecated in favor of native JavaScript APIs (e.g., `Set.prototype.intersection()`, `URL.canParse`, `Object.groupBy`).
- gotcha The `deburr` function prior to v4.0.2 incorrectly handled certain ligatures and special Latin characters (e.g., æ, œ, ß, ø), passing them through unchanged instead of decomposing them. This could result in unexpected string normalization behavior.
Install
-
npm install moderndash -
yarn add moderndash -
pnpm add moderndash
Imports
- chunk
const chunk = require('moderndash').chunkimport { chunk } from 'moderndash' - camelCase
const camelCase = require('moderndash').camelCaseimport { camelCase } from 'moderndash' - merge
const merge = require('moderndash').mergeimport { merge } from 'moderndash'
Quickstart
import { chunk, camelCase, merge } from 'moderndash';
console.log('--- moderndash Quickstart ---');
// Example 1: Chunk an array into smaller arrays
const myArray = [1, 2, 3, 4, 5, 6, 7];
const chunkedArray = chunk(myArray, 3);
console.log('Chunked array:', chunkedArray);
// Expected: [[1, 2, 3], [4, 5, 6], [7]]
// Example 2: Convert a string to camel case
const myString = 'hello world moderndash example';
const camelCasedString = camelCase(myString);
console.log('Camel cased string:', camelCasedString);
// Expected: "helloWorldModerndashExample"
// Example 3: Deep merge objects
const object1 = { 'a': [{ 'b': 2 }, { 'd': 4 }] };
const object2 = { 'a': [{ 'c': 3 }, { 'e': 5 }] };
const mergedObject = merge(object1, object2);
console.log('Merged object:', JSON.stringify(mergedObject, null, 2));
/* Expected (keys merged by index in arrays):
{
"a": [
{ "b": 2, "c": 3 },
{ "d": 4, "e": 5 }
]
}*/