1.0.0 • Published 2 years ago

@swapnilp/lotide v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 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 @swapnilp/lotide

Require it:

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

Call it:

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

Documentation

The following functions are currently implemented:

  • assertEqual: Compares two values and tells us whether they match or not.
  • eqArrays: Checks whether two arrays are equal or not.
  • assertArraysEqual: Asserts whether two arrays are equal or not.
  • eqObjects: Checks whether two objects are equal or not.
  • assertObjectsEqual: Asserts whether two objects are equal or not.
  • head: Returns the first item of an array.
  • tail: Returns an array minus the first element.
  • middle: Returns the middle-most element/elements of an array.
  • flatten: When given an array containing elements (including nested arrays) it returns a "flattened" version of the array.
  • countOnly: When given an array and an object, it returns an object containing counts of everything that the input object listed.
  • countLetters: Returns the count of each letter/character in a given string.
  • letterPositions: Returns all the indices of every letter/character in a given string.
  • findKey: Takes in an object and a callback function. It scans the object and returns the first key for which the callback function returns a truthy value. If no key is found, then it returns undefined.
  • findKeyByValue: Takes in an object and a value. Scans the object and returns the first key which contains the given value. If no key with the said value is found, then it returns undefined. takeUntil: Keeps collecting items from a given array until the callback function provided, returns a truthy value. map: Takes in two arguments: An array to map and a callback function. Returns a new array based on the results of the callback function. without: Returns a subset of a given array without the unwanted elements.