-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
88 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# deverything | ||
|
||
## 0.39.0 | ||
|
||
### Minor Changes | ||
|
||
- seriesAll and handle suffix | ||
|
||
## 0.38.0 | ||
|
||
### Minor Changes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { describe, expect, test } from "@jest/globals"; | ||
import { seriesAll } from "./seriesAll"; | ||
import { sleep } from "./sleep"; | ||
|
||
describe("seriesAll", () => { | ||
const fn1 = () => Promise.resolve(1); | ||
const fn2 = () => sleep(100).then(() => 2); | ||
const fn3 = () => 3; | ||
|
||
test("simple", async () => { | ||
expect(seriesAll<number>([fn1, fn2, fn3])).resolves.toEqual([1, 2, 3]); | ||
expect(await seriesAll([() => true])).toStrictEqual([true]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* | ||
* @description Run a series of (async) functions in order and return the results | ||
* @example | ||
* const results = await seriesAll([ | ||
* () => Promise.resolve(1), | ||
* () => sleep(100).then(() => 2), | ||
* () => Promise.resolve(3), | ||
* ]); | ||
* @returns [1, 2, 3] | ||
*/ | ||
export const seriesAll = async <T>(series: Function[]): Promise<T[]> => { | ||
const results = []; | ||
for (const fn of series) { | ||
results.push(await fn()); | ||
} | ||
return results; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
import { WESTERN_FIRST_NAMES, WESTERN_LAST_NAMES } from "../constants/names"; | ||
import { incrementalId } from "../helpers/incrementalId"; | ||
import { randomArrayItem } from "./randomArrayItem"; | ||
import { randomNumericId } from "./randomNumericId"; | ||
|
||
export const randomHandle = () => | ||
/** | ||
* | ||
* @returns a unique social-like handle | ||
* @example "john.doe15" | ||
*/ | ||
export const randomHandle = ({ suffix }: { suffix?: string } = {}) => | ||
( | ||
randomArrayItem(WESTERN_FIRST_NAMES) + | ||
"." + | ||
randomArrayItem(WESTERN_LAST_NAMES) | ||
).toLowerCase() + randomNumericId(); // use randomNumericId too keep handles process-unique | ||
).toLowerCase() + | ||
incrementalId() + // process-unique | ||
suffix | ||
? suffix | ||
: ""; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ( | ||
k: infer I | ||
) => void | ||
? I | ||
: never; | ||
|
||
type LastOf<T> = UnionToIntersection< | ||
T extends any ? () => T : never | ||
> extends () => infer R | ||
? R | ||
: never; | ||
|
||
type Push<T extends any[], V> = [...T, V]; | ||
|
||
type TuplifyUnion< | ||
T, | ||
L = LastOf<T>, | ||
N = [T] extends [never] ? true : false | ||
> = true extends N ? [] : Push<TuplifyUnion<Exclude<T, L>>, L>; | ||
|
||
// The magic happens here! | ||
export type Tuple< | ||
T, | ||
A extends T[] = [] | ||
> = TuplifyUnion<T>["length"] extends A["length"] | ||
? [...A] | ||
: Tuple<T, [T, ...A]>; |