From b0e30b558c6ab51c19ba4eb26a42b917213ea88e Mon Sep 17 00:00:00 2001 From: Luke Davies Date: Thu, 28 Feb 2019 23:56:16 +0000 Subject: [PATCH] Added prettier --- .prettierrc | 5 + lib/aggregates.ts | 14 +- lib/iterators.ts | 141 +++++--- package.json | 4 +- test/aggregates.spec.ts | 551 +++++++++++++++++++++++----- test/iterators.spec.ts | 781 +++++++++++++++++++++++++++++++--------- test/mod.spec.ts | 77 +++- yarn.lock | 5 + 8 files changed, 1252 insertions(+), 326 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..6de9cff --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "singleQuote": true, + "trailingComma": "all", + "endOfLine": "lf" +} diff --git a/lib/aggregates.ts b/lib/aggregates.ts index 9e91c54..673a985 100644 --- a/lib/aggregates.ts +++ b/lib/aggregates.ts @@ -146,7 +146,7 @@ export function average( if (ccount === 0) { throw new Error(Errors.Empty); } - return total / ccount as any; + return (total / ccount) as any; } /** @@ -187,7 +187,7 @@ export function count( function getElementAt( iterable: Iterable, index: number, -): { found: false } | { found: true, element: TElement } { +): { found: false } | { found: true; element: TElement } { let cindex = 0; for (const element of iterable) { if (cindex === index) { @@ -241,7 +241,7 @@ export function elementAtOrDefault( function getFirst( iterable: Iterable, predicate: BoolPredicate = () => true, -): { items: false } | { items: true, element: TElement } { +): { items: false } | { items: true; element: TElement } { for (const element of iterable) { if (predicate(element)) { return { items: true, element }; @@ -331,7 +331,7 @@ export function iterableEquals( function getLast( iterable: Iterable, predicate: BoolPredicate = () => true, -): { items: false } | { items: true, element: TElement } { +): { items: false } | { items: true; element: TElement } { let items = false; let latest: TElement; for (const element of iterable) { @@ -449,7 +449,9 @@ export function min( */ export function resolveAll( iterable: Iterable, -): Promise ? TResult[] : TElement[]> { +): Promise< + TElement extends PromiseLike ? TResult[] : TElement[] +> { return Promise.all(iterable) as any; } @@ -459,7 +461,7 @@ export function resolveAll( function getSingle( iterable: Iterable, predicate: BoolPredicate, -): { found: false } | { found: true, element: TElement } { +): { found: false } | { found: true; element: TElement } { for (const element of iterable) { if (predicate(element)) { return { found: true, element }; diff --git a/lib/iterators.ts b/lib/iterators.ts index 42f2a5c..feb2ec6 100644 --- a/lib/iterators.ts +++ b/lib/iterators.ts @@ -1,5 +1,12 @@ import * as aggregates from './aggregates.ts'; -import { AggFn, BoolPredicate, CallbackFn, ComparerFn, MapFn, StrFn } from './aggregates.ts'; +import { + AggFn, + BoolPredicate, + CallbackFn, + ComparerFn, + MapFn, + StrFn, +} from './aggregates.ts'; // Helpers types. @@ -11,7 +18,10 @@ type IndexMapFn = (source: TSource, index: number) => TResult; /** * A function that combines 2 types into another. */ -type CombineFn = (first: TFirst, second: TSecond) => TResult; +type CombineFn = ( + first: TFirst, + second: TSecond, +) => TResult; /** * A function that takes in 2 values and returns the sorting number. */ @@ -24,8 +34,10 @@ type IndexPredicate = (element: TSource, index: number) => boolean; * A function that takes in a value and an index and returns whether the * value is of a given type. */ -type IndexIsPredicate = - (element: TSource, index: number) => element is TResult; +type IndexIsPredicate = ( + element: TSource, + index: number, +) => element is TResult; /** * A grouping of elements based on the key. @@ -91,7 +103,10 @@ export abstract class Lazy implements Iterable { * account that some lazy iterators *require* the interable to be finite to work. * Check the remarks on the function you want to use to see which ones will work. */ - public static repeat(element: TElement, count?: number): Lazy { + public static repeat( + element: TElement, + count?: number, + ): Lazy { return new LazyRepeat(element, count); } @@ -278,8 +293,14 @@ export abstract class Lazy implements Iterable { * @remarks This will iterate until the condition is satisfied, or until the * iterable ends. */ - public firstOrDefault(defaultValue: TElement, predicate: BoolPredicate): TElement; - public firstOrDefault(defaultValue: TElement, predicate?: BoolPredicate) { + public firstOrDefault( + defaultValue: TElement, + predicate: BoolPredicate, + ): TElement; + public firstOrDefault( + defaultValue: TElement, + predicate?: BoolPredicate, + ) { return aggregates.firstOrDefault(this, defaultValue, predicate); } @@ -303,7 +324,10 @@ export abstract class Lazy implements Iterable { * @remarks This will check for both order and value, and will iterate * both iterables completely. */ - public iterableEquals(second: Iterable, comparer?: ComparerFn) { + public iterableEquals( + second: Iterable, + comparer?: ComparerFn, + ) { return aggregates.iterableEquals(this, second, comparer); } @@ -343,8 +367,14 @@ export abstract class Lazy implements Iterable { * satisfied the condition. * @remarks This will cause a complete iteration of the iterable object. */ - public lastOrDefault(defaultValue: TElement, predicate: BoolPredicate): TElement; - public lastOrDefault(defaultValue: TElement, predicate?: BoolPredicate) { + public lastOrDefault( + defaultValue: TElement, + predicate: BoolPredicate, + ): TElement; + public lastOrDefault( + defaultValue: TElement, + predicate?: BoolPredicate, + ) { return aggregates.lastOrDefault(this, defaultValue, predicate); } @@ -394,8 +424,12 @@ export abstract class Lazy implements Iterable { * @returns A promise that will resolve to a lazy iterable object. * @remarks This will cause a complete iteration of the iterable object. */ - public resolveAll(): Promise ? Lazy : Lazy> { - return aggregates.resolveAll(this).then(iterable => Lazy.from(iterable)) as any; + public resolveAll(): Promise< + TElement extends PromiseLike ? Lazy : Lazy + > { + return aggregates + .resolveAll(this) + .then(iterable => Lazy.from(iterable)) as any; } /** @@ -421,7 +455,10 @@ export abstract class Lazy implements Iterable { * @remarks This will iterate until the condition is met or until the iterable * ends. */ - public singleOrDefault(predicate: BoolPredicate, defaultValue: TElement) { + public singleOrDefault( + predicate: BoolPredicate, + defaultValue: TElement, + ) { return aggregates.singleOrDefault(this, predicate, defaultValue); } @@ -482,7 +519,10 @@ export abstract class Lazy implements Iterable { * @returns A `Map` derived from the iterable. * @remarks This will cause a complete iteration of the iterable object. */ - public toMap(keyFn: MapFn, valueFn?: MapFn) { + public toMap( + keyFn: MapFn, + valueFn?: MapFn, + ) { return aggregates.toMap(this, keyFn, valueFn); } @@ -565,7 +605,9 @@ export abstract class Lazy implements Iterable { * @remarks When this is iterated (not before), the underlying iterator is walked through * completely. */ - public groupBy(keyFn: MapFn): Lazy>; + public groupBy( + keyFn: MapFn, + ): Lazy>; /** * Groups the elements by key and projects each element using the given function. * @param keyFn The function to extract the key from each element. @@ -591,11 +633,7 @@ export abstract class Lazy implements Iterable { elementSelector: MapFn, resultSelector: CombineFn, TResult>, ): Lazy; - public groupBy< - TKey, - TItem = TElement, - TResult = IGrouping - >( + public groupBy>( keyFn: MapFn, elementSelector?: MapFn, resultSelector?: CombineFn, TResult>, @@ -719,7 +757,9 @@ export abstract class Lazy implements Iterable { * @param selector The transformation function to use for each element. * @remarks Does not cause additional unexpected iteration. */ - public select(selector: IndexMapFn): Lazy { + public select( + selector: IndexMapFn, + ): Lazy { return new LazySelect(this, selector); } @@ -730,7 +770,9 @@ export abstract class Lazy implements Iterable { * is the index that the element was at in the source iterable, *not* the resulting one. * @remarks Does not cause additional unexpected iteration. */ - public selectMany(selector: IndexMapFn>): Lazy { + public selectMany( + selector: IndexMapFn>, + ): Lazy { return new LazySelectMany(this, selector); } @@ -902,9 +944,7 @@ class LazyEmpty extends Lazy { * @hidden */ class LazyIterator extends Lazy { - public constructor( - private readonly _iterable: Iterable, - ) { + public constructor(private readonly _iterable: Iterable) { super(); } @@ -960,7 +1000,10 @@ class LazyIterator extends Lazy { return super.first(); } - public firstOrDefault(defaultValue: TElement, predicate?: BoolPredicate) { + public firstOrDefault( + defaultValue: TElement, + predicate?: BoolPredicate, + ) { if (predicate) { return super.firstOrDefault(defaultValue, predicate); } @@ -992,7 +1035,10 @@ class LazyIterator extends Lazy { return super.last(); } - public lastOrDefault(defaultValue: TElement, predicate?: BoolPredicate) { + public lastOrDefault( + defaultValue: TElement, + predicate?: BoolPredicate, + ) { if (predicate) { return super.lastOrDefault(defaultValue, predicate); } @@ -1092,9 +1138,7 @@ class LazyAppendPrepend extends Lazy { class LazyConcat extends Lazy { private readonly _iterables: Array>; - public constructor( - ..._iterables: Array> - ) { + public constructor(..._iterables: Array>) { super(); this._iterables = _iterables; } @@ -1135,7 +1179,8 @@ class LazyDefaultIfEmpty extends Lazy { class LazyDistinct extends Lazy { public constructor( private readonly _iterable: Iterable, - private readonly _compareOn: MapFn = ((element: TElement) => element) as any, + private readonly _compareOn: MapFn = ((element: TElement) => + element) as any, ) { super(); } @@ -1159,7 +1204,8 @@ class LazyExcept extends Lazy { public constructor( private readonly _firstIterable: Iterable, private readonly _secondIterable: Iterable, - private readonly _compareOn: MapFn = ((element: TElement) => element) as any, + private readonly _compareOn: MapFn = ((element: TElement) => + element) as any, ) { super(); } @@ -1189,13 +1235,17 @@ class LazyGroupBy< TKey, TElement = TSource, TResult = IGrouping - > extends Lazy { +> extends Lazy { public constructor( private readonly _iterable: Iterable, private readonly _keyFn: MapFn, - private readonly _elementSelector: MapFn = source => source as any, - private readonly _resultSelector: CombineFn, TResult> = - (key, elements) => ({ key, elements }) as any, + private readonly _elementSelector: MapFn = source => + source as any, + private readonly _resultSelector: CombineFn< + TKey, + Iterable, + TResult + > = (key, elements) => ({ key, elements } as any), ) { super(); } @@ -1261,7 +1311,8 @@ class LazyIntersect extends Lazy { public constructor( private readonly _firstIterable: Iterable, private readonly _secondIterable: Iterable, - private readonly _compareOn: MapFn = ((element: TElement) => element) as any, + private readonly _compareOn: MapFn = ((element: TElement) => + element) as any, ) { super(); } @@ -1359,9 +1410,7 @@ class LazyOrderBy extends Lazy { * @hidden */ class LazyReverse extends Lazy { - public constructor( - private readonly _iterable: Iterable, - ) { + public constructor(private readonly _iterable: Iterable) { super(); } @@ -1581,7 +1630,8 @@ class LazyUnion extends Lazy { public constructor( private readonly _firstIterable: Iterable, private readonly _secondIterable: Iterable, - private readonly _compareOn: MapFn = ((element: TElement) => element) as any, + private readonly _compareOn: MapFn = ((element: TElement) => + element) as any, ) { super(); } @@ -1625,11 +1675,16 @@ class LazyWhere extends Lazy { /** * @hidden */ -class LazyZip extends Lazy { +class LazyZip extends Lazy< + TResult +> { public constructor( private readonly _firstIterable: Iterable, private readonly _secondIterable: Iterable, - private readonly _selector: CombineFn = (first, second) => [first, second] as any, + private readonly _selector: CombineFn = ( + first, + second, + ) => [first, second] as any, ) { super(); } diff --git a/package.json b/package.json index 1dba59b..139f313 100644 --- a/package.json +++ b/package.json @@ -13,11 +13,13 @@ "prepare": "rm -rf dist/* && deno --allow-read --allow-write https://gist.githubusercontent.com/luvies/d85fc46c5b4e255b845743082bdbc3c0/raw/fcad5914596c75f72868500c87493f5cc569629e/node_prebuild.ts --in lib --out prebuild && tsc --project ./tsconfig.build.json", "test": "deno ./test/run_tests.ts", "init-types": "deno --prefetch ./test/run_tests.ts", - "lint": "tslint --project .", + "lint": "tslint --project . && prettier --check 'lib/**/*.ts' 'test/**/*.ts'", + "fix": "tslint --project . --fix && prettier --check --write 'lib/**/*.ts' 'test/**/*.ts'", "docs": "yarn prepare && typedoc --out docs ./prebuild --mode file" }, "devDependencies": { "deno_ls_plugin": "^0.1.0", + "prettier": "^1.16.4", "tslint": "^5.13.0", "tslint-config-prettier": "^1.18.0", "tslint-eslint-rules": "^5.4.0", diff --git a/test/aggregates.spec.ts b/test/aggregates.spec.ts index 413f447..fef4808 100644 --- a/test/aggregates.spec.ts +++ b/test/aggregates.spec.ts @@ -2,11 +2,26 @@ import { assert, test } from 'https://deno.land/x/std@v0.2.8/testing/mod.ts'; import { Lazy } from '../lib/mod.ts'; test(function aggregate() { - assert.equal(Lazy.from([1, 2, 3]).aggregate((acc, curr) => acc + curr, 0), 1 + 2 + 3); - assert.equal(Lazy.from([1, 2, 3, 4]).aggregate((acc, curr) => acc + curr, 0), 1 + 2 + 3 + 4); - assert.equal(Lazy.from([1, 2, 3, 4]).aggregate((acc, curr) => acc * curr, 1), 1 * 2 * 3 * 4); - assert.equal(Lazy.from([1, 2, 3]).aggregate((acc, curr) => acc + curr, ''), '123'); - assert.equal(Lazy.from([1, 2, 3]).aggregate((acc, curr) => acc + curr), 1 + 2 + 3); + assert.equal( + Lazy.from([1, 2, 3]).aggregate((acc, curr) => acc + curr, 0), + 1 + 2 + 3, + ); + assert.equal( + Lazy.from([1, 2, 3, 4]).aggregate((acc, curr) => acc + curr, 0), + 1 + 2 + 3 + 4, + ); + assert.equal( + Lazy.from([1, 2, 3, 4]).aggregate((acc, curr) => acc * curr, 1), + 1 * 2 * 3 * 4, + ); + assert.equal( + Lazy.from([1, 2, 3]).aggregate((acc, curr) => acc + curr, ''), + '123', + ); + assert.equal( + Lazy.from([1, 2, 3]).aggregate((acc, curr) => acc + curr), + 1 + 2 + 3, + ); }); test(function all() { @@ -29,7 +44,8 @@ test(function any() { }); test(function average() { - const avg = (lst: number[]) => lst.reduce((prev, curr) => prev + curr) / lst.length; + const avg = (lst: number[]) => + lst.reduce((prev, curr) => prev + curr) / lst.length; let orig = [1, 2, 3, 4]; assert.equal(Lazy.from(orig).average(), avg(orig)); @@ -49,7 +65,10 @@ test(function average() { { value: 4 }, { value: 5 }, ]; - assert.equal(Lazy.from(objs).average(o => o.value), avg(objs.map(o => o.value))); + assert.equal( + Lazy.from(objs).average(o => o.value), + avg(objs.map(o => o.value)), + ); }); test(function contains() { @@ -87,17 +106,67 @@ test(function count() { assert.equal(Lazy.from([1, 2, 3, 4]).count(i => i % 2 === 0), 2); // Test iterated array access. - assert.equal(Lazy.from([]).select(v => v * 2).count(), 0); - assert.equal(Lazy.from([1]).select(v => v * 2).count(), 1); - assert.equal(Lazy.from([1, 2]).select(v => v * 2).count(), 2); - assert.equal(Lazy.from([1, 2, 3]).select(v => v * 2).count(), 3); - assert.equal(Lazy.from([1, 2, 3, 4]).select(v => v * 2).count(), 4); - - assert.equal(Lazy.from([]).select(v => v + 1).count(i => i % 2 === 0), 0); - assert.equal(Lazy.from([1]).select(v => v + 1).count(i => i % 2 === 0), 1); - assert.equal(Lazy.from([1, 2]).select(v => v + 1).count(i => i % 2 === 0), 1); - assert.equal(Lazy.from([1, 2, 3]).select(v => v + 1).count(i => i % 2 === 0), 2); - assert.equal(Lazy.from([1, 2, 3, 4]).select(v => v + 1).count(i => i % 2 === 0), 2); + assert.equal( + Lazy.from([]) + .select(v => v * 2) + .count(), + 0, + ); + assert.equal( + Lazy.from([1]) + .select(v => v * 2) + .count(), + 1, + ); + assert.equal( + Lazy.from([1, 2]) + .select(v => v * 2) + .count(), + 2, + ); + assert.equal( + Lazy.from([1, 2, 3]) + .select(v => v * 2) + .count(), + 3, + ); + assert.equal( + Lazy.from([1, 2, 3, 4]) + .select(v => v * 2) + .count(), + 4, + ); + + assert.equal( + Lazy.from([]) + .select(v => v + 1) + .count(i => i % 2 === 0), + 0, + ); + assert.equal( + Lazy.from([1]) + .select(v => v + 1) + .count(i => i % 2 === 0), + 1, + ); + assert.equal( + Lazy.from([1, 2]) + .select(v => v + 1) + .count(i => i % 2 === 0), + 1, + ); + assert.equal( + Lazy.from([1, 2, 3]) + .select(v => v + 1) + .count(i => i % 2 === 0), + 2, + ); + assert.equal( + Lazy.from([1, 2, 3, 4]) + .select(v => v + 1) + .count(i => i % 2 === 0), + 2, + ); }); test(function elementAt() { @@ -113,18 +182,50 @@ test(function elementAt() { orig = []; assert.throws(() => Lazy.from(orig).elementAt(0)); - // Test iterated array access. orig = [1, 2, 3, 4, 5]; - assert.equal(Lazy.from(orig).select(v => v * 2).elementAt(0), 2); - assert.equal(Lazy.from(orig).select(v => v * 2).elementAt(1), 4); - assert.equal(Lazy.from(orig).select(v => v * 2).elementAt(2), 6); - assert.equal(Lazy.from(orig).select(v => v * 2).elementAt(3), 8); - assert.equal(Lazy.from(orig).select(v => v * 2).elementAt(4), 10); - assert.throws(() => Lazy.from(orig).select(v => v * 2).elementAt(5)); + assert.equal( + Lazy.from(orig) + .select(v => v * 2) + .elementAt(0), + 2, + ); + assert.equal( + Lazy.from(orig) + .select(v => v * 2) + .elementAt(1), + 4, + ); + assert.equal( + Lazy.from(orig) + .select(v => v * 2) + .elementAt(2), + 6, + ); + assert.equal( + Lazy.from(orig) + .select(v => v * 2) + .elementAt(3), + 8, + ); + assert.equal( + Lazy.from(orig) + .select(v => v * 2) + .elementAt(4), + 10, + ); + assert.throws(() => + Lazy.from(orig) + .select(v => v * 2) + .elementAt(5), + ); orig = []; - assert.throws(() => Lazy.from(orig).select(v => v * 2).elementAt(0)); + assert.throws(() => + Lazy.from(orig) + .select(v => v * 2) + .elementAt(0), + ); }); test(function elementAtOrDefault() { @@ -142,15 +243,50 @@ test(function elementAtOrDefault() { // Test iterated array access. orig = [1, 2, 3, 4, 5]; - assert.equal(Lazy.from(orig).select(v => v * 2).elementAtOrDefault(0, 9), 2); - assert.equal(Lazy.from(orig).select(v => v * 2).elementAtOrDefault(1, 9), 4); - assert.equal(Lazy.from(orig).select(v => v * 2).elementAtOrDefault(2, 9), 6); - assert.equal(Lazy.from(orig).select(v => v * 2).elementAtOrDefault(3, 9), 8); - assert.equal(Lazy.from(orig).select(v => v * 2).elementAtOrDefault(4, 9), 10); - assert.equal(Lazy.from(orig).select(v => v * 2).elementAtOrDefault(5, 9), 9); + assert.equal( + Lazy.from(orig) + .select(v => v * 2) + .elementAtOrDefault(0, 9), + 2, + ); + assert.equal( + Lazy.from(orig) + .select(v => v * 2) + .elementAtOrDefault(1, 9), + 4, + ); + assert.equal( + Lazy.from(orig) + .select(v => v * 2) + .elementAtOrDefault(2, 9), + 6, + ); + assert.equal( + Lazy.from(orig) + .select(v => v * 2) + .elementAtOrDefault(3, 9), + 8, + ); + assert.equal( + Lazy.from(orig) + .select(v => v * 2) + .elementAtOrDefault(4, 9), + 10, + ); + assert.equal( + Lazy.from(orig) + .select(v => v * 2) + .elementAtOrDefault(5, 9), + 9, + ); orig = []; - assert.equal(Lazy.from(orig).select(v => v * 2).elementAtOrDefault(0, 9), 9); + assert.equal( + Lazy.from(orig) + .select(v => v * 2) + .elementAtOrDefault(0, 9), + 9, + ); }); test(function first() { @@ -166,15 +302,53 @@ test(function first() { assert.throws(() => Lazy.from([]).first(i => i % 2 === 0)); // Test iterated array access. - assert.equal(Lazy.from([1, 2, 3]).select(v => v * 2).first(), 2); - assert.equal(Lazy.from([2, 3, 1]).select(v => v * 2).first(), 4); - assert.equal(Lazy.from([3, 2, 1]).select(v => v * 2).first(), 6); - assert.throws(() => Lazy.from([]).select(v => v * 2).first()); - - assert.equal(Lazy.from([1, 2, 3]).select(v => v * 2).first(i => i % 3 === 0), 6); - assert.equal(Lazy.from([2, 3, 1]).select(v => v * 2).first(i => i % 3 === 0), 6); - assert.equal(Lazy.from([3, 2, 1]).select(v => v * 2).first(i => i % 3 === 0), 6); - assert.throws(() => Lazy.from([]).select(v => v * 2).first(i => i % 3 === 0)); + assert.equal( + Lazy.from([1, 2, 3]) + .select(v => v * 2) + .first(), + 2, + ); + assert.equal( + Lazy.from([2, 3, 1]) + .select(v => v * 2) + .first(), + 4, + ); + assert.equal( + Lazy.from([3, 2, 1]) + .select(v => v * 2) + .first(), + 6, + ); + assert.throws(() => + Lazy.from([]) + .select(v => v * 2) + .first(), + ); + + assert.equal( + Lazy.from([1, 2, 3]) + .select(v => v * 2) + .first(i => i % 3 === 0), + 6, + ); + assert.equal( + Lazy.from([2, 3, 1]) + .select(v => v * 2) + .first(i => i % 3 === 0), + 6, + ); + assert.equal( + Lazy.from([3, 2, 1]) + .select(v => v * 2) + .first(i => i % 3 === 0), + 6, + ); + assert.throws(() => + Lazy.from([]) + .select(v => v * 2) + .first(i => i % 3 === 0), + ); }); test(function firstOrDefault() { @@ -190,19 +364,59 @@ test(function firstOrDefault() { assert.equal(Lazy.from([]).firstOrDefault(9, i => i % 2 === 0), 9); // Test iterated array access. - assert.equal(Lazy.from([1, 2, 3]).select(v => v * 2).firstOrDefault(9), 2); - assert.equal(Lazy.from([2, 3, 1]).select(v => v * 2).firstOrDefault(9), 4); - assert.equal(Lazy.from([3, 2, 1]).select(v => v * 2).firstOrDefault(9), 6); - assert.equal(Lazy.from([]).select(v => v * 2).firstOrDefault(9), 9); - - assert.equal(Lazy.from([1, 2, 3]).select(v => v * 2).firstOrDefault(9, i => i % 3 === 0), 6); - assert.equal(Lazy.from([2, 3, 1]).select(v => v * 2).firstOrDefault(9, i => i % 3 === 0), 6); - assert.equal(Lazy.from([3, 2, 1]).select(v => v * 2).firstOrDefault(9, i => i % 3 === 0), 6); - assert.equal(Lazy.from([]).select(v => v * 2).firstOrDefault(9, i => i % 3 === 0), 9); + assert.equal( + Lazy.from([1, 2, 3]) + .select(v => v * 2) + .firstOrDefault(9), + 2, + ); + assert.equal( + Lazy.from([2, 3, 1]) + .select(v => v * 2) + .firstOrDefault(9), + 4, + ); + assert.equal( + Lazy.from([3, 2, 1]) + .select(v => v * 2) + .firstOrDefault(9), + 6, + ); + assert.equal( + Lazy.from([]) + .select(v => v * 2) + .firstOrDefault(9), + 9, + ); + + assert.equal( + Lazy.from([1, 2, 3]) + .select(v => v * 2) + .firstOrDefault(9, i => i % 3 === 0), + 6, + ); + assert.equal( + Lazy.from([2, 3, 1]) + .select(v => v * 2) + .firstOrDefault(9, i => i % 3 === 0), + 6, + ); + assert.equal( + Lazy.from([3, 2, 1]) + .select(v => v * 2) + .firstOrDefault(9, i => i % 3 === 0), + 6, + ); + assert.equal( + Lazy.from([]) + .select(v => v * 2) + .firstOrDefault(9, i => i % 3 === 0), + 9, + ); }); test(function forEach() { - const items: Array<{ v: number, i: number }> = []; + const items: Array<{ v: number; i: number }> = []; Lazy.from([1, 2, 3, 4, 5]).forEach((v, i) => items.push({ v, i })); assert.equal(items, [ { v: 1, i: 0 }, @@ -218,14 +432,22 @@ test(function iterableEquals() { assert.equal(Lazy.from([1, 2]).iterableEquals([1, 2]), true); assert.equal(Lazy.from([1, 2, 3]).iterableEquals([1, 2, 3]), true); assert.equal(Lazy.from([1, 2, 3, 4]).iterableEquals([1, 2, 3, 4]), true); - assert.equal(Lazy.from([1, 2, 3, 4, 5]).iterableEquals([1, 2, 3, 4, 5]), true); - assert.equal(Lazy.from([1, 2, 3, 4, 5]).iterableEquals([5, 4, 3, 2, 1]), false); + assert.equal( + Lazy.from([1, 2, 3, 4, 5]).iterableEquals([1, 2, 3, 4, 5]), + true, + ); + assert.equal( + Lazy.from([1, 2, 3, 4, 5]).iterableEquals([5, 4, 3, 2, 1]), + false, + ); assert.equal(Lazy.from([1, 2, 3, 4, 5]).iterableEquals([1, 2, 3, 4]), false); - assert.equal(Lazy.from([ - { value: 1 }, { value: 2 }, { value: 3 }, - ]).iterableEquals([ - { value: 1 }, { value: 2 }, { value: 3 }, - ], (a, b) => a.value === b.value), true); + assert.equal( + Lazy.from([{ value: 1 }, { value: 2 }, { value: 3 }]).iterableEquals( + [{ value: 1 }, { value: 2 }, { value: 3 }], + (a, b) => a.value === b.value, + ), + true, + ); }); test(function last() { @@ -245,19 +467,75 @@ test(function last() { assert.throws(() => Lazy.from([]).last(i => i % 2 === 0)); // Test iterated array access. - assert.equal(Lazy.from([1]).select(v => v * 2).last(), 2); - assert.equal(Lazy.from([1, 2]).select(v => v * 2).last(), 4); - assert.equal(Lazy.from([1, 2, 3]).select(v => v * 2).last(), 6); - assert.equal(Lazy.from([1, 2, 3, 4]).select(v => v * 2).last(), 8); - assert.equal(Lazy.from([1, 2, 3, 4, 5]).select(v => v * 2).last(), 10); - assert.throws(() => Lazy.from([]).select(v => v * 2).last()); - - assert.throws(() => Lazy.from([1]).select(v => v * 2).last(i => i % 3 === 0)); - assert.throws(() => Lazy.from([1, 2]).select(v => v * 2).last(i => i % 3 === 0)); - assert.equal(Lazy.from([1, 2, 3]).select(v => v * 2).last(i => i % 3 === 0), 6); - assert.equal(Lazy.from([1, 2, 3, 4]).select(v => v * 2).last(i => i % 3 === 0), 6); - assert.equal(Lazy.from([1, 2, 3, 4, 5]).select(v => v * 2).last(i => i % 3 === 0), 6); - assert.throws(() => Lazy.from([]).select(v => v * 2).last(i => i % 3 === 0)); + assert.equal( + Lazy.from([1]) + .select(v => v * 2) + .last(), + 2, + ); + assert.equal( + Lazy.from([1, 2]) + .select(v => v * 2) + .last(), + 4, + ); + assert.equal( + Lazy.from([1, 2, 3]) + .select(v => v * 2) + .last(), + 6, + ); + assert.equal( + Lazy.from([1, 2, 3, 4]) + .select(v => v * 2) + .last(), + 8, + ); + assert.equal( + Lazy.from([1, 2, 3, 4, 5]) + .select(v => v * 2) + .last(), + 10, + ); + assert.throws(() => + Lazy.from([]) + .select(v => v * 2) + .last(), + ); + + assert.throws(() => + Lazy.from([1]) + .select(v => v * 2) + .last(i => i % 3 === 0), + ); + assert.throws(() => + Lazy.from([1, 2]) + .select(v => v * 2) + .last(i => i % 3 === 0), + ); + assert.equal( + Lazy.from([1, 2, 3]) + .select(v => v * 2) + .last(i => i % 3 === 0), + 6, + ); + assert.equal( + Lazy.from([1, 2, 3, 4]) + .select(v => v * 2) + .last(i => i % 3 === 0), + 6, + ); + assert.equal( + Lazy.from([1, 2, 3, 4, 5]) + .select(v => v * 2) + .last(i => i % 3 === 0), + 6, + ); + assert.throws(() => + Lazy.from([]) + .select(v => v * 2) + .last(i => i % 3 === 0), + ); }); test(function lastOrDefault() { @@ -273,23 +551,86 @@ test(function lastOrDefault() { assert.equal(Lazy.from([1, 2]).lastOrDefault(9, i => i % 2 === 0), 2); assert.equal(Lazy.from([1, 2, 3]).lastOrDefault(9, i => i % 2 === 0), 2); assert.equal(Lazy.from([1, 2, 3, 4]).lastOrDefault(9, i => i % 2 === 0), 4); - assert.equal(Lazy.from([1, 2, 3, 4, 5]).lastOrDefault(9, i => i % 2 === 0), 4); + assert.equal( + Lazy.from([1, 2, 3, 4, 5]).lastOrDefault(9, i => i % 2 === 0), + 4, + ); assert.equal(Lazy.from([]).lastOrDefault(9, i => i % 2 === 0), 9); // Test iterated array access. - assert.equal(Lazy.from([1]).select(v => v * 2).lastOrDefault(9), 2); - assert.equal(Lazy.from([1, 2]).select(v => v * 2).lastOrDefault(9), 4); - assert.equal(Lazy.from([1, 2, 3]).select(v => v * 2).lastOrDefault(9), 6); - assert.equal(Lazy.from([1, 2, 3, 4]).select(v => v * 2).lastOrDefault(9), 8); - assert.equal(Lazy.from([1, 2, 3, 4, 5]).select(v => v * 2).lastOrDefault(9), 10); - assert.equal(Lazy.from([]).select(v => v * 2).lastOrDefault(9), 9); - - assert.equal(Lazy.from([1]).select(v => v * 2).lastOrDefault(9, i => i % 3 === 0), 9); - assert.equal(Lazy.from([1, 2]).select(v => v * 2).lastOrDefault(9, i => i % 3 === 0), 9); - assert.equal(Lazy.from([1, 2, 3]).select(v => v * 2).lastOrDefault(9, i => i % 3 === 0), 6); - assert.equal(Lazy.from([1, 2, 3, 4]).select(v => v * 2).lastOrDefault(9, i => i % 3 === 0), 6); - assert.equal(Lazy.from([1, 2, 3, 4, 5]).select(v => v * 2).lastOrDefault(9, i => i % 3 === 0), 6); - assert.equal(Lazy.from([]).select(v => v * 2).lastOrDefault(9, i => i % 3 === 0), 9); + assert.equal( + Lazy.from([1]) + .select(v => v * 2) + .lastOrDefault(9), + 2, + ); + assert.equal( + Lazy.from([1, 2]) + .select(v => v * 2) + .lastOrDefault(9), + 4, + ); + assert.equal( + Lazy.from([1, 2, 3]) + .select(v => v * 2) + .lastOrDefault(9), + 6, + ); + assert.equal( + Lazy.from([1, 2, 3, 4]) + .select(v => v * 2) + .lastOrDefault(9), + 8, + ); + assert.equal( + Lazy.from([1, 2, 3, 4, 5]) + .select(v => v * 2) + .lastOrDefault(9), + 10, + ); + assert.equal( + Lazy.from([]) + .select(v => v * 2) + .lastOrDefault(9), + 9, + ); + + assert.equal( + Lazy.from([1]) + .select(v => v * 2) + .lastOrDefault(9, i => i % 3 === 0), + 9, + ); + assert.equal( + Lazy.from([1, 2]) + .select(v => v * 2) + .lastOrDefault(9, i => i % 3 === 0), + 9, + ); + assert.equal( + Lazy.from([1, 2, 3]) + .select(v => v * 2) + .lastOrDefault(9, i => i % 3 === 0), + 6, + ); + assert.equal( + Lazy.from([1, 2, 3, 4]) + .select(v => v * 2) + .lastOrDefault(9, i => i % 3 === 0), + 6, + ); + assert.equal( + Lazy.from([1, 2, 3, 4, 5]) + .select(v => v * 2) + .lastOrDefault(9, i => i % 3 === 0), + 6, + ); + assert.equal( + Lazy.from([]) + .select(v => v * 2) + .lastOrDefault(9, i => i % 3 === 0), + 9, + ); }); test(function max() { @@ -362,9 +703,18 @@ test(function single() { { key: 2, value: 'b' }, { key: 3, value: 'c' }, ]; - assert.equal(Lazy.from(orig).single(v => v.key === 1), { key: 1, value: 'a' }); - assert.equal(Lazy.from(orig).single(v => v.key === 2), { key: 2, value: 'b' }); - assert.equal(Lazy.from(orig).single(v => v.key === 3), { key: 3, value: 'c' }); + assert.equal(Lazy.from(orig).single(v => v.key === 1), { + key: 1, + value: 'a', + }); + assert.equal(Lazy.from(orig).single(v => v.key === 2), { + key: 2, + value: 'b', + }); + assert.equal(Lazy.from(orig).single(v => v.key === 3), { + key: 3, + value: 'c', + }); assert.throws(() => Lazy.from(orig).single(v => v.key === 4)); }); @@ -409,7 +759,10 @@ test(function stringJoin() { assert.equal(Lazy.from([1]).stringJoin(',', i => `${i * 2}`), '2'); assert.equal(Lazy.from([1, 2]).stringJoin(',', i => `${i * 2}`), '2,4'); assert.equal(Lazy.from([1, 2, 3]).stringJoin(',', i => `${i * 2}`), '2,4,6'); - assert.equal(Lazy.from([1, 2, 3, 4]).stringJoin(',', i => `${i * 2}`), '2,4,6,8'); + assert.equal( + Lazy.from([1, 2, 3, 4]).stringJoin(',', i => `${i * 2}`), + '2,4,6,8', + ); }); test(function sum() { @@ -434,9 +787,15 @@ test(function toJSON() { const s = JSON.stringify; assert.equal(s(Lazy.from([1, 2, 3, 4, 5])), s([1, 2, 3, 4, 5])); - assert.equal(s(Lazy.from([1, 2, 3, 4, 5]).select(i => i * 2)), s([2, 4, 6, 8, 10])); + assert.equal( + s(Lazy.from([1, 2, 3, 4, 5]).select(i => i * 2)), + s([2, 4, 6, 8, 10]), + ); assert.equal(s(Lazy.from([1, 2, 3, 4, 5]).reverse()), s([5, 4, 3, 2, 1])); - assert.equal(s(Lazy.from([1, 2, 3, 4, 5]).where(i => i % 2 === 0)), s([2, 4])); + assert.equal( + s(Lazy.from([1, 2, 3, 4, 5]).where(i => i % 2 === 0)), + s([2, 4]), + ); }); test(function toMap() { @@ -448,14 +807,16 @@ test(function toMap() { { key: 5, value: 'e' }, ]; - const map1 = new Map(orig.map<[number, string]>(v => [v.key, v.value])); + const map1 = new Map( + orig.map<[number, string]>(v => [v.key, v.value]), + ); for (const [key, value] of Lazy.from(orig).toMap(v => v.key, v => v.value)) { assert(map1.has(key)); assert.equal(map1.get(key), value); } - const map2 = new Map( - orig.map<[number, { key: number, value: string }]>(v => [v.key, v]), + const map2 = new Map( + orig.map<[number, { key: number; value: string }]>(v => [v.key, v]), ); for (const [key, value] of Lazy.from(orig).toMap(v => v.key, v => v)) { assert(map2.has(key)); diff --git a/test/iterators.spec.ts b/test/iterators.spec.ts index fd52dca..4ea00c0 100644 --- a/test/iterators.spec.ts +++ b/test/iterators.spec.ts @@ -3,13 +3,28 @@ import { Lazy } from '../lib/mod.ts'; test(function append() { let orig = [1, 2, 3, 4]; - assert.equal(Lazy.from(orig).append(5).toArray(), [...orig, 5]); + assert.equal( + Lazy.from(orig) + .append(5) + .toArray(), + [...orig, 5], + ); orig = [4, 3, 2, 1]; - assert.equal(Lazy.from(orig).append(-1).toArray(), [...orig, -1]); + assert.equal( + Lazy.from(orig) + .append(-1) + .toArray(), + [...orig, -1], + ); orig = [9, 8, 7, 6, 5, 4, 3, 2, 1]; - assert.equal(Lazy.from(orig).append(0).toArray(), [...orig, 0]); + assert.equal( + Lazy.from(orig) + .append(0) + .toArray(), + [...orig, 0], + ); }); test(function apply() { @@ -29,9 +44,7 @@ test(function apply() { } class LazySquare extends Lazy { - public constructor( - private readonly _iterable: Iterable, - ) { + public constructor(private readonly _iterable: Iterable) { super(); } @@ -43,9 +56,7 @@ test(function apply() { } class LazyToString extends Lazy { - public constructor( - private readonly _iterable: Iterable, - ) { + public constructor(private readonly _iterable: Iterable) { super(); } @@ -55,18 +66,28 @@ test(function apply() { } } } - const iterableToString = (t: Iterable) => new LazyToString(t); + const iterableToString = (t: Iterable) => + new LazyToString(t); const orig = [1, 2, 3, 4]; assert.equal( - Lazy.from(orig).apply( - t => new LazyNumberToString(t, e => e.toString()), - ).toArray(), + Lazy.from(orig) + .apply( + t => new LazyNumberToString(t, e => e.toString()), + ) + .toArray(), ['1', '2', '3', '4'], ); - assert.equal(Lazy.from(orig).apply(t => new LazySquare(t)).toArray(), [1, 4, 9, 16]); assert.equal( - Lazy.from(orig).apply, string>(iterableToString).toArray(), + Lazy.from(orig) + .apply(t => new LazySquare(t)) + .toArray(), + [1, 4, 9, 16], + ); + assert.equal( + Lazy.from(orig) + .apply, string>(iterableToString) + .toArray(), ['1', '2', '3', '4'], ); }); @@ -74,29 +95,64 @@ test(function apply() { test(function concat() { let first = [1, 2, 3, 4]; let second = [5, 6, 7, 8]; - assert.equal(Lazy.from(first).concat(second).toArray(), [...first, ...second]); + assert.equal( + Lazy.from(first) + .concat(second) + .toArray(), + [...first, ...second], + ); first = [9, 8, 7, 6]; second = [1, 2, 3, 4]; - assert.equal(Lazy.from(first).concat(second).toArray(), [...first, ...second]); + assert.equal( + Lazy.from(first) + .concat(second) + .toArray(), + [...first, ...second], + ); - assert.equal(Lazy.from([1]).concat([2], [3]).toArray(), [1, 2, 3]); + assert.equal( + Lazy.from([1]) + .concat([2], [3]) + .toArray(), + [1, 2, 3], + ); }); test(function defaultIfEmpty() { let orig = [1, 2, 3]; - assert.equal(Lazy.from(orig).defaultIfEmpty(9).toArray(), orig); + assert.equal( + Lazy.from(orig) + .defaultIfEmpty(9) + .toArray(), + orig, + ); orig = []; - assert.equal(Lazy.from(orig).defaultIfEmpty(9).toArray(), [9]); + assert.equal( + Lazy.from(orig) + .defaultIfEmpty(9) + .toArray(), + [9], + ); }); test(function distinct() { let orig = [1, 2, 3, 1, 2, 3]; - assert.equal(Lazy.from(orig).distinct().toArray(), [1, 2, 3]); + assert.equal( + Lazy.from(orig) + .distinct() + .toArray(), + [1, 2, 3], + ); orig = [1, 2, 3, 1, 8, 9]; - assert.equal(Lazy.from(orig).distinct().toArray(), [1, 2, 3, 8, 9]); + assert.equal( + Lazy.from(orig) + .distinct() + .toArray(), + [1, 2, 3, 8, 9], + ); const objs = [ { value: 1 }, @@ -105,18 +161,34 @@ test(function distinct() { { value: 2 }, { value: 1 }, ]; - assert.equal(Lazy.from(objs).distinct(o => o.value).toArray(), [ - { value: 1 }, - { value: 2 }, - { value: 3 }, - ]); + assert.equal( + Lazy.from(objs) + .distinct(o => o.value) + .toArray(), + [{ value: 1 }, { value: 2 }, { value: 3 }], + ); }); test(function except() { const orig = [1, 2, 3, 4, 5]; - assert.equal(Lazy.from(orig).except([2, 4]).toArray(), [1, 3, 5]); - assert.equal(Lazy.from(orig).except([1]).toArray(), [2, 3, 4, 5]); - assert.equal(Lazy.from(orig).except([4, 5]).toArray(), [1, 2, 3]); + assert.equal( + Lazy.from(orig) + .except([2, 4]) + .toArray(), + [1, 3, 5], + ); + assert.equal( + Lazy.from(orig) + .except([1]) + .toArray(), + [2, 3, 4, 5], + ); + assert.equal( + Lazy.from(orig) + .except([4, 5]) + .toArray(), + [1, 2, 3], + ); }); test(function groupBy() { @@ -131,7 +203,9 @@ test(function groupBy() { ]; assert.equal( - Lazy.from(objs).groupBy(f => f.key).toArray(), + Lazy.from(objs) + .groupBy(f => f.key) + .toArray(), [ { key: 1, elements: [{ key: 1, value: 'a' }, { key: 1, value: 'f' }] }, { key: 2, elements: [{ key: 2, value: 'b' }, { key: 2, value: 'e' }] }, @@ -140,7 +214,9 @@ test(function groupBy() { ], ); assert.equal( - Lazy.from(objs).groupBy(f => f.key, f => f.value).toArray(), + Lazy.from(objs) + .groupBy(f => f.key, f => f.value) + .toArray(), [ { key: 1, elements: ['a', 'f'] }, { key: 2, elements: ['b', 'e'] }, @@ -149,11 +225,13 @@ test(function groupBy() { ], ); assert.equal( - Lazy.from(objs).groupBy( - f => f.key, - f => f.value, - (key, f) => ({ k: key, values: Array.from(f) }), - ).toArray(), + Lazy.from(objs) + .groupBy( + f => f.key, + f => f.value, + (key, f) => ({ k: key, values: Array.from(f) }), + ) + .toArray(), [ { k: 1, values: ['a', 'f'] }, { k: 2, values: ['b', 'e'] }, @@ -185,12 +263,18 @@ test(function groupJoin() { { key: 9, value: 'j' }, ]; assert.equal( - Lazy.from(first).groupJoin( - second, - f => f.key, - s => s.key, - (f, s) => ({ key: f.key, firstValue: f.value, secondValues: Array.from(s).map(v => v.value) }), - ).toArray(), + Lazy.from(first) + .groupJoin( + second, + f => f.key, + s => s.key, + (f, s) => ({ + key: f.key, + firstValue: f.value, + secondValues: Array.from(s).map(v => v.value), + }), + ) + .toArray(), [ { key: 1, firstValue: 5, secondValues: ['a', 'f'] }, { key: 2, firstValue: 4, secondValues: ['b', 'g'] }, @@ -203,10 +287,30 @@ test(function groupJoin() { test(function itersect() { const orig = [1, 2, 3, 4, 5]; - assert.equal(Lazy.from(orig).intersect([1, 2, 3]).toArray(), [1, 2, 3]); - assert.equal(Lazy.from(orig).intersect([2, 3, 4]).toArray(), [2, 3, 4]); - assert.equal(Lazy.from(orig).intersect([3, 4, 5]).toArray(), [3, 4, 5]); - assert.equal(Lazy.from(orig).intersect([1, 3, 5, 7, 9]).toArray(), [1, 3, 5]); + assert.equal( + Lazy.from(orig) + .intersect([1, 2, 3]) + .toArray(), + [1, 2, 3], + ); + assert.equal( + Lazy.from(orig) + .intersect([2, 3, 4]) + .toArray(), + [2, 3, 4], + ); + assert.equal( + Lazy.from(orig) + .intersect([3, 4, 5]) + .toArray(), + [3, 4, 5], + ); + assert.equal( + Lazy.from(orig) + .intersect([1, 3, 5, 7, 9]) + .toArray(), + [1, 3, 5], + ); }); test(function join() { @@ -226,12 +330,14 @@ test(function join() { ]; assert.equal( - Lazy.from(first).join( - second, - v => v.key, - v => v.k, - (f, s) => ({ ky: f.key, value1: f.value1, value2: s.value2 }), - ).toArray(), + Lazy.from(first) + .join( + second, + v => v.key, + v => v.k, + (f, s) => ({ ky: f.key, value1: f.value1, value2: s.value2 }), + ) + .toArray(), [ { ky: 1, value1: 'a1', value2: 'a2' }, { ky: 2, value1: 'b1', value2: 'b2' }, @@ -244,8 +350,18 @@ test(function join() { test(function orderBy() { const orig = [2, 1, 5, 3, 4]; - assert.equal(Lazy.from(orig).orderBy(v => v).toArray(), [1, 2, 3, 4, 5]); - assert.equal(Lazy.from(orig).orderBy(v => v, (a, b) => a - b).toArray(), [1, 2, 3, 4, 5]); + assert.equal( + Lazy.from(orig) + .orderBy(v => v) + .toArray(), + [1, 2, 3, 4, 5], + ); + assert.equal( + Lazy.from(orig) + .orderBy(v => v, (a, b) => a - b) + .toArray(), + [1, 2, 3, 4, 5], + ); const objs = [ { value: 2 }, @@ -254,23 +370,29 @@ test(function orderBy() { { value: 3 }, { value: 7 }, ]; - assert.equal(Lazy.from(objs).orderBy(v => v.value).toArray(), [ - { value: 1 }, - { value: 2 }, - { value: 3 }, - { value: 5 }, - { value: 7 }, - ]); + assert.equal( + Lazy.from(objs) + .orderBy(v => v.value) + .toArray(), + [{ value: 1 }, { value: 2 }, { value: 3 }, { value: 5 }, { value: 7 }], + ); assert.equal( - Lazy.from([undefined, 1, 2, undefined, 3, 4, undefined, 5]).orderBy(v => v).toArray(), + Lazy.from([undefined, 1, 2, undefined, 3, 4, undefined, 5]) + .orderBy(v => v) + .toArray(), [1, 2, 3, 4, 5, undefined, undefined, undefined], ); }); test(function orderByDecending() { const orig = [2, 1, 5, 3, 4]; - assert.equal(Lazy.from(orig).orderByDecending(v => v).toArray(), [5, 4, 3, 2, 1]); + assert.equal( + Lazy.from(orig) + .orderByDecending(v => v) + .toArray(), + [5, 4, 3, 2, 1], + ); const objs = [ { value: 2 }, @@ -279,35 +401,62 @@ test(function orderByDecending() { { value: 3 }, { value: 7 }, ]; - assert.equal(Lazy.from(objs).orderByDecending(v => v.value).toArray(), [ - { value: 7 }, - { value: 5 }, - { value: 3 }, - { value: 2 }, - { value: 1 }, - ]); + assert.equal( + Lazy.from(objs) + .orderByDecending(v => v.value) + .toArray(), + [{ value: 7 }, { value: 5 }, { value: 3 }, { value: 2 }, { value: 1 }], + ); assert.equal( - Lazy.from([undefined, 1, 2, undefined, 3, 4, undefined, 5]).orderByDecending(v => v).toArray(), + Lazy.from([undefined, 1, 2, undefined, 3, 4, undefined, 5]) + .orderByDecending(v => v) + .toArray(), [5, 4, 3, 2, 1, undefined, undefined, undefined], ); }); test(function prepend() { let orig = [1, 2, 3, 4]; - assert.equal(Lazy.from(orig).prepend(5).toArray(), [5, ...orig]); + assert.equal( + Lazy.from(orig) + .prepend(5) + .toArray(), + [5, ...orig], + ); orig = [4, 3, 2, 1]; - assert.equal(Lazy.from(orig).prepend(-1).toArray(), [-1, ...orig]); + assert.equal( + Lazy.from(orig) + .prepend(-1) + .toArray(), + [-1, ...orig], + ); orig = [9, 8, 7, 6, 5, 4, 3, 2, 1]; - assert.equal(Lazy.from(orig).prepend(0).toArray(), [0, ...orig]); + assert.equal( + Lazy.from(orig) + .prepend(0) + .toArray(), + [0, ...orig], + ); }); test(function reverse() { const orig = [1, 2, 3, 4, 5]; - assert.equal(Lazy.from(orig).reverse().toArray(), [5, 4, 3, 2, 1]); - assert.equal(Lazy.from(orig).reverse().reverse().toArray(), orig); + assert.equal( + Lazy.from(orig) + .reverse() + .toArray(), + [5, 4, 3, 2, 1], + ); + assert.equal( + Lazy.from(orig) + .reverse() + .reverse() + .toArray(), + orig, + ); }); test(function select() { @@ -318,22 +467,26 @@ test(function select() { { value: 4 }, { value: 5 }, ]; - assert.equal(Lazy.from(orig).select(v => v.value).toArray(), [1, 2, 3, 4, 5]); + assert.equal( + Lazy.from(orig) + .select(v => v.value) + .toArray(), + [1, 2, 3, 4, 5], + ); - orig = [ - { value: 5 }, - { value: 4 }, - { value: 3 }, - { value: 2 }, - { value: 1 }, - ]; - assert.equal(Lazy.from(orig).select((v, i) => ({ v: v.value, i })).toArray(), [ - { v: 5, i: 0 }, - { v: 4, i: 1 }, - { v: 3, i: 2 }, - { v: 2, i: 3 }, - { v: 1, i: 4 }, - ]); + orig = [{ value: 5 }, { value: 4 }, { value: 3 }, { value: 2 }, { value: 1 }]; + assert.equal( + Lazy.from(orig) + .select((v, i) => ({ v: v.value, i })) + .toArray(), + [ + { v: 5, i: 0 }, + { v: 4, i: 1 }, + { v: 3, i: 2 }, + { v: 2, i: 3 }, + { v: 1, i: 4 }, + ], + ); }); test(function selectMany() { @@ -344,7 +497,12 @@ test(function selectMany() { { value: [4] }, { value: [5] }, ]; - assert.equal(Lazy.from(orig).selectMany(v => v.value).toArray(), [1, 2, 3, 4, 5]); + assert.equal( + Lazy.from(orig) + .selectMany(v => v.value) + .toArray(), + [1, 2, 3, 4, 5], + ); orig = [ { value: [5, 6] }, @@ -353,136 +511,415 @@ test(function selectMany() { { value: [2] }, { value: [1] }, ]; - assert.equal(Lazy.from(orig).selectMany( - (v, i) => Lazy.from(v.value).select(v2 => ({ v: v2, i })), - ).toArray(), [ + assert.equal( + Lazy.from(orig) + .selectMany((v, i) => Lazy.from(v.value).select(v2 => ({ v: v2, i }))) + .toArray(), + [ { v: 5, i: 0 }, { v: 6, i: 0 }, { v: 4, i: 1 }, { v: 3, i: 2 }, { v: 2, i: 3 }, { v: 1, i: 4 }, - ]); + ], + ); - const arrarr = [ - [1, 2, 3], - [4, 5, 6], - [7, 8, 9], - ]; - assert.equal(Lazy.from(arrarr).selectMany(v => v).toArray(), [1, 2, 3, 4, 5, 6, 7, 8, 9]); + const arrarr = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; + assert.equal( + Lazy.from(arrarr) + .selectMany(v => v) + .toArray(), + [1, 2, 3, 4, 5, 6, 7, 8, 9], + ); }); test(function skip() { const orig = [1, 2, 3, 4, 5, 6, 7, 8, 9]; - assert.equal(Lazy.from(orig).skip(0).toArray(), [1, 2, 3, 4, 5, 6, 7, 8, 9]); - assert.equal(Lazy.from(orig).skip(1).toArray(), [2, 3, 4, 5, 6, 7, 8, 9]); - assert.equal(Lazy.from(orig).skip(2).toArray(), [3, 4, 5, 6, 7, 8, 9]); - assert.equal(Lazy.from(orig).skip(3).toArray(), [4, 5, 6, 7, 8, 9]); - assert.equal(Lazy.from(orig).skip(4).toArray(), [5, 6, 7, 8, 9]); - assert.equal(Lazy.from(orig).skip(5).toArray(), [6, 7, 8, 9]); + assert.equal( + Lazy.from(orig) + .skip(0) + .toArray(), + [1, 2, 3, 4, 5, 6, 7, 8, 9], + ); + assert.equal( + Lazy.from(orig) + .skip(1) + .toArray(), + [2, 3, 4, 5, 6, 7, 8, 9], + ); + assert.equal( + Lazy.from(orig) + .skip(2) + .toArray(), + [3, 4, 5, 6, 7, 8, 9], + ); + assert.equal( + Lazy.from(orig) + .skip(3) + .toArray(), + [4, 5, 6, 7, 8, 9], + ); + assert.equal( + Lazy.from(orig) + .skip(4) + .toArray(), + [5, 6, 7, 8, 9], + ); + assert.equal( + Lazy.from(orig) + .skip(5) + .toArray(), + [6, 7, 8, 9], + ); }); test(function skipLast() { const orig = [1, 2, 3, 4, 5, 6, 7, 8, 9]; - assert.equal(Lazy.from(orig).skipLast(0).toArray(), [1, 2, 3, 4, 5, 6, 7, 8, 9]); - assert.equal(Lazy.from(orig).skipLast(1).toArray(), [1, 2, 3, 4, 5, 6, 7, 8]); - assert.equal(Lazy.from(orig).skipLast(2).toArray(), [1, 2, 3, 4, 5, 6, 7]); - assert.equal(Lazy.from(orig).skipLast(3).toArray(), [1, 2, 3, 4, 5, 6]); - assert.equal(Lazy.from(orig).skipLast(4).toArray(), [1, 2, 3, 4, 5]); - assert.equal(Lazy.from(orig).skipLast(5).toArray(), [1, 2, 3, 4]); + assert.equal( + Lazy.from(orig) + .skipLast(0) + .toArray(), + [1, 2, 3, 4, 5, 6, 7, 8, 9], + ); + assert.equal( + Lazy.from(orig) + .skipLast(1) + .toArray(), + [1, 2, 3, 4, 5, 6, 7, 8], + ); + assert.equal( + Lazy.from(orig) + .skipLast(2) + .toArray(), + [1, 2, 3, 4, 5, 6, 7], + ); + assert.equal( + Lazy.from(orig) + .skipLast(3) + .toArray(), + [1, 2, 3, 4, 5, 6], + ); + assert.equal( + Lazy.from(orig) + .skipLast(4) + .toArray(), + [1, 2, 3, 4, 5], + ); + assert.equal( + Lazy.from(orig) + .skipLast(5) + .toArray(), + [1, 2, 3, 4], + ); }); test(function skipWhile() { const orig = [1, 2, 3, 4, 5, 6, 7, 8, 9]; - assert.equal(Lazy.from(orig).skipWhile(v => v !== 1).toArray(), [1, 2, 3, 4, 5, 6, 7, 8, 9]); - assert.equal(Lazy.from(orig).skipWhile(v => v !== 2).toArray(), [2, 3, 4, 5, 6, 7, 8, 9]); - assert.equal(Lazy.from(orig).skipWhile(v => v !== 3).toArray(), [3, 4, 5, 6, 7, 8, 9]); - assert.equal(Lazy.from(orig).skipWhile(v => v !== 4).toArray(), [4, 5, 6, 7, 8, 9]); - assert.equal(Lazy.from(orig).skipWhile(v => v !== 5).toArray(), [5, 6, 7, 8, 9]); - assert.equal(Lazy.from(orig).skipWhile(v => v !== 6).toArray(), [6, 7, 8, 9]); + assert.equal( + Lazy.from(orig) + .skipWhile(v => v !== 1) + .toArray(), + [1, 2, 3, 4, 5, 6, 7, 8, 9], + ); + assert.equal( + Lazy.from(orig) + .skipWhile(v => v !== 2) + .toArray(), + [2, 3, 4, 5, 6, 7, 8, 9], + ); + assert.equal( + Lazy.from(orig) + .skipWhile(v => v !== 3) + .toArray(), + [3, 4, 5, 6, 7, 8, 9], + ); + assert.equal( + Lazy.from(orig) + .skipWhile(v => v !== 4) + .toArray(), + [4, 5, 6, 7, 8, 9], + ); + assert.equal( + Lazy.from(orig) + .skipWhile(v => v !== 5) + .toArray(), + [5, 6, 7, 8, 9], + ); + assert.equal( + Lazy.from(orig) + .skipWhile(v => v !== 6) + .toArray(), + [6, 7, 8, 9], + ); }); test(function take() { const orig = [1, 2, 3, 4, 5, 6, 7, 8, 9]; - assert.equal(Lazy.from(orig).take(-1).toArray(), []); - assert.equal(Lazy.from(orig).take(0).toArray(), []); - assert.equal(Lazy.from(orig).take(1).toArray(), [1]); - assert.equal(Lazy.from(orig).take(2).toArray(), [1, 2]); - assert.equal(Lazy.from(orig).take(3).toArray(), [1, 2, 3]); - assert.equal(Lazy.from(orig).take(4).toArray(), [1, 2, 3, 4]); - assert.equal(Lazy.from(orig).take(5).toArray(), [1, 2, 3, 4, 5]); + assert.equal( + Lazy.from(orig) + .take(-1) + .toArray(), + [], + ); + assert.equal( + Lazy.from(orig) + .take(0) + .toArray(), + [], + ); + assert.equal( + Lazy.from(orig) + .take(1) + .toArray(), + [1], + ); + assert.equal( + Lazy.from(orig) + .take(2) + .toArray(), + [1, 2], + ); + assert.equal( + Lazy.from(orig) + .take(3) + .toArray(), + [1, 2, 3], + ); + assert.equal( + Lazy.from(orig) + .take(4) + .toArray(), + [1, 2, 3, 4], + ); + assert.equal( + Lazy.from(orig) + .take(5) + .toArray(), + [1, 2, 3, 4, 5], + ); }); test(function takeLast() { const orig = [1, 2, 3, 4, 5, 6, 7, 8, 9]; - assert.equal(Lazy.from(orig).takeLast(0).toArray(), []); - assert.equal(Lazy.from(orig).takeLast(1).toArray(), [9]); - assert.equal(Lazy.from(orig).takeLast(2).toArray(), [8, 9]); - assert.equal(Lazy.from(orig).takeLast(3).toArray(), [7, 8, 9]); - assert.equal(Lazy.from(orig).takeLast(4).toArray(), [6, 7, 8, 9]); - assert.equal(Lazy.from(orig).takeLast(5).toArray(), [5, 6, 7, 8, 9]); + assert.equal( + Lazy.from(orig) + .takeLast(0) + .toArray(), + [], + ); + assert.equal( + Lazy.from(orig) + .takeLast(1) + .toArray(), + [9], + ); + assert.equal( + Lazy.from(orig) + .takeLast(2) + .toArray(), + [8, 9], + ); + assert.equal( + Lazy.from(orig) + .takeLast(3) + .toArray(), + [7, 8, 9], + ); + assert.equal( + Lazy.from(orig) + .takeLast(4) + .toArray(), + [6, 7, 8, 9], + ); + assert.equal( + Lazy.from(orig) + .takeLast(5) + .toArray(), + [5, 6, 7, 8, 9], + ); }); test(function takeWhile() { const orig = [1, 2, 3, 4, 5, 6, 7, 8, 9]; - assert.equal(Lazy.from(orig).takeWhile(v => v !== 4).toArray(), [1, 2, 3]); - assert.equal(Lazy.from(orig).takeWhile(v => v !== 5).toArray(), [1, 2, 3, 4]); - assert.equal(Lazy.from(orig).takeWhile(v => v !== 6).toArray(), [1, 2, 3, 4, 5]); - assert.equal(Lazy.from(orig).takeWhile(v => v !== 7).toArray(), [1, 2, 3, 4, 5, 6]); - assert.equal(Lazy.from(orig).takeWhile(v => v !== 8).toArray(), [1, 2, 3, 4, 5, 6, 7]); - assert.equal(Lazy.from(orig).takeWhile(v => v !== 9).toArray(), [1, 2, 3, 4, 5, 6, 7, 8]); + assert.equal( + Lazy.from(orig) + .takeWhile(v => v !== 4) + .toArray(), + [1, 2, 3], + ); + assert.equal( + Lazy.from(orig) + .takeWhile(v => v !== 5) + .toArray(), + [1, 2, 3, 4], + ); + assert.equal( + Lazy.from(orig) + .takeWhile(v => v !== 6) + .toArray(), + [1, 2, 3, 4, 5], + ); + assert.equal( + Lazy.from(orig) + .takeWhile(v => v !== 7) + .toArray(), + [1, 2, 3, 4, 5, 6], + ); + assert.equal( + Lazy.from(orig) + .takeWhile(v => v !== 8) + .toArray(), + [1, 2, 3, 4, 5, 6, 7], + ); + assert.equal( + Lazy.from(orig) + .takeWhile(v => v !== 9) + .toArray(), + [1, 2, 3, 4, 5, 6, 7, 8], + ); }); test(function union() { - assert.equal(Lazy.from([1, 2, 3]).union([3, 4, 5]).toArray(), [1, 2, 3, 4, 5]); - assert.equal(Lazy.from([1, 2, 3]).union([2, 3, 4, 5]).toArray(), [1, 2, 3, 4, 5]); - assert.equal(Lazy.from([1, 2, 3]).union([3, 3, 4, 5]).toArray(), [1, 2, 3, 4, 5]); - assert.equal(Lazy.from([1, 2, 3, 2]).union([3, 4, 5]).toArray(), [1, 2, 3, 4, 5]); + assert.equal( + Lazy.from([1, 2, 3]) + .union([3, 4, 5]) + .toArray(), + [1, 2, 3, 4, 5], + ); + assert.equal( + Lazy.from([1, 2, 3]) + .union([2, 3, 4, 5]) + .toArray(), + [1, 2, 3, 4, 5], + ); + assert.equal( + Lazy.from([1, 2, 3]) + .union([3, 3, 4, 5]) + .toArray(), + [1, 2, 3, 4, 5], + ); + assert.equal( + Lazy.from([1, 2, 3, 2]) + .union([3, 4, 5]) + .toArray(), + [1, 2, 3, 4, 5], + ); }); test(function where() { - assert.equal(Lazy.from([1, 2, 3, 4, 5]).where(v => v === 1).toArray(), [1]); - assert.equal(Lazy.from([1, 2, 3, 4, 5]).where(v => v === 2).toArray(), [2]); - assert.equal(Lazy.from([1, 2, 3, 4, 5]).where(v => v === 3).toArray(), [3]); - assert.equal(Lazy.from([1, 2, 3, 4, 5]).where(v => v % 2 === 0).toArray(), [2, 4]); - assert.equal(Lazy.from([ - { key: 1, value: 'a' }, - { key: 2, value: 'b' }, - { key: 3, value: 'c' }, - { key: 4, value: 'd' }, - { key: 5, value: 'e' }, - ]).where(v => v.value === 'a' || v.value === 'e').toArray(), [ + assert.equal( + Lazy.from([1, 2, 3, 4, 5]) + .where(v => v === 1) + .toArray(), + [1], + ); + assert.equal( + Lazy.from([1, 2, 3, 4, 5]) + .where(v => v === 2) + .toArray(), + [2], + ); + assert.equal( + Lazy.from([1, 2, 3, 4, 5]) + .where(v => v === 3) + .toArray(), + [3], + ); + assert.equal( + Lazy.from([1, 2, 3, 4, 5]) + .where(v => v % 2 === 0) + .toArray(), + [2, 4], + ); + assert.equal( + Lazy.from([ { key: 1, value: 'a' }, + { key: 2, value: 'b' }, + { key: 3, value: 'c' }, + { key: 4, value: 'd' }, { key: 5, value: 'e' }, - ]); + ]) + .where(v => v.value === 'a' || v.value === 'e') + .toArray(), + [{ key: 1, value: 'a' }, { key: 5, value: 'e' }], + ); - assert.equal(Lazy.from([1, 2, 3, 4, 5]).where((_, i) => i === 0).toArray(), [1]); - assert.equal(Lazy.from([1, 2, 3, 4, 5]).where((_, i) => i === 2).toArray(), [3]); - assert.equal(Lazy.from([1, 2, 3, 4, 5]).where((_, i) => i === 4).toArray(), [5]); - assert.equal(Lazy.from([1, 2, 3, 4, 5]).where((v, i) => v < i).toArray(), []); - assert.equal(Lazy.from([1, 2, 3, 4, 5]).where((v, i) => v > i).toArray(), [1, 2, 3, 4, 5]); + assert.equal( + Lazy.from([1, 2, 3, 4, 5]) + .where((_, i) => i === 0) + .toArray(), + [1], + ); + assert.equal( + Lazy.from([1, 2, 3, 4, 5]) + .where((_, i) => i === 2) + .toArray(), + [3], + ); + assert.equal( + Lazy.from([1, 2, 3, 4, 5]) + .where((_, i) => i === 4) + .toArray(), + [5], + ); + assert.equal( + Lazy.from([1, 2, 3, 4, 5]) + .where((v, i) => v < i) + .toArray(), + [], + ); + assert.equal( + Lazy.from([1, 2, 3, 4, 5]) + .where((v, i) => v > i) + .toArray(), + [1, 2, 3, 4, 5], + ); assert.equal( - Lazy.from([1, 2, 3, 4, 5]).where((v): v is 1 | 3 | 5 => v % 2 === 1).toArray(), + Lazy.from([1, 2, 3, 4, 5]) + .where((v): v is 1 | 3 | 5 => v % 2 === 1) + .toArray(), [1, 3, 5], ); assert.equal( - Lazy.from([1, 2, 3, 4, 5]).where((v): v is 2 | 4 => v % 2 === 0).toArray(), + Lazy.from([1, 2, 3, 4, 5]) + .where((v): v is 2 | 4 => v % 2 === 0) + .toArray(), [2, 4], ); }); test(function zip() { - assert.equal(Lazy.from([1, 2, 3, 4]).zip([4, 3, 2, 1]).toArray(), [[1, 4], [2, 3], [3, 2], [4, 1]]); - assert.equal(Lazy.from([1, 2, 3, 4]).zip([4, 3, 2, 1, 0]).toArray(), [[1, 4], [2, 3], [3, 2], [4, 1]]); - assert.equal(Lazy.from([1, 2, 3, 4, 5]).zip([4, 3, 2, 1]).toArray(), [[1, 4], [2, 3], [3, 2], [4, 1]]); assert.equal( - Lazy.from([1, 2, 3, 4]).zip(['4', '3', '2', '1']).toArray(), + Lazy.from([1, 2, 3, 4]) + .zip([4, 3, 2, 1]) + .toArray(), + [[1, 4], [2, 3], [3, 2], [4, 1]], + ); + assert.equal( + Lazy.from([1, 2, 3, 4]) + .zip([4, 3, 2, 1, 0]) + .toArray(), + [[1, 4], [2, 3], [3, 2], [4, 1]], + ); + assert.equal( + Lazy.from([1, 2, 3, 4, 5]) + .zip([4, 3, 2, 1]) + .toArray(), + [[1, 4], [2, 3], [3, 2], [4, 1]], + ); + assert.equal( + Lazy.from([1, 2, 3, 4]) + .zip(['4', '3', '2', '1']) + .toArray(), [[1, '4'], [2, '3'], [3, '2'], [4, '1']], ); assert.equal( - Lazy.from([1, 2, 3, 4]).zip([4, 3, 2, 1], (first, second) => ({ first, second })).toArray(), + Lazy.from([1, 2, 3, 4]) + .zip([4, 3, 2, 1], (first, second) => ({ first, second })) + .toArray(), [ { first: 1, second: 4 }, { first: 2, second: 3 }, @@ -491,7 +928,9 @@ test(function zip() { ], ); assert.equal( - Lazy.from([1, 2, 3, 4]).zip([4, 3, 2, 1, 0], (first, second) => ({ first, second })).toArray(), + Lazy.from([1, 2, 3, 4]) + .zip([4, 3, 2, 1, 0], (first, second) => ({ first, second })) + .toArray(), [ { first: 1, second: 4 }, { first: 2, second: 3 }, @@ -500,7 +939,9 @@ test(function zip() { ], ); assert.equal( - Lazy.from([1, 2, 3, 4, 5]).zip([4, 3, 2, 1], (first, second) => ({ first, second })).toArray(), + Lazy.from([1, 2, 3, 4, 5]) + .zip([4, 3, 2, 1], (first, second) => ({ first, second })) + .toArray(), [ { first: 1, second: 4 }, { first: 2, second: 3 }, diff --git a/test/mod.spec.ts b/test/mod.spec.ts index d436dde..fb3d6c3 100644 --- a/test/mod.spec.ts +++ b/test/mod.spec.ts @@ -17,12 +17,42 @@ test(function range() { assert.equal(Lazy.range(1, 0).toArray(), [1]); assert.equal(Lazy.range(5, 0).toArray(), [5, 4, 3, 2, 1]); - assert.equal(Lazy.range(-1).take(5).toArray(), [-1, 0, 1, 2, 3]); - assert.equal(Lazy.range(0).take(5).toArray(), [0, 1, 2, 3, 4]); - assert.equal(Lazy.range(1).take(5).toArray(), [1, 2, 3, 4, 5]); - assert.equal(Lazy.range(2).take(5).toArray(), [2, 3, 4, 5, 6]); - assert.equal(Lazy.range(3).take(5).toArray(), [3, 4, 5, 6, 7]); - assert.equal(Lazy.range(4).take(5).toArray(), [4, 5, 6, 7, 8]); + assert.equal( + Lazy.range(-1) + .take(5) + .toArray(), + [-1, 0, 1, 2, 3], + ); + assert.equal( + Lazy.range(0) + .take(5) + .toArray(), + [0, 1, 2, 3, 4], + ); + assert.equal( + Lazy.range(1) + .take(5) + .toArray(), + [1, 2, 3, 4, 5], + ); + assert.equal( + Lazy.range(2) + .take(5) + .toArray(), + [2, 3, 4, 5, 6], + ); + assert.equal( + Lazy.range(3) + .take(5) + .toArray(), + [3, 4, 5, 6, 7], + ); + assert.equal( + Lazy.range(4) + .take(5) + .toArray(), + [4, 5, 6, 7, 8], + ); }); test(function repeat() { @@ -33,11 +63,36 @@ test(function repeat() { assert.equal(Lazy.repeat('a', 5).toArray(), ['a', 'a', 'a', 'a', 'a']); assert.throws(() => Lazy.repeat('a', -1)); - assert.equal(Lazy.repeat('a').take(1).toArray(), ['a']); - assert.equal(Lazy.repeat('a').take(2).toArray(), ['a', 'a']); - assert.equal(Lazy.repeat('a').take(3).toArray(), ['a', 'a', 'a']); - assert.equal(Lazy.repeat('a').take(4).toArray(), ['a', 'a', 'a', 'a']); - assert.equal(Lazy.repeat('a').take(5).toArray(), ['a', 'a', 'a', 'a', 'a']); + assert.equal( + Lazy.repeat('a') + .take(1) + .toArray(), + ['a'], + ); + assert.equal( + Lazy.repeat('a') + .take(2) + .toArray(), + ['a', 'a'], + ); + assert.equal( + Lazy.repeat('a') + .take(3) + .toArray(), + ['a', 'a', 'a'], + ); + assert.equal( + Lazy.repeat('a') + .take(4) + .toArray(), + ['a', 'a', 'a', 'a'], + ); + assert.equal( + Lazy.repeat('a') + .take(5) + .toArray(), + ['a', 'a', 'a', 'a', 'a'], + ); }); test(async function _forAwait() { diff --git a/yarn.lock b/yarn.lock index 7391d18..a5d0a18 100644 --- a/yarn.lock +++ b/yarn.lock @@ -365,6 +365,11 @@ path-parse@^1.0.6: resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== +prettier@^1.16.4: + version "1.16.4" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.16.4.tgz#73e37e73e018ad2db9c76742e2647e21790c9717" + integrity sha512-ZzWuos7TI5CKUeQAtFd6Zhm2s6EpAD/ZLApIhsF9pRvRtM1RFo61dM/4MSRUA0SuLugA/zgrZD8m0BaY46Og7g== + progress@^2.0.0: version "2.0.3" resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8"