@gottfriedk/lotide

1.0.0 • Public • Published

Project: Lotide

About

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!

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

Require it:

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

Call it:

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

Documentation

Table of contents

  1. assertArraysEqual
  2. assertEqual
  3. assertObjectsEqual
  4. countLetters
  5. countOnly
  6. eqArrays
  7. eqObjects
  8. findKey
  9. findKeyByValue
  10. flatten
  11. head
  12. letterPositions
  13. map
  14. middle
  15. tail
  16. takeUntil
  17. without

1. assertArraysEqual

assertArraysEqual(array1, array2): a function that determines whether 2 arrays are strictly equal.

Params:

  • (A) Type: array -- should be the array you want to test. Actual
  • (B) 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.


2. assertEqual

assertEqual(actual, expected): a function that determines whether two primitives are strictly equal.

Params:

  • (a) primitive data type, to be tested
  • (b) 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.


3. assertObjectsEqual

assertObjectsEqual(obj1, obj2): is a function that determines whether two objects are strictly equal. Does not return a value.

Params:

  • (a) the object to be tested. Actual
  • (b) 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.


4. countLetters

countLetters('string'): a function that counts the letters of a string.

Params:

  • (a) a 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.


5. countOnly

countOnly(allItems, itemsToCount): a function that counts the specified items from an array.

Params:

  • (a) an array of items
  • (b) 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.


6. eqArrays

eqArrays(array1, array2): is a function that determines whether 2 arrays are strictly equal.

Params:

  • (a) array to test
  • (b) 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.


7. eqObjects

eqObjects(obj1, obj2): is a function that determines whether 2 objects are strictly equal.

Params:

  • (a) object to test
  • (b) 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.


8. findKey

findKey(object, callback): returns the key of an object based on the criteria, defined in a callback function.

Params:

  • (a) an object
  • (b) 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.


9. findKeyByValue

findKeyByValue(object, value): returns the first key of an objects property whos value matches the provided argument.

Params:

  • (a) an object
  • (b) 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.


10. flatten

flatten(array): returns nested arrays as one flat array.

Params:

  • (a) 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.


11. head

head(array): returns the first item in an array.

Params:

  • (a) an array

Behaviour:

Slices and returns a shallow copy of the first item of the array passed as an argument. Does not alter the array.


12. letterPositions

letterPositions('string'): Returns an object of letters that appear in the string and their index positions, listed in an array.

Params:

  • (a) a 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.


13. map

map(array, callback): Performs a callback function on each item of an array.

Params:

  • (a) an array
  • (b) a callback function

Behaviour:

Returns a new array based on the results of a callback function being performed on each item in the array.


14. middle

middle(array): Return the middle item or items of an array.

Params:

  • (a) an array

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.


15. tail

tail(array): Returns an array of all items except for the first one.

Params:

  • (a) an array

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.


16. takeUntil

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:

  • (a) an array
  • (b) a callback function

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.


17. without

without(source, itemsToRemove): Returns an array without the items specified.

Params:

  • (a) an source array
  • (b) an array of items to remove

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.


Package Sidebar

Install

npm i @gottfriedk/lotide

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

22.2 kB

Total Files

22

Last publish

Collaborators

  • gottfriedk