@fgv/ts-sudoku-lib 2.0.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/cspell.json +13 -0
- package/dist/ts-sudoku-lib.d.ts +763 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +59 -0
- package/lib/index.js.map +1 -0
- package/lib/packlets/collections/collections.d.ts +55 -0
- package/lib/packlets/collections/collections.d.ts.map +1 -0
- package/lib/packlets/collections/collections.js +137 -0
- package/lib/packlets/collections/collections.js.map +1 -0
- package/lib/packlets/collections/data/puzzles.json +61 -0
- package/lib/packlets/collections/index.d.ts +2 -0
- package/lib/packlets/collections/index.d.ts.map +1 -0
- package/lib/packlets/collections/index.js +41 -0
- package/lib/packlets/collections/index.js.map +1 -0
- package/lib/packlets/common/cage.d.ts +23 -0
- package/lib/packlets/common/cage.d.ts.map +1 -0
- package/lib/packlets/common/cage.js +87 -0
- package/lib/packlets/common/cage.js.map +1 -0
- package/lib/packlets/common/cell.d.ts +34 -0
- package/lib/packlets/common/cell.d.ts.map +1 -0
- package/lib/packlets/common/cell.js +92 -0
- package/lib/packlets/common/cell.js.map +1 -0
- package/lib/packlets/common/common.d.ts +77 -0
- package/lib/packlets/common/common.d.ts.map +1 -0
- package/lib/packlets/common/common.js +49 -0
- package/lib/packlets/common/common.js.map +1 -0
- package/lib/packlets/common/converters.d.ts +24 -0
- package/lib/packlets/common/converters.d.ts.map +1 -0
- package/lib/packlets/common/converters.js +73 -0
- package/lib/packlets/common/converters.js.map +1 -0
- package/lib/packlets/common/ids.d.ts +15 -0
- package/lib/packlets/common/ids.d.ts.map +1 -0
- package/lib/packlets/common/ids.js +107 -0
- package/lib/packlets/common/ids.js.map +1 -0
- package/lib/packlets/common/index.d.ts +12 -0
- package/lib/packlets/common/index.d.ts.map +1 -0
- package/lib/packlets/common/index.js +65 -0
- package/lib/packlets/common/index.js.map +1 -0
- package/lib/packlets/common/model.d.ts +15 -0
- package/lib/packlets/common/model.d.ts.map +1 -0
- package/lib/packlets/common/model.js +26 -0
- package/lib/packlets/common/model.js.map +1 -0
- package/lib/packlets/common/public.d.ts +65 -0
- package/lib/packlets/common/public.d.ts.map +1 -0
- package/lib/packlets/common/public.js +26 -0
- package/lib/packlets/common/public.js.map +1 -0
- package/lib/packlets/common/puzzle.d.ts +99 -0
- package/lib/packlets/common/puzzle.d.ts.map +1 -0
- package/lib/packlets/common/puzzle.js +389 -0
- package/lib/packlets/common/puzzle.js.map +1 -0
- package/lib/packlets/common/puzzleSession.d.ts +214 -0
- package/lib/packlets/common/puzzleSession.d.ts.map +1 -0
- package/lib/packlets/common/puzzleSession.js +361 -0
- package/lib/packlets/common/puzzleSession.js.map +1 -0
- package/lib/packlets/common/puzzleState.d.ts +52 -0
- package/lib/packlets/common/puzzleState.d.ts.map +1 -0
- package/lib/packlets/common/puzzleState.js +100 -0
- package/lib/packlets/common/puzzleState.js.map +1 -0
- package/lib/packlets/file/converters.d.ts +17 -0
- package/lib/packlets/file/converters.d.ts.map +1 -0
- package/lib/packlets/file/converters.js +49 -0
- package/lib/packlets/file/converters.js.map +1 -0
- package/lib/packlets/file/index.d.ts +4 -0
- package/lib/packlets/file/index.d.ts.map +1 -0
- package/lib/packlets/file/index.js +54 -0
- package/lib/packlets/file/index.js.map +1 -0
- package/lib/packlets/file/model.d.ts +9 -0
- package/lib/packlets/file/model.d.ts.map +1 -0
- package/lib/packlets/file/model.js +26 -0
- package/lib/packlets/file/model.js.map +1 -0
- package/lib/packlets/puzzles/anyPuzzle.d.ts +10 -0
- package/lib/packlets/puzzles/anyPuzzle.d.ts.map +1 -0
- package/lib/packlets/puzzles/anyPuzzle.js +51 -0
- package/lib/packlets/puzzles/anyPuzzle.js.map +1 -0
- package/lib/packlets/puzzles/index.d.ts +6 -0
- package/lib/packlets/puzzles/index.d.ts.map +1 -0
- package/lib/packlets/puzzles/index.js +35 -0
- package/lib/packlets/puzzles/index.js.map +1 -0
- package/lib/packlets/puzzles/killerSudokuPuzzle.d.ts +14 -0
- package/lib/packlets/puzzles/killerSudokuPuzzle.d.ts.map +1 -0
- package/lib/packlets/puzzles/killerSudokuPuzzle.js +136 -0
- package/lib/packlets/puzzles/killerSudokuPuzzle.js.map +1 -0
- package/lib/packlets/puzzles/sudokuPuzzle.d.ts +10 -0
- package/lib/packlets/puzzles/sudokuPuzzle.d.ts.map +1 -0
- package/lib/packlets/puzzles/sudokuPuzzle.js +47 -0
- package/lib/packlets/puzzles/sudokuPuzzle.js.map +1 -0
- package/lib/packlets/puzzles/sudokuXPuzzle.d.ts +11 -0
- package/lib/packlets/puzzles/sudokuXPuzzle.d.ts.map +1 -0
- package/lib/packlets/puzzles/sudokuXPuzzle.js +65 -0
- package/lib/packlets/puzzles/sudokuXPuzzle.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* MIT License
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2023 Erik Fortune
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.KillerSudokuPuzzle = void 0;
|
|
27
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
28
|
+
const common_1 = require("../common");
|
|
29
|
+
const cageDefFormat = /^[A-Za-z][0-9][0-9]$/;
|
|
30
|
+
/**
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
class KillerSudokuPuzzle extends common_1.Puzzle {
|
|
34
|
+
constructor(puzzle, cages) {
|
|
35
|
+
super(puzzle, cages);
|
|
36
|
+
}
|
|
37
|
+
static create(desc) {
|
|
38
|
+
/* c8 ignore next 3 */
|
|
39
|
+
if (desc.type !== 'killer-sudoku') {
|
|
40
|
+
return (0, ts_utils_1.fail)(`Puzzle '${desc.description}' unsupported type ${desc.type}`);
|
|
41
|
+
}
|
|
42
|
+
return (0, ts_utils_1.captureResult)(() => {
|
|
43
|
+
const { cages, givens } = KillerSudokuPuzzle._getKillerCages(desc);
|
|
44
|
+
const cells = KillerSudokuPuzzle._getKillerCells(desc, givens);
|
|
45
|
+
return new KillerSudokuPuzzle(Object.assign(Object.assign({}, desc), { cells }), cages);
|
|
46
|
+
})
|
|
47
|
+
.onSuccess((puzzle) => {
|
|
48
|
+
return (0, ts_utils_1.succeed)(puzzle);
|
|
49
|
+
})
|
|
50
|
+
.onFailure((message) => {
|
|
51
|
+
return (0, ts_utils_1.fail)(`Failed to load killer puzzle "${desc.description}" - ${message}`);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
static _getKillerCages(puzzle) {
|
|
55
|
+
const decl = puzzle.cells.split('|');
|
|
56
|
+
if (decl.length !== 2) {
|
|
57
|
+
throw new Error(`malformed cells|cages "${puzzle.cells}"`);
|
|
58
|
+
}
|
|
59
|
+
const cageCells = KillerSudokuPuzzle._getCageCells(puzzle, decl[0]);
|
|
60
|
+
const allCages = KillerSudokuPuzzle._getCages(puzzle, cageCells, decl[1]);
|
|
61
|
+
const cages = allCages.filter(([__id, cage]) => cage.numCells > 1);
|
|
62
|
+
const givens = allCages.filter(([__id, cage]) => cage.numCells === 1).map(([__id, cage]) => cage);
|
|
63
|
+
return { cages, givens };
|
|
64
|
+
}
|
|
65
|
+
static _getCageCells(puzzle, mappingDecl) {
|
|
66
|
+
var _a;
|
|
67
|
+
const cages = new Map();
|
|
68
|
+
const cageMapping = Array.from(mappingDecl);
|
|
69
|
+
if (cageMapping.length !== puzzle.rows * puzzle.cols) {
|
|
70
|
+
const expected = puzzle.rows * puzzle.cols;
|
|
71
|
+
const got = cageMapping.length;
|
|
72
|
+
throw new Error(`expected ${expected} cell mappings, found ${got}`);
|
|
73
|
+
}
|
|
74
|
+
for (let row = 0; row < puzzle.rows; row++) {
|
|
75
|
+
for (let col = 0; col < puzzle.cols; col++) {
|
|
76
|
+
const cage = cageMapping.shift();
|
|
77
|
+
const cell = common_1.Ids.cellId({ row, col }).orThrow();
|
|
78
|
+
const cells = (_a = cages.get(cage)) !== null && _a !== void 0 ? _a : [];
|
|
79
|
+
cells.push(cell);
|
|
80
|
+
cages.set(cage, cells);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return cages;
|
|
84
|
+
}
|
|
85
|
+
static _getCages(__puzzle, cageCells, cagePart) {
|
|
86
|
+
const cages = new Map();
|
|
87
|
+
const cageDefs = cagePart.split(',');
|
|
88
|
+
if (cageDefs.length !== cageCells.size) {
|
|
89
|
+
throw new Error(`expected ${cageCells.size} cage sizes, found ${cageDefs.length}`);
|
|
90
|
+
}
|
|
91
|
+
for (const def of cageDefs) {
|
|
92
|
+
if (!cageDefFormat.test(def)) {
|
|
93
|
+
throw new Error(`malformed cage spec ${def}`);
|
|
94
|
+
}
|
|
95
|
+
const cage = def.slice(0, 1);
|
|
96
|
+
const cageId = common_1.Ids.cageId(`K${cage}`).orThrow();
|
|
97
|
+
const total = Number.parseInt(def.slice(1));
|
|
98
|
+
const cells = cageCells.get(cage);
|
|
99
|
+
/* c8 ignore next 3 - should never happen */
|
|
100
|
+
if (!cells) {
|
|
101
|
+
throw new Error(`cage ${cageId} has no cells`);
|
|
102
|
+
}
|
|
103
|
+
if (cells.length < 1 || cells.length > 9) {
|
|
104
|
+
throw new Error(`invalid cell count ${cells.length} for cage ${cageId}`);
|
|
105
|
+
}
|
|
106
|
+
const { min, max } = common_1.totalsByCageSize[cells.length];
|
|
107
|
+
if (total < min || total > max) {
|
|
108
|
+
throw new Error(`invalid total ${total} for cage ${cageId} (expected ${min}..${max})`);
|
|
109
|
+
}
|
|
110
|
+
cages.set(cageId, common_1.Cage.create(cageId, 'killer', total, cells).orThrow());
|
|
111
|
+
}
|
|
112
|
+
return Array.from(cages.entries());
|
|
113
|
+
}
|
|
114
|
+
static _getKillerCells(puzzle, givens) {
|
|
115
|
+
const cells = [];
|
|
116
|
+
for (let row = 0; row < puzzle.rows; row++) {
|
|
117
|
+
for (let col = 0; col < puzzle.cols; col++) {
|
|
118
|
+
const cellId = common_1.Ids.cellId({ row, col }).orThrow();
|
|
119
|
+
const cage = givens.find((g) => g.cellIds[0] === cellId);
|
|
120
|
+
if (cage) {
|
|
121
|
+
/* c8 ignore next 3 - defense in depth should never happen */
|
|
122
|
+
if (cage.total < 1 || cage.total > 9) {
|
|
123
|
+
throw new Error(`invalid total ${cage.total} for cell ${cellId}`);
|
|
124
|
+
}
|
|
125
|
+
cells.push(String(cage.total));
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
cells.push('.');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return cells.join('');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.KillerSudokuPuzzle = KillerSudokuPuzzle;
|
|
136
|
+
//# sourceMappingURL=killerSudokuPuzzle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"killerSudokuPuzzle.js","sourceRoot":"","sources":["../../../src/packlets/puzzles/killerSudokuPuzzle.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAEH,4CAAqE;AACrE,sCAAoG;AAEpG,MAAM,aAAa,GAAW,sBAAsB,CAAC;AAErD;;GAEG;AACH,MAAa,kBAAmB,SAAQ,eAAM;IAC5C,YAAoB,MAA0B,EAAE,KAAuB;QACrE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACvB,CAAC;IAEM,MAAM,CAAC,MAAM,CAAC,IAAwB;QAC3C,sBAAsB;QACtB,IAAI,IAAI,CAAC,IAAI,KAAK,eAAe,EAAE;YACjC,OAAO,IAAA,eAAI,EAAC,WAAW,IAAI,CAAC,WAAW,sBAAsB,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;SAC3E;QAED,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE;YACxB,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,kBAAkB,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;YACnE,MAAM,KAAK,GAAG,kBAAkB,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAC/D,OAAO,IAAI,kBAAkB,iCAAM,IAAI,KAAE,KAAK,KAAI,KAAK,CAAC,CAAC;QAC3D,CAAC,CAAC;aACC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE;YACpB,OAAO,IAAA,kBAAO,EAAC,MAAM,CAAC,CAAC;QACzB,CAAC,CAAC;aACD,SAAS,CAAC,CAAC,OAAO,EAAE,E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AC,OAAO,EAAE,CAAC,CAAC;IACrC,CAAC;IAEO,MAAM,CAAC,eAAe,CAAC,MAA0B,EAAE,MAAc;QACvE,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;YAC1C,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;gBAC1C,MAAM,MAAM,GAAG,YAAG,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;gBAClD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC;gBACzD,IAAI,IAAI,EAAE;oBACR,6DAA6D;oBAC7D,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,EAAE;wBACpC,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,CAAC,KAAK,aAAa,MAAM,EAAE,CAAC,CAAC;qBACnE;oBACD,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;iBAChC;qBAAM;oBACL,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;iBACjB;aACF;SACF;QACD,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC;CACF;AAtHD,gDAsHC","sourcesContent":["/*\n * MIT License\n *\n * Copyright (c) 2023 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result, captureResult, fail, succeed } from '@fgv/ts-utils';\nimport { Cage, CageId, CellId, IPuzzleDescription, Ids, Puzzle, totalsByCageSize } from '../common';\n\nconst cageDefFormat: RegExp = /^[A-Za-z][0-9][0-9]$/;\n\n/**\n * @public\n */\nexport class KillerSudokuPuzzle extends Puzzle {\n private constructor(puzzle: IPuzzleDescription, cages: [CageId, Cage][]) {\n super(puzzle, cages);\n }\n\n public static create(desc: IPuzzleDescription): Result<Puzzle> {\n /* c8 ignore next 3 */\n if (desc.type !== 'killer-sudoku') {\n return fail(`Puzzle '${desc.description}' unsupported type ${desc.type}`);\n }\n\n return captureResult(() => {\n const { cages, givens } = KillerSudokuPuzzle._getKillerCages(desc);\n const cells = KillerSudokuPuzzle._getKillerCells(desc, givens);\n return new KillerSudokuPuzzle({ ...desc, cells }, cages);\n })\n .onSuccess((puzzle) => {\n return succeed(puzzle);\n })\n .onFailure((message) => {\n return fail(`Failed to load killer puzzle \"${desc.description}\" - ${message}`);\n });\n }\n\n private static _getKillerCages(puzzle: IPuzzleDescription): { cages: [CageId, Cage][]; givens: Cage[] } {\n const decl = puzzle.cells.split('|');\n if (decl.length !== 2) {\n throw new Error(`malformed cells|cages \"${puzzle.cells}\"`);\n }\n\n const cageCells = KillerSudokuPuzzle._getCageCells(puzzle, decl[0]);\n const allCages = KillerSudokuPuzzle._getCages(puzzle, cageCells, decl[1]);\n const cages = allCages.filter(([__id, cage]) => cage.numCells > 1);\n const givens = allCages.filter(([__id, cage]) => cage.numCells === 1).map(([__id, cage]) => cage);\n return { cages, givens };\n }\n\n private static _getCageCells(puzzle: IPuzzleDescription, mappingDecl: string): Map<string, CellId[]> {\n const cages: Map<string, CellId[]> = new Map();\n const cageMapping = Array.from(mappingDecl);\n\n if (cageMapping.length !== puzzle.rows * puzzle.cols) {\n const expected = puzzle.rows * puzzle.cols;\n const got = cageMapping.length;\n throw new Error(`expected ${expected} cell mappings, found ${got}`);\n }\n\n for (let row = 0; row < puzzle.rows; row++) {\n for (let col = 0; col < puzzle.cols; col++) {\n const cage = cageMapping.shift()!;\n const cell = Ids.cellId({ row, col }).orThrow();\n const cells = cages.get(cage) ?? [];\n cells.push(cell);\n cages.set(cage, cells);\n }\n }\n\n return cages;\n }\n\n private static _getCages(\n __puzzle: IPuzzleDescription,\n cageCells: Map<string, CellId[]>,\n cagePart: string\n ): [CageId, Cage][] {\n const cages = new Map<CageId, Cage>();\n\n const cageDefs = cagePart.split(',');\n if (cageDefs.length !== cageCells.size) {\n throw new Error(`expected ${cageCells.size} cage sizes, found ${cageDefs.length}`);\n }\n\n for (const def of cageDefs) {\n if (!cageDefFormat.test(def)) {\n throw new Error(`malformed cage spec ${def}`);\n }\n const cage = def.slice(0, 1);\n const cageId = Ids.cageId(`K${cage}`).orThrow();\n\n const total = Number.parseInt(def.slice(1));\n const cells = cageCells.get(cage);\n /* c8 ignore next 3 - should never happen */\n if (!cells) {\n throw new Error(`cage ${cageId} has no cells`);\n }\n if (cells.length < 1 || cells.length > 9) {\n throw new Error(`invalid cell count ${cells.length} for cage ${cageId}`);\n }\n const { min, max } = totalsByCageSize[cells.length];\n if (total < min || total > max) {\n throw new Error(`invalid total ${total} for cage ${cageId} (expected ${min}..${max})`);\n }\n\n cages.set(cageId, Cage.create(cageId, 'killer', total, cells).orThrow());\n }\n\n return Array.from(cages.entries());\n }\n\n private static _getKillerCells(puzzle: IPuzzleDescription, givens: Cage[]): string {\n const cells: string[] = [];\n for (let row = 0; row < puzzle.rows; row++) {\n for (let col = 0; col < puzzle.cols; col++) {\n const cellId = Ids.cellId({ row, col }).orThrow();\n const cage = givens.find((g) => g.cellIds[0] === cellId);\n if (cage) {\n /* c8 ignore next 3 - defense in depth should never happen */\n if (cage.total < 1 || cage.total > 9) {\n throw new Error(`invalid total ${cage.total} for cell ${cellId}`);\n }\n cells.push(String(cage.total));\n } else {\n cells.push('.');\n }\n }\n }\n return cells.join('');\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
import { IPuzzleDescription, Puzzle } from '../common';
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare class SudokuPuzzle extends Puzzle {
|
|
7
|
+
private constructor();
|
|
8
|
+
static create(puzzle: IPuzzleDescription): Result<Puzzle>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=sudokuPuzzle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sudokuPuzzle.d.ts","sourceRoot":"","sources":["../../../src/packlets/puzzles/sudokuPuzzle.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,MAAM,EAAgC,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEvD;;GAEG;AACH,qBAAa,YAAa,SAAQ,MAAM;IACtC,OAAO;WAIO,MAAM,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC;CAUjE"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* MIT License
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2023 Erik Fortune
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.SudokuPuzzle = void 0;
|
|
27
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
28
|
+
const common_1 = require("../common");
|
|
29
|
+
/**
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
class SudokuPuzzle extends common_1.Puzzle {
|
|
33
|
+
constructor(puzzle) {
|
|
34
|
+
super(puzzle);
|
|
35
|
+
}
|
|
36
|
+
static create(puzzle) {
|
|
37
|
+
/* c8 ignore next 3 */
|
|
38
|
+
if (puzzle.type !== 'sudoku') {
|
|
39
|
+
return (0, ts_utils_1.fail)(`Puzzle '${puzzle.description}' unsupported type ${puzzle.type}`);
|
|
40
|
+
}
|
|
41
|
+
return (0, ts_utils_1.captureResult)(() => new SudokuPuzzle(puzzle)).onSuccess((puzzle) => {
|
|
42
|
+
return (0, ts_utils_1.succeed)(puzzle);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.SudokuPuzzle = SudokuPuzzle;
|
|
47
|
+
//# sourceMappingURL=sudokuPuzzle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sudokuPuzzle.js","sourceRoot":"","sources":["../../../src/packlets/puzzles/sudokuPuzzle.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAEH,4CAAqE;AACrE,sCAAuD;AAEvD;;GAEG;AACH,MAAa,YAAa,SAAQ,eAAM;IACtC,YAAoB,MAA0B;QAC5C,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAEM,MAAM,CAAC,MAAM,CAAC,MAA0B;QAC7C,sBAAsB;QACtB,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE;YAC5B,OAAO,IAAA,eAAI,EAAC,WAAW,MAAM,CAAC,WAAW,sBAAsB,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;SAC/E;QAED,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE;YACxE,OAAO,IAAA,kBAAO,EAAC,MAAM,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAfD,oCAeC","sourcesContent":["/*\n * MIT License\n *\n * Copyright (c) 2023 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result, captureResult, fail, succeed } from '@fgv/ts-utils';\nimport { IPuzzleDescription, Puzzle } from '../common';\n\n/**\n * @public\n */\nexport class SudokuPuzzle extends Puzzle {\n private constructor(puzzle: IPuzzleDescription) {\n super(puzzle);\n }\n\n public static create(puzzle: IPuzzleDescription): Result<Puzzle> {\n /* c8 ignore next 3 */\n if (puzzle.type !== 'sudoku') {\n return fail(`Puzzle '${puzzle.description}' unsupported type ${puzzle.type}`);\n }\n\n return captureResult(() => new SudokuPuzzle(puzzle)).onSuccess((puzzle) => {\n return succeed(puzzle);\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
import { IPuzzleDescription, Puzzle } from '../common';
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare class SudokuXPuzzle extends Puzzle {
|
|
7
|
+
private constructor();
|
|
8
|
+
static create(puzzle: IPuzzleDescription): Result<Puzzle>;
|
|
9
|
+
private static _getXCages;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=sudokuXPuzzle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sudokuXPuzzle.d.ts","sourceRoot":"","sources":["../../../src/packlets/puzzles/sudokuXPuzzle.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,MAAM,EAA0B,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAwB,kBAAkB,EAAO,MAAM,EAAE,MAAM,WAAW,CAAC;AAElF;;GAEG;AACH,qBAAa,aAAc,SAAQ,MAAM;IACvC,OAAO;WAIO,MAAM,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC;IAYhE,OAAO,CAAC,MAAM,CAAC,UAAU;CAmB1B"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* MIT License
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2023 Erik Fortune
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.SudokuXPuzzle = void 0;
|
|
27
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
28
|
+
const common_1 = require("../common");
|
|
29
|
+
/**
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
class SudokuXPuzzle extends common_1.Puzzle {
|
|
33
|
+
constructor(puzzle, extraCages) {
|
|
34
|
+
super(puzzle, extraCages);
|
|
35
|
+
}
|
|
36
|
+
static create(puzzle) {
|
|
37
|
+
/* c8 ignore next 3 */
|
|
38
|
+
if (puzzle.type !== 'sudoku-x') {
|
|
39
|
+
return fail(`Puzzle '${puzzle.description}' unsupported type ${puzzle.type}`);
|
|
40
|
+
}
|
|
41
|
+
return (0, ts_utils_1.captureResult)(() => {
|
|
42
|
+
return new SudokuXPuzzle(puzzle, SudokuXPuzzle._getXCages(puzzle));
|
|
43
|
+
}).onSuccess((puzzle) => {
|
|
44
|
+
return (0, ts_utils_1.succeed)(puzzle);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
static _getXCages(puzzle) {
|
|
48
|
+
const x1Cells = [];
|
|
49
|
+
const x2Cells = [];
|
|
50
|
+
for (let row = 0, col1 = 0, col2 = puzzle.cols - 1; row < puzzle.rows; row++, col1++, col2--) {
|
|
51
|
+
x1Cells.push(common_1.Ids.cellId({ row, col: col1 }).orThrow());
|
|
52
|
+
x2Cells.push(common_1.Ids.cellId({ row, col: col2 }).orThrow());
|
|
53
|
+
}
|
|
54
|
+
const x1Id = common_1.Ids.cageId('X1').orThrow();
|
|
55
|
+
const x2Id = common_1.Ids.cageId('X2').orThrow();
|
|
56
|
+
const x1 = common_1.Cage.create(x1Id, 'x', 45, x1Cells).orThrow();
|
|
57
|
+
const x2 = common_1.Cage.create(x2Id, 'x', 45, x2Cells).orThrow();
|
|
58
|
+
return [
|
|
59
|
+
[x1Id, x1],
|
|
60
|
+
[x2Id, x2]
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.SudokuXPuzzle = SudokuXPuzzle;
|
|
65
|
+
//# sourceMappingURL=sudokuXPuzzle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sudokuXPuzzle.js","sourceRoot":"","sources":["../../../src/packlets/puzzles/sudokuXPuzzle.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAEH,4CAA+D;AAC/D,sCAAkF;AAElF;;GAEG;AACH,MAAa,aAAc,SAAQ,eAAM;IACvC,YAAoB,MAA0B,EAAE,UAA4B;QAC1E,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC5B,CAAC;IAEM,MAAM,CAAC,MAAM,CAAC,MAA0B;QAC7C,sBAAsB;QACtB,IAAI,MAAM,CAAC,IAAI,KAAK,UAAU,EAAE;YAC9B,OAAO,IAAI,CAAC,WAAW,MAAM,CAAC,WAAW,sBAAsB,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;SAC/E;QACD,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE;YACxB,OAAO,IAAI,aAAa,CAAC,MAAM,EAAE,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;QACrE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE;YACtB,OAAO,IAAA,kBAAO,EAAC,MAAM,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,MAAM,CAAC,UAAU,CAAC,MAA0B;QAClD,MAAM,OAAO,GAAa,EAAE,CAAC;QAC7B,MAAM,OAAO,GAAa,EAAE,CAAC;QAE7B,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC,IAAI,GAAG,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,EAAE;YAC5F,OAAO,CAAC,IAAI,CAAC,YAAG,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YACvD,OAAO,CAAC,IAAI,CAAC,YAAG,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;SACxD;QAED,MAAM,IAAI,GAAG,YAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;QACxC,MAAM,IAAI,GAAG,YAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;QAExC,MAAM,EAAE,GAAG,aAAI,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;QACzD,MAAM,EAAE,GAAG,aAAI,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;QACzD,OAAO;YACL,CAAC,IAAI,EAAE,EAAE,CAAC;YACV,CAAC,IAAI,EAAE,EAAE,CAAC;SACX,CAAC;IACJ,CAAC;CACF;AApCD,sCAoCC","sourcesContent":["/*\n * MIT License\n *\n * Copyright (c) 2023 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result, captureResult, succeed } from '@fgv/ts-utils';\nimport { Cage, CageId, CellId, IPuzzleDescription, Ids, Puzzle } from '../common';\n\n/**\n * @public\n */\nexport class SudokuXPuzzle extends Puzzle {\n private constructor(puzzle: IPuzzleDescription, extraCages: [CageId, Cage][]) {\n super(puzzle, extraCages);\n }\n\n public static create(puzzle: IPuzzleDescription): Result<Puzzle> {\n /* c8 ignore next 3 */\n if (puzzle.type !== 'sudoku-x') {\n return fail(`Puzzle '${puzzle.description}' unsupported type ${puzzle.type}`);\n }\n return captureResult(() => {\n return new SudokuXPuzzle(puzzle, SudokuXPuzzle._getXCages(puzzle));\n }).onSuccess((puzzle) => {\n return succeed(puzzle);\n });\n }\n\n private static _getXCages(puzzle: IPuzzleDescription): [CageId, Cage][] {\n const x1Cells: CellId[] = [];\n const x2Cells: CellId[] = [];\n\n for (let row = 0, col1 = 0, col2 = puzzle.cols - 1; row < puzzle.rows; row++, col1++, col2--) {\n x1Cells.push(Ids.cellId({ row, col: col1 }).orThrow());\n x2Cells.push(Ids.cellId({ row, col: col2 }).orThrow());\n }\n\n const x1Id = Ids.cageId('X1').orThrow();\n const x2Id = Ids.cageId('X2').orThrow();\n\n const x1 = Cage.create(x1Id, 'x', 45, x1Cells).orThrow();\n const x2 = Cage.create(x2Id, 'x', 45, x2Cells).orThrow();\n return [\n [x1Id, x1],\n [x2Id, x2]\n ];\n }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fgv/ts-sudoku-lib",
|
|
3
|
+
"version": "2.0.2-alpha.0",
|
|
4
|
+
"description": "Sudoku rules library",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "dist/ts-json.d.ts",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/ErikFortune/fgv.git"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"typescript",
|
|
13
|
+
"node"
|
|
14
|
+
],
|
|
15
|
+
"author": "Erik Fortune",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/ErikFortune/fgv/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/ErikFortune/fgv/libraries/ts-sudoku-lib#readme",
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@fgv/ts-json": "2.0.2-alpha.0",
|
|
23
|
+
"@fgv/ts-utils": "2.0.2-alpha.0",
|
|
24
|
+
"@fgv/ts-utils-jest": "2.0.2-alpha.0",
|
|
25
|
+
"@microsoft/api-documenter": "^7.22.14",
|
|
26
|
+
"@microsoft/api-extractor": "^7.35.2",
|
|
27
|
+
"@types/jest": "^29.5.2",
|
|
28
|
+
"@types/node": "^20.2.5",
|
|
29
|
+
"@typescript-eslint/eslint-plugin": "^5.59.9",
|
|
30
|
+
"@typescript-eslint/parser": "^5.59.9",
|
|
31
|
+
"cspell": "^6.31.1",
|
|
32
|
+
"eslint": "^8.42.0",
|
|
33
|
+
"eslint-config-prettier": "^8.8.0",
|
|
34
|
+
"eslint-config-standard": "^17.1.0",
|
|
35
|
+
"eslint-plugin-header": "^3.1.1",
|
|
36
|
+
"eslint-plugin-import": "^2.27.5",
|
|
37
|
+
"eslint-plugin-node": "^11.1.0",
|
|
38
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
39
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
40
|
+
"jest": "^29.5.0",
|
|
41
|
+
"prettier": "^2.8.8",
|
|
42
|
+
"rimraf": "^5.0.1",
|
|
43
|
+
"ts-jest": "^29.1.0",
|
|
44
|
+
"ts-node": "^10.9.1",
|
|
45
|
+
"typescript": "^5.1.3",
|
|
46
|
+
"eslint-plugin-n": "^16.0.0",
|
|
47
|
+
"@rushstack/heft": "~0.53.0",
|
|
48
|
+
"@rushstack/heft-node-rig": "~2.2.3",
|
|
49
|
+
"@types/heft-jest": "1.0.3",
|
|
50
|
+
"@rushstack/eslint-config": "~3.3.1",
|
|
51
|
+
"@rushstack/heft-jest-plugin": "~0.7.4",
|
|
52
|
+
"eslint-plugin-tsdoc": "~0.2.17"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"@fgv/ts-utils": "^2.0.2-alpha.0",
|
|
56
|
+
"@fgv/ts-json": "^2.0.2-alpha.0"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "heft test --clean",
|
|
60
|
+
"clean": "heft clean",
|
|
61
|
+
"test": "heft test",
|
|
62
|
+
"build-docs": "api-documenter markdown --input-folder ./temp --output-folder docs",
|
|
63
|
+
"build-all": "rushx build; rushx build-docs",
|
|
64
|
+
"test-handles": "jest --runInBand --detectOpenHandles",
|
|
65
|
+
"clean-jest": "jest --clear-cache",
|
|
66
|
+
"coverage": "jest --coverage --no-cache",
|
|
67
|
+
"lint": "eslint src --ext .ts",
|
|
68
|
+
"fixlint": "eslint src --ext .ts --fix"
|
|
69
|
+
}
|
|
70
|
+
}
|