1.0.1 • Published 4 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 initemsToCount
are found inallItems
.itemsToCount
is 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 initemsToCount
and 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. Returnstrue
is yes andfalse
if 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. Returnsundefined
if not found.findKeyByValue(obj, val)
: Returns the first key in the objectobj
with the given valueval
. Returnsundefined
if 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 stringsentence
and 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. Ifarray
has an even number of elements, then the middle two elements are returned in an array.tail(array)
: Returns an array that contains the elements ofarray
less the first element. Ifarray
is not a valid array, thenundefined
is returned.takeUntil(array, callback)
:callback
is called on the elements ofarray
. The first elements up until the callback function returnsfalse
is returned in an array.without(source, itemsToRemove)
: Returns a subset ofsource
removing any elements initemsToRemove
.