The Lotide project is a library of useful data processing utilites for common Javascript tasks.
A Lightwieght and powerful mini clone of the Lodash library. Heavily inspired by the Lodash, Lotide offers simpler, singular purpose derivatives. .. Enjoy!
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.
Install it:
npm install @gottfriedk/lotide
Require it:
const _ = require('@gottfriedk/lotide');
Call it:
const results = _.tail([1, 2, 3]) // => [2, 3]
- assertArraysEqual
- assertEqual
- assertObjectsEqual
- countLetters
- countOnly
- eqArrays
- eqObjects
- findKey
- findKeyByValue
- flatten
- head
- letterPositions
- map
- middle
- tail
- takeUntil
- without
assertArraysEqual(array1, array2)
: a function that determines whether 2 arrays are strictly equal.
Params:
- (array1) Type: array -- should be the array you want to test. Actual
- (array2) type: array -- expected outcome
Behaviour:
dependancy: eqArrays()
. Takes in a truthy statment based on a comparison made by calling back eqArrays()
, then logs the results of that assertion to the console. Does not return a value.
assertEqual(actual, expected)
: a function that determines whether two primitives are strictly equal.
Params:
- (actual) primitive data type, to be tested
- (expected) the expected primitive data type
Behaviour:
Uses strict equality ===
of the two primitives and then logs the results of the assertion to the console. Returns a Boolean value.
assertObjectsEqual(obj1, obj2)
: is a function that determines whether two objects are strictly equal. Does not return a value.
Params:
- (obj1) the object to be tested. Actual
- (obj2) the expected object. To test against
Behaviour:
dependancy: eqObjects()
. Takes in a truthy statment based on a comparison made by calling back eqObjects()
, then logs the results of that assertion to the console. Does not return a value.
countLetters(string)
: a function that counts the letters of a string.
Params:
- (string) any String
Behaviour:
Returns a new Object. The key/value pairs of the return object are comprised of letters that appear in the string and the numeric quantity of times they appear.
countOnly(allItems, itemsToCount)
: a function that counts the specified items from an array.
Params:
- (allItems) an array of items
- (itemsToCount) an object of truthy values
Behaviour:
The key from parameter B has a truthy value. If true and the key matches an item from parameter A, this returns an object of the items counted and their numerical quantity.
eqArrays(array1, array2)
: is a function that determines whether 2 arrays are strictly equal.
Params:
- (array1) array to test
- (array2) the expected array to test against
Behaviour:
Returns a Boolean value. Loops through each of the items in the array testing for strict equality. Will return false if the index of the items are out of order.
eqObjects(obj1, obj2)
: is a function that determines whether 2 objects are strictly equal.
Params:
- (obj1) object to test
- (obj2) the expected object to test against
Behaviour:
Returns a Boolean value. Loops through each of the key:value pairs in both objects testing for strict equality, using one array of keys.
findKey(object, callback)
: returns the key of an object based on the criteria, defined in a callback function.
Params:
- (object) an object
- (callback) a callback function
Behaviour:
Returns the first key, as a String, for which the callback returns a truthy value. If no key is found, it returns undefined.
findKeyByValue(object, value)
: returns the first key of an objects property whos value matches the provided argument.
Params:
- (object) an object
- (value) any primitive value to check for
Behaviour:
Returns the first key, as a String, that matches the argument passed to the second parameter, by looping through the key:value pairs. If no key is found, it returns undefined.
flatten(array)
: returns nested arrays as one flat array.
Params:
- (array) an array
Behaviour:
Iterates through the array and pushes each item to a new array. If the item is an array, it will be concatenated to the new array. Only works with one level of depth or nesting.
head(array)
: returns the first item in an array.
Params:
- (array) an array of any length
Behaviour:
Slices and returns a shallow copy of the first item of the array passed as an argument. Does not alter the array.
letterPositions(string)
: Returns an object of letters that appear in the string and their index positions, listed in an array.
Params:
- (string) any String
Behaviour:
Returns a new Object with the letters that appear in the string as the keys, and the array of numbers representing thier index positions in the string. Upper Case and whitespace are ignored.
map(array, callback)
: Performs a callback function on each item of an array.
Params:
- (array) an array of any length
- (callback) a callback function
Behaviour:
Returns a new array based on the results of a callback function being performed on each item in the array.
middle(array)
: Return the middle item or items of an array.
Params:
- (array) an array of any length
Behaviour:
Returns a new array that contains the middle item of an array passed as an argument. If the array length is even numbered, the two middle items will be returned.
tail(array)
: Returns an array of all items except for the first one.
Params:
- (array) an array of any length
Behaviour:
Returns a new array that contains the all items of an array passed as an argument, except for the item at index[0]. If the argument passed is an array of one item or less, the function will return an empty array.
takeUntil(array, callback)
: Returns a new array, from the beginning up to an item that evaluates to true, based on a truthy evaluation of a callback.
Params:
- (array) an array of any length
- (callback) a callback function that provides the stopping condition for the new array
Behaviour:
Returns a new array, by looping the array, comparing for strict equality, every item to a value provided by the callback function. The value provided by the callback is the item in the list you want to stop at. The new array is every item up until said value.
without(source, itemsToRemove)
: Returns an array without the items specified.
Params:
- (source) an source array
- (itemsToRemove) an array of items to remove from the source array
Behaviour:
Returns a new array of items without certain items specified by another array passed in as an argument in parameter b, by iterating through the list of unwanted items and filtering each one out at every pass.