Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
copy-props
Advanced tools
Copy properties deeply between two objects.
$ npm i copy-props
Load this module :
const copyProps = require('copy-props');
Copy src to dst simply (and return dst) :
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) :
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.b.b1',
'b.b2': 'f.b.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) :
var src = { a: 1, b: { b1: 'bbb' } };
var dst = { a: 0 };
copyProps(src, dst, function(value, keyChain) {
if (keyChain === 'a') {
return value * 2;
}
if (keyChain === 'b.b1') {
return value.toUpperCase();
}
});
// => { a: 2, b: { b1: 'BBB' } }
Copy properties of src to dst deeply. If map is given, it is able to copy between different properties. If converter is given, it is able to convert the terminal values.
Arguments:
Return [object] : dst object after copying.
fromToProps is a non-nested key-value object. And the keys are property key chains of src and the values 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
.
copyProps(src, dst, {
'aaa.bbb.ccc' : 'xxx.yyy'
})
converter(value, keyChain) => any
converter is a function to convert terminal values of propeerties of src.
Arguments:
Return: [any] : converted value.
MIT
FAQs
Copy properties deeply between two objects.
The npm package copy-props receives a total of 245,426 weekly downloads. As such, copy-props popularity was classified as popular.
We found that copy-props demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.