1.0.1 • Published 6 years ago
@fgfl/lotide v1.0.1
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 @fgfl/lotide
Require it:
const _ = require('@fgfl/lotide');
Call it:
const results = _.tail([1, 2, 3]) // => [2, 3]
Documentation
The following functions are currently implemented:
countLetters(str): Returns the number of letters in stringstr. Spaces are not counted. Returns an empty object if an empty string is passed in.countOnly(allItems, itemsToCount): Counts the number of times and the items initemsToCountare found inallItems.itemsToCountis and object where the key is the item and the value is a boolean specifying whether to count the item. The results are returned in an object where the keys are the elements initemsToCountand the values are the counts. If the item is not found inallItems, the item is not added to the return object.eqArray(array1, array2): Checks if two arrays are equal. Returns true is yes and false if no.eqObjects(object1, object 2): Checks if two objects are equal. Returnstrueis yes andfalseif no.head(array): Returns the first element of an array. It does not check if the array is valid.isNonNullObject(object): Returns true if the obeject type is 'object' and notnull.findKey(obj, stopSearch): Find and returns the first key in obj for which the stopSearch callback function returns true. Returnsundefinedif not found.findKeyByValue(obj, val): Returns the first key in the objectobjwith the given valueval. Returnsundefinedif value is not found.flatten(array): Returns a "flattened" version ofarray.letterPositions(sentence): Returns an object where the keys are the distinct letters in the stringsentenceand the values are arrays with the positions where the letters are found insentence.map(array, callback): Returns an new array based on the results of the callback functioncallback.middle(array): Returns and array containing the middle element of an array. Ifarrayhas an even number of elements, then the middle two elements are returned in an array.tail(array): Returns an array that contains the elements ofarrayless the first element. Ifarrayis not a valid array, thenundefinedis returned.takeUntil(array, callback):callbackis called on the elements ofarray. The first elements up until the callback function returnsfalseis returned in an array.without(source, itemsToRemove): Returns a subset ofsourceremoving any elements initemsToRemove.