UNPKG

@papb/json-excel

Version:

Create a pretty Excel table from JSON data with a very simple API

34 lines 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.assertNonemptyStringSquareMatrix = void 0; function indexToEnglishOrdinal(index) { var _a; return (_a = ['first', 'second', 'third'][index]) !== null && _a !== void 0 ? _a : `${index + 1}th`; } function assertNonemptyStringSquareMatrix(arg) { if (!Array.isArray(arg)) { throw new TypeError(`Expected string[][], got ${typeof arg}`); } if (arg.length === 0) { throw new TypeError('Expected nonempty string[][], got empty array'); } for (const x of arg) { if (!Array.isArray(x)) { throw new TypeError(`Expected each row to be string[], got ${typeof x}`); } for (const y of x) { if (typeof y !== 'string') { throw new TypeError(`Expected each cell to be string, got ${typeof y}`); } } } const typedArg = arg; const columnCount = typedArg[0].length; for (let i = 1; i < typedArg.length; i++) { if (typedArg[i].length !== columnCount) { throw new TypeError(`Expected every row to have the same amount of columns (${columnCount}}, but got ${typedArg[i].length} for the ${indexToEnglishOrdinal(i)} row`); } } } exports.assertNonemptyStringSquareMatrix = assertNonemptyStringSquareMatrix; //# sourceMappingURL=check-square-matrix.js.map