3 category: JavaScript libraries
8 This is not a complete list.
16 _.filter(list, (n) => n % 2) // → Array
17 _.find(list, (n) => n % 2) // → item
18 _.findLast(list, ...) // → item
21 Works for both arrays and objects.
26 _.at([ abcd ], 0) // → [ a ] - same as list[0]
27 _.at([ abcd ], [ 0, 1 ]) // → [ ab ]
33 _.set(object, 'users[0].name', value)
34 _.get(object, 'users[0].name')
35 _.get(object, ['users', 0, 'name'])
41 _.forEach(list, (item, i) => ...)
42 _.forEachRight(list, ...)
48 _.every(users, (u) => u.active) // → true|false (aka _.all)
49 _.any(users, ...) // → true|false (aka _.some)
57 _.chunk([ abcd ], 2) // → [ [ab], [cd] ]
60 _.fill(Array(4), 'x') // → [ 'x', 'x', 'x', 'x' ]
68 _.drop([ abcdef ], 2) // → [ cdef ]
69 _.dropRight([ abcdef ], 2) // → [ abcd ]
70 _.take([ abcdef ], 2) // → [ ab ]
71 _.takeRight([ abcdef ], 2) // → [ de ]
72 _.slice([ abcdef ], 2, 4) // → [ cd ]
76 _.initial([ abcdef ]) // → [ abcde ] - dropRight(list, 1)
77 _.rest([ abcdef ]) // → [ bcdef ] - takeRight(list, 1)
81 _.dropWhile(list, 'active') // works like filter
82 _.dropWhile(list, 'active', true)
83 _.dropWhile(list, { active: true })
84 _.dropWhile(list, (n) => ...)
85 _.dropRightWhile(list, ...)
89 _.without([ abcde ], b) // → [ acde ]
93 _.remove(list, (n) => n % 2)
99 _.first([ abcdef ]) // → a
100 _.last([ abcdef ]) // → f
107 _.difference([ abc ], [ bc ]) // → [ a ]
108 _.intersection([ abc ], [ bcd ]) // → [ bc ]
109 _.union([ abc ], [ bcd ]) // → [ abcd ] (unique)
119 _.findIndex(list, fn)
120 _.findLastIndex(list, fn)
124 _.sortedIndex(list, val)
125 _.sortedLastIndex(list, val)
137 greet = (greeting, name) => `${greeting}, ${name}!`
142 fn = _.partial(fn, 'hi')
143 fn('joe') // → 'hi, joe!'
145 fn = _.partial(fn, 'joe')
146 fn('yo') // → 'yo, joe!'
150 _.curry(greet)('hi') // → function(name)
151 _.curryRight(greet)('joe') // → function(greet)
154 ## Decorating functions
166 _.before(5, fn) // only works 5 times
167 _.after(5, fn) // works only after 5 times
168 _.once(fn) // like _.before(fn, 1)
174 _.wrap(_.escape, (name) => `hi ${name}`)
175 // same as doing `name = _.escape(name)`
190 _.capitalize('hello world') // → 'Hello world'
191 _.startCase('hello_world') // → 'Hello World'
192 _.snakeCase('hello world') // → 'hello_world'
193 _.kebabCase('hello world') // → 'hello-world'
194 _.camelCase('hello world') // → 'helloWorld'
200 _.pad('abc', 3) // → 'abc'
201 _.pad('abc', 8) // → ' abc '
202 _.pad('abc', 8, '_-') // → '_-abc_-_'
203 _.padStart('abc', 3) // → 'abc'
204 _.padStart('abc', 6) // → ' abc'
205 _.padStart('abc', 6, '_-')// → '_-_abc'
206 _.padEnd('abc', 3) // → 'abc'
207 _.padEnd('abc', 6) // → 'abc '
208 _.padEnd('abc', 6, '_-') // → 'abc_-_'
214 _.trim(' str ') // → 'str'
215 _.trimLeft(' str ') // → 'str '
216 _.trimRight(' str ') // → ' str'
222 _.repeat('-', 2) // → '--'
223 _.deburr('déjà vu') // → 'deja vu'
224 _.trunc('hello world', 5) // → 'hello...'
228 _.startsWith('abc', 'a') // → true
229 _.endsWith('abc', 'c') // → true
247 .reduce((total, n) => total + n)
250 .thru((n) => n.reverse())