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

iterable-operator

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iterable-operator - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

lib/top-async.d.ts

2

lib/index.d.ts

@@ -87,1 +87,3 @@ export * from './is-iterable';

export * from './prefetch-async';
export * from './top';
export * from './top-async';

@@ -103,2 +103,4 @@ "use strict";

__exportStar(require("./prefetch-async"), exports);
__exportStar(require("./top"), exports);
__exportStar(require("./top-async"), exports);
//# sourceMappingURL=index.js.map

3

lib/some-async.d.ts

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

export declare function someAsync<T>(iterable: Iterable<T> | AsyncIterable<T>, predicate: (element: T, index: number) => Promise<unknown>): Promise<boolean>;
import { Awaitable } from 'justypes';
export declare function someAsync<T>(iterable: Iterable<T> | AsyncIterable<T>, predicate: (element: T, index: number) => Awaitable<unknown>): Promise<boolean>;

@@ -0,3 +1,5 @@

export declare type GetTypeOfIterable<T> = T extends Iterable<infer U> ? U : never;
export declare function copyAsyncIterable<T>(iterable: AsyncIterable<T>): AsyncGenerator<Awaited<T>, void, unknown>;
export declare function copyIterable<T>(iterable: Iterable<T>): Generator<T, void, unknown>;
export declare type GetTypeOfIterable<T> = T extends Iterable<infer U> ? U : never;
export declare function findInsertionIndex<T>(sortedArray: readonly T[], insertionElement: T, compare: (a: T, b: T) => number): number;
export declare function getIntermediateIndex(startIndex: number, endIndex: number): number;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.copyIterable = exports.copyAsyncIterable = void 0;
exports.getIntermediateIndex = exports.findInsertionIndex = exports.copyIterable = exports.copyAsyncIterable = void 0;
async function* copyAsyncIterable(iterable) {

@@ -16,2 +16,40 @@ for await (const element of iterable) {

exports.copyIterable = copyIterable;
function findInsertionIndex(sortedArray, insertionElement, compare) {
if (sortedArray.length === 0) {
return 0;
}
else {
let startIndex = 0;
let endIndex = sortedArray.length - 1;
while (true) {
const intermediateIndex = getIntermediateIndex(startIndex, endIndex);
const result = compare(insertionElement, sortedArray[intermediateIndex]);
if (result > 0) {
startIndex = intermediateIndex + 1;
if (startIndex > endIndex) {
return startIndex;
}
}
else if (result < 0) {
endIndex = intermediateIndex;
if (endIndex === startIndex) {
return endIndex;
}
}
else {
for (let i = intermediateIndex; i < sortedArray.length; i++) {
if (compare(insertionElement, sortedArray[intermediateIndex]) !== 0) {
return i;
}
}
return sortedArray.length;
}
}
}
}
exports.findInsertionIndex = findInsertionIndex;
function getIntermediateIndex(startIndex, endIndex) {
return startIndex + Math.floor((endIndex - startIndex) / 2);
}
exports.getIntermediateIndex = getIntermediateIndex;
//# sourceMappingURL=utils.js.map
{
"name": "iterable-operator",
"version": "3.0.0",
"version": "3.1.0",
"description": "Utilities for JavaScript Iterable and AsyncIterable",

@@ -71,2 +71,3 @@ "keywords": [

"eslint": "^8.30.0",
"extra-sort": "^0.1.1",
"husky": "^4.3.8",

@@ -73,0 +74,0 @@ "jest": "^29.3.1",

@@ -680,3 +680,3 @@ # iterable-operator

iterable: Iterable<T> | AsyncIterable<T>
, predicate: (element: T, index: number) => Promise<unknown>
, predicate: (element: T, index: number) => Awaitable<unknown>
): Promise<boolean>

@@ -739,3 +739,24 @@ ```

function prefetch<T>(iterable: Iterable<T>, size: number): AsyncIterableIterator<T>
function prefetchAsync<T>(iterable: AsyncIterable<T>, size: number): AsyncIterableIterator<T>
function prefetchAsync<T>(
iterable: AsyncIterable<T>
, size: number
): AsyncIterableIterator<T>
```
### top, topAsync
```ts
function top<T>(
iterable: Iterable<T>
, num: number
, compare: (a: T, b: T) => number
): T[]
function topAsync<T>(
iterable: AsyncIterable<T>
, num: number
, compare: (a: T, b: T) => number
): Promise<T[]>
```
```ts
top([1, 2, 3], 2, (a, b) => b - a) // [3, 2]
```

Sorry, the diff of this file is not supported yet

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

  • 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