mirror of
https://github.com/swc-project/swc.git
synced 2024-12-20 12:12:16 +03:00
31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
// Loaded from https://deno.land/x/ramda@v0.27.2/source/modify.js
|
|
|
|
|
|
import _curry3 from './internal/_curry3.js';
|
|
import modifyPath from './modifyPath.js';
|
|
|
|
|
|
/**
|
|
* Creates a copy of the passed object by applying an `fn` function to the given `prop` property.
|
|
*
|
|
* The function will not be invoked, and the object will not change
|
|
* if its corresponding property does not exist in the object.
|
|
* All non-primitive properties are copied to the new object by reference.
|
|
*
|
|
* @func
|
|
* @memberOf R
|
|
* @category Object
|
|
* @sig Idx -> (v -> v) -> {k: v} -> {k: v}
|
|
* @param {String|Number} prop The property to be modified.
|
|
* @param {Function} fn The function to apply to the property.
|
|
* @param {Object} object The object to be transformed.
|
|
* @return {Object} The transformed object.
|
|
* @example
|
|
*
|
|
* const person = {name: 'James', age: 20, pets: ['dog', 'cat']};
|
|
* R.modify('age', R.add(1), person); //=> {name: 'James', age: 21, pets: ['dog', 'cat']}
|
|
* R.modify('pets', R.append('turtle'), person); //=> {name: 'James', age: 20, pets: ['dog', 'cat', 'turtle']}
|
|
*/
|
|
var modify = _curry3(function modify(prop, fn, object) { return modifyPath([prop], fn, object); });
|
|
export default modify;
|