1.0.4 • Published 4 years ago

@neethums/lotide v1.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

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 @neethums/lotide

Require it:

const _ = require('@neethums/lotide');

Call it:

const results = _.tail([1, 2, 3]) // => [2, 3]

Documentation

The following functions are currently implemented:

  • head(array):  A function used for finding the first element of an array. eg. head([1, 2, 3]) // 1

  • tail(array):  A function that returns all elements following the first element of an array. eg. tail([3,2,4,5]) //[2,4,5]

  • middle(array):  A function that returns the middle element(s) of an array. eg. middle([1, 2, 3, 4]) //[2,3]
  • assertArraysEqual(actual, expected):  A function for checking if actual and expected array are the same. eg. assertArraysEqual([5,6,7],[5,6,7]) //true
  • assertEqual(actual, expected):  A function to check if actual and expected primitive values are the same.eg. assertEqual(40,60) //false
  • assertObjectsEqual(actual, expected):  A function to check if actualand expected objects are the same.<assertObjectsEqual({a: 1, b: 2}, {b: 2, a: 1}) //true
  • countLetters(string):  A function for counting the number of letters in a given string. eg. countLetters("abcd abcd aad") // { a: 4, b: 2, c: 2, d: 3 }
  • countOnly(allItems, itemsToCount):  A function for counting the specified items in allItems array based on the itemsToCount object.eg. const firstNames = [ "Karl", "Salima", "Agouhanna", "Fang", "Kavith", "Jason", "Salima", "Fang", "Joe" ];countOnly(firstNames, { "Jason": true, "Karima": true, "Fang": true }) // { Fang: 2, Jason: 1 }
  • eqArrays(array1, array2):  A function for checking if two arrays are equal. eg. eqArrays(["1", "2", "3"], ["1", "2", "3"]) //true
  • eqObjects(object1, object2):  A function for checking if object1 is equal to object2. eg. const ab = { a: "1", b: "2" }; const ba = { b: "2", a: "1" }; eqObjects(ab, ba) //true
  • findKey(object, callback):  A function for finding the key based on the callback function eg. findKey({ "Blue Hill": { stars: 1 }, "Akaleri": { stars: 3 }, "noma": { stars: 2 }, "elBulli": { stars: 3 }, "Ora": { stars: 2 }, "Akelarre": { stars: 3 } }, x => x.stars === 2); // => "noma"
  • findKeyByValue(object,value):  A function for finding the key of a given object when given its value. eg. const bestTVShowsByGenre = { "sci_fi": "The Expanse", comedy: "Brooklyn Nine-Nine", drama: "The Wire" };findKeyByValue(bestTVShowsByGenre, "The Wire") //drama
  • flatten(array):  A function used for flattening nested arrays. eg. flatten([1,2,[3,4],5,[6,7,8,9],10]) //[1,2,3,4,5,6,7,8,9,10]
  • letterPositions(string):  A function that returns the array of indexes of each letter.letterPositions("hello") //{ h: [ 0 ], e: [ 1 ], l: [ 2, 3 ], o: [ 4 ] }
  • map(array, callback):  A function that takes in an array and returns a new array after applying the callback function. eg. const words = ["ground", "control", "to", "major", "tom"]; map(words, word => word[0]) //['g','c','t','m','t']
  • takeUntil(array, callback):  A function that takes in an array and returns the elements of that array until the callback condition is met. eg. const data1 = [1, 2, 5, 7, 2, -1, 2, 4, 5];takeUntil(data1, x => x < 0) //[ 1, 2, 5, 7, 2 ]
  • without(array, itemsToRemove):  A function that returns the given array by removing the itemsToRemove. eg. without([1, 2, 3], [1]) //[2,3]
1.0.4

4 years ago

1.0.333

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago