What is min-dash?
The min-dash npm package is a minimal utility library for JavaScript that provides a set of functions for common programming tasks. It is designed to be lightweight and efficient, making it suitable for use in performance-sensitive applications.
What are min-dash's main functionalities?
Array Manipulation
min-dash provides functions like `filter` and `map` to manipulate arrays. `filter` is used to create a new array with all elements that pass the test implemented by the provided function. `map` creates a new array with the results of calling a provided function on every element in the calling array.
const { filter, map } = require('min-dash');
const numbers = [1, 2, 3, 4, 5];
const evenNumbers = filter(numbers, n => n % 2 === 0);
const squaredNumbers = map(numbers, n => n * n);
console.log(evenNumbers); // [2, 4]
console.log(squaredNumbers); // [1, 4, 9, 16, 25]
Object Manipulation
min-dash provides functions like `assign` and `keys` for object manipulation. `assign` is used to copy the values of all enumerable own properties from one or more source objects to a target object. `keys` returns an array of a given object's own enumerable property names.
const { assign, keys } = require('min-dash');
const obj1 = { a: 1, b: 2 };
const obj2 = { b: 3, c: 4 };
const mergedObj = assign({}, obj1, obj2);
const objKeys = keys(mergedObj);
console.log(mergedObj); // { a: 1, b: 3, c: 4 }
console.log(objKeys); // ['a', 'b', 'c']
Function Utilities
min-dash provides function utilities like `bind` and `debounce`. `bind` creates a new function that, when called, has its `this` keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called. `debounce` creates a debounced function that delays invoking the provided function until after a specified wait time has elapsed since the last time the debounced function was invoked.
const { bind, debounce } = require('min-dash');
function greet(name) {
console.log('Hello ' + name);
}
const boundGreet = bind(greet, null, 'World');
boundGreet(); // 'Hello World'
const debouncedGreet = debounce(greet, 1000);
debouncedGreet('Alice');
debouncedGreet('Bob'); // Only 'Hello Bob' will be logged after 1 second
Other packages similar to min-dash
lodash
Lodash is a modern JavaScript utility library delivering modularity, performance, and extras. It provides a wide range of utility functions for common programming tasks, similar to min-dash, but with a larger footprint and more features.
underscore
Underscore is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects. It offers similar functionalities to min-dash but is more comprehensive and has been around longer.
ramda
Ramda is a practical functional library for JavaScript programmers. It makes it easy to create functional pipelines and is designed to be a more functional programming-oriented alternative to libraries like lodash and underscore.
min-dash
Minimal utility tool belt to be used with bpmn.io related libraries.
Features
- fine selection of powerful utilities on board
- ES2015 compatible
- complete bundle
2kB
minified and gzipped - utilities optimized for speed (i.e. sorting and union only by key)
How to use
import {
find,
sortBy,
assign
} from 'min-dash';
Your favourite module bundler should apply tree-shaking to only include the components your application requires. If you're using CommonJS modules give common-shake a try.
Related
- 1-liners - a slightly more opinionated collection of useful utilities
- min-dom - minimal DOM utility toolbelt
- tiny-svg - tiny SVG utility toolbelt
License
MIT