Initial import with skill sheet working
This commit is contained in:
21
node_modules/copy-props/LICENSE
generated
vendored
Normal file
21
node_modules/copy-props/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2016-2022 Takayuki Sato <sttk.xslet@gmail.com>, Blaine Bublitz <blaine.bublitz@gmail.com>, and Eric Schoffstall <yo@contra.io>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
238
node_modules/copy-props/README.md
generated
vendored
Normal file
238
node_modules/copy-props/README.md
generated
vendored
Normal file
@ -0,0 +1,238 @@
|
||||
<p align="center">
|
||||
<a href="http://gulpjs.com">
|
||||
<img height="257" width="114" src="https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
# copy-props
|
||||
|
||||
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url]
|
||||
|
||||
Copy properties between two objects deeply.
|
||||
|
||||
## Install
|
||||
|
||||
To install from npm:
|
||||
|
||||
```sh
|
||||
$ npm i copy-props --save
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Copy _src_ to _dst_ simply (and return _dst_) :
|
||||
|
||||
```js
|
||||
const copyProps = require('copy-props');
|
||||
|
||||
var src = { a: 1, b: { b1: 'bbb' }, c: 'ccc' };
|
||||
var dst = { a: 2, b: { b1: 'xxx', b2: 'yyy' } };
|
||||
|
||||
copyProps(src, dst);
|
||||
// => { a: 1, b: { b1: 'bbb', b2: 'yyy' }, c: 'ccc' }
|
||||
```
|
||||
|
||||
Copy _src_ to _dst_ with property mapping (and return _dst_) :
|
||||
|
||||
```js
|
||||
const copyProps = require('copy-props');
|
||||
|
||||
var src = { a: 1, b: { b1: 'bbb' }, c: 'ccc', d: 'ddd' };
|
||||
var dst = { f: { a: 2, b1: 'xxx', b2: 'yyy' }, e: 'zzz' };
|
||||
|
||||
copyProps(src, dst, {
|
||||
a: 'f.a',
|
||||
'b.b1': 'f.b1',
|
||||
'b.b2': 'f.b2',
|
||||
c: 'f.c',
|
||||
});
|
||||
// => { f: { a: 1, b1: 'bbb', b2: 'yyy', c: 'ccc' }, e: 'zzz' }
|
||||
```
|
||||
|
||||
Copy _src_ to _dst_ with convert function (and return _dst_) :
|
||||
|
||||
```js
|
||||
const copyProps = require('copy-props');
|
||||
|
||||
var src = { a: 1, b: { b1: 'bbb' } };
|
||||
var dst = { a: 0 };
|
||||
|
||||
copyProps(src, dst, function (srcInfo) {
|
||||
if (srcInfo.keyChain === 'a') {
|
||||
return srcInfo.value * 2;
|
||||
}
|
||||
if (srcInfo.keyChain === 'b.b1') {
|
||||
return srcInfo.value.toUpperCase();
|
||||
}
|
||||
});
|
||||
// => { a: 2, b: { b1: 'BBB' } }
|
||||
```
|
||||
|
||||
Can use an array instead of a map as property mapping :
|
||||
|
||||
```js
|
||||
const copyProps = require('copy-props');
|
||||
|
||||
var src = { a: 1, b: { c: 'CCC' }, d: { e: 'EEE' } };
|
||||
var dst = { a: 9, b: { c: 'xxx' }, d: { e: 'yyy' } };
|
||||
var fromto = ['b.c', 'd.e'];
|
||||
copyProps(src, dst, fromto);
|
||||
// => { a: 9, b: { c: 'CCC' }, d: { e: 'EEE' } }
|
||||
```
|
||||
|
||||
Can copy reversively (from _dst_ to _src_) by reverse flag (and return _src_):
|
||||
|
||||
```js
|
||||
const copyProps = require('copy-props');
|
||||
|
||||
var src = { a: 1, b: { b1: 'bbb' }, c: 'ccc' };
|
||||
var dst = { a: 2, b: { b1: 'xxx', b2: 'yyy' } };
|
||||
|
||||
copyProps(src, dst, true);
|
||||
// => { a: 2, b: { b1: 'xxx', b2: 'yyy' }, c: 'ccc' }
|
||||
```
|
||||
|
||||
```js
|
||||
const copyProps = require('copy-props');
|
||||
|
||||
var src = { a: 1, b: { b1: 'bbb' }, c: 'ccc', d: 'ddd' };
|
||||
var dst = { f: { a: 2, b1: 'xxx', b2: 'yyy' }, e: 'zzz' };
|
||||
|
||||
copyProps(
|
||||
src,
|
||||
dst,
|
||||
{
|
||||
a: 'f.a',
|
||||
'b.b2': 'f.b2',
|
||||
c: 'f.c',
|
||||
},
|
||||
true
|
||||
);
|
||||
// => { a: 2, b: { b1: 'bbb', b2: 'yyy' }, c: 'ccc', d: 'ddd' }
|
||||
```
|
||||
|
||||
If a value of source property is undefined (when not using converter), or a result of converter is undefined (when using converter), the value is not copied.
|
||||
|
||||
```js
|
||||
const copyProps = require('copy-props');
|
||||
|
||||
var src = { a: 'A', b: undefined, c: null, d: 1 };
|
||||
var dst = { a: 'a', b: 'b', c: 'c' };
|
||||
|
||||
copyProps(src, dst, function (srcInfo) {
|
||||
if (srcInfo.keyChain === 'd') {
|
||||
return undefined;
|
||||
} else {
|
||||
return srcInfo.value;
|
||||
}
|
||||
});
|
||||
// => { a: 'A', b: 'b', c: null }
|
||||
```
|
||||
|
||||
You can operate the parent node object directly in converter.
|
||||
|
||||
```js
|
||||
const copyProps = require('copy-props');
|
||||
|
||||
var src = { a: 1, b: 2 };
|
||||
var dst = {};
|
||||
|
||||
copyProps(src, dst, function (srcInfo, dstInfo) {
|
||||
Object.defineProperty(dstInfo.parent, dstInfo.key, {
|
||||
writable: false,
|
||||
enumerable: true,
|
||||
configurable: false,
|
||||
value: srcInfo.value * 2,
|
||||
});
|
||||
}); // => { a: 2, b: 4 }
|
||||
|
||||
dst; // => { a: 2, b: 4 }
|
||||
dst.a = 9;
|
||||
dst; // -> { a: 2, b: 4 }
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### <u>copyProps(src, dst [, fromto] [, converter] [, reverse]) => object</u>
|
||||
|
||||
Copy properties of _src_ to _dst_ deeply.
|
||||
If _fromto_ is given, it is able to copy between different properties.
|
||||
If _converter_ is given, it is able to convert the terminal values.
|
||||
|
||||
#### Parameters:
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| :---------- | :-----------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| _src_ | object | A source object of copy. |
|
||||
| _dst_ | object | A destinate object of copy. |
|
||||
| _fromto_ | object | array | An object mapping properties between _src_ and _dst_. (Optional) |
|
||||
| _converter_ | function | A function to convert terminal values in _src_. (Optional) |
|
||||
| _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) |
|
||||
|
||||
#### Returns:
|
||||
|
||||
_dst_ object after copying.
|
||||
|
||||
**Type:** object
|
||||
|
||||
- **Format of <i>fromto</i>**
|
||||
|
||||
_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_.
|
||||
The key chain is a string which is concatenated property keys on each level with dots, like `'aaa.bbb.ccc'`.
|
||||
|
||||
The following example copys the value of `src.aaa.bbb.ccc` to `dst.xxx.yyy`.
|
||||
|
||||
```js
|
||||
copyProps(src, dst, {
|
||||
'aaa.bbb.ccc': 'xxx.yyy',
|
||||
});
|
||||
```
|
||||
|
||||
_fromto_ can be an array. In that case, the array works as a map which has pairs of same key and value.
|
||||
|
||||
- **API of <i>converter</i>**
|
||||
|
||||
**<u>converter(srcInfo, dstInfo) : Any</u>**
|
||||
|
||||
_converter_ is a function to convert terminal values of propeerties of _src_.
|
||||
|
||||
**Parameters:**
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| :-------- | :----: | :---------------------------------------------------------------- |
|
||||
| _srcInfo_ | object | An object which has informations about the current node of _src_. |
|
||||
| _dstInfo_ | object | An object which has informations about the current node of _dst_. |
|
||||
|
||||
**Return:**
|
||||
|
||||
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.
|
||||
|
||||
**Type:** _Any_
|
||||
|
||||
- **Properties of <i>srcInfo</i> and <i>dstInfo</i>**
|
||||
|
||||
_srcInfo_ and _dstInfo_ has same properties, as follows:
|
||||
|
||||
| Property | Type | Description |
|
||||
| :--------- | :----: | :------------------------------------------------------ |
|
||||
| _value_ | _Any_ | The value of the current node. |
|
||||
| _key_ | string | The key name of the current node. |
|
||||
| _keyChain_ | string | The full key of the current node concatenated with dot. |
|
||||
| _depth_ | number | The depth of the current node. |
|
||||
| _parent_ | object | The parent node of the current node. |
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
[downloads-image]: https://img.shields.io/npm/dm/copy-props.svg?style=flat-square
|
||||
[npm-url]: https://www.npmjs.org/package/copy-props
|
||||
[npm-image]: https://img.shields.io/npm/v/copy-props.svg?style=flat-square
|
||||
|
||||
[ci-url]: https://github.com/gulpjs/copy-props/actions?query=workflow:dev
|
||||
[ci-image]: https://img.shields.io/github/workflow/status/gulpjs/copy-props/dev?style=flat-square
|
||||
|
||||
[coveralls-url]: https://coveralls.io/r/gulpjs/copy-props
|
||||
[coveralls-image]: https://img.shields.io/coveralls/gulpjs/copy-props/master.svg
|
||||
<!-- prettier-ignore-end -->
|
234
node_modules/copy-props/index.js
generated
vendored
Normal file
234
node_modules/copy-props/index.js
generated
vendored
Normal file
@ -0,0 +1,234 @@
|
||||
'use strict';
|
||||
|
||||
var eachProps = require('each-props');
|
||||
var isPlainObject = require('is-plain-object').isPlainObject;
|
||||
|
||||
module.exports = function (src, dst, fromto, converter, reverse) {
|
||||
if (!isObject(src)) {
|
||||
src = {};
|
||||
}
|
||||
|
||||
if (!isObject(dst)) {
|
||||
dst = {};
|
||||
}
|
||||
|
||||
if (isPlainObject(fromto)) {
|
||||
fromto = onlyValueIsString(fromto);
|
||||
} else if (Array.isArray(fromto)) {
|
||||
fromto = arrayToObject(fromto);
|
||||
} else if (typeof fromto === 'boolean') {
|
||||
reverse = fromto;
|
||||
converter = noop;
|
||||
fromto = null;
|
||||
} else if (typeof fromto === 'function') {
|
||||
reverse = converter;
|
||||
converter = fromto;
|
||||
fromto = null;
|
||||
} else {
|
||||
fromto = null;
|
||||
}
|
||||
|
||||
if (typeof converter !== 'function') {
|
||||
if (typeof converter === 'boolean') {
|
||||
reverse = converter;
|
||||
converter = noop;
|
||||
} else {
|
||||
converter = noop;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof reverse !== 'boolean') {
|
||||
reverse = false;
|
||||
}
|
||||
|
||||
if (reverse) {
|
||||
var tmp = src;
|
||||
src = dst;
|
||||
dst = tmp;
|
||||
|
||||
if (fromto) {
|
||||
fromto = invert(fromto);
|
||||
}
|
||||
}
|
||||
|
||||
var opts = {
|
||||
dest: dst,
|
||||
fromto: fromto,
|
||||
convert: converter,
|
||||
};
|
||||
|
||||
if (fromto) {
|
||||
eachProps(src, copyWithFromto, opts);
|
||||
setParentEmptyObject(dst, fromto);
|
||||
} else {
|
||||
eachProps(src, copyWithoutFromto, opts);
|
||||
}
|
||||
|
||||
return dst;
|
||||
};
|
||||
|
||||
function copyWithFromto(value, keyChain, nodeInfo) {
|
||||
if (isPlainObject(value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var dstKeyChains = nodeInfo.fromto[keyChain];
|
||||
if (!dstKeyChains) {
|
||||
return;
|
||||
}
|
||||
delete nodeInfo.fromto[keyChain];
|
||||
|
||||
if (!Array.isArray(dstKeyChains)) {
|
||||
dstKeyChains = [dstKeyChains];
|
||||
}
|
||||
|
||||
var srcInfo = {
|
||||
keyChain: keyChain,
|
||||
value: value,
|
||||
key: nodeInfo.name,
|
||||
depth: nodeInfo.depth,
|
||||
parent: nodeInfo.parent,
|
||||
};
|
||||
|
||||
for (var i = 0, n = dstKeyChains.length; i < n; i++) {
|
||||
setDeep(nodeInfo.dest, dstKeyChains[i], function (parent, key, depth) {
|
||||
var dstInfo = {
|
||||
keyChain: dstKeyChains[i],
|
||||
value: parent[key],
|
||||
key: key,
|
||||
depth: depth,
|
||||
parent: parent,
|
||||
};
|
||||
|
||||
return nodeInfo.convert(srcInfo, dstInfo);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function copyWithoutFromto(value, keyChain, nodeInfo) {
|
||||
if (isPlainObject(value)) {
|
||||
for (var k in value) {
|
||||
return;
|
||||
}
|
||||
setDeep(nodeInfo.dest, keyChain, newObject);
|
||||
return;
|
||||
}
|
||||
|
||||
var srcInfo = {
|
||||
keyChain: keyChain,
|
||||
value: value,
|
||||
key: nodeInfo.name,
|
||||
depth: nodeInfo.depth,
|
||||
parent: nodeInfo.parent,
|
||||
};
|
||||
|
||||
setDeep(nodeInfo.dest, keyChain, function (parent, key, depth) {
|
||||
var dstInfo = {
|
||||
keyChain: keyChain,
|
||||
value: parent[key],
|
||||
key: key,
|
||||
depth: depth,
|
||||
parent: parent,
|
||||
};
|
||||
|
||||
return nodeInfo.convert(srcInfo, dstInfo);
|
||||
});
|
||||
}
|
||||
|
||||
function newObject() {
|
||||
return {};
|
||||
}
|
||||
|
||||
function noop(srcInfo) {
|
||||
return srcInfo.value;
|
||||
}
|
||||
|
||||
function onlyValueIsString(obj) {
|
||||
var newObj = {};
|
||||
for (var key in obj) {
|
||||
var val = obj[key];
|
||||
if (typeof val === 'string') {
|
||||
newObj[key] = val;
|
||||
}
|
||||
}
|
||||
return newObj;
|
||||
}
|
||||
|
||||
function arrayToObject(arr) {
|
||||
var obj = {};
|
||||
for (var i = 0, n = arr.length; i < n; i++) {
|
||||
var elm = arr[i];
|
||||
if (typeof elm === 'string') {
|
||||
obj[elm] = elm;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
function invert(fromto) {
|
||||
var inv = {};
|
||||
for (var key in fromto) {
|
||||
var val = fromto[key];
|
||||
if (!inv[val]) {
|
||||
inv[val] = [];
|
||||
}
|
||||
inv[val].push(key);
|
||||
}
|
||||
return inv;
|
||||
}
|
||||
|
||||
function setDeep(obj, keyChain, valueCreator) {
|
||||
_setDeep(obj, keyChain.split('.'), 1, valueCreator);
|
||||
}
|
||||
|
||||
function _setDeep(obj, keyElems, depth, valueCreator) {
|
||||
var key = keyElems.shift();
|
||||
if (isPossibilityOfPrototypePollution(key)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!keyElems.length) {
|
||||
var value = valueCreator(obj, key, depth);
|
||||
if (value === undefined) {
|
||||
return;
|
||||
}
|
||||
if (isPlainObject(value)) {
|
||||
// value is always an empty object.
|
||||
if (isPlainObject(obj[key])) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
obj[key] = value;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isPlainObject(obj[key])) {
|
||||
obj[key] = {};
|
||||
}
|
||||
_setDeep(obj[key], keyElems, depth + 1, valueCreator);
|
||||
}
|
||||
|
||||
function setParentEmptyObject(obj, fromto) {
|
||||
for (var srcKeyChain in fromto) {
|
||||
var dstKeyChains = fromto[srcKeyChain];
|
||||
if (!Array.isArray(dstKeyChains)) {
|
||||
dstKeyChains = [dstKeyChains];
|
||||
}
|
||||
|
||||
for (var i = 0, n = dstKeyChains.length; i < n; i++) {
|
||||
setDeep(obj, dstKeyChains[i], newUndefined);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function newUndefined() {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function isObject(v) {
|
||||
return Object.prototype.toString.call(v) === '[object Object]';
|
||||
}
|
||||
|
||||
function isPossibilityOfPrototypePollution(key) {
|
||||
return key === '__proto__' || key === 'constructor';
|
||||
}
|
50
node_modules/copy-props/package.json
generated
vendored
Normal file
50
node_modules/copy-props/package.json
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "copy-props",
|
||||
"version": "4.0.0",
|
||||
"description": "Copy properties deeply between two objects.",
|
||||
"author": "Gulp Team <team@gulpjs.com> (https://gulpjs.com/)",
|
||||
"main": "index.js",
|
||||
"files": [
|
||||
"index.js",
|
||||
"LICENSE"
|
||||
],
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"pretest": "npm run lint",
|
||||
"test": "nyc mocha --async-only"
|
||||
},
|
||||
"repository": "gulpjs/copy-prop",
|
||||
"keywords": [
|
||||
"object",
|
||||
"property",
|
||||
"copy",
|
||||
"deep",
|
||||
"map",
|
||||
"convert"
|
||||
],
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 10.13.0"
|
||||
},
|
||||
"nyc": {
|
||||
"reporter": [
|
||||
"lcov",
|
||||
"text-summary"
|
||||
]
|
||||
},
|
||||
"prettier": {
|
||||
"singleQuote": true
|
||||
},
|
||||
"dependencies": {
|
||||
"each-props": "^3.0.0",
|
||||
"is-plain-object": "^5.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-config-gulp": "^5.0.1",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"expect": "^27.5.1",
|
||||
"mocha": "^8.4.0",
|
||||
"nyc": "^15.1.0"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user