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

iterator-helper

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iterator-helper - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

dist/index.mjs

2

dist/index.js

@@ -10,5 +10,5 @@ "use strict";

var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./ItHelper"), exports);
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HIterator = exports.iter = exports.HAsyncIterator = exports.aiter = void 0;
exports.HIterator = exports.iter = exports.HAsyncIterator = exports.aiter = exports.awrap = exports.wrap = void 0;
const IteratorSlot = Symbol('IteratorSlot');
function wrap(func) {
return function (...args) {
// @ts-expect-error
return iter(func.call(this, ...args));
};
}
exports.wrap = wrap;
function awrap(func) {
return function (...args) {
// @ts-expect-error
return aiter(func.call(this, ...args));
};
}
exports.awrap = awrap;
function aiter(item) {

@@ -36,3 +50,3 @@ if (Symbol.asyncIterator in item) {

while (!value.done) {
const real_value = callback(value.value);
const real_value = await callback(value.value);
const next_value = yield real_value;

@@ -53,3 +67,3 @@ value = await it.next(next_value);

const real_value = value.value;
if (callback(real_value)) {
if (await callback(real_value)) {
next_value = yield real_value;

@@ -67,3 +81,3 @@ }

const real_value = value.value;
if (callback(real_value))
if (await callback(real_value))
return real_value;

@@ -79,3 +93,3 @@ value = await it.next();

const real_value = value.value;
if (!callback(real_value))
if (!await callback(real_value))
return false;

@@ -92,3 +106,3 @@ value = await it.next();

const real_value = value.value;
if (callback(real_value))
if (await callback(real_value))
return true;

@@ -191,3 +205,3 @@ value = await it.next();

const real_value = value.value;
const mapped = mapper(real_value);
const mapped = await mapper(real_value);
if (Symbol.asyncIterator in mapped) {

@@ -216,3 +230,3 @@ // @ts-ignore

for await (const value of it) {
acc = reducer(acc, value);
acc = await reducer(acc, value);
}

@@ -227,3 +241,3 @@ return acc;

const real_value = value.value;
callback(real_value);
await callback(real_value);
value = await it.next();

@@ -294,3 +308,3 @@ }

const real_value = value.value;
if (callback(real_value)) {
if (await callback(real_value)) {
next_value = yield real_value;

@@ -316,3 +330,3 @@ }

const real_value = value.value;
if (!finished && callback(real_value)) {
if (!finished && await callback(real_value)) {
value = await it.next(next_value);

@@ -354,3 +368,3 @@ continue;

const real_value = value.value;
if (callback(real_value))
if (await callback(real_value))
partition1.push(real_value);

@@ -370,3 +384,3 @@ else

const real_value = value.value;
if (callback(real_value))
if (await callback(real_value))
return i;

@@ -373,0 +387,0 @@ value = await it.next();

{
"name": "iterator-helper",
"version": "1.0.1",
"version": "1.1.0",
"description": "",
"main": "dist/index.js",
"module": "dist/index.mjs",
"scripts": {
"test": "node dist/test.js"
"test": "node dist/test.js",
"build": "tsc && npm run build-esm",
"build-esm": "tsc --project ./tsconfig-esm.json && node rename_mjs.js"
},

@@ -9,0 +12,0 @@ "keywords": [

@@ -29,3 +29,3 @@ # iterator-helper

for (const [index, element] of mapped_cycle) {
console.log(index, element);
console.log(index, element);
// 0, 2

@@ -64,3 +64,3 @@ // 1, 4

const current = this.position;
this.position += this.step;
this.position += this.step;

@@ -81,2 +81,21 @@ return { value: current, done: false };

## Generators helpers
If you have some (a)sync generators, you can wrap them with the appropriate wrapper:
```ts
import { wrap, awrap } from 'iterator-helper';
function* generateNumbers() {
yield 1;
yield* [2, 3, 4];
}
// wrap for sync generators, awrap for async generators.
generateNumbers = wrap(generateNumbers);
// It works!
generateNumbers().filter(e => e % 2 === 0).toArray();
```
## API

@@ -83,0 +102,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