1.0.1 • Published 3 years ago
@tonyhaofu/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 @tonyhaofu/lotide
Require it:
const _ = require('@tonyhaofu/lotide');
Call it:
const results = _.tail([1, 2, 3]) // => [2, 3]
Documentation
The following functions are currently implemented:
assertArraysEqual(array1, array2)
: asserting that two arrays are the same (supports nesting)assertEqual(actual, expected)
: asserting that two parameters are equal (does not support objects or arrays) using===
assertObjectsEqual(object1, object2)
: asserting that two objects are equal (supports nesting)countLetters(str)
: counts occurence of letters in stringcountOnly(allItems, itemsToCount)
: given an arrayallItems
, returns obj with key: value pairs representing elements in array and the number of times that element occurs in the array but only for elements that appear in arrayitemsToCount
eqArrays(array1, array2)
: returns boolean of whether the 2 arrays are equal (supports nesting)eqObjects(object1, object2)
: returns boolean of whether 2 objects are equal (supports nesting)findKey(dict, callback)
: returns key value for the first property ofdict
object wherecallback
returnstrue
findKeyByValue(dict, value)
: returns key for the first property ofdict
where the value is equal tovalue
flatten(arr)
: flattens a nested arrayhead(arr)
: returns the first element of an arrayletterPositions(sentence)
: returns an object with keys equal to the letters of the stringsentence
and values equal to an array containing the indices at which those letters appear insentence
with the white-space removedmap(array, callback)
: returns array with mapped values usingcallback
functionmiddle(arr)
: returns array containing the middle element(s) of arrayarr
tail(arr)
: returns array containing the elements of arrayarr
not including the first elementtakeUntil(array, callback)
: returns array of elements from arrayarray
untilcallback(element)
returns true. Does not include that valuewithout(source, itemsToRemove)
: returns array with elements from arraysource
but with elements contained in arrayitemsToRemove
removed.