1.0.0 • Published 4 years ago
@trachea/lotide v1.0.0
Lotide
A mini clone of the Lodash library.
Purpose
BEWARE: This library was published for learning purposes. It is not intended for use in production-grade software.
This project was created and published by me as part of my learnings at Lighthouse Labs.
Usage
Install it:
npm install @trachea/lotide
Require it:
const _ = require('@trachea/lotide');
Call it:
const results = _.tail([1, 2, 3]) // => [2, 3]
Documentation
The following functions are currently implemented:
assertArraysEqual(arr1, arr2): Used for internal testing. Checks ifarr1andarr2have the same elementsassertEqual(a, b): Used for internal testing. Checks ifa === b. Only works for primitive data types.assertObjectsEqual(obj1, obj2): Used for internal testing. Checks if the two objects:obj1andobj2have the same keys-value pairs.countLetters(string): Takes in astringand returns an object where the keys each unique letter instringand the values are the number of occurences instring.countOnly(arr, obj): Returns an objects where the keys are elements inarrsuch that the key exists inobjand it's value istrueand the values are the number of occurences inarr.eqArrays(arr1, arr2): Returns true only if all the elements inarr1exist inarr2and the lenght ofarrandarr2are the same.eqObjects(obj1, obj2): Returns true only if both objects have the same number of key-value pairs and every key-value pair inobj1exists inobj2.findKey(obj, function): Returns the first occurence of the key inobjthat satisfiesfunction.functionmust be a callback function that returns true only if a condition is met. If no key is found, returnsundefined.findKeyByValue(obj, value): Returns the first occurence of the key inobjthat has valuevalue. If no key is found, returnsundefined.flatten(arr): Returns a new array that is contains every element inarrflattened.head(arr): Returns the first element ofarr.letterPositions(string): Returns an object that contains each unique letter instringwhere the value is an array where the element representing the index where the key appears instring.map(arr, function): Returns a new array that is the same length asarrand each element is the result offunction(element).middle(arr): Returns an array that contains the middle value ofarr. One value if length ofarris odd and two values if length ofarris even. If the length ofarris less or equal to two, then returns an empty array.tail(arr): Returns a new array which isarrwithout it's first element.takeUntil(arr, function): Returns an array that is all the elements inarruntil an element satisifiesfunctionandfunctionreturns true;without(sources, values): Returns an array that issourceswhere all occurences of any element invalueshas been removed.
1.0.0
4 years ago