Skip to content

Commit 404ff55

Browse files
phatedactions-user
authored andcommitted
chore: Run prettier
1 parent 85b1165 commit 404ff55

10 files changed

+1600
-1068
lines changed

README.md

Lines changed: 70 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ For Web browser:
3434

3535
## Usage
3636

37-
Copy *src* to *dst* simply (and return *dst*) :
37+
Copy _src_ to _dst_ simply (and return _dst_) :
3838

3939
```js
4040
var src = { a: 1, b: { b1: 'bbb' }, c: 'ccc' };
@@ -44,7 +44,7 @@ copyProps(src, dst);
4444
// => { a: 1, b: { b1: 'bbb', b2: 'yyy' }, c: 'ccc' }
4545
```
4646

47-
Copy *src* to *dst* with property mapping (and return *dst*) :
47+
Copy _src_ to _dst_ with property mapping (and return _dst_) :
4848

4949
```js
5050
var src = { a: 1, b: { b1: 'bbb' }, c: 'ccc', d: 'ddd' };
@@ -54,18 +54,18 @@ copyProps(src, dst, {
5454
a: 'f.a',
5555
'b.b1': 'f.b1',
5656
'b.b2': 'f.b2',
57-
'c': 'f.c',
57+
c: 'f.c',
5858
});
5959
// => { f: { a: 1, b1: 'bbb', b2: 'yyy', c: 'ccc' }, e: 'zzz' }
6060
```
6161

62-
Copy *src* to *dst* with convert function (and return *dst*) :
62+
Copy _src_ to _dst_ with convert function (and return _dst_) :
6363

6464
```js
6565
var src = { a: 1, b: { b1: 'bbb' } };
6666
var dst = { a: 0 };
6767

68-
copyProps(src, dst, function(srcInfo) {
68+
copyProps(src, dst, function (srcInfo) {
6969
if (srcInfo.keyChain === 'a') {
7070
return srcInfo.value * 2;
7171
}
@@ -81,12 +81,12 @@ Can use an array instead of a map as property mapping :
8181
```js
8282
var src = { a: 1, b: { c: 'CCC' }, d: { e: 'EEE' } };
8383
var dst = { a: 9, b: { c: 'xxx' }, d: { e: 'yyy' } };
84-
var fromto = [ 'b.c', 'd.e' ];
84+
var fromto = ['b.c', 'd.e'];
8585
copyProps(src, dst, fromto);
8686
// => { a: 9, b: { c: 'CCC' }, d: { e: 'EEE' } }
8787
```
8888

89-
Can copy reversively (from *dst* to *src*) by reverse flag (and return *src*):
89+
Can copy reversively (from _dst_ to _src_) by reverse flag (and return _src_):
9090

9191
```js
9292
var src = { a: 1, b: { b1: 'bbb' }, c: 'ccc' };
@@ -100,11 +100,16 @@ copyProps(src, dst, true);
100100
var src = { a: 1, b: { b1: 'bbb' }, c: 'ccc', d: 'ddd' };
101101
var dst = { f: { a: 2, b1: 'xxx', b2: 'yyy' }, e: 'zzz' };
102102

103-
copyProps(src, dst, {
104-
a: 'f.a',
105-
'b.b2': 'f.b2',
106-
'c': 'f.c',
107-
}, true);
103+
copyProps(
104+
src,
105+
dst,
106+
{
107+
a: 'f.a',
108+
'b.b2': 'f.b2',
109+
c: 'f.c',
110+
},
111+
true
112+
);
108113
// => { a: 2, b: { b1: 'bbb', b2: 'yyy' }, c: 'ccc', d: 'ddd' }
109114
```
110115

@@ -114,7 +119,7 @@ If a value of source property is undefined (when not using converter), or a resu
114119
var src = { a: 'A', b: undefined, c: null, d: 1 };
115120
var dst = { a: 'a', b: 'b', c: 'c' };
116121

117-
copyProps(src, dst, function(srcInfo) {
122+
copyProps(src, dst, function (srcInfo) {
118123
if (srcInfo.keyChain === 'd') {
119124
return undefined;
120125
} else {
@@ -130,90 +135,89 @@ You can operate the parent node object directly in converter.
130135
var src = { a: 1, b: 2 };
131136
var dst = {};
132137

133-
copyProps(src, dst, function(srcInfo, dstInfo) {
138+
copyProps(src, dst, function (srcInfo, dstInfo) {
134139
Object.defineProperty(dstInfo.parent, dstInfo.key, {
135140
writable: false,
136141
enumerable: true,
137142
configurable: false,
138-
value: srcInfo.value * 2
139-
})
143+
value: srcInfo.value * 2,
144+
});
140145
}); // => { a: 2, b: 4 }
141146

142-
dst // => { a: 2, b: 4 }
143-
dst.a = 9
144-
dst // -> { a: 2, b: 4 }
147+
dst; // => { a: 2, b: 4 }
148+
dst.a = 9;
149+
dst; // -> { a: 2, b: 4 }
145150
```
146151

147152
## API
148153

149154
### <u>copyProps(src, dst [, fromto] [, converter] [, reverse]) => object</u>
150155

151-
Copy properties of *src* to *dst* deeply.
152-
If *fromto* is given, it is able to copy between different properties.
153-
If *converter* is given, it is able to convert the terminal values.
156+
Copy properties of _src_ to _dst_ deeply.
157+
If _fromto_ is given, it is able to copy between different properties.
158+
If _converter_ is given, it is able to convert the terminal values.
154159

155160
#### Parameters:
156161

157-
| Parameter | Type | Description |
158-
|:------------|:------:|:-------------------------------------------------|
159-
| *src* | object | A source object of copy. |
160-
| *dst* | object | A destinate object of copy. |
161-
| *fromto* | object &#124; array | An object mapping properties between *src* and *dst*. (Optional) |
162-
| *converter* |function| A function to convert terminal values in *src*. (Optional) |
163-
| *reverse* |boolean | True, if copying reversively from dst to src and returns src object. `fromto` is also reversively used from value to key. This default value is `false`. (Optional) |
162+
| Parameter | Type | Description |
163+
| :---------- | :-----------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
164+
| _src_ | object | A source object of copy. |
165+
| _dst_ | object | A destinate object of copy. |
166+
| _fromto_ | object &#124; array | An object mapping properties between _src_ and _dst_. (Optional) |
167+
| _converter_ | function | A function to convert terminal values in _src_. (Optional) |
168+
| _reverse_ | boolean | True, if copying reversively from dst to src and returns src object. `fromto` is also reversively used from value to key. This default value is `false`. (Optional) |
164169

165170
#### Returns:
166171

167-
*dst* object after copying.
172+
_dst_ object after copying.
168173

169174
**Type:** object
170175

171-
* **Format of <i>fromto</i>**
176+
- **Format of <i>fromto</i>**
177+
178+
_fromto_ is a non-nested key-value object. And the *key*s are property key chains of _src_ and the *value*s are property key chains of _dst_.
179+
The key chain is a string which is concatenated property keys on each level with dots, like `'aaa.bbb.ccc'`.
180+
181+
The following example copys the value of `src.aaa.bbb.ccc` to `dst.xxx.yyy`.
172182

173-
*fromto* is a non-nested key-value object. And the *key*s are property key chains of *src* and the *value*s are property key chains of *dst*.
174-
The key chain is a string which is concatenated property keys on each level with dots, like `'aaa.bbb.ccc'`.
183+
```js
184+
copyProps(src, dst, {
185+
'aaa.bbb.ccc': 'xxx.yyy',
186+
});
187+
```
175188

176-
The following example copys the value of `src.aaa.bbb.ccc` to `dst.xxx.yyy`.
189+
_fromto_ can be an array. In that case, the array works as a map which has pairs of same key and value.
177190

178-
```js
179-
copyProps(src, dst, {
180-
'aaa.bbb.ccc' : 'xxx.yyy'
181-
})
182-
```
191+
- **API of <i>converter</i>**
183192

184-
*fromto* can be an array. In that case, the array works as a map which has pairs of same key and value.
185-
186-
* **API of <i>converter</i>**
193+
**<u>converter(srcInfo, dstInfo) : Any</u>**
187194

188-
**<u>converter(srcInfo, dstInfo) : Any</u>**
195+
_converter_ is a function to convert terminal values of propeerties of _src_.
189196

190-
*converter* is a function to convert terminal values of propeerties of *src*.
197+
**Parameters:**
191198

192-
**Parameters:**
199+
| Parameter | Type | Description |
200+
| :-------- | :----: | :---------------------------------------------------------------- |
201+
| _srcInfo_ | object | An object which has informations about the current node of _src_. |
202+
| _dstInfo_ | object | An object which has informations about the current node of _dst_. |
193203

194-
| Parameter | Type | Description |
195-
|:------------|:------:|:---------------------------------------------|
196-
| *srcInfo* | object | An object which has informations about the current node of *src*. |
197-
| *dstInfo* | object | An object which has informations about the current node of *dst*. |
198-
199-
**Return:**
200-
201-
The converted value to be set as a destination property value. If this value is undefined, the destination property is not set to the destination node object.
202-
203-
**Type:** *Any*
204-
205-
* **Properties of <i>srcInfo</i> and <i>dstInfo</i>**
204+
**Return:**
206205

207-
*srcInfo* and *dstInfo* has same properties, as follows:
208-
209-
| Property | Type | Description |
210-
|:-----------|:------:|:------------------------------------------|
211-
| *value* | *Any* | The value of the current node. |
212-
| *key* | string | The key name of the current node. |
213-
| *keyChain* | string | The full key of the current node concatenated with dot. |
214-
| *depth* | number | The depth of the current node. |
215-
| *parent* | object | The parent node of the current node. |
206+
The converted value to be set as a destination property value. If this value is undefined, the destination property is not set to the destination node object.
216207

208+
**Type:** _Any_
209+
210+
- **Properties of <i>srcInfo</i> and <i>dstInfo</i>**
211+
212+
_srcInfo_ and _dstInfo_ has same properties, as follows:
213+
214+
| Property | Type | Description |
215+
| :--------- | :----: | :------------------------------------------------------ |
216+
| _value_ | _Any_ | The value of the current node. |
217+
| _key_ | string | The key name of the current node. |
218+
| _keyChain_ | string | The full key of the current node concatenated with dot. |
219+
| _depth_ | number | The depth of the current node. |
220+
| _parent_ | object | The parent node of the current node. |
217221

218222
## License
219223

@@ -222,7 +226,6 @@ Copyright (C) 2016-2021 Gulp Team.
222226
This program is free software under [MIT][mit-url] License.
223227
See the file LICENSE in this distribution for more details.
224228

225-
226229
<!-- prettier-ignore-start -->
227230
[downloads-image]: https://img.shields.io/npm/dm/copy-props.svg?style=flat-square
228231
[npm-url]: https://www.npmjs.org/package/copy-props

index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
var eachProps = require('each-props');
44
var isPlainObject = require('is-plain-object').isPlainObject;
55

6-
module.exports = function(src, dst, fromto, converter, reverse) {
7-
6+
module.exports = function (src, dst, fromto, converter, reverse) {
87
if (!isObject(src)) {
98
src = {};
109
}
@@ -92,7 +91,7 @@ function copyWithFromto(value, keyChain, nodeInfo) {
9291
};
9392

9493
for (var i = 0, n = dstKeyChains.length; i < n; i++) {
95-
setDeep(nodeInfo.dest, dstKeyChains[i], function(parent, key, depth) {
94+
setDeep(nodeInfo.dest, dstKeyChains[i], function (parent, key, depth) {
9695
var dstInfo = {
9796
keyChain: dstKeyChains[i],
9897
value: parent[key],
@@ -123,7 +122,7 @@ function copyWithoutFromto(value, keyChain, nodeInfo) {
123122
parent: nodeInfo.parent,
124123
};
125124

126-
setDeep(nodeInfo.dest, keyChain, function(parent, key, depth) {
125+
setDeep(nodeInfo.dest, keyChain, function (parent, key, depth) {
127126
var dstInfo = {
128127
keyChain: keyChain,
129128
value: parent[key],
@@ -193,7 +192,8 @@ function _setDeep(obj, keyElems, depth, valueCreator) {
193192
if (value === undefined) {
194193
return;
195194
}
196-
if (isPlainObject(value)) { // value is always an empty object.
195+
if (isPlainObject(value)) {
196+
// value is always an empty object.
197197
if (isPlainObject(obj[key])) {
198198
return;
199199
}
@@ -230,5 +230,5 @@ function isObject(v) {
230230
}
231231

232232
function isPossibilityOfPrototypePollution(key) {
233-
return (key === '__proto__' || key === 'constructor');
233+
return key === '__proto__' || key === 'constructor';
234234
}

0 commit comments

Comments
 (0)