diff --git a/README.md b/README.md index 20fc58ec..bc92ad7f 100644 --- a/README.md +++ b/README.md @@ -371,7 +371,7 @@ Returns the second element or undefined when there are less than two elements in ```typescript -([, x]: [any, any]) => any +([, x]: any[]) => any ``` @@ -573,21 +573,21 @@ Runs the given tasks in a sequence. ```typescript ( - now: any + now: string | number | Date ) => ( { endedAt: aEnd, startedAt: aStart }: { - endedAt: any; - startedAt: any; + endedAt: string | number | Date; + startedAt: string | number | Date; }, { endedAt: bEnd, startedAt: bStart }: { - endedAt: any; - startedAt: any; + endedAt: string | number | Date; + startedAt: string | number | Date; } ) => number ``` @@ -599,7 +599,10 @@ Runs the given tasks in a sequence. ```typescript -(min: any, max: any) => (dateStringOrDate: any) => Date +( + min: number | Date, + max: number | Date +) => (dateStringOrDate: string | number | Date) => Date ``` @@ -609,7 +612,10 @@ Runs the given tasks in a sequence. ```typescript -(a: any, b: any) => number +( + a: string | number | Date, + b: string | number | Date +) => number ``` @@ -619,7 +625,10 @@ Runs the given tasks in a sequence. ```typescript -(from: any, to: any) => (date?: Date) => boolean +( + from: string | number | Date, + to: string | number | Date +) => (date?: Date) => boolean ``` @@ -639,7 +648,7 @@ Runs the given tasks in a sequence. local?: boolean; now?: Date; timezoneOffset?: number; -}) => (date: any) => any[] +}) => (date?: string | number | Date) => string[] ``` @@ -649,7 +658,22 @@ Runs the given tasks in a sequence. ```typescript -(leapYear: any) => number[] +( + leapYear: boolean +) => [ + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number +] ``` @@ -659,7 +683,7 @@ Runs the given tasks in a sequence. ```typescript -(year: any) => number +(year: number) => number ``` @@ -669,7 +693,7 @@ Runs the given tasks in a sequence. ```typescript -(monthIndex: any) => string +(monthIndex: number) => string ``` @@ -679,7 +703,10 @@ Runs the given tasks in a sequence. ```typescript -(source: any, showSeconds: any) => string +( + source: [number, number, number], + showSeconds: boolean +) => string ``` @@ -690,7 +717,7 @@ Runs the given tasks in a sequence. ```typescript ( - date: any, + date: string | number | Date, timezoneOffset?: number, local?: boolean ) => Date @@ -703,7 +730,7 @@ Runs the given tasks in a sequence. ```typescript -(sourceDate: any, timezoneOffset?: number) => string +(sourceDate: Date, timezoneOffset?: number) => string ``` @@ -714,7 +741,7 @@ Runs the given tasks in a sequence. ```typescript ( - sourceDate: any, + sourceDate: Date, showSeconds?: boolean, timezoneOffset?: number ) => string @@ -728,7 +755,7 @@ Runs the given tasks in a sequence. ```typescript ( - sourceDate: any, + sourceDate: Date, showDay?: boolean, timezoneOffset?: number ) => string @@ -741,7 +768,7 @@ Runs the given tasks in a sequence. ```typescript -(duration: any, showSeconds?: boolean) => string +(duration: number, showSeconds?: boolean) => string ``` @@ -752,7 +779,7 @@ Runs the given tasks in a sequence. ```typescript ( - sourceDate: any, + sourceDate: Date, showSeconds?: boolean, timezoneOffset?: number ) => string @@ -765,7 +792,7 @@ Runs the given tasks in a sequence. ```typescript -(days: any) => number +(days: number) => number ``` @@ -775,7 +802,7 @@ Runs the given tasks in a sequence. ```typescript -(hours: any) => number +(hours: number) => number ``` @@ -785,7 +812,7 @@ Runs the given tasks in a sequence. ```typescript -(minutes: any) => number +(minutes: number) => number ``` @@ -795,7 +822,7 @@ Runs the given tasks in a sequence. ```typescript -(seconds: any) => number +(seconds: number) => number ``` @@ -805,7 +832,7 @@ Runs the given tasks in a sequence. ```typescript -(...xs: any[]) => string +(...xs: string[]) => string ``` @@ -815,7 +842,7 @@ Runs the given tasks in a sequence. ```typescript -(year: any) => boolean +(year: number) => boolean ``` @@ -835,7 +862,7 @@ string[] ```typescript -(date: any) => Date +(date: number | Date) => Date ``` @@ -855,7 +882,7 @@ string[] ```typescript -(dateTimeString: any) => any +(dateTimeString: string) => string[] ``` @@ -866,7 +893,7 @@ string[] ```typescript ( - date: any, + date: string | number | Date, timezoneOffset?: number, local?: boolean ) => Date @@ -879,7 +906,10 @@ string[] ```typescript -(sourceDate: any, numberOfDays: any) => Date +( + sourceDate: string | number | Date, + numberOfDays: number +) => Date ``` @@ -889,7 +919,7 @@ string[] ```typescript -(date: any) => string +(date: Date) => string ``` @@ -899,7 +929,7 @@ string[] ```typescript -(xs: any) => any +(xs: (string | number | Date)[]) => Date[] ``` @@ -909,7 +939,7 @@ string[] ```typescript -(milliseconds: any) => number +(milliseconds: number) => number ``` @@ -919,7 +949,7 @@ string[] ```typescript -(milliseconds: any) => number +(milliseconds: number) => number ``` @@ -929,7 +959,7 @@ string[] ```typescript -(x: any) => any +(x: Date) => string ``` @@ -939,7 +969,7 @@ string[] ```typescript -(date: any) => string +(date: Date) => string ``` @@ -949,7 +979,7 @@ string[] ```typescript -(date: any, timezoneOffset?: number) => Date +(date: Date, timezoneOffset?: number) => Date ``` @@ -959,7 +989,7 @@ string[] ```typescript -(milliseconds: any) => number +(milliseconds: number) => number ``` @@ -969,7 +999,7 @@ string[] ```typescript -(milliseconds: any) => number +(milliseconds: number) => number ``` @@ -979,7 +1009,7 @@ string[] ```typescript -(date: any) => boolean +(date?: any) => boolean ``` @@ -1008,7 +1038,14 @@ Computes a difference between two objects. ```typescript -(obj1: object, obj2: object) => object +( + obj1?: { + [index: string]: any; + }, + obj2?: { + [index: string]: any; + } +) => object ``` @@ -1023,15 +1060,7 @@ Provides a way to encode strings and bytes from and into Base64URL. ```typescript { - decode: ( - text: string, - context?: { - atob: (byteString: string) => string; - TextDecoder: new (encoding: string) => { - decode: (input?: Uint8Array) => string; - }; - } - ) => string; + decode: (text: string, context?: DecodeContext) => string; decodeBytes: ( text: string, context?: { @@ -1050,15 +1079,7 @@ Provides a way to encode strings and bytes from and into Base64URL. }; } ) => string; - encodeBytes: ( - bytes: number[], - context?: { - btoa: (byteString: string) => string; - TextEncoder: new () => { - encode: (input?: string) => Uint8Array; - }; - } - ) => string; + encodeBytes: (bytes: number[], context?: EncodeContext) => string; fromByteString: (byteString: string) => number[]; toByteString: (bytes: number[]) => string; } @@ -1319,6 +1340,18 @@ Checks if given value is an integer. ``` +#### nonNullable + +Checks and asserts the given value is not a null or undefined. + +##### Type signature + + +```typescript +(val: T) => val is NonNullable +``` + + #### normal Checks if the given value is a number in a normal range [0, 1]. @@ -1865,7 +1898,12 @@ Merges two objects deeply. ```typescript -(a: object, b: object) => object +( + a: { + [index: string]: any; + }, + b: object +) => object ``` @@ -1909,7 +1947,9 @@ Sorts the given object by a comparator. ```typescript -(f: any) => (xs: any) => object +( + f: (a: any, b: any) => number +) => (xs: object) => object ``` @@ -1947,7 +1987,7 @@ Serializes the given object into a query string. ```typescript -(xs?: {}) => string +(xs?: { [index: string]: any }) => string ``` @@ -1961,7 +2001,7 @@ Checks if the given range is empty. ```typescript -([min, max]: [any, any]) => boolean +([min, max]: [number, number]) => boolean ``` @@ -1982,7 +2022,10 @@ Checks if the given ranges are equal. ```typescript -([a, b]: [any, any], [c, d]: [any, any]) => boolean +( + [a, b]: [number, number], + [c, d]: [number, number] +) => boolean ``` @@ -1994,7 +2037,7 @@ Computes the signed length of the given range. ```typescript -([min, max]: [any, any]) => number +([min, max]: [number, number]) => number ``` @@ -2177,7 +2220,10 @@ Calculates a cross product of the given vectors. Returns a scalar. ```typescript -([a, b]: [any, any], [c, d]: [any, any]) => number +( + [a, b]: [number, number], + [c, d]: [number, number] +) => number ``` @@ -2189,7 +2235,10 @@ Calculates a dot product of the given vectors. Returns a scalar. ```typescript -([a, b]: [any, any], [c, d]: [any, any]) => number +( + [a, b]: [number, number], + [c, d]: [number, number] +) => number ``` @@ -2278,7 +2327,7 @@ Normalizes the given vector. Returns [0, 0] vector for points. ```typescript -(vector: [number, number]) => number[] +(vector: [number, number]) => [number, number] ``` @@ -2452,10 +2501,10 @@ Tests if the current event seems like an intent to open a new tab. Useful for cl metaKey, shiftKey }: { - button: any; - ctrlKey: any; - metaKey: any; - shiftKey: any; + button?: number; + ctrlKey?: boolean; + metaKey?: boolean; + shiftKey?: boolean; }) => boolean ``` diff --git a/array/README.md b/array/README.md index b1bc4adb..28e53f64 100644 --- a/array/README.md +++ b/array/README.md @@ -360,7 +360,7 @@ Returns the second element or undefined when there are less than two elements in ```typescript -([, x]: [any, any]) => any +([, x]: any[]) => any ``` diff --git a/array/differs.js b/array/differs.js index af794c77..7ea5ae73 100644 --- a/array/differs.js +++ b/array/differs.js @@ -1,5 +1,9 @@ +import isNonNullable from "../is/nonNullable.js"; + export default (xs, ys) => Boolean(!xs && ys) || Boolean(!ys && xs) || + !isNonNullable(ys) || + !isNonNullable(xs) || xs.length !== ys.length || xs.some((x, index) => x !== ys[index]); diff --git a/array/differs.test.ts b/array/differs.test.ts index dde1b8a9..82e1bfbf 100644 --- a/array/differs.test.ts +++ b/array/differs.test.ts @@ -11,6 +11,8 @@ describe("differs", () => { it("short-circuits over parameter presence", () => { expect(differs(null, [1, 2])).toBe(true); expect(differs([2, 3], undefined)).toBe(true); + expect(differs(null, null)).toBe(true); + expect(differs(undefined, undefined)).toBe(true); }); it("compares elements index-wise", () => { diff --git a/array/differs.ts b/array/differs.ts index 51d620fd..6228d015 100644 --- a/array/differs.ts +++ b/array/differs.ts @@ -1,5 +1,9 @@ +import isNonNullable from "../is/nonNullable"; + export default (xs?: any[], ys?: any[]) => Boolean(!xs && ys) || Boolean(!ys && xs) || + !isNonNullable(ys) || + !isNonNullable(xs) || xs.length !== ys.length || xs.some((x, index) => x !== ys[index]); diff --git a/array/first.ts b/array/first.ts index 42b96520..82aedf95 100644 --- a/array/first.ts +++ b/array/first.ts @@ -1 +1 @@ -export default ([x]) => x; +export default ([x]: [any]) => x; diff --git a/array/second.json b/array/second.json index 0b9838fe..e5fb2002 100644 --- a/array/second.json +++ b/array/second.json @@ -1,7 +1,7 @@ { "name": "second", "description": "Returns the second element or undefined when there are less than two elements in the given array.", - "signature": "([, x]: [any, any]) => any", + "signature": "([, x]: any[]) => any", "examples": [ { "language": "javascript", diff --git a/array/second.md b/array/second.md index 7917e7c8..d05ce695 100644 --- a/array/second.md +++ b/array/second.md @@ -6,6 +6,6 @@ Returns the second element or undefined when there are less than two elements in ```typescript -([, x]: [any, any]) => any +([, x]: any[]) => any ``` diff --git a/array/second.ts b/array/second.ts index 41953d02..623dd03d 100644 --- a/array/second.ts +++ b/array/second.ts @@ -1 +1 @@ -export default ([, x]) => x; +export default ([, x]: any[]): any => x; diff --git a/async/debounce.ts b/async/debounce.ts index cb278823..e264751f 100644 --- a/async/debounce.ts +++ b/async/debounce.ts @@ -1,7 +1,7 @@ /* eslint-env browser */ export default (f: { (...args: any[]): any }, wait: number) => { - let timeout; + let timeout: any; return (...args: any[]) => { const resolve = () => { diff --git a/compile.js b/compile.js index b2eeff10..88cb1f3f 100644 --- a/compile.js +++ b/compile.js @@ -68,27 +68,51 @@ const main = async cwd => { "--skipLibCheck", "--module ES6", "--target ES2020", + "--noImplicitAny", + "--strict", "-d", quotePath(path.posix.normalize(filePath)) ]; const command = [executable, ...args].join(" "); - console.time(command); - const windows = process.platform === "win32"; - const { stdout, stderr } = await execAsync(command, { + const execOptions = { windowsVerbatimArguments: windows - }); + }; + + console.time(command); + + const { stdout, stderr } = await execAsync(command, execOptions); console.timeEnd(command); - console.log(`Compiled ${relativeFilePath}`); + console.log(`Compiled with strict mode ${relativeFilePath}`); if (stdout || stderr) { console.log({ stdout, stderr }); } + + const nonStrictCommand = [ + executable, + ...args.filter(x => x !== "--strict") + ].join(" "); + + console.time(nonStrictCommand); + + const { stdout: secondStdout, stderr: secondStderr } = await execAsync( + nonStrictCommand, + execOptions + ); + + console.timeEnd(nonStrictCommand); + + console.log(`Compiled without strict mode ${relativeFilePath}`); + + if (secondStdout || secondStderr) { + console.log({ secondStdout, secondStderr }); + } } catch (error) { console.error(error); diff --git a/date/README.md b/date/README.md index d5cb0a97..46c3f123 100644 --- a/date/README.md +++ b/date/README.md @@ -5,21 +5,21 @@ ```typescript ( - now: any + now: string | number | Date ) => ( { endedAt: aEnd, startedAt: aStart }: { - endedAt: any; - startedAt: any; + endedAt: string | number | Date; + startedAt: string | number | Date; }, { endedAt: bEnd, startedAt: bStart }: { - endedAt: any; - startedAt: any; + endedAt: string | number | Date; + startedAt: string | number | Date; } ) => number ``` @@ -31,7 +31,10 @@ ```typescript -(min: any, max: any) => (dateStringOrDate: any) => Date +( + min: number | Date, + max: number | Date +) => (dateStringOrDate: string | number | Date) => Date ``` @@ -41,7 +44,10 @@ ```typescript -(a: any, b: any) => number +( + a: string | number | Date, + b: string | number | Date +) => number ``` @@ -51,7 +57,10 @@ ```typescript -(from: any, to: any) => (date?: Date) => boolean +( + from: string | number | Date, + to: string | number | Date +) => (date?: Date) => boolean ``` @@ -71,7 +80,7 @@ local?: boolean; now?: Date; timezoneOffset?: number; -}) => (date: any) => any[] +}) => (date?: string | number | Date) => string[] ``` @@ -81,7 +90,22 @@ ```typescript -(leapYear: any) => number[] +( + leapYear: boolean +) => [ + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number +] ``` @@ -91,7 +115,7 @@ ```typescript -(year: any) => number +(year: number) => number ``` @@ -101,7 +125,7 @@ ```typescript -(monthIndex: any) => string +(monthIndex: number) => string ``` @@ -111,7 +135,10 @@ ```typescript -(source: any, showSeconds: any) => string +( + source: [number, number, number], + showSeconds: boolean +) => string ``` @@ -122,7 +149,7 @@ ```typescript ( - date: any, + date: string | number | Date, timezoneOffset?: number, local?: boolean ) => Date @@ -135,7 +162,7 @@ ```typescript -(sourceDate: any, timezoneOffset?: number) => string +(sourceDate: Date, timezoneOffset?: number) => string ``` @@ -146,7 +173,7 @@ ```typescript ( - sourceDate: any, + sourceDate: Date, showSeconds?: boolean, timezoneOffset?: number ) => string @@ -160,7 +187,7 @@ ```typescript ( - sourceDate: any, + sourceDate: Date, showDay?: boolean, timezoneOffset?: number ) => string @@ -173,7 +200,7 @@ ```typescript -(duration: any, showSeconds?: boolean) => string +(duration: number, showSeconds?: boolean) => string ``` @@ -184,7 +211,7 @@ ```typescript ( - sourceDate: any, + sourceDate: Date, showSeconds?: boolean, timezoneOffset?: number ) => string @@ -197,7 +224,7 @@ ```typescript -(days: any) => number +(days: number) => number ``` @@ -207,7 +234,7 @@ ```typescript -(hours: any) => number +(hours: number) => number ``` @@ -217,7 +244,7 @@ ```typescript -(minutes: any) => number +(minutes: number) => number ``` @@ -227,7 +254,7 @@ ```typescript -(seconds: any) => number +(seconds: number) => number ``` @@ -237,7 +264,7 @@ ```typescript -(...xs: any[]) => string +(...xs: string[]) => string ``` @@ -247,7 +274,7 @@ ```typescript -(year: any) => boolean +(year: number) => boolean ``` @@ -267,7 +294,7 @@ string[] ```typescript -(date: any) => Date +(date: number | Date) => Date ``` @@ -287,7 +314,7 @@ string[] ```typescript -(dateTimeString: any) => any +(dateTimeString: string) => string[] ``` @@ -298,7 +325,7 @@ string[] ```typescript ( - date: any, + date: string | number | Date, timezoneOffset?: number, local?: boolean ) => Date @@ -311,7 +338,10 @@ string[] ```typescript -(sourceDate: any, numberOfDays: any) => Date +( + sourceDate: string | number | Date, + numberOfDays: number +) => Date ``` @@ -321,7 +351,7 @@ string[] ```typescript -(date: any) => string +(date: Date) => string ``` @@ -331,7 +361,7 @@ string[] ```typescript -(xs: any) => any +(xs: (string | number | Date)[]) => Date[] ``` @@ -341,7 +371,7 @@ string[] ```typescript -(milliseconds: any) => number +(milliseconds: number) => number ``` @@ -351,7 +381,7 @@ string[] ```typescript -(milliseconds: any) => number +(milliseconds: number) => number ``` @@ -361,7 +391,7 @@ string[] ```typescript -(x: any) => any +(x: Date) => string ``` @@ -371,7 +401,7 @@ string[] ```typescript -(date: any) => string +(date: Date) => string ``` @@ -381,7 +411,7 @@ string[] ```typescript -(date: any, timezoneOffset?: number) => Date +(date: Date, timezoneOffset?: number) => Date ``` @@ -391,7 +421,7 @@ string[] ```typescript -(milliseconds: any) => number +(milliseconds: number) => number ``` @@ -401,7 +431,7 @@ string[] ```typescript -(milliseconds: any) => number +(milliseconds: number) => number ``` @@ -411,6 +441,6 @@ string[] ```typescript -(date: any) => boolean +(date?: any) => boolean ``` diff --git a/date/byDateWithFallback.json b/date/byDateWithFallback.json index f611cceb..f045e83e 100644 --- a/date/byDateWithFallback.json +++ b/date/byDateWithFallback.json @@ -1,7 +1,7 @@ { "name": "byDateWithFallback", "description": "TODO: Fill short description here.", - "signature": "(\n now: any\n) => (\n {\n endedAt: aEnd,\n startedAt: aStart\n }: {\n endedAt: any;\n startedAt: any;\n },\n {\n endedAt: bEnd,\n startedAt: bStart\n }: {\n endedAt: any;\n startedAt: any;\n }\n) => number", + "signature": "(\n now: string | number | Date\n) => (\n {\n endedAt: aEnd,\n startedAt: aStart\n }: {\n endedAt: string | number | Date;\n startedAt: string | number | Date;\n },\n {\n endedAt: bEnd,\n startedAt: bStart\n }: {\n endedAt: string | number | Date;\n startedAt: string | number | Date;\n }\n) => number", "examples": [ { "language": "javascript", diff --git a/date/byDateWithFallback.md b/date/byDateWithFallback.md index 6d938882..df10b168 100644 --- a/date/byDateWithFallback.md +++ b/date/byDateWithFallback.md @@ -5,21 +5,21 @@ ```typescript ( - now: any + now: string | number | Date ) => ( { endedAt: aEnd, startedAt: aStart }: { - endedAt: any; - startedAt: any; + endedAt: string | number | Date; + startedAt: string | number | Date; }, { endedAt: bEnd, startedAt: bStart }: { - endedAt: any; - startedAt: any; + endedAt: string | number | Date; + startedAt: string | number | Date; } ) => number ``` diff --git a/date/byDateWithFallback.ts b/date/byDateWithFallback.ts index 3c6c5296..85c42ed5 100644 --- a/date/byDateWithFallback.ts +++ b/date/byDateWithFallback.ts @@ -1,6 +1,12 @@ -export default now => ( - { endedAt: aEnd, startedAt: aStart }, - { endedAt: bEnd, startedAt: bStart } +export default (now: Date | string | number) => ( + { + endedAt: aEnd, + startedAt: aStart + }: { endedAt: Date | string | number; startedAt: Date | string | number }, + { + endedAt: bEnd, + startedAt: bStart + }: { endedAt: Date | string | number; startedAt: Date | string | number } ) => { const aEndDate = new Date(aEnd || now); const aStartDate = new Date(aStart || now); diff --git a/date/clamp.json b/date/clamp.json index 53da8bbf..93413be6 100644 --- a/date/clamp.json +++ b/date/clamp.json @@ -1,7 +1,7 @@ { "name": "clamp", "description": "TODO: Fill short description here.", - "signature": "(min: any, max: any) => (dateStringOrDate: any) => Date", + "signature": "(\n min: number | Date,\n max: number | Date\n) => (dateStringOrDate: string | number | Date) => Date", "examples": [ { "language": "javascript", diff --git a/date/clamp.md b/date/clamp.md index 4e872f0d..012878c8 100644 --- a/date/clamp.md +++ b/date/clamp.md @@ -4,6 +4,9 @@ ```typescript -(min: any, max: any) => (dateStringOrDate: any) => Date +( + min: number | Date, + max: number | Date +) => (dateStringOrDate: string | number | Date) => Date ``` diff --git a/date/clamp.ts b/date/clamp.ts index 51fd80cd..e8115276 100644 --- a/date/clamp.ts +++ b/date/clamp.ts @@ -1,4 +1,6 @@ -export default (min, max) => dateStringOrDate => { +export default (min: Date | number, max: Date | number) => ( + dateStringOrDate: string | number | Date +) => { const date = new Date(dateStringOrDate); const clamped = new Date( diff --git a/date/dateDiff.json b/date/dateDiff.json index 913e706c..a6d66fda 100644 --- a/date/dateDiff.json +++ b/date/dateDiff.json @@ -1,7 +1,7 @@ { "name": "dateDiff", "description": "TODO: Fill short description here.", - "signature": "(a: any, b: any) => number", + "signature": "(\n a: string | number | Date,\n b: string | number | Date\n) => number", "examples": [ { "language": "javascript", diff --git a/date/dateDiff.md b/date/dateDiff.md index cba3b9dd..ebc6761f 100644 --- a/date/dateDiff.md +++ b/date/dateDiff.md @@ -4,6 +4,9 @@ ```typescript -(a: any, b: any) => number +( + a: string | number | Date, + b: string | number | Date +) => number ``` diff --git a/date/dateDiff.ts b/date/dateDiff.ts index 2e4d2ce6..d8e585a3 100644 --- a/date/dateDiff.ts +++ b/date/dateDiff.ts @@ -1,4 +1,4 @@ -export default (a, b) => { +export default (a: string | number | Date, b: string | number | Date) => { const d1 = new Date(a); const d2 = new Date(b); diff --git a/date/dateInRange.json b/date/dateInRange.json index ef4edab0..db7e8e6e 100644 --- a/date/dateInRange.json +++ b/date/dateInRange.json @@ -1,7 +1,7 @@ { "name": "dateInRange", "description": "TODO: Fill short description here.", - "signature": "(from: any, to: any) => (date?: Date) => boolean", + "signature": "(\n from: string | number | Date,\n to: string | number | Date\n) => (date?: Date) => boolean", "examples": [ { "language": "javascript", diff --git a/date/dateInRange.md b/date/dateInRange.md index 115a6199..067db71b 100644 --- a/date/dateInRange.md +++ b/date/dateInRange.md @@ -4,6 +4,9 @@ ```typescript -(from: any, to: any) => (date?: Date) => boolean +( + from: string | number | Date, + to: string | number | Date +) => (date?: Date) => boolean ``` diff --git a/date/dateInRange.ts b/date/dateInRange.ts index 29997ef7..25859e6c 100644 --- a/date/dateInRange.ts +++ b/date/dateInRange.ts @@ -1,4 +1,6 @@ -export default (from, to) => (date = new Date()) => { +export default (from: string | number | Date, to: string | number | Date) => ( + date = new Date() +) => { const dateTime = new Date(date).getTime(); const fromTime = new Date(from).getTime(); const toTime = new Date(to).getTime(); diff --git a/date/dayRange.json b/date/dayRange.json index 9d5d6503..76b43def 100644 --- a/date/dayRange.json +++ b/date/dayRange.json @@ -1,7 +1,7 @@ { "name": "dayRange", "description": "TODO: Fill short description here.", - "signature": "({\n iso,\n local,\n now,\n timezoneOffset\n}: {\n iso?: boolean;\n local?: boolean;\n now?: Date;\n timezoneOffset?: number;\n}) => (date: any) => any[]", + "signature": "({\n iso,\n local,\n now,\n timezoneOffset\n}: {\n iso?: boolean;\n local?: boolean;\n now?: Date;\n timezoneOffset?: number;\n}) => (date?: string | number | Date) => string[]", "examples": [ { "language": "javascript", diff --git a/date/dayRange.md b/date/dayRange.md index d6729e2c..a0aa3418 100644 --- a/date/dayRange.md +++ b/date/dayRange.md @@ -14,6 +14,6 @@ local?: boolean; now?: Date; timezoneOffset?: number; -}) => (date: any) => any[] +}) => (date?: string | number | Date) => string[] ``` diff --git a/date/dayRange.ts b/date/dayRange.ts index 62c9f654..cab26edc 100644 --- a/date/dayRange.ts +++ b/date/dayRange.ts @@ -10,7 +10,7 @@ export default ({ local = true, now = new Date(), timezoneOffset = 0 -}) => date => { +}) => (date?: string | number | Date) => { const convert = iso ? toISO : toISOFromLocalDateTime; const [start] = splitDateTime( diff --git a/date/daysInMonths.json b/date/daysInMonths.json index 9f0cfdad..83aeb8f5 100644 --- a/date/daysInMonths.json +++ b/date/daysInMonths.json @@ -1,7 +1,7 @@ { "name": "daysInMonths", "description": "TODO: Fill short description here.", - "signature": "(leapYear: any) => number[]", + "signature": "(\n leapYear: boolean\n) => [\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number,\n number\n]", "examples": [ { "language": "javascript", diff --git a/date/daysInMonths.md b/date/daysInMonths.md index b5b51fee..620aa894 100644 --- a/date/daysInMonths.md +++ b/date/daysInMonths.md @@ -4,6 +4,21 @@ ```typescript -(leapYear: any) => number[] +( + leapYear: boolean +) => [ + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number +] ``` diff --git a/date/daysInMonths.ts b/date/daysInMonths.ts index 2ad5657f..571a118f 100644 --- a/date/daysInMonths.ts +++ b/date/daysInMonths.ts @@ -1,14 +1,16 @@ -export default leapYear => [ - 31, - leapYear ? 29 : 28, - 31, - 30, - 31, - 30, - 31, - 31, - 30, - 31, - 30, - 31 -]; +export default ( + leapYear: boolean +): [ + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number, + number +] => [31, leapYear ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; diff --git a/date/daysInYear.json b/date/daysInYear.json index 601818cc..0d97c09a 100644 --- a/date/daysInYear.json +++ b/date/daysInYear.json @@ -1,7 +1,7 @@ { "name": "daysInYear", "description": "TODO: Fill short description here.", - "signature": "(year: any) => number", + "signature": "(year: number) => number", "examples": [ { "language": "javascript", diff --git a/date/daysInYear.md b/date/daysInYear.md index 03de6148..a6f167df 100644 --- a/date/daysInYear.md +++ b/date/daysInYear.md @@ -4,6 +4,6 @@ ```typescript -(year: any) => number +(year: number) => number ``` diff --git a/date/daysInYear.ts b/date/daysInYear.ts index 13c489da..4a364b99 100644 --- a/date/daysInYear.ts +++ b/date/daysInYear.ts @@ -2,4 +2,4 @@ import sum from "../array/sum"; import daysInMonths from "./daysInMonths"; import leapYear from "./leapYear"; -export default year => sum(daysInMonths(leapYear(year))); +export default (year: number) => sum(daysInMonths(leapYear(year))); diff --git a/date/displayMonth.json b/date/displayMonth.json index f033d622..95707c1c 100644 --- a/date/displayMonth.json +++ b/date/displayMonth.json @@ -1,7 +1,7 @@ { "name": "displayMonth", "description": "TODO: Fill short description here.", - "signature": "(monthIndex: any) => string", + "signature": "(monthIndex: number) => string", "examples": [ { "language": "javascript", diff --git a/date/displayMonth.md b/date/displayMonth.md index 23bb48d2..71e29976 100644 --- a/date/displayMonth.md +++ b/date/displayMonth.md @@ -4,6 +4,6 @@ ```typescript -(monthIndex: any) => string +(monthIndex: number) => string ``` diff --git a/date/displayMonth.ts b/date/displayMonth.ts index 83a1e0b6..29e50e5b 100644 --- a/date/displayMonth.ts +++ b/date/displayMonth.ts @@ -1,3 +1,3 @@ import monthNames from "./monthNames"; -export default monthIndex => monthNames[monthIndex % 12]; +export default (monthIndex: number) => monthNames[monthIndex % 12]; diff --git a/date/displayTime.json b/date/displayTime.json index c73d4c32..837310bf 100644 --- a/date/displayTime.json +++ b/date/displayTime.json @@ -1,7 +1,7 @@ { "name": "displayTime", "description": "TODO: Fill short description here.", - "signature": "(source: any, showSeconds: any) => string", + "signature": "(\n source: [number, number, number],\n showSeconds: boolean\n) => string", "examples": [ { "language": "javascript", diff --git a/date/displayTime.md b/date/displayTime.md index e02d2a67..3ae4381c 100644 --- a/date/displayTime.md +++ b/date/displayTime.md @@ -4,6 +4,9 @@ ```typescript -(source: any, showSeconds: any) => string +( + source: [number, number, number], + showSeconds: boolean +) => string ``` diff --git a/date/displayTime.ts b/date/displayTime.ts index fc78bc18..b1bfe6fc 100644 --- a/date/displayTime.ts +++ b/date/displayTime.ts @@ -1,4 +1,4 @@ -export default (source, showSeconds) => { +export default (source: [number, number, number], showSeconds: boolean) => { const [hours, minutes, seconds] = source.map(_ => _ + ""); const padded = [ diff --git a/date/endOfDay.json b/date/endOfDay.json index 47e30618..0458a645 100644 --- a/date/endOfDay.json +++ b/date/endOfDay.json @@ -1,7 +1,7 @@ { "name": "endOfDay", "description": "TODO: Fill short description here.", - "signature": "(\n date: any,\n timezoneOffset?: number,\n local?: boolean\n) => Date", + "signature": "(\n date: string | number | Date,\n timezoneOffset?: number,\n local?: boolean\n) => Date", "examples": [ { "language": "javascript", diff --git a/date/endOfDay.md b/date/endOfDay.md index 15f9a5fe..8ba2cda9 100644 --- a/date/endOfDay.md +++ b/date/endOfDay.md @@ -5,7 +5,7 @@ ```typescript ( - date: any, + date: string | number | Date, timezoneOffset?: number, local?: boolean ) => Date diff --git a/date/endOfDay.ts b/date/endOfDay.ts index 71f92a0f..546a0024 100644 --- a/date/endOfDay.ts +++ b/date/endOfDay.ts @@ -1,6 +1,10 @@ import toLocalDateTime from "./toLocalDateTime"; -export default (date, timezoneOffset = 0, local = true) => { +export default ( + date: string | number | Date, + timezoneOffset = 0, + local = true +) => { const newDate = new Date(date); newDate.setHours(24, 0, 0, 0); diff --git a/date/formatDate.json b/date/formatDate.json index 2ba85e7e..e15a49e6 100644 --- a/date/formatDate.json +++ b/date/formatDate.json @@ -1,7 +1,7 @@ { "name": "formatDate", "description": "TODO: Fill short description here.", - "signature": "(sourceDate: any, timezoneOffset?: number) => string", + "signature": "(sourceDate: Date, timezoneOffset?: number) => string", "examples": [ { "language": "javascript", diff --git a/date/formatDate.md b/date/formatDate.md index 00d03f08..3227aad4 100644 --- a/date/formatDate.md +++ b/date/formatDate.md @@ -4,6 +4,6 @@ ```typescript -(sourceDate: any, timezoneOffset?: number) => string +(sourceDate: Date, timezoneOffset?: number) => string ``` diff --git a/date/formatDate.ts b/date/formatDate.ts index f6fcac30..50bd88b1 100644 --- a/date/formatDate.ts +++ b/date/formatDate.ts @@ -1,6 +1,6 @@ import toLocalDateTime from "./toLocalDateTime"; -export default (sourceDate, timezoneOffset = 0) => { +export default (sourceDate: Date, timezoneOffset: number = 0) => { const localDate = toLocalDateTime(sourceDate, timezoneOffset); const [m, a, y] = [ diff --git a/date/formatDateTime.json b/date/formatDateTime.json index 9c6bde48..69a087ec 100644 --- a/date/formatDateTime.json +++ b/date/formatDateTime.json @@ -1,7 +1,7 @@ { "name": "formatDateTime", "description": "TODO: Fill short description here.", - "signature": "(\n sourceDate: any,\n showSeconds?: boolean,\n timezoneOffset?: number\n) => string", + "signature": "(\n sourceDate: Date,\n showSeconds?: boolean,\n timezoneOffset?: number\n) => string", "examples": [ { "language": "javascript", diff --git a/date/formatDateTime.md b/date/formatDateTime.md index 572aeb24..69eae52e 100644 --- a/date/formatDateTime.md +++ b/date/formatDateTime.md @@ -5,7 +5,7 @@ ```typescript ( - sourceDate: any, + sourceDate: Date, showSeconds?: boolean, timezoneOffset?: number ) => string diff --git a/date/formatDateTime.ts b/date/formatDateTime.ts index a350c841..94cd878c 100644 --- a/date/formatDateTime.ts +++ b/date/formatDateTime.ts @@ -1,7 +1,7 @@ import formatDate from "./formatDate"; import formatTime from "./formatTime"; -export default (sourceDate, showSeconds = false, timezoneOffset = 0) => { +export default (sourceDate: Date, showSeconds = false, timezoneOffset = 0) => { const date = formatDate(sourceDate, timezoneOffset); const time = formatTime(sourceDate, showSeconds, timezoneOffset); diff --git a/date/formatDisplayDate.json b/date/formatDisplayDate.json index 3e1f8d4c..145194da 100644 --- a/date/formatDisplayDate.json +++ b/date/formatDisplayDate.json @@ -1,7 +1,7 @@ { "name": "formatDisplayDate", "description": "TODO: Fill short description here.", - "signature": "(\n sourceDate: any,\n showDay?: boolean,\n timezoneOffset?: number\n) => string", + "signature": "(\n sourceDate: Date,\n showDay?: boolean,\n timezoneOffset?: number\n) => string", "examples": [ { "language": "javascript", diff --git a/date/formatDisplayDate.md b/date/formatDisplayDate.md index 52deddcd..dd9dd814 100644 --- a/date/formatDisplayDate.md +++ b/date/formatDisplayDate.md @@ -5,7 +5,7 @@ ```typescript ( - sourceDate: any, + sourceDate: Date, showDay?: boolean, timezoneOffset?: number ) => string diff --git a/date/formatDisplayDate.ts b/date/formatDisplayDate.ts index 70eddb0c..38fb8ab9 100644 --- a/date/formatDisplayDate.ts +++ b/date/formatDisplayDate.ts @@ -1,7 +1,7 @@ import toLocalDateTime from "./toLocalDateTime"; import displayMonth from "./displayMonth"; -export default (sourceDate, showDay = false, timezoneOffset = 0) => { +export default (sourceDate: Date, showDay = false, timezoneOffset = 0) => { const localDate = toLocalDateTime(sourceDate, timezoneOffset); const day = localDate.getDate(); const monthIndex = localDate.getMonth(); diff --git a/date/formatDuration.json b/date/formatDuration.json index 108d59f6..18c116f0 100644 --- a/date/formatDuration.json +++ b/date/formatDuration.json @@ -1,7 +1,7 @@ { "name": "formatDuration", "description": "TODO: Fill short description here.", - "signature": "(duration: any, showSeconds?: boolean) => string", + "signature": "(duration: number, showSeconds?: boolean) => string", "examples": [ { "language": "javascript", diff --git a/date/formatDuration.md b/date/formatDuration.md index 3dead43e..5a59ebe8 100644 --- a/date/formatDuration.md +++ b/date/formatDuration.md @@ -4,6 +4,6 @@ ```typescript -(duration: any, showSeconds?: boolean) => string +(duration: number, showSeconds?: boolean) => string ``` diff --git a/date/formatDuration.ts b/date/formatDuration.ts index bda1bc18..9401437c 100644 --- a/date/formatDuration.ts +++ b/date/formatDuration.ts @@ -5,7 +5,7 @@ import toMinutes from "./toMinutes"; import toSeconds from "./toSeconds"; import displayTime from "./displayTime"; -export default (duration, showSeconds = false) => { +export default (duration: number, showSeconds = false) => { const hours = Math.floor(toHours(duration)); const minutes = Math.floor(toMinutes(duration - fromHours(hours))); diff --git a/date/formatTime.js b/date/formatTime.js index 6c01768f..1cb569ae 100644 --- a/date/formatTime.js +++ b/date/formatTime.js @@ -4,11 +4,11 @@ import displayTime from "./displayTime.js"; export default (sourceDate, showSeconds = false, timezoneOffset = 0) => { const localDate = toLocalDateTime(sourceDate, timezoneOffset); - const source = [ + const [hours, minutes, seconds] = [ localDate.getUTCHours(), localDate.getUTCMinutes(), localDate.getUTCSeconds() ]; - return displayTime(source, showSeconds); + return displayTime([hours, minutes, seconds], showSeconds); }; diff --git a/date/formatTime.json b/date/formatTime.json index a2391390..e918ede6 100644 --- a/date/formatTime.json +++ b/date/formatTime.json @@ -1,7 +1,7 @@ { "name": "formatTime", "description": "TODO: Fill short description here.", - "signature": "(\n sourceDate: any,\n showSeconds?: boolean,\n timezoneOffset?: number\n) => string", + "signature": "(\n sourceDate: Date,\n showSeconds?: boolean,\n timezoneOffset?: number\n) => string", "examples": [ { "language": "javascript", diff --git a/date/formatTime.md b/date/formatTime.md index e496b1e7..92ee6ff9 100644 --- a/date/formatTime.md +++ b/date/formatTime.md @@ -5,7 +5,7 @@ ```typescript ( - sourceDate: any, + sourceDate: Date, showSeconds?: boolean, timezoneOffset?: number ) => string diff --git a/date/formatTime.ts b/date/formatTime.ts index 26e55f00..e657b22a 100644 --- a/date/formatTime.ts +++ b/date/formatTime.ts @@ -1,14 +1,14 @@ import toLocalDateTime from "./toLocalDateTime"; import displayTime from "./displayTime"; -export default (sourceDate, showSeconds = false, timezoneOffset = 0) => { +export default (sourceDate: Date, showSeconds = false, timezoneOffset = 0) => { const localDate = toLocalDateTime(sourceDate, timezoneOffset); - const source = [ + const [hours, minutes, seconds] = [ localDate.getUTCHours(), localDate.getUTCMinutes(), localDate.getUTCSeconds() ]; - return displayTime(source, showSeconds); + return displayTime([hours, minutes, seconds], showSeconds); }; diff --git a/date/fromDays.json b/date/fromDays.json index de6eab7b..22b866f5 100644 --- a/date/fromDays.json +++ b/date/fromDays.json @@ -1,7 +1,7 @@ { "name": "fromDays", "description": "TODO: Fill short description here.", - "signature": "(days: any) => number", + "signature": "(days: number) => number", "examples": [ { "language": "javascript", diff --git a/date/fromDays.md b/date/fromDays.md index 588ae71c..cc963c98 100644 --- a/date/fromDays.md +++ b/date/fromDays.md @@ -4,6 +4,6 @@ ```typescript -(days: any) => number +(days: number) => number ``` diff --git a/date/fromDays.ts b/date/fromDays.ts index ea8d490e..a30ed404 100644 --- a/date/fromDays.ts +++ b/date/fromDays.ts @@ -1,3 +1,3 @@ import fromHours from "./fromHours"; -export default days => fromHours(days * 24); +export default (days: number) => fromHours(days * 24); diff --git a/date/fromHours.json b/date/fromHours.json index 65034044..c04a6a8c 100644 --- a/date/fromHours.json +++ b/date/fromHours.json @@ -1,7 +1,7 @@ { "name": "fromHours", "description": "TODO: Fill short description here.", - "signature": "(hours: any) => number", + "signature": "(hours: number) => number", "examples": [ { "language": "javascript", diff --git a/date/fromHours.md b/date/fromHours.md index ded6d442..a8b3f21f 100644 --- a/date/fromHours.md +++ b/date/fromHours.md @@ -4,6 +4,6 @@ ```typescript -(hours: any) => number +(hours: number) => number ``` diff --git a/date/fromHours.ts b/date/fromHours.ts index 6a5f9617..58d75a47 100644 --- a/date/fromHours.ts +++ b/date/fromHours.ts @@ -1,3 +1,3 @@ import fromMinutes from "./fromMinutes"; -export default hours => fromMinutes(hours * 60); +export default (hours: number) => fromMinutes(hours * 60); diff --git a/date/fromMinutes.json b/date/fromMinutes.json index 986a93ee..ac3e6e8c 100644 --- a/date/fromMinutes.json +++ b/date/fromMinutes.json @@ -1,7 +1,7 @@ { "name": "fromMinutes", "description": "TODO: Fill short description here.", - "signature": "(minutes: any) => number", + "signature": "(minutes: number) => number", "examples": [ { "language": "javascript", diff --git a/date/fromMinutes.md b/date/fromMinutes.md index 41238e7e..c095e696 100644 --- a/date/fromMinutes.md +++ b/date/fromMinutes.md @@ -4,6 +4,6 @@ ```typescript -(minutes: any) => number +(minutes: number) => number ``` diff --git a/date/fromMinutes.ts b/date/fromMinutes.ts index 6e32741a..26e5d2ec 100644 --- a/date/fromMinutes.ts +++ b/date/fromMinutes.ts @@ -1,3 +1,3 @@ import fromSeconds from "./fromSeconds"; -export default minutes => fromSeconds(minutes * 60); +export default (minutes: number) => fromSeconds(minutes * 60); diff --git a/date/fromSeconds.json b/date/fromSeconds.json index ef4d3ada..12343565 100644 --- a/date/fromSeconds.json +++ b/date/fromSeconds.json @@ -1,7 +1,7 @@ { "name": "fromSeconds", "description": "TODO: Fill short description here.", - "signature": "(seconds: any) => number", + "signature": "(seconds: number) => number", "examples": [ { "language": "javascript", diff --git a/date/fromSeconds.md b/date/fromSeconds.md index 2f674d1d..1da52d80 100644 --- a/date/fromSeconds.md +++ b/date/fromSeconds.md @@ -4,6 +4,6 @@ ```typescript -(seconds: any) => number +(seconds: number) => number ``` diff --git a/date/fromSeconds.ts b/date/fromSeconds.ts index c0770d78..f19d1e92 100644 --- a/date/fromSeconds.ts +++ b/date/fromSeconds.ts @@ -1 +1 @@ -export default seconds => seconds * 1000; +export default (seconds: number) => seconds * 1000; diff --git a/date/joinDateTime.json b/date/joinDateTime.json index e0ab224e..1c4641a3 100644 --- a/date/joinDateTime.json +++ b/date/joinDateTime.json @@ -1,7 +1,7 @@ { "name": "joinDateTime", "description": "TODO: Fill short description here.", - "signature": "(...xs: any[]) => string", + "signature": "(...xs: string[]) => string", "examples": [ { "language": "javascript", diff --git a/date/joinDateTime.md b/date/joinDateTime.md index 4075dc00..de8bd7a6 100644 --- a/date/joinDateTime.md +++ b/date/joinDateTime.md @@ -4,6 +4,6 @@ ```typescript -(...xs: any[]) => string +(...xs: string[]) => string ``` diff --git a/date/joinDateTime.ts b/date/joinDateTime.ts index 328ef7c9..23c1b067 100644 --- a/date/joinDateTime.ts +++ b/date/joinDateTime.ts @@ -1 +1 @@ -export default (...xs) => xs.join("T"); +export default (...xs: string[]) => xs.join("T"); diff --git a/date/leapYear.json b/date/leapYear.json index 72cbaea0..55c89670 100644 --- a/date/leapYear.json +++ b/date/leapYear.json @@ -1,7 +1,7 @@ { "name": "leapYear", "description": "TODO: Fill short description here.", - "signature": "(year: any) => boolean", + "signature": "(year: number) => boolean", "examples": [ { "language": "javascript", diff --git a/date/leapYear.md b/date/leapYear.md index d36cc719..6c5b9c9c 100644 --- a/date/leapYear.md +++ b/date/leapYear.md @@ -4,6 +4,6 @@ ```typescript -(year: any) => boolean +(year: number) => boolean ``` diff --git a/date/leapYear.ts b/date/leapYear.ts index 62ab3314..9009ddcd 100644 --- a/date/leapYear.ts +++ b/date/leapYear.ts @@ -1 +1 @@ -export default year => new Date(year, 1, 29).getMonth() === 1; +export default (year: number) => new Date(year, 1, 29).getMonth() === 1; diff --git a/date/offsetByBit.js b/date/offsetByBit.js index 7581ee97..07a6a757 100644 --- a/date/offsetByBit.js +++ b/date/offsetByBit.js @@ -2,4 +2,4 @@ import fromSeconds from "./fromSeconds.js"; const SECOND = fromSeconds(1); -export default date => new Date(date - SECOND); +export default date => new Date(date.valueOf() - SECOND); diff --git a/date/offsetByBit.json b/date/offsetByBit.json index b88fa0ba..5fd24cad 100644 --- a/date/offsetByBit.json +++ b/date/offsetByBit.json @@ -1,7 +1,7 @@ { "name": "offsetByBit", "description": "TODO: Fill short description here.", - "signature": "(date: any) => Date", + "signature": "(date: number | Date) => Date", "examples": [ { "language": "javascript", diff --git a/date/offsetByBit.md b/date/offsetByBit.md index 0ad50b67..a06f446d 100644 --- a/date/offsetByBit.md +++ b/date/offsetByBit.md @@ -4,6 +4,6 @@ ```typescript -(date: any) => Date +(date: number | Date) => Date ``` diff --git a/date/offsetByBit.ts b/date/offsetByBit.ts index 6df9dd14..0fb12447 100644 --- a/date/offsetByBit.ts +++ b/date/offsetByBit.ts @@ -2,4 +2,4 @@ import fromSeconds from "./fromSeconds"; const SECOND = fromSeconds(1); -export default date => new Date(date - SECOND); +export default (date: Date | number) => new Date(date.valueOf() - SECOND); diff --git a/date/splitDateTime.json b/date/splitDateTime.json index ae00daa1..8ac0b4f2 100644 --- a/date/splitDateTime.json +++ b/date/splitDateTime.json @@ -1,7 +1,7 @@ { "name": "splitDateTime", "description": "TODO: Fill short description here.", - "signature": "(dateTimeString: any) => any", + "signature": "(dateTimeString: string) => string[]", "examples": [ { "language": "javascript", diff --git a/date/splitDateTime.md b/date/splitDateTime.md index 8fc84f93..c3d271cf 100644 --- a/date/splitDateTime.md +++ b/date/splitDateTime.md @@ -4,6 +4,6 @@ ```typescript -(dateTimeString: any) => any +(dateTimeString: string) => string[] ``` diff --git a/date/splitDateTime.ts b/date/splitDateTime.ts index 0b871afb..f781a075 100644 --- a/date/splitDateTime.ts +++ b/date/splitDateTime.ts @@ -1 +1 @@ -export default dateTimeString => dateTimeString.split("T"); +export default (dateTimeString: string) => dateTimeString.split("T"); diff --git a/date/startOfDay.json b/date/startOfDay.json index 51703226..d37e783c 100644 --- a/date/startOfDay.json +++ b/date/startOfDay.json @@ -1,7 +1,7 @@ { "name": "startOfDay", "description": "TODO: Fill short description here.", - "signature": "(\n date: any,\n timezoneOffset?: number,\n local?: boolean\n) => Date", + "signature": "(\n date: string | number | Date,\n timezoneOffset?: number,\n local?: boolean\n) => Date", "examples": [ { "language": "javascript", diff --git a/date/startOfDay.md b/date/startOfDay.md index 22e28d4a..43f4f558 100644 --- a/date/startOfDay.md +++ b/date/startOfDay.md @@ -5,7 +5,7 @@ ```typescript ( - date: any, + date: string | number | Date, timezoneOffset?: number, local?: boolean ) => Date diff --git a/date/startOfDay.ts b/date/startOfDay.ts index 82289a4b..c32f86d5 100644 --- a/date/startOfDay.ts +++ b/date/startOfDay.ts @@ -1,6 +1,10 @@ import toLocalDateTime from "./toLocalDateTime"; -export default (date, timezoneOffset = 0, local = true) => { +export default ( + date: string | number | Date, + timezoneOffset = 0, + local = true +) => { const newDate = new Date(date); newDate.setHours(0, 0, 0, 0); diff --git a/date/subtractDays.json b/date/subtractDays.json index 51bec5c9..fb15ab8f 100644 --- a/date/subtractDays.json +++ b/date/subtractDays.json @@ -1,7 +1,7 @@ { "name": "subtractDays", "description": "TODO: Fill short description here.", - "signature": "(sourceDate: any, numberOfDays: any) => Date", + "signature": "(\n sourceDate: string | number | Date,\n numberOfDays: number\n) => Date", "examples": [ { "language": "javascript", diff --git a/date/subtractDays.md b/date/subtractDays.md index 3e2d05d0..51f6ab60 100644 --- a/date/subtractDays.md +++ b/date/subtractDays.md @@ -4,6 +4,9 @@ ```typescript -(sourceDate: any, numberOfDays: any) => Date +( + sourceDate: string | number | Date, + numberOfDays: number +) => Date ``` diff --git a/date/subtractDays.ts b/date/subtractDays.ts index 3dbbb505..0efa06f3 100644 --- a/date/subtractDays.ts +++ b/date/subtractDays.ts @@ -1,4 +1,4 @@ -export default (sourceDate, numberOfDays) => { +export default (sourceDate: string | number | Date, numberOfDays: number) => { const date = new Date(sourceDate); date.setDate(date.getDate() - numberOfDays); diff --git a/date/toDate.json b/date/toDate.json index 6b36007d..59a70d33 100644 --- a/date/toDate.json +++ b/date/toDate.json @@ -1,7 +1,7 @@ { "name": "toDate", "description": "TODO: Fill short description here.", - "signature": "(date: any) => string", + "signature": "(date: Date) => string", "examples": [ { "language": "javascript", diff --git a/date/toDate.md b/date/toDate.md index 64346443..f0d05cc7 100644 --- a/date/toDate.md +++ b/date/toDate.md @@ -4,6 +4,6 @@ ```typescript -(date: any) => string +(date: Date) => string ``` diff --git a/date/toDate.ts b/date/toDate.ts index 04b7bb21..987c7e9c 100644 --- a/date/toDate.ts +++ b/date/toDate.ts @@ -1,4 +1,4 @@ -export default date => { +export default (date: Date) => { const day = date.getDate(); const month = date.getMonth() + 1; const year = date.getFullYear(); diff --git a/date/toDates.json b/date/toDates.json index 1e8459a0..d2382d71 100644 --- a/date/toDates.json +++ b/date/toDates.json @@ -1,7 +1,7 @@ { "name": "toDates", "description": "TODO: Fill short description here.", - "signature": "(xs: any) => any", + "signature": "(xs: (string | number | Date)[]) => Date[]", "examples": [ { "language": "javascript", diff --git a/date/toDates.md b/date/toDates.md index 225de78f..2464a4b6 100644 --- a/date/toDates.md +++ b/date/toDates.md @@ -4,6 +4,6 @@ ```typescript -(xs: any) => any +(xs: (string | number | Date)[]) => Date[] ``` diff --git a/date/toDates.ts b/date/toDates.ts index 8fb2e180..6490b81b 100644 --- a/date/toDates.ts +++ b/date/toDates.ts @@ -1 +1 @@ -export default xs => xs.map(x => new Date(x)); +export default (xs: (string | number | Date)[]) => xs.map(x => new Date(x)); diff --git a/date/toDays.json b/date/toDays.json index 57e70b9e..f8fb1d70 100644 --- a/date/toDays.json +++ b/date/toDays.json @@ -1,7 +1,7 @@ { "name": "toDays", "description": "TODO: Fill short description here.", - "signature": "(milliseconds: any) => number", + "signature": "(milliseconds: number) => number", "examples": [ { "language": "javascript", diff --git a/date/toDays.md b/date/toDays.md index b748b5f9..984bdaa4 100644 --- a/date/toDays.md +++ b/date/toDays.md @@ -4,6 +4,6 @@ ```typescript -(milliseconds: any) => number +(milliseconds: number) => number ``` diff --git a/date/toDays.ts b/date/toDays.ts index 1d9e7132..cffed990 100644 --- a/date/toDays.ts +++ b/date/toDays.ts @@ -1,3 +1,3 @@ import toHours from "./toHours"; -export default milliseconds => toHours(milliseconds) / 24; +export default (milliseconds: number) => toHours(milliseconds) / 24; diff --git a/date/toHours.json b/date/toHours.json index 7d2eb044..18ccfee2 100644 --- a/date/toHours.json +++ b/date/toHours.json @@ -1,7 +1,7 @@ { "name": "toHours", "description": "TODO: Fill short description here.", - "signature": "(milliseconds: any) => number", + "signature": "(milliseconds: number) => number", "examples": [ { "language": "javascript", diff --git a/date/toHours.md b/date/toHours.md index 1ed852a6..91bbc2b2 100644 --- a/date/toHours.md +++ b/date/toHours.md @@ -4,6 +4,6 @@ ```typescript -(milliseconds: any) => number +(milliseconds: number) => number ``` diff --git a/date/toHours.ts b/date/toHours.ts index 44509b4b..bec1f273 100644 --- a/date/toHours.ts +++ b/date/toHours.ts @@ -1,3 +1,3 @@ import toMinutes from "./toMinutes"; -export default milliseconds => toMinutes(milliseconds) / 60; +export default (milliseconds: number) => toMinutes(milliseconds) / 60; diff --git a/date/toISO.json b/date/toISO.json index d2792866..231ca90f 100644 --- a/date/toISO.json +++ b/date/toISO.json @@ -1,7 +1,7 @@ { "name": "toISO", "description": "TODO: Fill short description here.", - "signature": "(x: any) => any", + "signature": "(x: Date) => string", "examples": [ { "language": "javascript", diff --git a/date/toISO.md b/date/toISO.md index 12d68ca9..49e8839c 100644 --- a/date/toISO.md +++ b/date/toISO.md @@ -4,6 +4,6 @@ ```typescript -(x: any) => any +(x: Date) => string ``` diff --git a/date/toISO.ts b/date/toISO.ts index 9ac56e00..12d68a84 100644 --- a/date/toISO.ts +++ b/date/toISO.ts @@ -1 +1 @@ -export default x => x.toISOString(); +export default (x: Date) => x.toISOString(); diff --git a/date/toISOFromLocalDateTime.json b/date/toISOFromLocalDateTime.json index 671c7b32..b06b6374 100644 --- a/date/toISOFromLocalDateTime.json +++ b/date/toISOFromLocalDateTime.json @@ -1,7 +1,7 @@ { "name": "toISOFromLocalDateTime", "description": "TODO: Fill short description here.", - "signature": "(date: any) => string", + "signature": "(date: Date) => string", "examples": [ { "language": "javascript", diff --git a/date/toISOFromLocalDateTime.md b/date/toISOFromLocalDateTime.md index 20392bf2..7310db3c 100644 --- a/date/toISOFromLocalDateTime.md +++ b/date/toISOFromLocalDateTime.md @@ -4,6 +4,6 @@ ```typescript -(date: any) => string +(date: Date) => string ``` diff --git a/date/toISOFromLocalDateTime.ts b/date/toISOFromLocalDateTime.ts index f4d527df..e3d6016f 100644 --- a/date/toISOFromLocalDateTime.ts +++ b/date/toISOFromLocalDateTime.ts @@ -1,6 +1,6 @@ import fromMinutes from "./fromMinutes"; -export default date => +export default (date: Date) => new Date( date.valueOf() - fromMinutes(date.getTimezoneOffset()) ).toISOString(); diff --git a/date/toLocalDateTime.json b/date/toLocalDateTime.json index a3f43527..a935be42 100644 --- a/date/toLocalDateTime.json +++ b/date/toLocalDateTime.json @@ -1,7 +1,7 @@ { "name": "toLocalDateTime", "description": "TODO: Fill short description here.", - "signature": "(date: any, timezoneOffset?: number) => Date", + "signature": "(date: Date, timezoneOffset?: number) => Date", "examples": [ { "language": "javascript", diff --git a/date/toLocalDateTime.md b/date/toLocalDateTime.md index a9c058c5..679d4a20 100644 --- a/date/toLocalDateTime.md +++ b/date/toLocalDateTime.md @@ -4,6 +4,6 @@ ```typescript -(date: any, timezoneOffset?: number) => Date +(date: Date, timezoneOffset?: number) => Date ``` diff --git a/date/toLocalDateTime.ts b/date/toLocalDateTime.ts index c739d259..7d84958d 100644 --- a/date/toLocalDateTime.ts +++ b/date/toLocalDateTime.ts @@ -1,4 +1,4 @@ import fromMinutes from "./fromMinutes"; -export default (date, timezoneOffset = 0) => +export default (date: Date, timezoneOffset: number = 0) => new Date(date.valueOf() - fromMinutes(timezoneOffset)); diff --git a/date/toMinutes.json b/date/toMinutes.json index a7ecfa08..1bfb4fae 100644 --- a/date/toMinutes.json +++ b/date/toMinutes.json @@ -1,7 +1,7 @@ { "name": "toMinutes", "description": "TODO: Fill short description here.", - "signature": "(milliseconds: any) => number", + "signature": "(milliseconds: number) => number", "examples": [ { "language": "javascript", diff --git a/date/toMinutes.md b/date/toMinutes.md index 74e2fc17..405f5c85 100644 --- a/date/toMinutes.md +++ b/date/toMinutes.md @@ -4,6 +4,6 @@ ```typescript -(milliseconds: any) => number +(milliseconds: number) => number ``` diff --git a/date/toMinutes.ts b/date/toMinutes.ts index 3ef8dcca..fd8f8a28 100644 --- a/date/toMinutes.ts +++ b/date/toMinutes.ts @@ -1,3 +1,3 @@ import toSeconds from "./toSeconds"; -export default milliseconds => toSeconds(milliseconds) / 60; +export default (milliseconds: number) => toSeconds(milliseconds) / 60; diff --git a/date/toSeconds.json b/date/toSeconds.json index bfd03aab..db6b3fc5 100644 --- a/date/toSeconds.json +++ b/date/toSeconds.json @@ -1,7 +1,7 @@ { "name": "toSeconds", "description": "TODO: Fill short description here.", - "signature": "(milliseconds: any) => number", + "signature": "(milliseconds: number) => number", "examples": [ { "language": "javascript", diff --git a/date/toSeconds.md b/date/toSeconds.md index e1adfbcf..003f9fd7 100644 --- a/date/toSeconds.md +++ b/date/toSeconds.md @@ -4,6 +4,6 @@ ```typescript -(milliseconds: any) => number +(milliseconds: number) => number ``` diff --git a/date/toSeconds.ts b/date/toSeconds.ts index 39f86994..eca6e443 100644 --- a/date/toSeconds.ts +++ b/date/toSeconds.ts @@ -1 +1 @@ -export default milliseconds => milliseconds / 1000; +export default (milliseconds: number) => milliseconds / 1000; diff --git a/date/valid.js b/date/valid.js index 83119e28..1e1ee749 100644 --- a/date/valid.js +++ b/date/valid.js @@ -1 +1 @@ -export default date => date && date instanceof Date; +export default date => (date ? date instanceof Date : false); diff --git a/date/valid.json b/date/valid.json index f7e19c9e..314fe758 100644 --- a/date/valid.json +++ b/date/valid.json @@ -1,7 +1,7 @@ { "name": "valid", "description": "TODO: Fill short description here.", - "signature": "(date: any) => boolean", + "signature": "(date?: any) => boolean", "examples": [ { "language": "javascript", diff --git a/date/valid.md b/date/valid.md index e2bfbf14..014ebdd5 100644 --- a/date/valid.md +++ b/date/valid.md @@ -4,6 +4,6 @@ ```typescript -(date: any) => boolean +(date?: any) => boolean ``` diff --git a/date/valid.ts b/date/valid.ts index 83119e28..0f82e166 100644 --- a/date/valid.ts +++ b/date/valid.ts @@ -1 +1 @@ -export default date => date && date instanceof Date; +export default (date?: any): boolean => (date ? date instanceof Date : false); diff --git a/debug/README.md b/debug/README.md index aba589e5..70607335 100644 --- a/debug/README.md +++ b/debug/README.md @@ -21,6 +21,13 @@ Computes a difference between two objects. ```typescript -(obj1: object, obj2: object) => object +( + obj1?: { + [index: string]: any; + }, + obj2?: { + [index: string]: any; + } +) => object ``` diff --git a/debug/assert.ts b/debug/assert.ts index 5638c800..ef948a26 100644 --- a/debug/assert.ts +++ b/debug/assert.ts @@ -22,7 +22,7 @@ const assert = ( } }; -export const throws = (f: () => void): Error => { +export const throws = (f: () => void): Error | undefined => { try { f(); diff --git a/debug/diff.js b/debug/diff.js index a87f7a81..cbd5d75e 100644 --- a/debug/diff.js +++ b/debug/diff.js @@ -41,7 +41,7 @@ const compareValues = (value1, value2) => { }; const diff = (obj1, obj2) => { - if (isValue(obj1) || isValue(obj2)) { + if (!obj1 || !obj2 || isValue(obj1) || isValue(obj2)) { const comparisonResult = compareValues(obj1, obj2); return comparisonResult !== VALUE_UNCHANGED @@ -49,31 +49,31 @@ const diff = (obj1, obj2) => { type: comparisonResult, data: [obj1, obj2] } - : null; + : {}; } const result = {}; for (const key in obj1) { - if (isFunction(obj1[key])) { - continue; - } - - let value2 = undefined; + const value1 = obj1[key]; - if (isDefined(obj2[key])) { - value2 = obj2[key]; + if (isFunction(value1)) { + continue; } - result[key] = diff(obj1[key], value2); + const value2 = obj2[key]; + result[key] = diff(value1, value2); } for (const key in obj2) { - if (isFunction(obj2[key]) || isDefined(result[key])) { + const value2 = obj2[key]; + const existingValue = result[key]; + + if (isFunction(value2) || isDefined(existingValue)) { continue; } - result[key] = diff(undefined, obj2[key]); + result[key] = diff(undefined, value2); } return filter( diff --git a/debug/diff.json b/debug/diff.json index 471e1e00..3047f61b 100644 --- a/debug/diff.json +++ b/debug/diff.json @@ -1,7 +1,7 @@ { "name": "diff", "description": "Computes a difference between two objects.", - "signature": "(obj1: object, obj2: object) => object", + "signature": "(\n obj1?: {\n [index: string]: any;\n },\n obj2?: {\n [index: string]: any;\n }\n) => object", "examples": [ { "language": "javascript", diff --git a/debug/diff.md b/debug/diff.md index ea57e1b3..a0d09d5f 100644 --- a/debug/diff.md +++ b/debug/diff.md @@ -6,6 +6,13 @@ Computes a difference between two objects. ```typescript -(obj1: object, obj2: object) => object +( + obj1?: { + [index: string]: any; + }, + obj2?: { + [index: string]: any; + } +) => object ``` diff --git a/debug/diff.test.ts b/debug/diff.test.ts index 8c62528c..83a9f278 100644 --- a/debug/diff.test.ts +++ b/debug/diff.test.ts @@ -77,4 +77,11 @@ describe("diff", () => { a: { data: [1, 5], type: VALUE_UPDATED } }); }); + + it("detects object deletions", () => { + expect(diff({ a: 1 }, undefined)).toEqual({ + data: [{ a: 1 }, undefined], + type: VALUE_DELETED + }); + }); }); diff --git a/debug/diff.ts b/debug/diff.ts index 4061dada..a560f2fe 100644 --- a/debug/diff.ts +++ b/debug/diff.ts @@ -40,8 +40,11 @@ const compareValues = (value1: any, value2: any) => { return VALUE_UPDATED; }; -const diff = (obj1: object, obj2: object) => { - if (isValue(obj1) || isValue(obj2)) { +const diff = ( + obj1?: { [index: string]: any }, + obj2?: { [index: string]: any } +): object => { + if (!obj1 || !obj2 || isValue(obj1) || isValue(obj2)) { const comparisonResult = compareValues(obj1, obj2); return comparisonResult !== VALUE_UNCHANGED @@ -49,31 +52,33 @@ const diff = (obj1: object, obj2: object) => { type: comparisonResult, data: [obj1, obj2] } - : null; + : {}; } - const result = {}; + const result: { [index: string]: any } = {}; for (const key in obj1) { - if (isFunction(obj1[key])) { + const value1 = obj1[key]; + + if (isFunction(value1)) { continue; } - let value2 = undefined; - - if (isDefined(obj2[key])) { - value2 = obj2[key]; - } + const value2 = obj2[key]; - result[key] = diff(obj1[key], value2); + result[key] = diff(value1, value2); } for (const key in obj2) { - if (isFunction(obj2[key]) || isDefined(result[key])) { + const value2 = obj2[key]; + + const existingValue = result[key]; + + if (isFunction(value2) || isDefined(existingValue)) { continue; } - result[key] = diff(undefined, obj2[key]); + result[key] = diff(undefined, value2); } return filter( diff --git a/encoding/README.md b/encoding/README.md index 08026f4b..78bb2f76 100644 --- a/encoding/README.md +++ b/encoding/README.md @@ -7,15 +7,7 @@ Provides a way to encode strings and bytes from and into Base64URL. ```typescript { - decode: ( - text: string, - context?: { - atob: (byteString: string) => string; - TextDecoder: new (encoding: string) => { - decode: (input?: Uint8Array) => string; - }; - } - ) => string; + decode: (text: string, context?: DecodeContext) => string; decodeBytes: ( text: string, context?: { @@ -34,15 +26,7 @@ Provides a way to encode strings and bytes from and into Base64URL. }; } ) => string; - encodeBytes: ( - bytes: number[], - context?: { - btoa: (byteString: string) => string; - TextEncoder: new () => { - encode: (input?: string) => Uint8Array; - }; - } - ) => string; + encodeBytes: (bytes: number[], context?: EncodeContext) => string; fromByteString: (byteString: string) => number[]; toByteString: (bytes: number[]) => string; } diff --git a/encoding/base64url.js b/encoding/base64url.js index c7e9165e..6c6d1a70 100644 --- a/encoding/base64url.js +++ b/encoding/base64url.js @@ -5,7 +5,7 @@ export const toByteString = bytes => bytes.map(_ => String.fromCharCode(_)).join(""); export const fromByteString = byteString => - [...byteString].map(_ => _.codePointAt(0)); + [...byteString].map(_ => _.codePointAt(0) || 0); const ENCODING = "utf-8"; diff --git a/encoding/base64url.json b/encoding/base64url.json index 78711552..34c52133 100644 --- a/encoding/base64url.json +++ b/encoding/base64url.json @@ -1,7 +1,7 @@ { "name": "base64url", "description": "Provides a way to encode strings and bytes from and into Base64URL.", - "signature": "{\n decode: (\n text: string,\n context?: {\n atob: (byteString: string) => string;\n TextDecoder: new (encoding: string) => {\n decode: (input?: Uint8Array) => string;\n };\n }\n ) => string;\n decodeBytes: (\n text: string,\n context?: {\n atob: (byteString: string) => string;\n TextDecoder: new (encoding: string) => {\n decode: (input?: Uint8Array) => string;\n };\n }\n ) => number[];\n encode: (\n text: string,\n context?: {\n btoa: (byteString: string) => string;\n TextEncoder: new () => {\n encode: (input?: string) => Uint8Array;\n };\n }\n ) => string;\n encodeBytes: (\n bytes: number[],\n context?: {\n btoa: (byteString: string) => string;\n TextEncoder: new () => {\n encode: (input?: string) => Uint8Array;\n };\n }\n ) => string;\n fromByteString: (byteString: string) => number[];\n toByteString: (bytes: number[]) => string;\n}", + "signature": "{\n decode: (text: string, context?: DecodeContext) => string;\n decodeBytes: (\n text: string,\n context?: {\n atob: (byteString: string) => string;\n TextDecoder: new (encoding: string) => {\n decode: (input?: Uint8Array) => string;\n };\n }\n ) => number[];\n encode: (\n text: string,\n context?: {\n btoa: (byteString: string) => string;\n TextEncoder: new () => {\n encode: (input?: string) => Uint8Array;\n };\n }\n ) => string;\n encodeBytes: (bytes: number[], context?: EncodeContext) => string;\n fromByteString: (byteString: string) => number[];\n toByteString: (bytes: number[]) => string;\n}", "examples": [ { "language": "javascript", diff --git a/encoding/base64url.md b/encoding/base64url.md index 08026f4b..78bb2f76 100644 --- a/encoding/base64url.md +++ b/encoding/base64url.md @@ -7,15 +7,7 @@ Provides a way to encode strings and bytes from and into Base64URL. ```typescript { - decode: ( - text: string, - context?: { - atob: (byteString: string) => string; - TextDecoder: new (encoding: string) => { - decode: (input?: Uint8Array) => string; - }; - } - ) => string; + decode: (text: string, context?: DecodeContext) => string; decodeBytes: ( text: string, context?: { @@ -34,15 +26,7 @@ Provides a way to encode strings and bytes from and into Base64URL. }; } ) => string; - encodeBytes: ( - bytes: number[], - context?: { - btoa: (byteString: string) => string; - TextEncoder: new () => { - encode: (input?: string) => Uint8Array; - }; - } - ) => string; + encodeBytes: (bytes: number[], context?: EncodeContext) => string; fromByteString: (byteString: string) => number[]; toByteString: (bytes: number[]) => string; } diff --git a/encoding/base64url.ts b/encoding/base64url.ts index 75b5c93d..98c75bc4 100644 --- a/encoding/base64url.ts +++ b/encoding/base64url.ts @@ -1,23 +1,34 @@ /* eslint-env browser, node */ +export interface EncodeContext { + btoa: (byteString: string) => string; + TextEncoder: new () => { + encode: { (input?: string): Uint8Array }; + }; +} + +export interface DecodeContext { + atob: (byteString: string) => string; + TextDecoder: new (encoding: string) => { + decode: (input?: Uint8Array) => string; + }; +} + const toArray = (typedArray: Uint8Array): number[] => [...typedArray]; export const toByteString = (bytes: number[]) => bytes.map(_ => String.fromCharCode(_)).join(""); -export const fromByteString = (byteString: string) => - [...byteString].map(_ => _.codePointAt(0)); +export const fromByteString = (byteString: string): number[] => + [...byteString].map(_ => _.codePointAt(0) || 0); const ENCODING = "utf-8"; const btoaImplementation = ( text: string, - context: { - btoa: (byteString: string) => string; - TextEncoder: new () => { - encode: { (input?: string): Uint8Array }; - }; - } = typeof window !== "undefined" ? window : undefined + context: EncodeContext | undefined = typeof window !== "undefined" + ? window + : undefined ) => context ? context.btoa( @@ -27,12 +38,9 @@ const btoaImplementation = ( const atobImplementation = ( text: string, - context: { - atob: (byteString: string) => string; - TextDecoder: new (encoding: string) => { - decode: (input?: Uint8Array) => string; - }; - } = typeof window !== "undefined" ? window : undefined + context: DecodeContext | undefined = typeof window !== "undefined" + ? window + : undefined ) => context ? new context.TextDecoder(ENCODING).decode( @@ -52,15 +60,8 @@ export const encode = ( .replace(/\+/g, "-") .replace(/\//g, "_"); -export const decode = ( - text: string, - context?: { - atob: (byteString: string) => string; - TextDecoder: new (encoding: string) => { - decode: (input?: Uint8Array) => string; - }; - } -) => atobImplementation(text.replace(/-/g, "+").replace(/_/g, "/"), context); +export const decode = (text: string, context?: DecodeContext) => + atobImplementation(text.replace(/-/g, "+").replace(/_/g, "/"), context); export const toBase64Url = (base64: string) => base64.replace(/\+/g, "-").replace(/\//g, "_"); @@ -68,13 +69,7 @@ export const toBase64Url = (base64: string) => export const fromBase64Url = (base64: string) => base64.replace(/-/g, "+").replace(/_/g, "/"); -export const encodeBytes = ( - bytes: number[], - context?: { - btoa: (byteString: string) => string; - TextEncoder: new () => { encode: (input?: string) => Uint8Array }; - } -) => { +export const encodeBytes = (bytes: number[], context?: EncodeContext) => { const sourceText = toByteString(bytes); return encode(sourceText, context); diff --git a/function/memoizeWith.ts b/function/memoizeWith.ts index 099dcf22..12f09e9a 100644 --- a/function/memoizeWith.ts +++ b/function/memoizeWith.ts @@ -1,10 +1,10 @@ export default (equals: (x: any, y: any) => boolean) => ( f: (...xs: any[]) => any ) => { - let memoized = undefined; - let memoizedArgs = undefined; + let memoized: any = undefined; + let memoizedArgs: any[] | undefined = undefined; - return (...args) => { + return (...args: any[]) => { if (memoized && equals(args, memoizedArgs)) { return memoized; } diff --git a/is/README.md b/is/README.md index d0d174b9..7b2cf479 100644 --- a/is/README.md +++ b/is/README.md @@ -94,6 +94,18 @@ Checks if given value is an integer. ``` +# nonNullable + +Checks and asserts the given value is not a null or undefined. + +## Type signature + + +```typescript +(val: T) => val is NonNullable +``` + + # normal Checks if the given value is a number in a normal range [0, 1]. diff --git a/is/byte.js b/is/byte.js index b25231df..2d422193 100644 --- a/is/byte.js +++ b/is/byte.js @@ -1,3 +1,4 @@ import integer from "./integer.js"; +import nonNullable from "./nonNullable.js"; -export default x => integer(x) && x >= 0 && x <= 255; +export default x => nonNullable(x) && integer(x) && x >= 0 && x <= 255; diff --git a/is/byte.ts b/is/byte.ts index 6afe9f0d..7eded0d0 100644 --- a/is/byte.ts +++ b/is/byte.ts @@ -1,3 +1,5 @@ import integer from "./integer"; +import nonNullable from "./nonNullable"; -export default (x?: number) => integer(x) && x >= 0 && x <= 255; +export default (x?: number) => + nonNullable(x) && integer(x) && x >= 0 && x <= 255; diff --git a/is/index.js b/is/index.js index 2880557e..84d2ff61 100644 --- a/is/index.js +++ b/is/index.js @@ -4,6 +4,7 @@ import date from "./date.js"; import defined from "./defined.js"; import _function from "./function.js"; import integer from "./integer.js"; +import nonNullable from "./nonNullable.js"; import normal from "./normal.js"; import number from "./number.js"; import object from "./object.js"; @@ -16,6 +17,7 @@ export { defined, _function, integer, + nonNullable, normal, number, object, @@ -29,6 +31,7 @@ export default { defined, _function, integer, + nonNullable, normal, number, object, diff --git a/is/index.ts b/is/index.ts index 0a1a25d4..524c029d 100644 --- a/is/index.ts +++ b/is/index.ts @@ -4,6 +4,7 @@ import date from "./date"; import defined from "./defined"; import _function from "./function"; import integer from "./integer"; +import nonNullable from "./nonNullable"; import normal from "./normal"; import number from "./number"; import object from "./object"; @@ -16,6 +17,7 @@ export { defined, _function, integer, + nonNullable, normal, number, object, @@ -29,6 +31,7 @@ export default { defined, _function, integer, + nonNullable, normal, number, object, diff --git a/is/integer.js b/is/integer.js index b79db0fd..21e7e213 100644 --- a/is/integer.js +++ b/is/integer.js @@ -1,3 +1,4 @@ import number from "./number.js"; +import nonNullable from "./nonNullable.js"; -export default x => number(x) && Math.floor(x) === x; +export default x => nonNullable(x) && number(x) && Math.floor(x) === x; diff --git a/is/integer.ts b/is/integer.ts index 1cba338e..47aa7d65 100644 --- a/is/integer.ts +++ b/is/integer.ts @@ -1,3 +1,5 @@ import number from "./number"; +import nonNullable from "./nonNullable"; -export default (x?: number) => number(x) && Math.floor(x) === x; +export default (x?: number) => + nonNullable(x) && number(x) && Math.floor(x) === x; diff --git a/is/nonNullable.js b/is/nonNullable.js new file mode 100644 index 00000000..6de4af85 --- /dev/null +++ b/is/nonNullable.js @@ -0,0 +1 @@ +export default val => val !== undefined && val !== null; diff --git a/is/nonNullable.json b/is/nonNullable.json new file mode 100644 index 00000000..a4eb5f36 --- /dev/null +++ b/is/nonNullable.json @@ -0,0 +1,12 @@ +{ + "name": "nonNullable", + "description": "Checks and asserts the given value is not a null or undefined.", + "signature": "(val: T) => val is NonNullable", + "examples": [ + { + "language": "javascript", + "content": "nonNullable(); // ⇒ TODO" + } + ], + "questions": ["TODO: List questions that may this function answers."] +} diff --git a/is/nonNullable.md b/is/nonNullable.md new file mode 100644 index 00000000..c45d8e8f --- /dev/null +++ b/is/nonNullable.md @@ -0,0 +1,11 @@ +# nonNullable + +Checks and asserts the given value is not a null or undefined. + +## Type signature + + +```typescript +(val: T) => val is NonNullable +``` + diff --git a/is/nonNullable.test.ts b/is/nonNullable.test.ts new file mode 100644 index 00000000..7e75f049 --- /dev/null +++ b/is/nonNullable.test.ts @@ -0,0 +1,25 @@ +/* eslint-env jest */ +// @ts-ignore ambiguous import +import nonNullable from "./nonNullable.ts"; + +describe("nonNullable", () => { + it("checks and asserts the given value is not a null or undefined", () => { + expect(nonNullable(undefined)).toBe(false); + expect(nonNullable(null)).toBe(false); + + expect(nonNullable(false)).toBe(true); + expect(nonNullable(0)).toBe(true); + expect(nonNullable("")).toBe(true); + + expect(nonNullable({})).toBe(true); + expect(nonNullable([])).toBe(true); + expect(nonNullable(NaN)).toBe(true); + expect(nonNullable(() => {})).toBe(true); + + expect(nonNullable("test")).toBe(true); + expect(nonNullable([1, 2, 3])).toBe(true); + expect(nonNullable({ a: 1, b: 2, c: 3 })).toBe(true); + expect(nonNullable(17.6)).toBe(true); + expect(nonNullable(Math.min)).toBe(true); + }); +}); diff --git a/is/nonNullable.ts b/is/nonNullable.ts new file mode 100644 index 00000000..7979cfd9 --- /dev/null +++ b/is/nonNullable.ts @@ -0,0 +1,2 @@ +export default (val: T): val is NonNullable => + val !== undefined && val !== null; diff --git a/is/normal.js b/is/normal.js index 284b2b93..16332193 100644 --- a/is/normal.js +++ b/is/normal.js @@ -1,3 +1,4 @@ import number from "./number.js"; +import nonNullable from "./nonNullable.js"; -export default x => number(x) && x >= 0 && x <= 1; +export default x => nonNullable(x) && number(x) && x >= 0 && x <= 1; diff --git a/is/normal.ts b/is/normal.ts index 2dc02f68..c75bd259 100644 --- a/is/normal.ts +++ b/is/normal.ts @@ -1,3 +1,4 @@ import number from "./number"; +import nonNullable from "./nonNullable"; -export default (x?: number) => number(x) && x >= 0 && x <= 1; +export default (x?: number) => nonNullable(x) && number(x) && x >= 0 && x <= 1; diff --git a/is/number.js b/is/number.js index 819511f5..492cfe77 100644 --- a/is/number.js +++ b/is/number.js @@ -1,2 +1,7 @@ +import nonNullable from "./nonNullable.js"; + export default x => - typeof x === "number" && !Number.isNaN(x) && Number.isFinite(x); + nonNullable(x) && + typeof x === "number" && + !Number.isNaN(x) && + Number.isFinite(x); diff --git a/is/number.ts b/is/number.ts index 102e7de3..f67dc8e9 100644 --- a/is/number.ts +++ b/is/number.ts @@ -1,2 +1,7 @@ +import nonNullable from "./nonNullable"; + export default (x?: any) => - typeof x === "number" && !Number.isNaN(x) && Number.isFinite(x); + nonNullable(x) && + typeof x === "number" && + !Number.isNaN(x) && + Number.isFinite(x); diff --git a/math/median.ts b/math/median.ts index a34e2de1..b332b629 100644 --- a/math/median.ts +++ b/math/median.ts @@ -1,7 +1,7 @@ import sort from "../array/sort"; import subtract from "./subtract"; -export default (xs?: number[]): number => { +export default (xs?: number[]): number | undefined => { if (!xs || xs.length === 0) { return undefined; } diff --git a/object/README.md b/object/README.md index e4f57227..3a155675 100644 --- a/object/README.md +++ b/object/README.md @@ -297,7 +297,12 @@ Merges two objects deeply. ```typescript -(a: object, b: object) => object +( + a: { + [index: string]: any; + }, + b: object +) => object ``` @@ -341,6 +346,8 @@ Sorts the given object by a comparator. ```typescript -(f: any) => (xs: any) => object +( + f: (a: any, b: any) => number +) => (xs: object) => object ``` diff --git a/object/merge.js b/object/merge.js index 24fc832b..3a428175 100644 --- a/object/merge.js +++ b/object/merge.js @@ -1,12 +1,13 @@ +import isNonNullable from "../is/nonNullable.js"; import isObject from "../is/object.js"; import map from "./map.js"; -const isNonNullishObject = x => x !== undefined && x !== null && isObject(x); +const isNonNullableObject = x => isNonNullable(x) && isObject(x); const merge = (a, b) => ({ ...a, ...map((value, key) => - isNonNullishObject(value) && isNonNullishObject(a[key]) + isNonNullableObject(value) && isNonNullableObject(a[key]) ? merge(a[key], value) : value )(b) diff --git a/object/merge.json b/object/merge.json index 8538d2ac..abd1806f 100644 --- a/object/merge.json +++ b/object/merge.json @@ -1,7 +1,7 @@ { "name": "merge", "description": "Merges two objects deeply.", - "signature": "(a: object, b: object) => object", + "signature": "(\n a: {\n [index: string]: any;\n },\n b: object\n) => object", "examples": [ { "language": "javascript", diff --git a/object/merge.md b/object/merge.md index d74ed2cd..6966e81a 100644 --- a/object/merge.md +++ b/object/merge.md @@ -6,7 +6,12 @@ Merges two objects deeply. ```typescript -(a: object, b: object) => object +( + a: { + [index: string]: any; + }, + b: object +) => object ``` diff --git a/object/merge.ts b/object/merge.ts index 7664e921..157c8c3a 100644 --- a/object/merge.ts +++ b/object/merge.ts @@ -1,13 +1,13 @@ +import isNonNullable from "../is/nonNullable"; import isObject from "../is/object"; import map from "./map"; -const isNonNullishObject = (x?: object) => - x !== undefined && x !== null && isObject(x); +const isNonNullableObject = (x?: object) => isNonNullable(x) && isObject(x); -const merge = (a: object, b: object): object => ({ +const merge = (a: { [index: string]: any }, b: object): object => ({ ...a, ...map((value, key) => - isNonNullishObject(value) && isNonNullishObject(a[key]) + isNonNullableObject(value) && isNonNullableObject(a[key]) ? merge(a[key], value) : value )(b) diff --git a/object/sort.json b/object/sort.json index 423a3e4a..2f1bbb63 100644 --- a/object/sort.json +++ b/object/sort.json @@ -1,7 +1,7 @@ { "name": "sort", "description": "Sorts the given object by a comparator.", - "signature": "(f: any) => (xs: any) => object", + "signature": "(\n f: (a: any, b: any) => number\n) => (xs: object) => object", "examples": [ { "language": "javascript", diff --git a/object/sort.md b/object/sort.md index d6515960..0e678206 100644 --- a/object/sort.md +++ b/object/sort.md @@ -6,6 +6,8 @@ Sorts the given object by a comparator. ```typescript -(f: any) => (xs: any) => object +( + f: (a: any, b: any) => number +) => (xs: object) => object ``` diff --git a/object/sort.ts b/object/sort.ts index ce7b9167..31e9848e 100644 --- a/object/sort.ts +++ b/object/sort.ts @@ -2,5 +2,5 @@ import sort from "../array/sort"; import entries from "./entries"; import fromEntries from "./fromEntries"; -export default f => xs => +export default (f: (a: any, b: any) => number) => (xs: object): object => fromEntries(sort(([, a], [, b]) => f(a, b))(entries(xs))); diff --git a/query/README.md b/query/README.md index 5dbadca9..2ab9105d 100644 --- a/query/README.md +++ b/query/README.md @@ -30,6 +30,6 @@ Serializes the given object into a query string. ```typescript -(xs?: {}) => string +(xs?: { [index: string]: any }) => string ``` diff --git a/query/serialize.js b/query/serialize.js index 130a257e..681ea6b9 100644 --- a/query/serialize.js +++ b/query/serialize.js @@ -3,7 +3,7 @@ import entries from "../object/entries.js"; export default (xs = {}) => entries(xs) .filter(([, value]) => Boolean(value) || value === 0) - .map(pair => pair.map(encodeURIComponent)) + .map(pair => pair.map(value => encodeURIComponent(value))) .reduce( (acc, [key, value]) => [ ...acc, diff --git a/query/serialize.json b/query/serialize.json index 041609ef..3d7f3e50 100644 --- a/query/serialize.json +++ b/query/serialize.json @@ -1,7 +1,7 @@ { "name": "serialize", "description": "Serializes the given object into a query string.", - "signature": "(xs?: {}) => string", + "signature": "(xs?: { [index: string]: any }) => string", "examples": [ { "language": "javascript", diff --git a/query/serialize.md b/query/serialize.md index 489d0be2..64666971 100644 --- a/query/serialize.md +++ b/query/serialize.md @@ -6,6 +6,6 @@ Serializes the given object into a query string. ```typescript -(xs?: {}) => string +(xs?: { [index: string]: any }) => string ``` diff --git a/query/serialize.ts b/query/serialize.ts index 91ce6262..bd01c100 100644 --- a/query/serialize.ts +++ b/query/serialize.ts @@ -1,9 +1,9 @@ import entries from "../object/entries"; -export default (xs = {}) => +export default (xs: { [index: string]: any } = {}): string => entries(xs) .filter(([, value]) => Boolean(value) || value === 0) - .map(pair => pair.map(encodeURIComponent)) + .map(pair => pair.map(value => encodeURIComponent(value))) .reduce( (acc, [key, value]) => [ ...acc, diff --git a/range/README.md b/range/README.md index 8f3eab5e..34683952 100644 --- a/range/README.md +++ b/range/README.md @@ -6,7 +6,7 @@ Checks if the given range is empty. ```typescript -([min, max]: [any, any]) => boolean +([min, max]: [number, number]) => boolean ``` @@ -27,7 +27,10 @@ Checks if the given ranges are equal. ```typescript -([a, b]: [any, any], [c, d]: [any, any]) => boolean +( + [a, b]: [number, number], + [c, d]: [number, number] +) => boolean ``` @@ -39,7 +42,7 @@ Computes the signed length of the given range. ```typescript -([min, max]: [any, any]) => number +([min, max]: [number, number]) => number ``` diff --git a/range/empty.json b/range/empty.json index 63c09b2a..b6a44e18 100644 --- a/range/empty.json +++ b/range/empty.json @@ -1,7 +1,7 @@ { "name": "empty", "description": "Checks if the given range is empty.", - "signature": "([min, max]: [any, any]) => boolean", + "signature": "([min, max]: [number, number]) => boolean", "examples": [ { "language": "javascript", diff --git a/range/empty.md b/range/empty.md index 16fda656..902a2436 100644 --- a/range/empty.md +++ b/range/empty.md @@ -6,7 +6,7 @@ Checks if the given range is empty. ```typescript -([min, max]: [any, any]) => boolean +([min, max]: [number, number]) => boolean ``` diff --git a/range/empty.ts b/range/empty.ts index 71065567..d607d8aa 100644 --- a/range/empty.ts +++ b/range/empty.ts @@ -1 +1 @@ -export default ([min, max]) => min === max; +export default ([min, max]: [number, number]): boolean => min === max; diff --git a/range/equals.json b/range/equals.json index 6e0992e8..c4023ff4 100644 --- a/range/equals.json +++ b/range/equals.json @@ -1,7 +1,7 @@ { "name": "equals", "description": "Checks if the given ranges are equal.", - "signature": "([a, b]: [any, any], [c, d]: [any, any]) => boolean", + "signature": "(\n [a, b]: [number, number],\n [c, d]: [number, number]\n) => boolean", "examples": [ { "language": "javascript", diff --git a/range/equals.md b/range/equals.md index 0210ff5a..2fd47b77 100644 --- a/range/equals.md +++ b/range/equals.md @@ -6,6 +6,9 @@ Checks if the given ranges are equal. ```typescript -([a, b]: [any, any], [c, d]: [any, any]) => boolean +( + [a, b]: [number, number], + [c, d]: [number, number] +) => boolean ``` diff --git a/range/equals.ts b/range/equals.ts index ab5c1860..2527842e 100644 --- a/range/equals.ts +++ b/range/equals.ts @@ -1 +1,2 @@ -export default ([a, b], [c, d]) => a === c && b === d; +export default ([a, b]: [number, number], [c, d]: [number, number]): boolean => + a === c && b === d; diff --git a/range/length.json b/range/length.json index 5436cc92..af5a5465 100644 --- a/range/length.json +++ b/range/length.json @@ -1,7 +1,7 @@ { "name": "length", "description": "Computes the signed length of the given range.", - "signature": "([min, max]: [any, any]) => number", + "signature": "([min, max]: [number, number]) => number", "examples": [ { "language": "javascript", diff --git a/range/length.md b/range/length.md index dc0e39a3..a8b8dc28 100644 --- a/range/length.md +++ b/range/length.md @@ -6,6 +6,6 @@ Computes the signed length of the given range. ```typescript -([min, max]: [any, any]) => number +([min, max]: [number, number]) => number ``` diff --git a/range/length.ts b/range/length.ts index 3961ffcd..1963a21b 100644 --- a/range/length.ts +++ b/range/length.ts @@ -1 +1 @@ -export default ([min, max]) => max - min; +export default ([min, max]: [number, number]): number => max - min; diff --git a/tsconfig.json b/tsconfig.json index bc4c76cd..85e96f61 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,9 +2,10 @@ "compilerOptions": { "module": "ES6", "noImplicitAny": true, - "removeComments": true, "preserveConstEnums": true, + "removeComments": true, "sourceMap": true, + "strict": true, "target": "ES2020" } } diff --git a/vector2/README.md b/vector2/README.md index 0f2cf614..7dc3a640 100644 --- a/vector2/README.md +++ b/vector2/README.md @@ -40,7 +40,10 @@ Calculates a cross product of the given vectors. Returns a scalar. ```typescript -([a, b]: [any, any], [c, d]: [any, any]) => number +( + [a, b]: [number, number], + [c, d]: [number, number] +) => number ``` @@ -52,7 +55,10 @@ Calculates a dot product of the given vectors. Returns a scalar. ```typescript -([a, b]: [any, any], [c, d]: [any, any]) => number +( + [a, b]: [number, number], + [c, d]: [number, number] +) => number ``` @@ -141,7 +147,7 @@ Normalizes the given vector. Returns [0, 0] vector for points. ```typescript -(vector: [number, number]) => number[] +(vector: [number, number]) => [number, number] ``` diff --git a/vector2/cross.json b/vector2/cross.json index ce55aa65..9214f26a 100644 --- a/vector2/cross.json +++ b/vector2/cross.json @@ -1,7 +1,7 @@ { "name": "cross", "description": "Calculates a cross product of the given vectors. Returns a scalar.", - "signature": "([a, b]: [any, any], [c, d]: [any, any]) => number", + "signature": "(\n [a, b]: [number, number],\n [c, d]: [number, number]\n) => number", "examples": [ { "language": "javascript", diff --git a/vector2/cross.md b/vector2/cross.md index ee43d9e1..72f7b55b 100644 --- a/vector2/cross.md +++ b/vector2/cross.md @@ -6,6 +6,9 @@ Calculates a cross product of the given vectors. Returns a scalar. ```typescript -([a, b]: [any, any], [c, d]: [any, any]) => number +( + [a, b]: [number, number], + [c, d]: [number, number] +) => number ``` diff --git a/vector2/cross.ts b/vector2/cross.ts index 327ae4d7..6b3fe15c 100644 --- a/vector2/cross.ts +++ b/vector2/cross.ts @@ -1 +1,2 @@ -export default ([a, b], [c, d]) => a * d - b * c; +export default ([a, b]: [number, number], [c, d]: [number, number]): number => + a * d - b * c; diff --git a/vector2/dot.json b/vector2/dot.json index a61d5e30..1052dc37 100644 --- a/vector2/dot.json +++ b/vector2/dot.json @@ -1,7 +1,7 @@ { "name": "dot", "description": "Calculates a dot product of the given vectors. Returns a scalar.", - "signature": "([a, b]: [any, any], [c, d]: [any, any]) => number", + "signature": "(\n [a, b]: [number, number],\n [c, d]: [number, number]\n) => number", "examples": [ { "language": "javascript", diff --git a/vector2/dot.md b/vector2/dot.md index f307618b..bee5beb8 100644 --- a/vector2/dot.md +++ b/vector2/dot.md @@ -6,6 +6,9 @@ Calculates a dot product of the given vectors. Returns a scalar. ```typescript -([a, b]: [any, any], [c, d]: [any, any]) => number +( + [a, b]: [number, number], + [c, d]: [number, number] +) => number ``` diff --git a/vector2/dot.ts b/vector2/dot.ts index c18e85fe..bc211e9e 100644 --- a/vector2/dot.ts +++ b/vector2/dot.ts @@ -1 +1,2 @@ -export default ([a, b], [c, d]) => a * c + b * d; +export default ([a, b]: [number, number], [c, d]: [number, number]): number => + a * c + b * d; diff --git a/vector2/normalize.js b/vector2/normalize.js index 49c0c810..c843a3d6 100644 --- a/vector2/normalize.js +++ b/vector2/normalize.js @@ -2,6 +2,7 @@ import length from "./length.js"; export default vector => { const magnitude = length(vector); + const [x, y] = vector; - return magnitude !== 0 ? vector.map(_ => _ / magnitude) : vector; + return magnitude !== 0 ? [x / magnitude, y / magnitude] : vector; }; diff --git a/vector2/normalize.json b/vector2/normalize.json index a81ef5de..026e6a0e 100644 --- a/vector2/normalize.json +++ b/vector2/normalize.json @@ -1,7 +1,7 @@ { "name": "normalize", "description": "Normalizes the given vector. Returns [0, 0] vector for points.", - "signature": "(vector: [number, number]) => number[]", + "signature": "(vector: [number, number]) => [number, number]", "examples": [ { "language": "javascript", diff --git a/vector2/normalize.md b/vector2/normalize.md index 17717177..04849d18 100644 --- a/vector2/normalize.md +++ b/vector2/normalize.md @@ -6,6 +6,6 @@ Normalizes the given vector. Returns [0, 0] vector for points. ```typescript -(vector: [number, number]) => number[] +(vector: [number, number]) => [number, number] ``` diff --git a/vector2/normalize.ts b/vector2/normalize.ts index 0a6954ab..d9c9da03 100644 --- a/vector2/normalize.ts +++ b/vector2/normalize.ts @@ -1,7 +1,9 @@ import length from "./length"; -export default (vector: [number, number]) => { +export default (vector: [number, number]): [number, number] => { const magnitude = length(vector); - return magnitude !== 0 ? vector.map(_ => _ / magnitude) : vector; + const [x, y] = vector; + + return magnitude !== 0 ? [x / magnitude, y / magnitude] : vector; }; diff --git a/web/README.md b/web/README.md index a8c5128e..a20ace5e 100644 --- a/web/README.md +++ b/web/README.md @@ -41,10 +41,10 @@ Tests if the current event seems like an intent to open a new tab. Useful for cl metaKey, shiftKey }: { - button: any; - ctrlKey: any; - metaKey: any; - shiftKey: any; + button?: number; + ctrlKey?: boolean; + metaKey?: boolean; + shiftKey?: boolean; }) => boolean ``` diff --git a/web/events/README.md b/web/events/README.md index cc6dbfb7..f487b478 100644 --- a/web/events/README.md +++ b/web/events/README.md @@ -27,10 +27,10 @@ Tests if the current event seems like an intent to open a new tab. Useful for cl metaKey, shiftKey }: { - button: any; - ctrlKey: any; - metaKey: any; - shiftKey: any; + button?: number; + ctrlKey?: boolean; + metaKey?: boolean; + shiftKey?: boolean; }) => boolean ``` diff --git a/web/events/openInNewTabIntent.json b/web/events/openInNewTabIntent.json index aef9d1bb..4e5b4791 100644 --- a/web/events/openInNewTabIntent.json +++ b/web/events/openInNewTabIntent.json @@ -1,7 +1,7 @@ { "name": "openInNewTabIntent", "description": "Tests if the current event seems like an intent to open a new tab. Useful for client-side navigation handling.", - "signature": "({\n button,\n ctrlKey,\n metaKey,\n shiftKey\n}: {\n button: any;\n ctrlKey: any;\n metaKey: any;\n shiftKey: any;\n}) => boolean", + "signature": "({\n button,\n ctrlKey,\n metaKey,\n shiftKey\n}: {\n button?: number;\n ctrlKey?: boolean;\n metaKey?: boolean;\n shiftKey?: boolean;\n}) => boolean", "examples": [ { "language": "javascript", diff --git a/web/events/openInNewTabIntent.md b/web/events/openInNewTabIntent.md index 93b3f02a..2e522bc7 100644 --- a/web/events/openInNewTabIntent.md +++ b/web/events/openInNewTabIntent.md @@ -12,10 +12,10 @@ Tests if the current event seems like an intent to open a new tab. Useful for cl metaKey, shiftKey }: { - button: any; - ctrlKey: any; - metaKey: any; - shiftKey: any; + button?: number; + ctrlKey?: boolean; + metaKey?: boolean; + shiftKey?: boolean; }) => boolean ``` diff --git a/web/events/openInNewTabIntent.ts b/web/events/openInNewTabIntent.ts index a44945b7..5dba11d4 100644 --- a/web/events/openInNewTabIntent.ts +++ b/web/events/openInNewTabIntent.ts @@ -1,2 +1,11 @@ -export default ({ button, ctrlKey, metaKey, shiftKey }) => - Boolean(ctrlKey || shiftKey || metaKey || button === 1); +export default ({ + button, + ctrlKey, + metaKey, + shiftKey +}: { + button?: number; + ctrlKey?: boolean; + metaKey?: boolean; + shiftKey?: boolean; +}) => Boolean(ctrlKey || shiftKey || metaKey || button === 1);