1.0.0 • Published 4 years ago

@js2oh/lotide v1.0.0

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.

Usage

Install it:

npm install @js2oh/lotide

Require it:

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

Call it:

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

Documentation

The following functions are currently implemented:

  • head(arr): returns the reference to the first element of the given array as an argument
  • tail(arr): returns the array except the first element as a new array
  • middle(arr): returns the middle element(s) of the given array as a new array
  • countLetters(str): returns the object which counts the number of each letter appear in the given string as value and letters as key
  • map(arr, callback): invokes the given callback function on each element of the given array, stores the returned values as the elements to the new array, and returns this new array
  • countLetters(allItems, itemsToCount): returns the objects that counts the number of specific array elements (selected by the given list of items) appear in the given array
  • findKey(obj, callback): invokes the given callback function on each value of the given object, and if the function returns true, then returns the first key of such object value
  • findKeyByValue(myObj, searchVal): returns the first key of the object which is equal to the given value
  • flatten(myObj, arr): flattens the given 2d array into a new 1d array and returns that array
  • letterPositions(sentence): returns the object whose keys are the letters appear in the given sentence and whose values are the arrays of the letter positions
  • takeUntil(array, callback): invokes the given callback function on each element of the given array, and if the function returns true, then returns all the elements before the element that made the function returns true
  • without(source, itemsToRemove): returns the array minus the given list of values to remove as a new array
  • printAssert(passed, actual, expected): given the condition and two values, if the condition is true, then prints that the assert test passed to the standard output; otherwise, prints that the assert test failed, but prints two given values regardless of the given condition
  • eqPrimitives(actual, expected): compare the two given primitive values strictly and returns the result as a boolean value
  • eqArrays(actual, expected): compare the two given arrays strictly and returns the result as a boolean value
  • eqObjects(actual, expected): compare the two given objects strictly and returns the result as a boolean value
  • assertArraysEqual(actual, expected): compare the two given primitive values strictly and outputs the assert result to the standard output
  • assertObjectEqual(actual, expected): compare the two given arrays strictly and outputs the assert result to the standard output
  • assertEqual(actual, expected): compare the two given objects strictly and outputs the assert result to the standard output