1.0.0 • Published 2 years ago

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

Require it:

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

Call it:

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

Documentation

The following functions are currently implemented:

  • head(array): Takes an array and return the first element of that array
  • tail(array): Takes an array and return the all the elements after the first element
  • middle(array): Takes an array and return the middle element(s) of the array. Function will return a single element if array length is an odd number. Function will return two elements if array length is an even number. Function will return empty array if array.length is <= 2.
  • assertArraysEqual(array1,array2): Takes two array(array1, array2) and compare them. Will return a true message if array1 and array2 is exactly the same. Will return a false message if array1 and array2 is NOT exactly the same.
  • assertObjectsEqual(object1, object2): Takes two object(object1, object2) and compare them. Will return a true message if object1 and object2 is exactly the same. Will return a false message if array1 and array2 is NOT exactly the same.
  • countLetters(string): Takes a string and return an object. The returned object will contain characters that occured and the occurance frequency of that chracter. Function will ignore spaces.
  • countOnly(array, object): Takes an array and an object, return an object. The input object needs have the selected string as a key, and a boolean that signals if that string is selected(true = selected, and false = not selected)(e.g. {sam: true}). The returned object will contain characters that occured and the occurance frequency of that chracter. Function will ignore spaces.
  • eqArrays(array1, array2): Takes two array(array1, array2) and compare them. Return true if array1 and array2 is exactly the same. Return false if array1 and array2 is NOT exactly the same
  • eqObjects(object1, object2): Takes two object(object1, object2) and compare them. Return true if object1 and object2 is exactly the same. Return false if object1 and object2 is NOT exactly the same
  • findKey(object, function): Takes an object and a function. Return the key of a specific object when the function returns true.
  • findKeyByValue(object, string): Takes an object and a string. Function will look for the matching string inside all the keys. If a matching string is found, return the matching string's key.
  • flatten(array): Takes an array and return an array. The returned array will merge all inner arrays to outer arrays. Only works on one layer of array.
  • letterPositions(string): Takes a string and returns an array that indicate the index position of all characters.
  • map(array, function): Takes an array and a function, apply the function to every element of array.
  • takeUntil(array, function): Takes an array and a function. Function will loop through all element in array, and stops when function returns true. Returned array will contains all the element until the stopping point.
  • without(array1, array2): Takes two array(array1, array2) and return a copy array1 that excluded all the values on array2.