Move Property
Move a property from one object to another object.
Installation
$ npm install utils-move-property
Usage
var mv = ;
mv( source, prop, target )
Moves a property from one object
to another object
.
var obj1 = 'a': 'b' ;var obj2 = {};var bool = ;// returns true
If the operation is successful, the function
returns true
; otherwise, false
.
var bool = ;// returns false
Notes
-
The property is deleted from the source
object
. -
The property's descriptor is preserved during transfer.
-
A transfer is shallow.
var arr = 1 2 3 ;var obj1 = 'a': arr ;var obj2 = {};var bool = ;console;// returns true -
If a source property is not
configurable
, thefunction
throws anError
, as the property cannot be deleted from the sourceobject
.
Examples
var mv = ;var obj1 ='beep': 'boop';var obj2 ='foo': 'bar';var bool = ;if bool === falseconsole;consoledir obj1 ;/*{}*/consoledir obj2 ;/*{'foo': 'bar','beep': 'boop'}*/
To run the example code from the top-level application directory,
$ node ./examples/index.js
Tests
Unit
This repository uses tape for unit tests. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ make view-cov
Browser Support
This repository uses Testling for browser testing. To run the tests in a (headless) local web browser, execute the following command in the top-level application directory:
$ make test-browsers
To view the tests in a local web browser,
$ make view-browser-tests
License
Copyright
Copyright © 2015. Athan Reines.