• Stars
    star
    226
  • Rank 176,514 (Top 4 %)
  • Language
  • Created almost 9 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

In response to You-Dont-Need-Lodash-Underscore βœ‹

You don't (may not) know Lodash/Underscore

In response to You-Dont-Need-Lodash-Underscore made by @cht8687, yes some of the methods could be replaced by native methods. This is not the case when things get a bit more complex. According to the Lodash author, @jdalton:

If you're only using a handful of methods on arrays and don't care about nullish guards, object iteration, smoothing over enviro/ES5/ES6 issues, FP goodies, iteratee shorthands, lazy evaluation, or other enhancements then built-ins are the way to go. Folks who use lodash know its 270+ modules work great combo'ed with ES6, enabling cleaner code and empowering beyond built-ins.

ESLint?

There is a plugin

Quick links

  1. _.each
  2. _.map
  3. _.every
  4. _.some
  5. _.reduce
  6. _.reduceRight
  7. _.filter
  8. _.find
  9. _.findIndex
  10. _.indexOf
  11. _.lastIndexOf
  12. _.isNaN

Note: The unit in performance field is Ops/sec.

_.each

Underscore/Lodash may exit iteration early by explicitly returning false.

// Underscore/Lodash
_.each([1, 2, 3], function(value, index) {
  console.log(value);
  return false;
});
// output: 1

// Native
[1, 2, 3].forEach(function(value, index) {
  console.log(value);
  return false; // does not exit the iteration!
});
// output: 1 2 3

Performance

Lodash Underscore Native
972,874 101,878 102,864 (89% slower)

⬆ back to top

_.map

Native doesn't support the _.property iteratee shorthand.

// Underscore/Lodash
var users = [
  { 'user': 'barney' },
  { 'user': 'fred' }
];
var arr = _.map(users, 'user');
console.log(arr);
// output: ['barney', 'fred']

// Native
var users = [
  { 'user': 'barney' },
  { 'user': 'fred' }
];
var arr = users.map('user');
// error!

Performance

Lodash Underscore Native
1,214,010 1,171,239 192,404 (94% slower)

⬆ back to top

_.every

Native doesn't support the _.property iteratee shorthand.

Performance

Lodash Underscore Native
1,342,410 1,373,736 1,410,766

⬆ back to top

_.some

Native doesn't support the _.matches iteratee shorthand.

// Underscore/Lodash
var users = [
  { 'user': 'barney', 'active': true },
  { 'user': 'fred',   'active': false }
];

// using the `_.matches` iteratee shorthand
_.some(users, { 'user': 'barney', 'active': false });
// output: false

// Native
var users = [
  { 'user': 'barney', 'active': true },
  { 'user': 'fred',   'active': false }
];
var result = array.some({ 'user': 'barney', 'active': false }); // error!

Performance

Todo

⬆ back to top

_.reduce

Performance

Lodash Underscore Native
8,734 5,481 7,467

⬆ back to top

_.reduceRight

Todo

⬆ back to top

_.filter

Native doesn't support the _.matches iteratee shorthand.

var users = [
  { 'user': 'barney', 'age': 36, 'active': true },
  { 'user': 'fred',   'age': 40, 'active': false }
];
// using the `_.matches` iteratee shorthand
_.filter(users, { 'age': 36, 'active': true });
// output: objects for ['barney']

// Native
var users = [
  { 'user': 'barney', 'age': 36, 'active': true },
  { 'user': 'fred',   'age': 40, 'active': false }
];
var filtered = users.filter({ 'age': 36, 'active': true }); // error!

Performance

Todo

⬆ back to top

_.find

Performance

Todo

⬆ back to top

_.findIndex

Performance

Todo

⬆ back to top

_.indexOf

Performance

Todo

⬆ back to top

_.lastIndexOf

Performance

Todo

⬆ back to top

_.isNaN

Native coerces the argument to a Number.

// Underscore/Lodash
console.log(_.isNaN("blabla"));
// output: false

// Native
// Confusing special-case behavior
console.log(isNaN("blabla"));
// output: true
// surprise!

// ES6
console.log(Number.isNaN("blabla"));
// output: false
// but browser support maybe the problem

⬆ back to top

References

Further reading

I'd like to quote jQuery's browser bug workarounds here:

While the sentiment of youmightnotneedjquery is great, developers should be aware that ditching libraries, like jQuery, can easily require large amounts of research on their end to avoid bugs (even in modern browsers). The snippets provided by youmightnotneedjquery are a starting point but hardly scratch the surface of being a solid robust replacement to jQuery.

The great thing about an established library, like jQuery, is it’s hammered on by lots of talented people, transparently improved, and refined by the community.

Concerned over file size? When it comes to page load time, count of HTTP requests (and placement) matter far more than total JS size. And heck, jQuery 1.9.x and 2.x allow custom builds, so you can minimize what of jQuery you end up shipping.

This line from youmightnotneedjquery is worth repeating… β€œAt the very least, make sure you know what jQuery is doing for you, and what it's not.”

~ John-David Dalton, Paul Irish

Feb 6, 2014

To extend, you should also know what your library/framework is doing. Browser support/fixing bugs is one thing. Tons of features/performance improvements should also take into account.

License

MIT

More Repositories

1

github-issue-templates

πŸ”£ A collection of GitHub issue and pull request templates
3,791
star
2

awesome-git-addons

😎 A curated list of add-ons that extend/enhance the git CLI.
1,793
star
3

awesome-pull-requests

How people work together (PR welcome!)
97
star
4

awesome-v8

A curated list of products that uses the Google V8 JavaScript engine.
29
star
5

github-remove-all-releases

Remove all releases of a GitHub repo
JavaScript
27
star
6

compare-func

Get a compare function for array to sort
JavaScript
16
star
7

html-comment-regex

Regular expression for matching HTML comments
JavaScript
15
star
8

mock-bin

Mock any executable binary
JavaScript
12
star
9

0126af95c0e2d9b0a7c78738c4c00a860b04acc8

r4nd0mstr1ng
JavaScript
12
star
10

angular-PapaParse

An Angular factory wrapper for PapaParse
JavaScript
11
star
11

mock-git

Mock any git command
JavaScript
11
star
12

sindresorhus

11
star
13

promise-to-callback

Convert promise to callback interface
JavaScript
9
star
14

git-latest-semver-tag

Get the most recent git semver tag of your repository
JavaScript
7
star
15

neoclock-js

πŸ• A NeoPixel wall clock made with JavaScript
JavaScript
7
star
16

trim-off-newlines

Similar to String#trim() but removes only newlines
JavaScript
7
star
17

fp-ts-extras

fp-ts extra functions and utilities
TypeScript
6
star
18

color-transitions

JavaScript
6
star
19

array-ify

Turn anything into an array
JavaScript
5
star
20

git-dummy-commit

Create a dummy commit for testing
JavaScript
5
star
21

skip-spotify-ads

Prevent Spotify from playing ads with a free account
5
star
22

mitsuyo-wechat

JavaScript
5
star
23

better-than-before

Useful when tests depend on each other
JavaScript
4
star
24

git-latest-tag

Get the most recent git tag of your repository using git-describe(1)
JavaScript
4
star
25

remove-html-comments

Remove comments in html
JavaScript
3
star
26

composition-trace

Impure trace function to see what's going on in a composition
JavaScript
3
star
27

inspect-compose

compose with debuggable glory
JavaScript
3
star
28

angular-ical

An Angular factory wrapper for ical.js
JavaScript
3
star
29

bling.js

Because you want the $ of jQuery without the jQuery
JavaScript
3
star
30

simple-timestamp

Get a simple timestamp
JavaScript
3
star
31

hook-writable-stream

Hooking into Node.js writable stream
JavaScript
3
star
32

chinese-surnames

πŸ‰ A list of Chinese surnames
JavaScript
3
star
33

console-module

Node-core console for userland
JavaScript
3
star
34

inspect-curry

curry with debuggable glory
JavaScript
3
star
35

You-Might-Not-Need-TypeScript

Bottom line: There’s no question that static types can feel good. Biting into a hot glazed donut feels good. But is it really good for you?
3
star
36

gulp-australian-stylesheets

Compile Australian CSS
JavaScript
2
star
37

You-Might-Not-Need-React-Router

2
star
38

javascript-cant-replace-html

Things that you can only do with HTML
2
star
39

capitalize-first-letter

Capitalize the first letter of a string
JavaScript
2
star
40

to-currency

JavaScript
2
star
41

clear-input-files

JavaScript
2
star
42

jekyll-netlify-cms

Ruby
2
star
43

gulp-remove-html-comments

Remove comments in html
HTML
2
star
44

fp-ts-string

TypeScript
2
star
45

mitsuyo

Python
2
star
46

dev-time.today

Get the current local time of a GitHub user.
JavaScript
2
star
47

uncomment-it

Uncomment html, js or css
JavaScript
2
star
48

html-non-conditional-comment-regex

Regular expression for matching non conditional HTML comments
JavaScript
2
star
49

supermoon-dates

JavaScript
2
star
50

list-to-matrix

JavaScript
2
star
51

grunt-australian-stylesheets

Compile Australian CSS
JavaScript
2
star
52

set-display-name-based-on-wrapped-component

Set display name for higher order components
JavaScript
1
star
53

confict-test

1
star
54

raining-phones

A jQuery plugin to generate Raining phones
JavaScript
1
star
55

cs240h

Haskell
1
star
56

regexpify

Turn a string to a regexp
JavaScript
1
star
57

grunt-remove-html-comments

Remove comments in html
JavaScript
1
star
58

conventional-committer

1
star
59

composition-debugger

Set a breakpoint in a composition
JavaScript
1
star
60

test

1
star
61

shisane

1
star
62

node4-module-paths

Get all paths of modules targeting node v4 and later in your node_modules folder
JavaScript
1
star
63

cht.js

1
star
64

gatsby-starter-netlify-cms

JavaScript
1
star
65

git-all-tags

JavaScript
1
star
66

siteminder-test

JavaScript
1
star
67

grunt-github-remove-all-releases

Remove all releases of a GitHub repo using github-remove-all-releases
JavaScript
1
star
68

hotpot

1
star
69

sindre-module-paths

Get all paths of sindre's modules in your node_modules folder
JavaScript
1
star
70

array-includes-one-element-in-array

JavaScript
1
star
71

array-includes-all-elements-in-array

JavaScript
1
star
72

unfuck-chinese-translations

Make Chinese great again
1
star
73

c-----logger

My personal updates
1
star
74

steves-styles

CSS
1
star
75

Blake-JS-test

JavaScript
1
star
76

monthly-missions

Haskell
1
star
77

australia-postcodes

1
star
78

force-env

Ensure environment variable exists. If not, throw to fail early.
TypeScript
1
star
79

simple-preprocess

Preprocess html, js and css based off environment configuration
JavaScript
1
star
80

steves-modules

Haskell
1
star
81

optics-exercises

Haskell
1
star
82

playground

My playground
1
star
83

shanghai-cuisine

🈸 A list of Shanghai cuisine
JavaScript
1
star
84

generator-steves-node

Create a Node.js module
JavaScript
1
star
85

diff-so-fancy-test

JavaScript
1
star
86

Optics-By-Example

1
star
87

grunt-uncomment-it

Uncomment html, js or css
JavaScript
1
star
88

vsauce-math-magic

JavaScript
1
star
89

a-test-repo

JavaScript
1
star
90

qantas

JavaScript
1
star
91

git-home

Open the Git home page of the repo in the current directory
1
star
92

git-flow

JavaScript
1
star
93

tj.js

1
star
94

source-reader

A better way to learn source code.
ApacheConf
1
star
95

polysemy-password-manager

Haskell
1
star
96

fdsfewrew

Haskell
1
star
97

shining-phone

A jQuery plugin to generate a shining phone
JavaScript
1
star
98

gulp-simple-preprocess

Preprocess html, js and css based off environment configuration
JavaScript
1
star
99

git-tails

Get git tail hashes from your repository in reverse chronological order
JavaScript
1
star
100

agri-digital

JavaScript
1
star