you-dont-need / You-Dont-Need-Lodash-Underscore

List of JavaScript methods which you can use natively + ESLint Plugin
MIT License
18.61k stars 813 forks source link

Purpose of this repo #372

Closed ArjixWasTaken closed 11 months ago

ArjixWasTaken commented 1 year ago

Lodash and Underscore are great modern JavaScript utility libraries, and they are widely used by Front-end developers. However, when you are targeting modern browsers, you may find out that there are many methods which are already supported natively thanks to ECMAScript5 [ES5] and ECMAScript2015 [ES6]. If you want your project to require fewer dependencies, and you know your target browser clearly, then you may not need Lodash/Underscore.

This implies that lodash is not using native ecmascript features, or at least that when lodash came out, you couldn't do what it does, and now you can.

But my main wonder is, since lodash is written in javascript, how come you claim the features it provides are not natively available? I would understand if you actually meant built-in method replacements, but you provide entire functions as replacements...

image

The "Native" alternative, is really not anymore native than what lodash has...

the implementation of _.chunk for reference:

function chunk(array, size = 1) {
  size = Math.max(toInteger(size), 0)
  const length = array == null ? 0 : array.length
  if (!length || size < 1) {
    return []
  }
  let index = 0
  let resIndex = 0
  const result = new Array(Math.ceil(length / size))

  while (index < length) {
    result[resIndex++] = slice(array, index, (index += size))
  }
  return result
}

So like, define "native", because you really make zero sense. If I copy the source code of _.chunk into my code w/o having lodash as a dependency, does that make it "native"?

If so, wouldn't using a tree shaker in the bundling step be the better option than manually using alternatives? Unless this is about projects that only need one lodash function and don't need the rest.

But even then a tree-shaker is pretty good at removing excess code.

Now, if you advertised this repo as an educational one, with the intent of teaching how to achieve what lodash does w/o using lodash, then that would make a lot of sense, but that is not in the README.

ArjixWasTaken commented 1 year ago

I guess one could argue that lodash uses a custom slice, whilst you use the built-in slice.

dev0T commented 1 year ago

I also think it is important to inform the differences of the two implementations other than just suggesting a native solution and ignoring the fact that one of the things lodash is aiming to improve is performance.

So yes, there's a huge difference between in "you don't need lodash" and "you might not need lodash".