0.1.0 • Published 3 years ago

extract-chain v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

extract-chain

Extract object's prototype chain properties, make them object's own properties.

Install

Install with npm:

$ npm install --save extract-chain

Usage

with es modules

import extractChain from ' extract-chain';

or with commonjs

const extractChain = require('extract-chain');
var source={
 name:"James Clerk Maxwell",
 born:"June 13 1831",
 field:"Math"
}

var target=Object.create(source)

extractChain(target)
/*{
  name:"James Clerk Maxwell",
  born:"June 13 1831",
  field:"Math"
 }
*/
target.hasOwnProperty('name')//true

NOTE if object already has a property with same name it will be overwritten.If you don't want this specify property name in array.

var source={
 name:"James Clerk Maxwell",
 born:"June 13 1831",
 field:"Math"
}

var target=Object.create(source)

target.name="John"

extractChain(target, ["name"])

console.log(target.name)//John

About

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

You can install dependencies and run tests with the following command:

$ npm install && npm test

Author

Tahir Genç

License

Copyright © 2021, Tahir Genç. Released under the MIT License.