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

like-ar

Package Overview
Dependencies
Maintainers
4
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.3.6 to 0.3.7

5

like-ar.d.ts

@@ -28,3 +28,3 @@ export as namespace likeAr;

export function toPlainObject<T, K extends keyof any>(arrayKeys:K[], arrayValues:T[]):{[key in K]:T}
export function createIndex<T, K extends keyof T>(array:T[], keyName:K):{[key:string]:T}
export function createIndex<T, K extends keyof T>(array:T[], keyName:K|K[]):{[key:string]:T}
export var testingLikeOldJs:boolean

@@ -35,3 +35,4 @@ export const Optimized:typeof likeAr

export function beingArray<T>(o:T[]):likeAr.ObjectWithArrayFunctions<{[key in number]:T}>
export const LikeAr:typeof strict
export const LikeAr:typeof strict & typeof likeAr
}

24

like-ar.js

@@ -275,10 +275,22 @@ "use strict";

/** @type {<T, K extends keyof T>(array:T[], keyName:K|K[])=>{[key:string]:T}} */
likeAr.createIndex = function createIndex(array, keyname){
/** @type {{[key:string]:any}} */
var o={};
var keyName=keyname;
var pairs=array;
pairs.forEach(function(pair, i){
o[pair[keyName]]=pair;
});
if (keyname instanceof Array) {
var pairs=array;
pairs.forEach(function(pair, i){
var key = []
for (var keyName of keyname) {
key.push(pair[keyName])
}
o[JSON.stringify(key)] = pair;
});
} else {
var pairs=array;
pairs.forEach(function(pair, i){
// @ts-expect-error pair[keyname] may be not a string, number or Symbol
o[pair[keyname]]=pair;
});
}
return o;

@@ -285,0 +297,0 @@ };

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

@@ -15,9 +15,10 @@ "repository": "codenautas/like-ar",

"devDependencies": {
"@types/mocha": "~9.0.0",
"@types/mocha": "~10.0.1",
"discrepances": "0.2.6",
"expect.js": "~0.3.1",
"istanbul": "~0.4.5",
"json4all": "~1.1.0",
"mocha": "~9.1.2",
"nyc": "~15.1.0"
"json4all": "~1.2.1",
"mocha": "~10.2.0",
"nyc": "~15.1.0",
"typescript": "^4.9.5"
},

@@ -24,0 +25,0 @@ "engines": {

@@ -25,3 +25,3 @@ # like-ar

The function `likeAr` wraps an object. The wraped object can be used like an array
The function `LikeAr` wraps an object. The wraped object can be used like an array
with some array functions: `forEach`, `map`, `filter` y `join`.

@@ -31,4 +31,4 @@

```sh
var likeAr = require('like-ar');
```js
var {LikeAr} = require('like-ar');

@@ -41,8 +41,8 @@ var object={

likeAr(object).forEach(function(value, attrName, object){
console.log(attrName,':',value);
LikeAr(object).forEach(function(value, attrName, object, position){
console.log(position+'.',attrName,':',value);
});
console.log(
likeAr(object).filter(function(value, attrName){
LikeAr(object).filter(function(value, attrName){
return attrName.contains('Name');

@@ -54,2 +54,12 @@ }).map(function(value,attrName){

var objectUpperCase=LikeAr(object).map(v=>v.toUpperCase());
/* objectUpperCase =
var object={
lastName:'PEREZ',
firstName:'DIEGO',
phone:'+45-11-2222-3333'
}
*/
```

@@ -60,3 +70,3 @@

## likeAr(object)
The callback functions receive these parameters: `value`, `key` and the original object.
The callback functions receive these parameters: `value`, `key`, the `original` object and the `position` (starting by 0).
The functions that in the Array case returns Arrays returns a chainable object.

@@ -72,6 +82,7 @@

`keys()` | array of keys
`plain()` | plain object without likeAr functions
`plain()` | plain object without LikeAr functions
## likeAr(object).build(cb(value, key))
## LikeAr(object).build(cb(value, key))
Builds a new object with new keys.

@@ -84,3 +95,3 @@

console.log(likeAr(pairs).build(funciton(pair){ return {[pair.field]: pair.value}; ));
console.log(LikeAr(pairs).build(funciton(pair){ return {[pair.field]: pair.value}; ));
// {lastName: "Perez", firstName: "Diego"}

@@ -90,3 +101,3 @@

console.log(likeAr(toJoin).build(funciton(objectWithOneKey){ return objectWithOneKey; ));
console.log(LikeAr(toJoin).build(funciton(objectWithOneKey){ return objectWithOneKey; ));
// {lastName: "Perez", firstName: "Diego"}

@@ -96,4 +107,4 @@

## likeAr.toPlainObject(array [,keyName [,valueName]])
## likeAr.toPlainObject(arrayOfKeys, arrayOfValues)
## LikeAr.toPlainObject(array [,keyName [,valueName]])
## LikeAr.toPlainObject(arrayOfKeys, arrayOfValues)

@@ -106,15 +117,15 @@ Returns a plain object from an array of pairs (or a pair of arrays) of key/values.

```sh
var likeAr = require('like-ar');
```ts
var {LikeAr} = require('like-ar');
var pairs=[['lastName', 'Perez'], ['firstName', 'Diego']];
console.log(likeAr.toPlainObject(pairs));
console.log(LikeAr.toPlainObject(pairs));
var pairs=[{field:'lastName', value:'Perez'}, {field:'firstName', value:'Diego'}];
console.log(likeAr.toPlainObject(pairs, 'field'));
console.log(LikeAr.toPlainObject(pairs, 'field'));
```
## likeAr.createIndex(array:T[],keyName:string):{[k:string]: T}
## LikeAr.createIndex(array:T[],keyName:string):{[k:string]: T}

@@ -125,8 +136,8 @@ Returns a plain object containing the same element indexed by keyName

```sh
var likeAr = require('like-ar');
```ts
var {LikeAr} = require('like-ar');
var persons=[{name:'Diego', lastName:'Rivera', age:30}, {name:'Frida', lastName:'Kahlo'}];
var idxPersons=likeAr.createIndex(persons, 'lastName');
var idxPersons=LikeAr.createIndex(persons, 'lastName');

@@ -133,0 +144,0 @@ idxPersons.Kahlo.age=20;

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