A lightweight TypeScript utility library to complement lodash.
Lightdash is an extensive object of utility functions to complement lodash written in TypeScript, designed to be lightweight and modern.
An utility library built on top of lodash, complementing it.
A standalone utility library to replace lodash.
Installation:
npm install lightdash
When Using ES Modules:
import { groupMapBy } from "lightdash";
groupMapBy([1, 2, 3, 4, 5], val => val % 2);
When using CommonJS (Node):
const { groupMapBy } = require("lightdash");
groupMapBy([1, 2, 3, 4, 5], val => val % 2);
Breaking:
Breaking:
Breaking:
Contributions are always welcome, no matter if you have a requests, 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.
Collects the values of an array in a map as array values, using the return value of the function as key.
Array to group.
Function to use for grouping.
Grouped map.
Collects elements in an array into a an array of merged elements.
Array to group.
Function returning the key for the value.
Function initializing a new mergable object.
Consumer mutating the existing object with the new data.
Grouped and merged map.
Inserts value(s) at the given position. If the index is equal or higher the array length, the value(s) will appended. If the index is less than 0, the value(s) will prepended.
Note: the input array is being mutated.
Array to insertAt to.
Index to start inserting.
Value(s) to insertAt.
Collection.
Removes the first occurrence of an element from an array.
Note: the input array is being mutated.
Array to modify.
The value to remove.
The mutated collection.
Returns a new collection with every n-th item from the input array.
Array to use.
Step to use.
Stepped collection.
Retrieves the corresponding enum item for a key; This can be useful for mapping external data to properly typed data. NOTE: due to the way enums work in TypeScript, a handful of quirks apply:
const
enums cannot be used due to being inlined during compilation.Enum to get an item of.
Item key to search.
Enum item or null if none matched
Retrieves the corresponding enum item for a value; This can be useful for mapping external data to properly typed data. NOTE: due to the way enums work in TypeScript, a handful of quirks apply:
const
enums cannot be used due to being inlined during compilation.Enum to get an item of.
Item value to search.
Enum item or null if none matched
Checks if the string is blank (no non-space content).
String to use.
If the file 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, mapping the keys and values.
Object to use.
Function mapping keys.
Function mapping values.
Map created from the object.
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.
Returns the levenshtein string distance of two strings.
First string to compare.
Second string to compare.
Distance between the two strings.
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.
Returns strings similar to the input based its levenshtein distance to the values in the list given.
String to check.
Array of values to compare the string to.
If the full map should be returned, rather than just the closest matches.
Array of the closest matches, or the map if returnFull
is true.
Generated using TypeDoc
Counts the values of an array in a map, using the return value of the function as key.
12.0.0
countMapBy([1, 2, 4, 2, 4, 4], val => val) // => Map{1: 1, 2: 2, 4: 3}