1.0.1 • Published 1 year ago

@mbieganek/lotide v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year 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 @mbieganek/lotide

Require it:

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

Call it:

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

Functions

The following functions are currently implemented:

assertArraysEqual(array1, array2) ⇒ boolean

Function that compares 2 arrays for equality and prints out a message telling us if they match or not

Kind: global function
Returns: boolean - The result of the evaluation

ParamTypeDescription
array1Array.<(string|number|boolean)>The first array to compare
array2Array.<(string|number|boolean)>The second array to compare

assertEqual(actual, expected) ⇒ string

Function that compares 2 values for equality and prints out a message telling us if they match or not

Kind: global function
Returns: string - Prints message with match outcome

ParamTypeDescription
actualstring | number | booleanThe first item to compare
expectedstring | number | booleanThe second item to compare

assertObjectsEqual(actual, expected)

Function that compares 2 objects for equality and prints out a message telling us if they match or not

Kind: global function

ParamTypeDescription
actualObjectThe first item to compare
expectedObjectThe second item to compare

countLetters(string) ⇒ Object

Function that counts the total instances of a letter in a string

Kind: global function
Returns: Object - An object with characters from string as value labels, and the total instances of that character as the value

ParamTypeDescription
stringstringThe string containing the elements you wish to count

countOnly(allItems, itemsToCount) ⇒ Object

Function that when given an array and an object, it will return an object containing counts of everything that the input object listed

Kind: global function
Returns: Object - A list of values found, and their total occurrences

ParamTypeDescription
allItemsArray.<string>Array of strings to look through
itemsToCountObjectObject with key value pairs specifying what to count
itemsToCount.keystringAll keys in itemsToCount match the value to find as the key name, with a boolean value indicating if the name will be counted. For example, to count John assign a property in itemsToCount of John: true

Example

When `allitems` is `['Karl', 'Fang', 'Salima', 'Fang']` and
`itemsToCount` is `{ Karl: false, Salima: true, Fang, true}` the
result will be `{ Salima: 1, Fang: 2 }`

eqArrays(array1, array2) ⇒ boolean

Function that compares 2 arrays for equality and returns the result

Kind: global function
Returns: boolean - The result of the evaluation

ParamTypeDescription
array1Array.<(string|number|boolean)>The first array to compare
array2Array.<(string|number|boolean)>The second array to compare

eqObjects(object1, object2) ⇒ boolean

Function that evaluates two provided objects for equality

Kind: global function
Returns: boolean - The outcome of the evaluation

ParamTypeDescription
object1ObjectThe first object to evaluate
object2ObjectThe second object to evaluate

findKey(object, action) ⇒ string | undefined

Function that scans an object and returns the first key for which the callback/predicate returns a truthy value. If no key is found, then it returns undefined.

Kind: global function
Returns: string | undefined - The name of the key, or undefined if none was found

ParamTypeDescription
objectObjectThe object from which to find a key
actionfunctionThe callback function that is used to evaluate the keys

findKeyByValue(object, keyValue) ⇒ string | undefined

Function that takes in an object and a value. It should scan the object and return the first key which contains the given value

Kind: global function
Returns: string | undefined - The name of the key that matches, or undefined if no match was found

ParamTypeDescription
objectObjectThe object to search
keyValuestring | number | booleanThe value to search for

flatten(array, buffer) ⇒ Array

Function that flattens an array with any number of nested arrays

Kind: global function
Returns: Array - The flattened array

ParamTypeDescription
arrayArrayThe array of elements to flatten
bufferArrayused as a pass-through value for recursion

head(array) ⇒ * | undefined

Function that returns the first element from an array, or undefined if the array was empty

Kind: global function
Returns: * | undefined - The first element from the array, or undefined

ParamTypeDescription
arrayArrayAn array containing one or more elements

letterPositions(sentence) ⇒ Object

Function that receives a string, and returns an object with a key for each unique character, as well the character positions in the string

Kind: global function
Returns: Object - An object with a key matching each unique character, and where to find them in the sentence

ParamTypeDescription
sentencestringThe string to analyze

map(array, callback) ⇒ Array

Function that will take in two arguments, an array to map, and a callback function. The function will return a new array based on the results of the callback function.

Kind: global function
Returns: Array - An array with the results of the callback function

ParamTypeDescription
arrayArrayAn array to map
callbackfunctionA callback function to call against each item in the array

isEven(number) ⇒ boolean

Function that evaluates a number as even

Kind: global function
Returns: boolean - The outcome of the evaluation

ParamTypeDescription
numbernumberThe number to evaluate as even

middle(array) ⇒ * | undefined

Function that returns the middel elemet(s) from an array, or undefined if the array was empty

Kind: global function
Returns: * | undefined - The first element from the array, or undefined

ParamTypeDescription
arrayArrayAn array containing three or more elements

printAssertEqualResult(hasEquality, actual, expected) ⇒ string

Function that builds a message for the assertEqual functions in this library

Kind: global function
Returns: string - A formatted message

ParamTypeDescription
hasEqualitybooleanResult of equality check
actual*Input passed to the equality check
expected*Expected input in the equality check

tail(array) ⇒ Array

Function that returns all but the first element from an array, or undefined if the array was empty. If the array is empty or only has one element, it returns an empty array

Kind: global function
Returns: Array - All but the first element from the array, or an empty array

ParamTypeDescription
arrayArrayAn array containing one or more elements

takeUntil(array, callback) ⇒ Array

Function that returns a slice of the provided array with elements taken from the beginning, up until the callback/predicate returns a truthy value

Kind: global function
Returns: Array - The elements that were sliced from the input array

ParamTypeDescription
arrayArrayThe array from which to slice elements
callbackfunctionThe predicate function determines when to stop slicing elements from the array

without(sourceItems, removeItems) ⇒ Array

Function that copies the source array, while excluding items that are found in the removeItems array

Kind: global function
Returns: Array - The copied array

ParamTypeDescription
sourceItemsArray.<(string|number|boolean)>The array to be copied
removeItemsArray.<(string|number|boolean)>An array of items to not include in the returned array

Credits

The functions section of this README was generated with jsdoc2md a suite of modules for generating markdown documentation from jsdoc-annotated source.