You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

async-ray

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-ray - npm Package Compare versions

Comparing version

to
3.1.0

CODE_OF_CONDUCT.md

13

dist/index.d.ts

@@ -1,2 +0,3 @@

import { AsyncArray } from './async_ray';
import { AsyncArray } from './async_array';
import { Chainable } from './chainable';
/**

@@ -11,1 +12,11 @@ * Get AsyncArray element

export declare function AsyncRay<T>(elements: T[]): AsyncArray<T>;
/**
* Get chainable instance
*
* @export
* @template T
* @param {T[]} input
* @returns
*/
export declare function Chain<T>(input: T[]): Chainable<T>;
export * from './methods';
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
const async_ray_1 = require("./async_ray");
const async_array_1 = require("./async_array");
const chainable_1 = require("./chainable");
/**

@@ -13,5 +17,18 @@ * Get AsyncArray element

function AsyncRay(elements) {
return new async_ray_1.AsyncArray(...elements);
return new async_array_1.AsyncArray(...elements);
}
exports.AsyncRay = AsyncRay;
/**
* Get chainable instance
*
* @export
* @template T
* @param {T[]} input
* @returns
*/
function Chain(input) {
return new chainable_1.Chainable(input);
}
exports.Chain = Chain;
__export(require("./methods"));
//# sourceMappingURL=index.js.map

18

dist/methods/index.d.ts

@@ -1,9 +0,9 @@

export * from './every';
export * from './filter';
export * from './find';
export * from './find_index';
export * from './foreach';
export * from './map';
export * from './reduce';
export * from './reduce_right';
export * from './some';
export * from './a_every';
export * from './a_filter';
export * from './a_find';
export * from './a_find_index';
export * from './a_foreach';
export * from './a_map';
export * from './a_reduce';
export * from './a_reduce_right';
export * from './a_some';

@@ -6,11 +6,11 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./every"));
__export(require("./filter"));
__export(require("./find"));
__export(require("./find_index"));
__export(require("./foreach"));
__export(require("./map"));
__export(require("./reduce"));
__export(require("./reduce_right"));
__export(require("./some"));
__export(require("./a_every"));
__export(require("./a_filter"));
__export(require("./a_find"));
__export(require("./a_find_index"));
__export(require("./a_foreach"));
__export(require("./a_map"));
__export(require("./a_reduce"));
__export(require("./a_reduce_right"));
__export(require("./a_some"));
//# sourceMappingURL=index.js.map

@@ -6,6 +6,7 @@ {

"types": "dist/index.d.ts",
"version": "3.0.1",
"version": "3.1.0",
"scripts": {
"pretest": "npm run build",
"test": "mocha -r ts-node/register/type-check test/*.ts",
"test": "nyc mocha",
"test-coverage-report": "npm test && cat ./coverage/lcov.info | codacy-coverage && rm -rf ./coverage",
"build": "tsc",

@@ -25,5 +26,8 @@ "format": "prettier --write \"**/*.ts\" \"**/*.js\"",

"@types/mocha": "^5.2.5",
"codacy-coverage": "^3.3.0",
"mocha": "^5.2.0",
"nyc": "^13.1.0",
"prettier": "^1.14.3",
"should": "^13.2.3",
"source-map-support": "^0.5.9",
"ts-node": "^7.0.1",

@@ -39,2 +43,21 @@ "tslint": "^5.11.0",

"dependencies": {},
"nyc": {
"extension": [
".ts"
],
"exclude": [
"**/*.d.ts",
"test/*.ts"
],
"require": [
"ts-node/register"
],
"reporter": [
"lcov",
"text-summary",
"html"
],
"sourceMap": true,
"instrument": true
},
"keywords": [

@@ -41,0 +64,0 @@ "Array",

# Async-Ray
[![License](https://img.shields.io/npm/l/async-ray.svg)](https://img.shields.io/npm/l/async-ray.svg)
[![Version](https://img.shields.io/npm/v/async-ray.svg)](https://img.shields.io/npm/v/async-ray.svg)
[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/rpgeeganage/async-ray.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/rpgeeganage/async-ray/context:javascript)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/967e339f9fdb4424a48ba37a0292f221)](https://app.codacy.com/app/rpgeeganage/async-ray?utm_source=github.com&utm_medium=referral&utm_content=rpgeeganage/async-ray&utm_campaign=Badge_Grade_Settings)
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/3e1503ed17af4dc5aadb1fbbc41191d3)](https://www.codacy.com/app/rpgeeganage/async-ray?utm_source=github.com&utm_medium=referral&utm_content=rpgeeganage/async-ray&utm_campaign=Badge_Coverage)
[![Build Status](https://travis-ci.org/rpgeeganage/async-ray.svg?branch=master)](https://travis-ci.org/rpgeeganage/async-ray)
[![Known Vulnerabilities](https://snyk.io/test/github/rpgeeganage/async-ray/badge.svg?targetFile=package.json)](https://snyk.io/test/github/rpgeeganage/async-ray?targetFile=package.json)
[![Maintainability](https://api.codeclimate.com/v1/badges/4c9603df3595612def57/maintainability)](https://codeclimate.com/github/rpgeeganage/async-ray/maintainability)

@@ -7,2 +15,8 @@ Purpose of this package is to provide `async/await` callbacks for `every`, `filter`, `find`, `findIndex`, `forEach`, `map`, `reduce`, `reduceRight` and `some` methods in **_Array_**.

### Content
* [ ***Basic Usage*** ](#basic-usage)
* [ ***Supported methods*** ](#supported-methods)
* [ ***Using methods individually*** ](#using-methods-individually)
* [ ***Chaining*** ](#chaining)
## Basic usage

@@ -25,3 +39,2 @@

## Methods
### .aEvery

@@ -230,72 +243,178 @@

```
## Using methods individually
You can use each method without creating ```AsyncRay ``` object.
```js
import {
aEvery, aFilter, aFind, aFindIndex,
aForEach, aMap, aReduce, aReduceRight, aSome
} from 'async-ray';
## Chaining
// aEvery
const everyResult = await aEvery(
[1, 2, 3],
async (e) => Promise.resolve(e > 0)
);
## Between AsyncRay methods
// aFilter
const filterResult = await aFilter(
[1, 2, 3],
async (e) => Promise.resolve(e > 1)
);
### **Only** `.aFilter` and `.aMap` may be chained together.
// aFind
const findResult = await aFind(
[1, 2, 3],
async (e) => Promise.resolve(e === 3)
);
Make sure to put before each AsyncRay method call an `await` (or call `.then(...)`) since a Promise is returned by the async methods.
// aFindIndex
const findIndexResult = await aFindIndex(
[1, 2, 3],
async (e) => Promise.resolve(e === 2)
);
#### sample
```js
await(await AsyncRay([1,2,3])
.aFilter(...))
.Map(...)
```
// aForEach
const forEachResult: number[] = [];
await aForEach(
[1, 2, 3],
async (e) => {
const op = await Promise.resolve(e * 10);
forEachResult.push(op);
}
);
// aMap
const mapResult = await aMap(
[1, 2, 3],
async (e) => Promise.resolve(e * 10)
);
## Between other [Array methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#) methods
// aReduce
const reduceResult = await aReduce(
[1, 2, 3],
async (acc, e) => Promise.resolve(e + acc),
0
);
`.aEvery`, `.aFilter`, `.aFind`,`.aFindIndex`, `.aForEach`, `.aMap`, `aReduce`, `aReduceRight` and `.aSome` can be chained with other [Array methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#).
// aReduceRight
const reduceRightResult = await aReduceRight(
[1, 2, 3],
async (acc, e) => Promise.resolve(e + acc),
0
);
#### sample 1 - `aMap` and `filter`
// aSome
const someResult = await aSome(
[1, 2, 3],
async (e) => Promise.resolve(e > 1)
);
```
## Chaining
### Async-Ray methods can be chained using ```Chain``` functionality
### Basic usage
```js
async function dummy(ele) {
return Promise.resolve(ele);
}
const { Chain } = require('async-ray');
```
---
***Chaining will return an instance of Async-Ray if returned type is an array.***
const inputArray = [1, 2, 3, 4];
---
const chainedValue = (await AsyncRay(inputArray).aMap(
async (ele) => await dummy(ele * 10)
)).filter((ele) => ele > 20);
#### sample 1 - `aMap()` and `aFilter()`
---
The `process()` method __***must be called explicitly***__ to process the chain because `aMap()` and `aFilter()` method returns an array.
```js
const input = [1, 2, 3];
console.log('Output is ', chainedValue);
// Output is [30, 40]
const op = await Chain(input)
.aMap(
async (e) => Promise.resolve(e * 10)
)
.aFilter(
async (e) => Promise.resolve(e > 10)
)
.aMap(
async (e) => Promise.resolve(e * 10)
)
// Call the process() method to execute the chain
.process();
console.log('Output is ', op);
// Output is [ 200, 300 ]
```
#### sample 2 - `aMap()`, `aFilter()` and `aFind()`
---
The `process()` method __***not be called***__ to because `aFind()` does not return an array.
```js
const input = [1, 2, 3];
#### sample 2 - `aMap` and `find`
const op = await Chain(input)
.aMap(
async (e) => Promise.resolve(e * 10)
)
.aFilter(
async (e) => Promise.resolve(e > 10)
)
.aMap(
async (e) => Promise.resolve(e * 10)
)
.aFind(
async (e) => Promise.resolve(e === 300)
);
// No need to call process() method
console.log('Output is ', op);
// Output is 300
```
#### Between other [Array methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#) methods
---
#### Sample 1 - Async-Ray `Chain` with `filter()`
```js
async function dummy(ele) {
return Promise.resolve(ele);
}
const input = [1, 2, 3];
const inputArray = [1, 2, 3, 4];
const op = (
await Chain(input)
.aMap(
async (e) => Promise.resolve(e * 10)
)
.aFilter(
async (e) => Promise.resolve(e > 10)
)
.aMap(
async (e) => Promise.resolve(e * 10)
)
.process()
)
.filter(e => e > 200)
const chainedValue = (await AsyncRay(inputArray).aMap(
async (ele) => await dummy(ele * 10)
)).find((ele) => ele === 20);
console.log('Output is ', chainedValue);
// Output is 20
console.log('Output is ', op);
// Output is [ 300 ]
```
---
#### sample 3 - `aMap` and `reduce`
#### Sample 2 - Async-Ray `Chain` with `find()`
```js
async function dummy(ele) {
return Promise.resolve(ele);
}
const input = [1, 2, 3];
const inputArray = [1, 2, 3, 4];
const op = (
await Chain(input)
.aMap(
async (e) => Promise.resolve(e * 10)
)
.aFilter(
async (e) => Promise.resolve(e > 10)
)
.aMap(
async (e) => Promise.resolve(e * 10)
)
.process()
)
.find(e => e === 200)
const chainedValue = (await AsyncRay(inputArray).aMap(
async (ele) => await dummy(ele * 10)
)).reduce((acc, ele) => acc + ele), 1);
console.log('Output is ', chainedValue);
// Output is 101
console.log('Output is ', op);
// Output is 200
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.