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

like-ar

Package Overview
Dependencies
Maintainers
0
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.5.0 to 0.5.1

3

like-ar.d.ts

@@ -21,3 +21,4 @@ export as namespace likeAr;

join :(separator?:string) => string
keyCount:()=>number
keyCount:()=>number
awaitAll:() => Promise<{[K in keyof T]:Awaited<T[K]>}>
}

@@ -24,0 +25,0 @@ export function toPlainObject<T>(array:[string, T][]):{[key:string]:T}

@@ -326,4 +326,38 @@ "use strict";

ObjectWithArrayMethodsOptimized.prototype.awaitAll = function awaitAll(){
var oThis = this._object;
var count = 0
var o = {}
return new Promise(function(resolve, reject){
for(var attr in oThis) if(itsAnOwnProperty(oThis,attr)){
count++
}
for(var attr in oThis) if(itsAnOwnProperty(oThis,attr)){
(function(p, attr){
if (!(p instanceof Promise)) p = Promise.resolve(p);
p.catch(reject).then(v => {count--; o[attr] = v; if (count == 0) resolve(o)});
})(oThis[attr], attr);
}
}) ;
}
LikeArStrict.prototype.awaitAll = function awaitAll(){
var oThis = this._object;
var count = 0
var o = {}
return new Promise(function(resolve, reject){
for(var attr in oThis) if(itsAnOwnProperty(oThis,attr)){
count++
}
for(var attr in oThis) if(itsAnOwnProperty(oThis,attr)){
(function(p, attr){
if (!(p instanceof Promise)) p = Promise.resolve(p);
p.catch(reject).then(v => {count--; o[attr] = v; if (count == 0) resolve(o)});
})(oThis[attr], attr);
}
}) ;
}
return likeAr;
});
{
"name": "like-ar",
"description": "Using objects like arrays with map, filter, forEach and others coming soon.",
"version": "0.5.0",
"version": "0.5.1",
"author": "Codenautas <codenautas@googlegroups.com>",

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

@@ -135,3 +135,19 @@ # like-ar

```
### `LikeAr.createIndex(array:T[], getKey:T => string): Record<string, T>`
Returns a plain object containing the same element indexed by `getKey(item)`
```ts
var {LikeAr} = require('like-ar');
var persons=[{name:'Diego', lastName:'Rivera', age:30}, {name:'Frida', lastName:'Kahlo'}];
var idxPersons=LikeAr.createIndex(persons, (p) => p.name + p.lastName);
idxPersons.FridaKahlo.age=20;
console.log(persons[1].age); // 20
```
### `LikeAr.iterator(arrayOrObject: T[] | Record<K,T>): Iterator<T>`

@@ -154,2 +170,22 @@

### `LikeAr<K,T>(object:Record<K,Promise<T>>).awaitAll(): Promise<Record<K,T>>`
It runs all promises in parallel. When all finished it retunrs
an object with the same keys and the resolution of each promise.
If some of the promises fails it will fail immediately.
```ts
var likear = require('like-ar').strict;
var sqls = {
persons: 'select * from person',
mascots: 'select * from mascot'
}
var data = await likear(sqls).map(async sql => db.query(sql)).awaitAll();
console.log(data);
```
### `LikeAr.empty(arrayOrObject: T[] | Record<K,T> | null): boolean`

@@ -156,0 +192,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