Git Product home page Git Product logo

lodash-recreated's Introduction

Lodash Recreated

Documentation Build Status Code Coverage License Contributions

lodash-recreated is a vanilla JavaScript Re-Creation of the popular library Lodash with Array, Object, Collection, Util and Lang utility methods, along with unit-tests written for each of the implemented methods.


Implemented Methods:

  • Array

    • chunk(array, [size=1])

    Creates an array of elements split into groups the length of size.
    If array can't be split evenly, the final chunk will be the remaining elements.
    https://lodash.com/docs/4.17.15#chunk

    • compact(array)

    Creates an array with all falsey values removed.
    The values false, null, 0, "", undefined, and NaN are falsey.
    https://lodash.com/docs/4.17.15#compact

    • concat(array, [values])

    Creates a new array concatenating array with any additional arrays and/or values.
    https://lodash.com/docs/4.17.15#concat

    • difference(array, [values])

    creates an array of array values not included in the other given arrays using SameValueZero for equality comparisons.
    https://lodash.com/docs/4.17.15#difference

    • differenceBy(array, [values], [iteratee=_.identity])

    This method is like difference except that it accepts iteratee which is invoked for each element of array and values to generate the criterion by which they're compared. The order and references of result values are determined by the first array.
    https://lodash.com/docs/4.17.15#differenceBy

    • differenceWith(array, [values], [comparator])

    This method is like _.difference except that it accepts comparator which is invoked to compare elements of array to values. The order and references of result values are determined by the first array. The comparator is invoked with two arguments: (arrVal, othVal).
    https://lodash.com/docs/4.17.15#differenceWith

    • drop(array, n = 1)

    creates a slice of an array with n elements dropped from the beginning.
    https://lodash.com/docs/4.17.15#drop

    • dropWhile(array, [predicate=_.identity])

    Creates a slice of array excluding elements dropped from the beginning, Elements are dropped until the predicate returns falsey.
    https://lodash.com/docs/4.17.15#dropWhile

    • dropRight(array, [n = 1])

    Creates a slice of array with n elements dropped from the end.
    https://lodash.com/docs/4.17.15#dropRight

    • dropRightWhile(array, predicate)

    Creates a slice of array excluding elements dropped from the end. Elements are dropped until predicate returns falsey.
    https://lodash.com/docs/4.17.15#dropRightWhile

    • flatten(array)

    Flattens array a single level deep.
    https://lodash.com/docs/4.17.15#flatten

    • flattenDeep(array)

    Recursively flattens array.
    https://lodash.com/docs/4.17.15#flattenDeep

    • flattenDepth(array, [depth = 1])

    Recursively flatten array up to depth times.
    _.flattenDepth(array, [depth=1])

    • fromPairs(pairs)

    this method returns an object composed from key-value pairs(arrays).
    https://lodash.com/docs/4.17.15#fromPairs

    • intersection([arrays])

    Write a function that creates an array of values found within all given arrays.
    The first array will serve as the base from which the remaining arrays will be checked to see if they have the matching values.
    https://lodash.com/docs/4.17.15#intersection

    • nth(array, [n=0])

    Gets the element at index n of array.
    If n is negative, the nth element from the end is returned.
    _.nth(array, [n=0])

    • pull(array, [values])

    Removes all given values from array using SameValueZero for equality comparisons.
    https://lodash.com/docs/4.17.15#pull

    • tail(array)

    Gets all but the first element of array.
    https://lodash.com/docs/4.17.15#tail

    • uniq(array)

    Creates a duplicate-free version of an array, using SameValueZero for equality comparisons,
    in which only the first occurrence of each element is kept. The order of result values
    is determined by the order they occur in the array. https://lodash.com/docs/4.17.15#uniq

  • Object

    • get(object, path, [defaultValue])

    Gets the value at path of object.
    If the resolved value is undefined, the defaultValue is returned in its place.
    https://lodash.com/docs/4.17.15#get

  • Collection

    • find (collection, predicate, startIndex)

    Iterates over elements of collection, returning the first element predicate returns truthy for.
    The predicate is invoked with three arguments: (value, index|key, collection).
    https://lodash.com/docs/4.17.15#find

    • groupBy(collection, [iteratee=_.identity])

    Creates an object composed of keys generated from the results of running each element of collection thru iteratee.
    The order of grouped values is determined by the order they occur in collection.
    https://lodash.com/docs/4.17.15#groupBy

    • countBy(collection, [iteratee=_.identity])

    Creates an object composed of keys generated from the results of running each element of collection thru iteratee.
    The corresponding value of each key is the number of times the key was returned by iteratee.
    https://lodash.com/docs/4.17.15#countBy

    • every(collection, [predicate=_.identity])

    Checks if predicate returns truthy for all elements of collection.
    Iteration is stopped once predicate returns falsey
    https://lodash.com/docs/4.17.15#every

    • invokeMap(collection, path, [args])

    Invokes the method at path of each element in collection, returning an array of
    the results of each invoked method. Any additional arguments are provided to each invoked method.
    . If path is a function, it's invoked for, and this bound to, each element in collection.
    https://lodash.com/docs/4.17.15#invokeMap

    • keyBy(collection, iteratee)

    Creates an object composed of keys generated from the results of
    running each element of collection thru iteratee. The corresponding value of each key is
    the last element responsible for generating the key.
    The iteratee is invoked with one argument: (value).
    https://lodash.com/docs/4.17.15#keyBy

  • Number

    • clamp(number, [lower], upper)

    Clamps number within the inclusive lower and upper bounds.
    https://lodash.com/docs/4.17.15#clamp

    • random(lower = 0, upper = 1, floating = false)

    Produces a random number between the inclusive lower and upper bounds.
    If only one argument is provided a number between 0 and the given number is returned.
    If floating is true, or either lower or upper are floats, a floating-point number is returned.
    https://lodash.com/docs/4.17.15#random

    • inRange(number, [start=0], end)

    Checks if n is between start and up to, but not including, end.
    If end is not specified, it's set to start with start then set to 0.
    If start is greater than end the params are swapped to support negative ranges.
    https://lodash.com/docs/4.17.15#inRange

  • Lang

    • isArguments(value)

    Checks if value is likely an Arguments object.
    https://lodash.com/docs/4.17.15#isArguments

    • isArray(value)

    Checks if value is classified as an Array object.
    https://lodash.com/docs/4.17.15#isArray

    • isArrayBuffer(value)

    Checks if value is classified as an ArrayBuffer object.
    https://lodash.com/docs/4.17.15#isArrayBuffer

    • isArrayLike(value)

    Checks if value is array-like. A value is considered array-like if
    it's not a function and has a value.length that's an integer
    greater than or equal to 0 and less than or equal to Number.MAX_SAFE_INTEGER.
    https://lodash.com/docs/4.17.15#isArrayLike

    • isArrayLikeObject(value)

    This method is like isArrayLike except that it also checks if value is an object.
    https://lodash.com/docs/4.17.15#isArrayLikeObject

    • isBoolean(value)

    Checks if value is classified as a boolean primitive or object.
    https://lodash.com/docs/4.17.15#isBoolean

    • isBuffer(value)

    Checks if value is a buffer.
    https://lodash.com/docs/4.17.15#isBuffer

    • isDate(value)

    Checks if value is classified as a Date object.
    https://lodash.com/docs/4.17.15#isDate

    • isEmpty(value)

    Checks if value is an empty object, collection, map, or set.
    Objects are considered empty if they have no own enumerable string keyed properties.
    Array-like values such as arguments objects, arrays, buffers, strings
    are considered empty if they have a length of 0.
    Similarly, maps and sets are considered empty if they have a size of 0.
    https://lodash.com/docs/4.17.15#isEmpty

Running Tests

The projects uses Jest JavaScript Testing Framework. to run all tests, all you have to do is run the command:

npm run test

License (MIT)

MIT License

Copyright (c) 2020 Hamza Hejja

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

lodash-recreated's People

Contributors

hamzahejja avatar

Watchers

 avatar

lodash-recreated's Issues

Implement _.compact Array method

Creates an array with all falsey values removed.
The values false, null, 0, "", undefined, and NaN are falsey.

Method Signature:

compact(array)

Arguments:

array (Array): The array to process.

Returns:

array with all falsey values removed.

Lodash _.compact Reference:

_.compact

Implement _.chunk Array method

Method Signature:

chunk(array, size = 1)

Arguments:

array (Array): The array to process.
size (number): The length of each chunk, default value = 1

Lodash _.chunk Reference:

_.chunk

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.