mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 19:07:49 +00:00
Move the "Convert" section to the bottom.
This commit is contained in:
@@ -23,52 +23,6 @@ var object = require('lodash/fp/object');
|
|||||||
var extend = require('lodash/fp/extend');
|
var extend = require('lodash/fp/extend');
|
||||||
```
|
```
|
||||||
|
|
||||||
## Convert
|
|
||||||
|
|
||||||
Although `lodash/fp` & its method modules come pre-converted, there are times
|
|
||||||
when you may want to customize the conversion. That’s when the `convert` method
|
|
||||||
comes in handy.
|
|
||||||
```js
|
|
||||||
// Every option is `true` by default.
|
|
||||||
var mapValues = fp.mapValues.convert({
|
|
||||||
// Specify capping iteratee arguments.
|
|
||||||
'cap': true,
|
|
||||||
// Specify currying.
|
|
||||||
'curry': true,
|
|
||||||
// Specify fixed arity.
|
|
||||||
'fixed': true,
|
|
||||||
// Specify immutable operations.
|
|
||||||
'immutable': true,
|
|
||||||
// Specify rearranging arguments.
|
|
||||||
'rearg': true
|
|
||||||
});
|
|
||||||
|
|
||||||
// Disable capping of iteratee arguments to access the `key` param.
|
|
||||||
var mapValuesWithKey = fp.mapValues.convert({ 'cap': false });
|
|
||||||
|
|
||||||
mapValuesWithKey(function(value, key) {
|
|
||||||
return key == 'a' ? -1 : value;
|
|
||||||
})({ 'a': 1, 'b': 1 });
|
|
||||||
// => { 'a': -1, 'b': 1 }
|
|
||||||
```
|
|
||||||
|
|
||||||
It’s also possible to use the convert module directly for manual conversions.
|
|
||||||
```js
|
|
||||||
var convert = require('lodash/fp/convert');
|
|
||||||
|
|
||||||
// Convert by name.
|
|
||||||
var assign = convert('assign', require('lodash.assign'));
|
|
||||||
|
|
||||||
// Convert by object.
|
|
||||||
var fp = convert({
|
|
||||||
'assign': require('lodash.assign'),
|
|
||||||
'chunk': require('lodash.chunk')
|
|
||||||
});
|
|
||||||
|
|
||||||
// Convert by `lodash` instance.
|
|
||||||
var fp = convert(lodash.runInContext());
|
|
||||||
```
|
|
||||||
|
|
||||||
## Chaining
|
## Chaining
|
||||||
|
|
||||||
The `lodash/fp` module **does not** convert chain sequence methods. See
|
The `lodash/fp` module **does not** convert chain sequence methods. See
|
||||||
@@ -138,3 +92,49 @@ There are <%= _.size(mapping.aliasToReal) %> method aliases:<br>
|
|||||||
<%= _.map(mapping.aliasToReal, function(realName, alias) {
|
<%= _.map(mapping.aliasToReal, function(realName, alias) {
|
||||||
return ' * `_.' + alias + '` is an alias of `_.' + realName + '`';
|
return ' * `_.' + alias + '` is an alias of `_.' + realName + '`';
|
||||||
}).join('\n') %>
|
}).join('\n') %>
|
||||||
|
|
||||||
|
## Convert
|
||||||
|
|
||||||
|
Although `lodash/fp` & its method modules come pre-converted, there are times
|
||||||
|
when you may want to customize the conversion. That’s when the `convert` method
|
||||||
|
comes in handy.
|
||||||
|
```js
|
||||||
|
// Every option is `true` by default.
|
||||||
|
var mapValues = fp.mapValues.convert({
|
||||||
|
// Specify capping iteratee arguments.
|
||||||
|
'cap': true,
|
||||||
|
// Specify currying.
|
||||||
|
'curry': true,
|
||||||
|
// Specify fixed arity.
|
||||||
|
'fixed': true,
|
||||||
|
// Specify immutable operations.
|
||||||
|
'immutable': true,
|
||||||
|
// Specify rearranging arguments.
|
||||||
|
'rearg': true
|
||||||
|
});
|
||||||
|
|
||||||
|
// Disable capping of iteratee arguments to access the `key` param.
|
||||||
|
var mapValuesWithKey = fp.mapValues.convert({ 'cap': false });
|
||||||
|
|
||||||
|
mapValuesWithKey(function(value, key) {
|
||||||
|
return key == 'a' ? -1 : value;
|
||||||
|
})({ 'a': 1, 'b': 1 });
|
||||||
|
// => { 'a': -1, 'b': 1 }
|
||||||
|
```
|
||||||
|
|
||||||
|
It’s also possible to use the convert module directly for manual conversions.
|
||||||
|
```js
|
||||||
|
var convert = require('lodash/fp/convert');
|
||||||
|
|
||||||
|
// Convert by name.
|
||||||
|
var assign = convert('assign', require('lodash.assign'));
|
||||||
|
|
||||||
|
// Convert by object.
|
||||||
|
var fp = convert({
|
||||||
|
'assign': require('lodash.assign'),
|
||||||
|
'chunk': require('lodash.chunk')
|
||||||
|
});
|
||||||
|
|
||||||
|
// Convert by `lodash` instance.
|
||||||
|
var fp = convert(lodash.runInContext());
|
||||||
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user