Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

like-ar

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

like-ar - npm Package Compare versions

Comparing version 0.2.6 to 0.2.7

5

like-ar.d.ts

@@ -12,4 +12,7 @@ declare module "like-ar"{

function likeAr<T>(o:{[key:string]:T}):ObjectWithArrayFunctions<T>
namespace likeAr{}
namespace likeAr{
function toPlainObject<T>(array:[string, T][]):{[key:string]:T}
function toPlainObject<T, K extends keyof T>(array:T, keyName:K, valueName:K):{[key:string]:T}
}
export = likeAr
}

@@ -141,4 +141,18 @@ "use strict";

likeAr.toPlainObject = function toPlainObject(pairs, keyName, valueName){
var o={};
pairs.forEach(function(pair, i){
if(keyName==null){
keyName=0;
valueName=valueName||1;
}else if(valueName==null){
valueName='value';
}
o[pair[keyName]]=pair[valueName];
});
return o;
};
return likeAr;
});

2

package.json
{
"name": "like-ar",
"description": "Using objects like arrays with map, filter, forEach and others coming soon.",
"version": "0.2.6",
"version": "0.2.7",
"author": "Codenautas <codenautas@googlegroups.com>",

@@ -6,0 +6,0 @@ "repository": "codenautas/like-ar",

@@ -10,5 +10,3 @@ # like-ar

[![coverage](https://img.shields.io/coveralls/codenautas/like-ar/master.svg)](https://coveralls.io/r/codenautas/like-ar)
[![climate](https://img.shields.io/codeclimate/github/codenautas/like-ar.svg)](https://codeclimate.com/github/codenautas/like-ar)
[![dependencies](https://img.shields.io/david/codenautas/like-ar.svg)](https://david-dm.org/codenautas/like-ar)
[![qa-control](http://codenautas.com/github/codenautas/like-ar.svg)](http://codenautas.com/github/codenautas/like-ar)

@@ -38,3 +36,4 @@

lastName:'Perez',
firstName:'Diego'
firstName:'Diego',
phone:'+45-11-2222-3333'
}

@@ -45,5 +44,16 @@

});
console.log(
likeAr(object).filter(function(value, attrName){
return attrName.contains('Name');
}).map(function(value,attrName){
return attrName+':'+value
}).join(', ')
);
```
# API
## likeAr(object)
The callback functions receive these parameters: `value`, `key` and the original object.

@@ -60,16 +70,23 @@ The functions that in the Array case returns Arrays returns a chainable object.

`keys()` | array of keys
`plain()` | plain array
`plain()` | plain object without likeAr functions
## likeAr.toPlainObject(array [,keyName [,valueName]])
Returns a plain object from an array of pairs.
Default values: `0` and `1` if `keyName` is not set. `"value"` for `valueName` if `keyName` is set.
# Usage
```sh
var likeAr = require('like-ar');
var object={
lastName:'Perez',
firstName:'Diego'
}
var pairs=[['lastName', 'Perez'], ['firstName', 'Diego']];
likeAr(object).forEach(function(value, attrName, object){
console.log(attrName,':',value);
});
console.log(likeAr.toPlainObject(pairs));
var pairs=[{field:'lastName', value:'Perez'}, {field:'firstName', value:'Diego'}];
console.log(likeAr.toPlainObject(pairs, 'field'));
```

@@ -76,0 +93,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc