A small TypeScript utility library to complement lodash.
Lightdash is a utility library aiming to complement lodash, written in TypeScript.
Installation:
npm install lightdash
When using ES Modules:
import { groupMapBy } from "lightdash";
groupMapBy([1, 2, 3, 4, 5], (val) => val % 2);
When using CommonJS (e.g. Node):
const { groupMapBy } = require("lightdash");
groupMapBy([1, 2, 3, 4, 5], (val) => val % 2);
Contributions are always welcome, no matter if you have a request, an idea, found a bug, or spotted a typo: Feel free to create a PR or open an issue!
Array to count.
Function to use for key generation.
Count map.
Groups the elements of an array into a map, with the key being based on a key mapper and the value being the values for the same key mapper result.
Array to group.
Function returning the key for the value.
Grouped map.
Groups the elements of an array into a map, with the key being based on a key mapper and the value being the values for the same key mapper result being reduced.
Array to group.
Function returning the key for the value.
Function initializing a new reduction result object.
Consumer mutating the existing reduction result object with the new data.
Grouped and reduced map.
Inserts the value(s) at the given position. If the index is equal or higher than the array length, the value(s) will be appended. If the index is less than 0, the value(s) will be prepended.
Note that the input array is being mutated.
Array to modify.
Index to insert at.
Value(s) to insert.
The mutated array.
Removes the first occurrence of an element from an array. If the element does not exist in the array nothing is done.
Note that the input array is being mutated.
Array to modify.
The value to remove.
The mutated array.
Returns a new array with every n-th item from the input array.
Array to use.
Step to use.
Stepped collection.
Checks if the string is blank (no non-space content).
String to use.
If the string is blank.
Checks if a value is a promise.
Value to check.
If the value is a promise.
Gets name of a value.
If the value is a function, its name is returned. If the value is a symbol, its key is returned. If the value is a string, it is returned as is. Otherwise null is returned.
Value to check.
The name of the value.
Throws an exception if the value is nil, returns the value otherwise.
Value to check.
Supplier for the error to be thrown.
The value provided with guarantee to be non-nil.
Creates a map from an objects entries.
Object to use.
Map created from the object.
Creates a map from an objects entries.
Object to use.
Function mapping an object key to a map key.
Function mapping an object value to a map value.
Map created from the object.
Gets the value of a map entry by its key, throwing if the map does not contain the key.
Map to check against.
Key to get the value for.
The corresponding value.
Recursively freezes objects, useful for constant objects.
This function mutates the input value and calls Object.freeze() recursively on all sub-objects.
Object to recursively freeze.
Recursively seals objects, useful for constant objects.
This function mutates the input value and calls Object.seal() recursively on all sub-objects.
Object to recursively seal.
Creates a PascalCase string from a string.
String to use.
PascalCase string of the input string.
Removes a value from the end of a string. If the string does not end with the value, nothing is done.
String to check.
Value to remove.
String with the value removed from the end.
Removes a value from the start of a string. If the string does not start with the value, nothing is done.
String to check.
Value to remove.
String with the value removed from the start.
Generated using TypeDoc
Counts the values of an array into a map, with the key being based on a key mapper and the value being the occurrences of the key mapper result in the initial array.
12.0.0
countMapBy([1, 2, 4, 2, 4, 4], val => val) // => Map{1: 1, 2: 2, 4: 3}