prototypes
Advanced tools
Comparing version 1.3.1 to 1.4.0
@@ -131,2 +131,28 @@ 'use strict'; | ||
/** | ||
* For each property in the mapping object, if 'this' has a property of the same name, then the name of the property in 'this' | ||
* is renamed to the value corresponding to the property from the mapping object. | ||
* Example: | ||
* var bla = {'yo': 'hi', 'bo': 'hi'}; | ||
* bla.renameProperties({'bo': 'do'}); | ||
* THEN | ||
* bla.hasOwnProperty('do') === true | ||
* bla.do === 'hi' | ||
*/ | ||
newObject.renameProperties = function(mappingObject) | ||
{ | ||
var self = this; | ||
newObject.forEach.call(mappingObject, function(newPropertyName, oldPropertyName) | ||
{ | ||
if (self.hasOwnProperty(oldPropertyName)) | ||
{ | ||
self[newPropertyName] = self[oldPropertyName]; | ||
delete self[oldPropertyName]; | ||
} | ||
}); | ||
return self; | ||
} | ||
/** | ||
* Get all values for a parameter object in an array. | ||
@@ -133,0 +159,0 @@ * Note: operates on the global Object, not on the prototype. |
{ | ||
"name": "prototypes", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "Some common prototypes for node.js: string.startsWith(), object.countProperties() and more. Facilities for functional programming with objects: object.forEach(), object.filter(). Functions are added safely using Object.defineProperty().", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/alexfernandez/prototypes", |
@@ -325,2 +325,12 @@ [![Build Status](https://secure.travis-ci.org/alexfernandez/prototypes.png)](http://travis-ci.org/alexfernandez/prototypes) | ||
### object.renameProperties(mappingObject) | ||
Rename an object's properties based on another 'mapping' object's key/value pairs. | ||
Example: | ||
```js | ||
{a: 1, b: 2}.renameProperties({a: 'z', b: 'y'}); | ||
//=> {z: 1, y: 2} | ||
``` | ||
## Object Functions | ||
@@ -327,0 +337,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27862
652
557