lodash: update

This commit is contained in:
Rico Sta. Cruz 2017-10-17 11:44:52 +08:00
parent 8de1797cd1
commit b6b59756cd
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
2 changed files with 65 additions and 55 deletions

104
lodash.md
View File

@ -3,20 +3,19 @@ title: Lodash
category: JavaScript libraries category: JavaScript libraries
layout: 2017/sheet layout: 2017/sheet
weight: -3 weight: -3
updated: 2017-10-17
description: |
This is not a complete list.
--- ---
This is not a complete list.
<!--more-->
## Collections ## Collections
### Finding ### Finding
```js ```js
_.filter(list, (n) => n % 2) //=> Array _.filter(list, (n) => n % 2) // Array
_.find(list, (n) => n % 2) //=> item _.find(list, (n) => n % 2) // item
_.findRight(list, ...) //=> item _.findRight(list, ...) // item
``` ```
Works for both arrays and objects. Works for both arrays and objects.
@ -24,8 +23,8 @@ Works for both arrays and objects.
### Accessing ### Accessing
```js ```js
_.at([ abcd ], 0) //=> [ a ] - same as list[0] _.at([ abcd ], 0) // [ a ] - same as list[0]
_.at([ abcd ], [ 0, 1 ]) //=> [ ab ] _.at([ abcd ], [ 0, 1 ]) // [ ab ]
``` ```
### Set/get ### Set/get
@ -46,8 +45,8 @@ _.map(list, ...)
``` ```
```js ```js
_.every(users, (u) => u.active) //=> true|false (aka _.all) _.every(users, (u) => u.active) // true|false (aka _.all)
_.any(users, ...) //=> true|false (aka _.some) _.any(users, ...) // true|false (aka _.some)
``` ```
## Array ## Array
@ -55,10 +54,10 @@ _.any(users, ...) //=> true|false (aka _.some)
### Arrays ### Arrays
```js ```js
_.chunk([ abcd ], 2) //=> [ [ab], [cd] ] _.chunk([ abcd ], 2) // [ [ab], [cd] ]
_.compact(list) _.compact(list)
_.fill(Array(4), 'x') //=> [ 'x', 'x', 'x', 'x' ] _.fill(Array(4), 'x') // [ 'x', 'x', 'x', 'x' ]
_.flatten _.flatten
_.flattenDeep _.flattenDeep
``` ```
@ -66,16 +65,16 @@ _.flattenDeep
### Filtering ### Filtering
```js ```js
_.drop([ abcdef ], 2) //=> [ cdef ] _.drop([ abcdef ], 2) // [ cdef ]
_.dropRight([ abcdef ], 2) //=> [ abcd ] _.dropRight([ abcdef ], 2) // [ abcd ]
_.take([ abcdef ], 2) //=> [ ab ] _.take([ abcdef ], 2) // [ ab ]
_.takeRight([ abcdef ], 2) //=> [ de ] _.takeRight([ abcdef ], 2) // [ de ]
_.slice([ abcdef ], 2, 4) //=> [ cd ] _.slice([ abcdef ], 2, 4) // [ cd ]
``` ```
```js ```js
_.initial([ abcdef ]) //=> [ abcde ] - dropRight(list, 1) _.initial([ abcdef ]) // [ abcde ] - dropRight(list, 1)
_.rest([ abcdef ]) //=> [ bcdef ] - takeRight(list, 1) _.rest([ abcdef ]) // [ bcdef ] - takeRight(list, 1)
``` ```
```js ```js
@ -87,7 +86,7 @@ _.dropRightWhile(list, ...)
``` ```
```js ```js
_.without([ abcde ], b) //=> [ acde ] _.without([ abcde ], b) // [ acde ]
``` ```
```js ```js
@ -97,30 +96,36 @@ _.remove(list, (n) => n % 2)
### Accessing ### Accessing
```js ```js
_.first([ abcdef ]) //=> a _.first([ abcdef ]) // a
_.last([ abcdef ]) //=> f _.last([ abcdef ]) // f
``` ```
### Sets ### Sets
``` ```js
_.uniq() _.uniq()
_.difference([ abc ], [ bc ]) //=> [ a ] _.difference([ abc ], [ bc ]) // → [ a ]
_.intersection([ abc ], [ bcd ]) //=> [ bc ] _.intersection([ abc ], [ bcd ]) // → [ bc ]
_.union([ abc ], [ bcd ]) //=> [ abcd ] (unique) _.union([ abc ], [ bcd ]) // → [ abcd ] (unique)
```
```js
Array#concat() Array#concat()
``` ```
### Indexes ### Indexes
```js
_.findIndex(list, fn)
_.findLastIndex(list, fn)
``` ```
_.findIndex
_.findLastIndex
```js
_.sortedIndex(list, val) _.sortedIndex(list, val)
_.sortedLastIndex(list, val) _.sortedLastIndex(list, val)
```
```js
_.indexOf(list, val) _.indexOf(list, val)
``` ```
@ -131,18 +136,19 @@ _.indexOf(list, val)
```js ```js
greet = (greeting, name) => `${greeting}, ${name}!` greet = (greeting, name) => `${greeting}, ${name}!`
``` ```
{: .-setup}
```js ```js
fn = _.partial(fn, 'hi') fn = _.partial(fn, 'hi')
fn('joe') //=> 'hi, joe!' fn('joe') // 'hi, joe!'
_.partial(fn, 'joe') fn = _.partial(fn, 'joe')
fn('yo') //=> 'yo, joe!' fn('yo') // 'yo, joe!'
``` ```
```js ```js
_.curry(greet)('hi') //=> function(name) _.curry(greet)('hi') // function(name)
_.curryRight(greet)('joe') //=> function(greet) _.curryRight(greet)('joe') // function(greet)
``` ```
## Decorating functions ## Decorating functions
@ -181,19 +187,19 @@ _.memoize(fn, ...)
### Capitalization ### Capitalization
```js ```js
_.capitalize('hello world') //=> 'Hello world' _.capitalize('hello world') // 'Hello world'
_.startCase('hello_world') //=> 'Hello World' _.startCase('hello_world') // 'Hello World'
_.snakeCase('hello world') //=> 'hello_world' _.snakeCase('hello world') // 'hello_world'
_.kebabCase('hello world') //=> 'hello-world' _.kebabCase('hello world') // 'hello-world'
_.camelCase('hello world') //=> 'helloWorld' _.camelCase('hello world') // 'helloWorld'
``` ```
### Padding ### Padding
```js ```js
_.pad('abc', 8) //=> ' abc ' _.pad('abc', 8) // ' abc '
_.padLeft('abc', 8) //=> ' abc' _.padLeft('abc', 8) // ' abc'
_.padLeft('abc', 8, '-') //=> '00000abc' _.padLeft('abc', 8, '-') // '00000abc'
_.padRight(...) _.padRight(...)
``` ```
@ -208,18 +214,20 @@ _.trimRight(' str ')
### Etc ### Etc
```js ```js
_.repeat('-', 2) //=> '--' _.repeat('-', 2) // '--'
_.deburr('déjà vu') //=> 'deja vu' _.deburr('déjà vu') // 'deja vu'
_.trunc('hello world', 5) //=> 'hello...' _.trunc('hello world', 5) // 'hello...'
``` ```
```js ```js
_.startsWith('abc', 'a') //=> true _.startsWith('abc', 'a') // true
_.endsWith('abc', 'c') //=> true _.endsWith('abc', 'c') // true
``` ```
## Objects ## Objects
### Keys and values
```js ```js
_.keys(obj) _.keys(obj)
_.values(obj) _.values(obj)
@ -227,6 +235,8 @@ _.values(obj)
## Chaining ## Chaining
### Chain and value
```js ```js
_([1, 2, 3]) _([1, 2, 3])
.reduce((total, n) => total + n) .reduce((total, n) => total + n)

View File

@ -4,14 +4,14 @@ category: JavaScript libraries
layout: 2017/sheet layout: 2017/sheet
updated: 2017-10-11 updated: 2017-10-11
keywords: keywords:
- @Component - "@Component"
- @Prop() - "@Prop()"
- @State() - "@State()"
- render() - "render()"
- componentWillLoad() - "componentWillLoad()"
- componentWillUpdate() - "componentWillUpdate()"
- Templating - "Templating"
- Lifecycle - "Lifecycle"
intro: | intro: |
[Stencil](https://github.com/ionic-team/stencil) is a compiler for web components made by the Ionic team. This guide targets Stencil v0.0.5. [Stencil](https://github.com/ionic-team/stencil) is a compiler for web components made by the Ionic team. This guide targets Stencil v0.0.5.
--- ---