Comparing version 0.2.10 to 0.2.11
@@ -6,2 +6,3 @@ declare module "like-ar"{ | ||
filter :( callback:(value:T , key:string)=>boolean) => ObjectWithArrayFunctions<T> | ||
build :<U>( callback:(value:T, key:string)=>{[key:string]:U}) => ObjectWithArrayFunctions<U> | ||
keys :() => string[] | ||
@@ -8,0 +9,0 @@ array :() => T[] |
@@ -99,2 +99,3 @@ "use strict"; | ||
{name:'plain' , useOptimized: true }, | ||
{name:'build' , useOptimized: true }, | ||
].forEach(function(method){ | ||
@@ -131,2 +132,14 @@ ObjectWithArrayMethodsNonOptimized.prototype[method.name] = method.useOptimized ? | ||
ObjectWithArrayMethodsOptimized.prototype.build = function build(f, fThis){ | ||
var oThis=this._object; | ||
var acumulator = likeAr(); | ||
for(var attr in oThis){ if(oThis.hasOwnProperty(attr)){ | ||
var result = f.call(fThis, oThis[attr], attr, oThis); | ||
for(var attrResult in result){ | ||
acumulator[attrResult]=result[attrResult]; | ||
} | ||
}} | ||
return acumulator; | ||
}; | ||
ObjectWithArrayMethodsOptimized.prototype.filter = function filter(f, fThis){ | ||
@@ -133,0 +146,0 @@ var oThis=this._object; |
{ | ||
"name": "like-ar", | ||
"description": "Using objects like arrays with map, filter, forEach and others coming soon.", | ||
"version": "0.2.10", | ||
"version": "0.2.11", | ||
"author": "Codenautas <codenautas@googlegroups.com>", | ||
@@ -6,0 +6,0 @@ "repository": "codenautas/like-ar", |
@@ -70,2 +70,21 @@ # like-ar | ||
## likeAr(object).build(cb(value, key)) | ||
Builds a new object with new keys. | ||
The callback function must return a `{key: value}` object to compose the final result. | ||
```ts | ||
var pairs=[{field:'lastName', value:'Perez'}, {field:'firstName', value:'Diego'}]; | ||
console.log(likeAr(pairs).build(funciton(pair){ return {[pair.field]: pair.value}; )); | ||
// {lastName: "Perez", firstName: "Diego"} | ||
var toJoin=[{lastName:'Perez'}, {firstName:'Diego'}]; | ||
console.log(likeAr(toJoin).build(funciton(objectWithOneKey){ return objectWithOneKey; )); | ||
// {lastName: "Perez", firstName: "Diego"} | ||
``` | ||
## likeAr.toPlainObject(array [,keyName [,valueName]]) | ||
@@ -72,0 +91,0 @@ ## likeAr.toPlainObject(arrayOfKeys, arrayOfValues) |
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
13565
177
114