Tiny, efficient, TypeScript utility functions inspired by Lodash.
npm install turtledash
turtledash provides a collection of utility functions for working with objects, arrays, and more:
- Lightweight implementation of common utility functions
- Fully typed with TypeScript
- Zero dependencies
- MIT licensed
Maps the values of an object to create a new object with the same keys.
const users = { 'fred': { 'age': 40 }, 'pebbles': { 'age': 1 } };
mapValues(users, user => user.age); // { 'fred': 40, 'pebbles': 1 }
Maps an object's entries and returns a new object.
Creates an object composed of the picked object properties.
Creates an object with properties that satisfy the provided predicate function.
Creates an object composed of properties not included in the provided array.
Creates a deep clone of the value.
Recursively merges own properties of the source object into the target object.
Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned.
Creates an array of elements selected from the original array at the specified indices.
Flattens an array a single level deep.
Creates an array of grouped elements.
Creates an array of unique values.
Creates an array of unique values from all given arrays.
Creates an array of unique values that are included in all given arrays.
Creates an array of values from the first array that are not included in the other arrays.
Returns a Promise that resolves after the specified number of milliseconds.
Generates cryptographically strong random bytes.
Generates a random hex string.
Normalizes strings by replacing punctuation marks and applying unicode normalization.
Generates a random integer between min and max, inclusive.
Returns a random element from an array.
Creates a function that linearly scales a value from one range to another.
Performs a deep equality check on JSON-compatible objects.
Creates a consistently sortable representation of an object for hashing purposes.
Creates a debounced function that delays invoking the provided function.
Creates a throttled function that only invokes the provided function at most once per specified interval.
import {
mapValues,
pick,
debounce,
randomIntFromRange
} from 'turtledash';
// Transform all values in an object
const users = { 'fred': { 'age': 40 }, 'pebbles': { 'age': 1 } };
const ages = mapValues(users, user => user.age);
// { 'fred': 40, 'pebbles': 1 }
// Pick specific properties from an object
const user = { id: 1, name: 'John', email: 'john@example.com', role: 'admin' };
const credentials = pick(user, ['name', 'email']);
// { name: 'John', email: 'john@example.com' }
// Create a debounced function
const saveChanges = debounce(() => {
// Save data to server
console.log('Saving changes...');
}, 500);
// Generate a random number in a range
const randomValue = randomIntFromRange(1, 100);
MIT License