@ts-common/iterator
Advanced tools
Comparing version 0.0.31 to 0.0.32
@@ -27,4 +27,5 @@ import { Tuple2 } from "@ts-common/tuple"; | ||
export declare const zip: <T>(...inputs: Iterable<T>[]) => Iterable<ReadonlyArray<T>>; | ||
export declare const arrayEqual: <T>(a: ReadonlyArray<T> | undefined, b: ReadonlyArray<T> | undefined, e: (ai: T, bi: T) => boolean) => boolean; | ||
export declare const isStrictEqual: (a: unknown, b: unknown) => boolean; | ||
export declare const isEqual: <A, B>(a: Iterable<A>, b: Iterable<B>, e?: (ai: A, bi: B) => boolean) => boolean; | ||
export declare const isArray: <T, U>(v: U | ReadonlyArray<T>) => v is ReadonlyArray<T>; | ||
export declare const toArray: <T>(i: Iterable<T>) => ReadonlyArray<T>; |
43
index.js
@@ -117,27 +117,34 @@ "use strict"; | ||
}; | ||
exports.arrayEqual = (a, b, e) => { | ||
/* tslint:disable-next-line:no-if-statement */ | ||
if (a === b) { | ||
// TypeScript gives an error in case if type of a and type of b are different | ||
exports.isStrictEqual = (a, b) => a === b; | ||
exports.isEqual = (a, b, e = exports.isStrictEqual) => { | ||
// tslint:disable-next-line:no-if-statement | ||
if (exports.isStrictEqual(a, b)) { | ||
return true; | ||
} | ||
/* tslint:disable-next-line:no-if-statement */ | ||
if (a === undefined || b === undefined) { | ||
return false; | ||
} | ||
const al = a.length; | ||
const bl = b.length; | ||
/* tslint:disable-next-line:no-if-statement */ | ||
if (al !== bl) { | ||
return false; | ||
} | ||
/* tslint:disable-next-line:no-loop-statement */ | ||
for (let i = 0; i < al; ++i) { | ||
/* tslint:disable-next-line:no-if-statement */ | ||
if (!e(a[i], b[i])) { | ||
const ai = a[Symbol.iterator](); | ||
const bi = b[Symbol.iterator](); | ||
// tslint:disable-next-line:no-loop-statement | ||
while (true) { | ||
const av = ai.next(); | ||
const bv = bi.next(); | ||
// tslint:disable-next-line:no-if-statement | ||
if (av.done || bv.done) { | ||
return av.done === bv.done; | ||
} | ||
// tslint:disable-next-line:no-if-statement | ||
if (!e(av.value, bv.value)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
/* | ||
export const arrayEqual = <T>( | ||
a: ReadonlyArray<T>|undefined, | ||
b: ReadonlyArray<T>|undefined, | ||
e: (ai: T, bi: T) => boolean = isStrictEqual, | ||
): boolean => | ||
a === undefined || b === undefined ? a === b : isEqual(a, b, e) | ||
*/ | ||
exports.isArray = (v) => v instanceof Array; | ||
exports.toArray = Array.from; |
{ | ||
"name": "@ts-common/iterator", | ||
"version": "0.0.31", | ||
"version": "0.0.32", | ||
"description": "Iterator library for JavaScript and TypeScript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
21422
179
0