From dfa2e41ed3e6c44134f3e2a0a42e64ad4fdf2af7 Mon Sep 17 00:00:00 2001 From: Florian Keller Date: Wed, 10 Jul 2019 23:17:52 +0200 Subject: [PATCH] Add types for sudokus (#36800) --- types/sudokus/index.d.ts | 17 +++++++++++++++++ types/sudokus/sudokus-tests.ts | 21 +++++++++++++++++++++ types/sudokus/tsconfig.json | 23 +++++++++++++++++++++++ types/sudokus/tslint.json | 1 + 4 files changed, 62 insertions(+) create mode 100644 types/sudokus/index.d.ts create mode 100644 types/sudokus/sudokus-tests.ts create mode 100644 types/sudokus/tsconfig.json create mode 100644 types/sudokus/tslint.json diff --git a/types/sudokus/index.d.ts b/types/sudokus/index.d.ts new file mode 100644 index 0000000000..8aa3c9cb97 --- /dev/null +++ b/types/sudokus/index.d.ts @@ -0,0 +1,17 @@ +// Type definitions for sudokus 1.0 +// Project: https://github.com/Moeriki/node-sudokus#readme +// Definitions by: Florian Keller +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export type ProgressFn = (state: Cell[][]) => void; + +export interface Cell { + fixed: boolean; + value: number; +} + +export interface Options { + onProgress?: ProgressFn; +} + +export function solve(data: number[][], options?: Options): number[][]; diff --git a/types/sudokus/sudokus-tests.ts b/types/sudokus/sudokus-tests.ts new file mode 100644 index 0000000000..10be98c344 --- /dev/null +++ b/types/sudokus/sudokus-tests.ts @@ -0,0 +1,21 @@ +import { solve, ProgressFn, Cell } from 'sudokus'; + +const onProgress: ProgressFn = (cell: Cell[][]) => { + cell[0][0].fixed; + cell[0][0].value; +}; + +solve( + [ + [0, 0, 0, 2, 9, 0, 1, 0, 0], + [6, 0, 0, 5, 0, 1, 0, 7, 0], + [0, 0, 0, 0, 0, 0, 0, 3, 4], + [0, 0, 0, 0, 0, 0, 9, 4, 0], + [4, 5, 0, 3, 0, 0, 0, 6, 2], + [2, 0, 9, 0, 0, 4, 3, 1, 0], + [0, 2, 0, 0, 0, 0, 4, 9, 0], + [0, 0, 6, 0, 0, 8, 0, 0, 0], + [0, 4, 3, 0, 2, 0, 0, 8, 7], + ], + { onProgress } +); diff --git a/types/sudokus/tsconfig.json b/types/sudokus/tsconfig.json new file mode 100644 index 0000000000..8002d5900a --- /dev/null +++ b/types/sudokus/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "sudokus-tests.ts" + ] +} diff --git a/types/sudokus/tslint.json b/types/sudokus/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/sudokus/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }