Skip to content

TheNoim/native-copy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

native-copy

This native nodejs addon copies objects according to a rule specified by you.

Example

const { copy } = require('native-copy');

const testObject = {
    copy: 1,
    doNotCopy: 0,
    arrayTest: [
        {
            copyPlz: 55555
        }
    ],
    arrayTest2: [
        1,
        2,
        3,
        {
            copy: 4,
            notCopy: 3
        },
        8
    ],
    deep: {
        plzCopy: 5,
        dont: 33
    }
};

const rules = {
    copy: true,
    arrayTest: {
        copyPlz: true
    },
    arrayTest2: [
        true,
        false,
        true,
        {
            copy: true,
        },
        true
    ],
    deep: {
        plzCopy: true
    }
};

const copied = copy([testObject], rules)

The copied variable will look like this:

[
	{
		"copy": 1,
		"arrayTest2": [
			1,
			3,
			{
				"copy": 4
			},
			8
		],
		"arrayTest": [
			{
				"copyPlz": 55555
			}
		],
		"deep": {
			"plzCopy": 5
		}
	}
]