@adamleseur/lotide 中文文档教程

发布于 5年前 浏览 11 项目主页 更新于 3年前

Lotide

Lodash 库的迷你克隆。

Purpose

注意:此库是出于学习目的而发布的。 它旨在用于生产级软件。

这个项目是我创建和发布的,是我在 Lighthouse Labs 学习的一部分。

Usage

安装它:

npm install @adamleseur/lotide

需要它:

const _ = require('@adamleseur/lotide');< /code>

调用它:

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

Documentation

目前实现了以下功能:

  • head(arr): Takes in an array and returns the first element in the array, doing away with the rest.
  • tail(arr): Takes in an array, disposing of the first element in the array and returning the remaining array.
  • middle(array): Takes in an array and returns the two middle values (if the array's length is even), one middle value (if the array's length is odd) or an empty array if the array length is shorter than three.
  • assertArraysEqual(actual, expected): Takes in two arrays and logs in the console whether or not they are identical. Also returns the message.
  • assertEqual(actual, expected): Takes in two elements that aren't objects or arrays and logs in the console whether or not they are identical. Also returns the message.
  • assertObjectsEqual(actual, expected): Takes in two objects and logs in the console whether or not they are identical. Also returns the message.
  • countLetters(string): Takes in a string and returns an object that illustrates what letters appeared (as keys) and how many times they appeared (as parameters).
  • countOnly(allItems, itemsToCount): Takes in an array of items as well as an object that illustrates which elements to count (through true/false parameters). Returns an object of counted elements and the amount of times they appeared.
  • eqArrays(arr1, arr2): Takes in two arrays and returns whether or not they are identical.
  • eqObjects(object1, object2): Takes in two objects and returns whether or not they are identical.
  • findKey(obj, callback): Takes in an object and loops through the keys. If the callback (relating to the key) is true, that key is returned.
  • findKeyByValue(obj, string): Takes in an object and a string and loops through the keys of the object. If the object's key's parameter matches the string, that key is returned.
  • flatten(arr): Takes in an array with nested arrays and turns it into a single, 'flattened' array without nested arrays.
  • letterPositions(sentence): Takes in a sentence and returns an object that includes each letter and the indexes where that letter appeared.
  • map(array, callback): Takes in an array and a callback function. Loops through the array and returns a new array with the specified callback function applied to every index of the old array.
  • takeUntil(array, callback): Takes in an array and a callback function. Pushes every element of the given array to a new array, until the callback function pertaining to that key equals true. Then, the new array is returned.
  • without(source, itemsToRemove): Takes in an array and an array of items to remove from said array. Returns array without items specified in itemsToRemove.

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

Require it:

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

Call it:

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

Documentation

The following functions are currently implemented:

  • head(arr): Takes in an array and returns the first element in the array, doing away with the rest.
  • tail(arr): Takes in an array, disposing of the first element in the array and returning the remaining array.
  • middle(array): Takes in an array and returns the two middle values (if the array's length is even), one middle value (if the array's length is odd) or an empty array if the array length is shorter than three.
  • assertArraysEqual(actual, expected): Takes in two arrays and logs in the console whether or not they are identical. Also returns the message.
  • assertEqual(actual, expected): Takes in two elements that aren't objects or arrays and logs in the console whether or not they are identical. Also returns the message.
  • assertObjectsEqual(actual, expected): Takes in two objects and logs in the console whether or not they are identical. Also returns the message.
  • countLetters(string): Takes in a string and returns an object that illustrates what letters appeared (as keys) and how many times they appeared (as parameters).
  • countOnly(allItems, itemsToCount): Takes in an array of items as well as an object that illustrates which elements to count (through true/false parameters). Returns an object of counted elements and the amount of times they appeared.
  • eqArrays(arr1, arr2): Takes in two arrays and returns whether or not they are identical.
  • eqObjects(object1, object2): Takes in two objects and returns whether or not they are identical.
  • findKey(obj, callback): Takes in an object and loops through the keys. If the callback (relating to the key) is true, that key is returned.
  • findKeyByValue(obj, string): Takes in an object and a string and loops through the keys of the object. If the object's key's parameter matches the string, that key is returned.
  • flatten(arr): Takes in an array with nested arrays and turns it into a single, 'flattened' array without nested arrays.
  • letterPositions(sentence): Takes in a sentence and returns an object that includes each letter and the indexes where that letter appeared.
  • map(array, callback): Takes in an array and a callback function. Loops through the array and returns a new array with the specified callback function applied to every index of the old array.
  • takeUntil(array, callback): Takes in an array and a callback function. Pushes every element of the given array to a new array, until the callback function pertaining to that key equals true. Then, the new array is returned.
  • without(source, itemsToRemove): Takes in an array and an array of items to remove from said array. Returns array without items specified in itemsToRemove.
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文