@mojir/lits 2.5.0 → 2.5.2
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/README.md +4 -5
- package/dist/cli/cli.js +1432 -705
- package/dist/cli/reference/api.d.ts +8 -6
- package/dist/cli/reference/index.d.ts +132 -132
- package/dist/cli/src/builtin/interface.d.ts +1 -0
- package/dist/cli/src/builtin/modules/convert/index.d.ts +2 -0
- package/dist/full.esm.js +1 -1
- package/dist/full.esm.js.map +1 -1
- package/dist/full.js +1 -1
- package/dist/full.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +1 -1
- package/dist/lits.iife.js.map +1 -1
- package/dist/modules/collection.esm.js +1 -1
- package/dist/modules/collection.esm.js.map +1 -1
- package/dist/modules/collection.js +1 -1
- package/dist/modules/collection.js.map +1 -1
- package/dist/modules/convert.esm.js +2 -0
- package/dist/modules/convert.esm.js.map +1 -0
- package/dist/modules/convert.js +2 -0
- package/dist/modules/convert.js.map +1 -0
- package/dist/modules/grid.esm.js +1 -1
- package/dist/modules/grid.esm.js.map +1 -1
- package/dist/modules/grid.js +1 -1
- package/dist/modules/grid.js.map +1 -1
- package/dist/modules/linear-algebra.esm.js +1 -1
- package/dist/modules/linear-algebra.esm.js.map +1 -1
- package/dist/modules/linear-algebra.js +1 -1
- package/dist/modules/linear-algebra.js.map +1 -1
- package/dist/modules/math.esm.js +1 -1
- package/dist/modules/math.esm.js.map +1 -1
- package/dist/modules/math.js +1 -1
- package/dist/modules/math.js.map +1 -1
- package/dist/modules/matrix.esm.js +1 -1
- package/dist/modules/matrix.esm.js.map +1 -1
- package/dist/modules/matrix.js +1 -1
- package/dist/modules/matrix.js.map +1 -1
- package/dist/modules/random.esm.js +1 -1
- package/dist/modules/random.esm.js.map +1 -1
- package/dist/modules/random.js +1 -1
- package/dist/modules/random.js.map +1 -1
- package/dist/modules/reference/api.d.ts +8 -6
- package/dist/modules/reference/index.d.ts +132 -132
- package/dist/modules/sequence.esm.js +1 -1
- package/dist/modules/sequence.esm.js.map +1 -1
- package/dist/modules/sequence.js +1 -1
- package/dist/modules/sequence.js.map +1 -1
- package/dist/modules/src/builtin/interface.d.ts +1 -0
- package/dist/modules/src/builtin/modules/convert/index.d.ts +2 -0
- package/dist/modules/src/modules/convert.d.ts +2 -0
- package/dist/modules/string.esm.js +1 -1
- package/dist/modules/string.esm.js.map +1 -1
- package/dist/modules/string.js +1 -1
- package/dist/modules/string.js.map +1 -1
- package/dist/modules/vector.esm.js +1 -1
- package/dist/modules/vector.esm.js.map +1 -1
- package/dist/modules/vector.js +1 -1
- package/dist/modules/vector.js.map +1 -1
- package/dist/reference/api.d.ts +8 -6
- package/dist/reference/index.d.ts +132 -132
- package/dist/src/builtin/interface.d.ts +1 -0
- package/dist/src/builtin/modules/convert/index.d.ts +2 -0
- package/dist/src/modules/convert.d.ts +2 -0
- package/dist/testFramework.esm.js +1 -1
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +1 -1
- package/dist/testFramework.js.map +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.esm.js","sources":["../../src/utils/debug/getCodeMarker.ts","../../src/errors.ts","../../src/constants/constants.ts","../../src/utils/debug/debugTools.ts","../../src/utils/symbols.ts","../../src/typeGuards/number.ts","../../src/utils/debug/getSourceCodeInfo.ts","../../src/utils/arity.ts","../../src/builtin/modules/convert/index.ts"],"sourcesContent":["import type { SourceCodeInfo } from '../../tokenizer/token'\n\nexport function getCodeMarker(sourceCodeInfo: SourceCodeInfo): string {\n if (!sourceCodeInfo.position || !sourceCodeInfo.code)\n return ''\n\n const leftPadding = sourceCodeInfo.position.column - 1\n const rightPadding = sourceCodeInfo.code.length - leftPadding - 1\n return `${' '.repeat(Math.max(leftPadding, 0))}^${' '.repeat(Math.max(rightPadding, 0))}`\n}\n","import { getCodeMarker } from '../src/utils/debug/getCodeMarker'\nimport type { Arr } from './interface'\nimport type { SourceCodeInfo } from './tokenizer/token'\n\nfunction getLitsErrorMessage(message: string, sourceCodeInfo?: SourceCodeInfo) {\n if (!sourceCodeInfo) {\n return message\n }\n const location = `${sourceCodeInfo.position.line}:${sourceCodeInfo.position.column}`\n const filePathLine = sourceCodeInfo.filePath\n ? `\\n${sourceCodeInfo.filePath}:${location}`\n : `\\nLocation ${location}`\n const codeLine = `\\n${sourceCodeInfo.code}`\n const codeMarker = `\\n${getCodeMarker(sourceCodeInfo)}`\n return `${message}${filePathLine}${codeLine}${codeMarker}`\n}\n\nexport class RecurSignal extends Error {\n public params: Arr\n constructor(params: Arr) {\n super(`recur, params: ${params}`)\n Object.setPrototypeOf(this, RecurSignal.prototype)\n this.name = 'RecurSignal'\n this.params = params\n }\n}\n\nexport class LitsError extends Error {\n public readonly sourceCodeInfo?: SourceCodeInfo\n public readonly shortMessage: string\n constructor(err: unknown, sourceCodeInfo: SourceCodeInfo | undefined) {\n const message = err instanceof Error\n ? err.message\n : `${err}`\n\n super(getLitsErrorMessage(message, sourceCodeInfo))\n this.shortMessage = message\n this.sourceCodeInfo = sourceCodeInfo\n Object.setPrototypeOf(this, LitsError.prototype)\n this.name = 'LitsError'\n }\n\n public getCodeMarker(): string | undefined {\n return this.sourceCodeInfo && getCodeMarker(this.sourceCodeInfo)\n }\n}\n\nexport class UserDefinedError extends LitsError {\n public userMessage: string\n constructor(message: string, sourceCodeInfo?: SourceCodeInfo) {\n super(message, sourceCodeInfo)\n this.userMessage = message\n Object.setPrototypeOf(this, UserDefinedError.prototype)\n this.name = 'UserDefinedError'\n }\n}\n\nexport class AssertionError extends LitsError {\n constructor(message: string | Error, sourceCodeInfo?: SourceCodeInfo) {\n super(message, sourceCodeInfo)\n Object.setPrototypeOf(this, AssertionError.prototype)\n this.name = 'AssertionError'\n }\n}\n\nexport class UndefinedSymbolError extends LitsError {\n public symbol: string\n constructor(symbolName: string, sourceCodeInfo?: SourceCodeInfo) {\n const message = `Undefined symbol '${symbolName}'.`\n super(message, sourceCodeInfo)\n this.symbol = symbolName\n Object.setPrototypeOf(this, UndefinedSymbolError.prototype)\n this.name = 'UndefinedSymbolError'\n }\n}\n\nexport function isLitsError(error: unknown): error is LitsError {\n return error instanceof LitsError\n}\n","export const NodeTypes = {\n Number: 1,\n String: 2,\n NormalExpression: 3,\n SpecialExpression: 4,\n UserDefinedSymbol: 5,\n NormalBuiltinSymbol: 6,\n SpecialBuiltinSymbol: 7,\n ReservedSymbol: 8,\n Binding: 9,\n Spread: 10,\n} as const\n\nconst NodeTypesSet = new Set(Object.values(NodeTypes))\n\nexport type NodeType = typeof NodeTypes[keyof typeof NodeTypes]\n\nexport function getNodeTypeName(type: NodeType): keyof typeof NodeTypes {\n return Object.keys(NodeTypes).find(key => NodeTypes[key as keyof typeof NodeTypes] === type) as keyof typeof NodeTypes\n}\n\n// TODO, is this needed?\nexport function isNodeType(type: unknown): type is NodeType {\n return typeof type === 'number' && NodeTypesSet.has(type as NodeType)\n}\n\nconst functionTypes = [\n 'UserDefined',\n 'Partial',\n 'Comp',\n 'Constantly',\n 'Juxt',\n 'Complement',\n 'EveryPred',\n 'SomePred',\n 'Fnull',\n 'Builtin',\n 'SpecialBuiltin',\n 'NativeJsFunction',\n 'Module',\n] as const\n\nconst functionTypeSet = new Set(functionTypes)\n\nexport type FunctionType = typeof functionTypes[number]\n\nexport function isFunctionType(type: unknown): type is FunctionType {\n return typeof type === 'string' && functionTypeSet.has(type as FunctionType)\n}\n","import { getNodeTypeName, isFunctionType, isNodeType } from '../../constants/constants'\nimport type { AstNode, LitsFunction } from '../../parser/types'\nimport { FUNCTION_SYMBOL } from '../symbols'\n\nfunction isLitsFunction(func: unknown): func is LitsFunction {\n if (func === null || typeof func !== 'object')\n return false\n\n return FUNCTION_SYMBOL in func && 'functionType' in func && isFunctionType(func.functionType)\n}\n\nfunction isNode(value: unknown): value is AstNode {\n if (!Array.isArray(value) || value.length < 2)\n return false\n return isNodeType(value[0])\n}\n\nexport function valueToString(value: unknown): string {\n if (isLitsFunction(value))\n // eslint-disable-next-line ts/no-unsafe-member-access\n return `<function ${(value as any).name || '\\u03BB'}>`\n\n if (isNode(value))\n return `${getNodeTypeName(value[0])}-node`\n\n if (value === null)\n return 'null'\n\n if (typeof value === 'object' && value instanceof RegExp)\n return `${value}`\n\n if (typeof value === 'object' && value instanceof Error)\n return value.toString()\n\n return JSON.stringify(value)\n}\n","export const FUNCTION_SYMBOL = '^^fn^^'\nexport const REGEXP_SYMBOL = '^^re^^'\n","import { LitsError } from '../errors'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { valueToString } from '../utils/debug/debugTools'\nimport { getSourceCodeInfo } from '../utils/debug/getSourceCodeInfo'\n\ntype SignOptions =\n | {\n positive?: true\n negative?: never\n nonPositive?: never\n nonNegative?: never\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: true\n nonPositive?: never\n nonNegative?: never\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: true\n nonNegative?: never\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: never\n nonNegative?: true\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: never\n nonNegative?: never\n zero?: true\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: never\n nonNegative?: never\n zero?: never\n nonZero?: true\n }\n\ntype GtOptions =\n | {\n gt?: number\n gte?: never\n }\n | {\n gt?: never\n gte?: number\n }\n\ntype LtOptions =\n | {\n lt?: number\n lte?: never\n }\n | {\n lt?: never\n lte?: number\n }\n\ntype NumberOptions = {\n integer?: true\n finite?: true\n} & SignOptions &\nGtOptions &\nLtOptions\n\nfunction getRangeString(options: NumberOptions): string {\n const hasUpperAndLowerBound\n = (typeof options.gt === 'number' || typeof options.gte === 'number')\n && (typeof options.lt === 'number' || typeof options.lte === 'number')\n if (hasUpperAndLowerBound) {\n return `${typeof options.gt === 'number' ? `${options.gt} < n ` : `${options.gte} <= n `}${\n typeof options.lt === 'number' ? `< ${options.lt}` : `<= ${options.lte}`\n }`\n }\n else if (typeof options.gt === 'number' || typeof options.gte === 'number') {\n return `${typeof options.gt === 'number' ? `n > ${options.gt}` : `n >= ${options.gte}`}`\n }\n else if (typeof options.lt === 'number' || typeof options.lte === 'number') {\n return `${typeof options.lt === 'number' ? `n < ${options.lt}` : `n <= ${options.lte}`}`\n }\n else { return '' }\n}\n\nfunction getSignString(options: NumberOptions): string {\n return options.positive\n ? 'positive'\n : options.negative\n ? 'negative'\n : options.nonNegative\n ? 'non negative'\n : options.nonPositive\n ? 'non positive'\n : options.nonZero\n ? 'non zero'\n : ''\n}\n\nfunction getNumberTypeName(options: NumberOptions): string {\n if (options.zero)\n return 'zero'\n\n const sign = getSignString(options)\n const numberType = options.integer ? 'integer' : 'number'\n const finite = options.finite ? 'finite' : ''\n const range = getRangeString(options)\n\n return [sign, finite, numberType, range].filter(x => !!x).join(' ')\n}\n\nexport function isNumber(value: unknown, options: NumberOptions = {}): value is number {\n if (typeof value !== 'number')\n return false\n\n if (Number.isNaN(value))\n return false\n\n if (options.integer && !Number.isInteger(value))\n return false\n\n if (options.finite && !Number.isFinite(value))\n return false\n\n if (options.zero && value !== 0)\n return false\n\n if (options.nonZero && value === 0)\n return false\n\n if (options.positive && value <= 0)\n return false\n\n if (options.negative && value >= 0)\n return false\n\n if (options.nonPositive && value > 0)\n return false\n\n if (options.nonNegative && value < 0)\n return false\n\n if (typeof options.gt === 'number' && value <= options.gt)\n return false\n\n if (typeof options.gte === 'number' && value < options.gte)\n return false\n\n if (typeof options.lt === 'number' && value >= options.lt)\n return false\n\n if (typeof options.lte === 'number' && value > options.lte)\n return false\n\n return true\n}\n\nexport function assertNumber(\n value: unknown,\n sourceCodeInfo?: SourceCodeInfo,\n options: NumberOptions = {},\n): asserts value is number {\n if (!isNumber(value, options)) {\n throw new LitsError(\n `Expected ${getNumberTypeName(options)}, got ${valueToString(value)}.`,\n getSourceCodeInfo(value, sourceCodeInfo),\n )\n }\n}\n\nexport function asNumber(\n value: unknown,\n sourceCodeInfo: SourceCodeInfo | undefined,\n options: NumberOptions = {},\n): number {\n assertNumber(value, sourceCodeInfo, options)\n return value\n}\n","import type { SourceCodeInfo } from '../../tokenizer/token'\n\nexport function getSourceCodeInfo(anyValue: any, sourceCodeInfo: SourceCodeInfo | undefined): SourceCodeInfo | undefined {\n // eslint-disable-next-line ts/no-unsafe-return, ts/no-unsafe-member-access\n return anyValue?.sourceCodeInfo ?? sourceCodeInfo\n}\n","import type { Arity } from '../builtin/interface'\nimport { LitsError } from '../errors'\nimport type { FunctionLike } from '../parser/types'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { isColl } from '../typeGuards/lits'\nimport { valueToString } from './debug/debugTools'\n\nexport function arityAccepts(arity: Arity, nbrOfParams: number): boolean {\n const { min, max } = arity\n if (typeof min === 'number' && nbrOfParams < min) {\n return false\n }\n if (typeof max === 'number' && nbrOfParams > max) {\n return false\n }\n return true\n}\n\nexport function arityAcceptsMin(arity: Arity, nbrOfParams: number): boolean {\n const { min } = arity\n if (typeof min === 'number' && nbrOfParams < min) {\n return false\n }\n return true\n}\n\nexport function getCommonArityFromFunctions(params: FunctionLike[]): Arity | null {\n return params.reduce((acc: Arity | null, param): Arity | null => {\n if (acc === null) {\n return null\n }\n const arity: Arity = (typeof param === 'number' || isColl(param)) ? toFixedArity(1) : param.arity\n const { min: aMin, max: aMax } = arity\n const { min: bMin, max: bMax } = acc\n const min = typeof aMin === 'number' && typeof bMin === 'number'\n ? Math.max(aMin, bMin)\n : typeof aMin === 'number' ? aMin : typeof bMin === 'number' ? bMin : undefined\n const max = typeof aMax === 'number' && typeof bMax === 'number'\n ? Math.min(aMax, bMax)\n : typeof aMax === 'number' ? aMax : typeof bMax === 'number' ? bMax : undefined\n\n if (typeof min === 'number' && typeof max === 'number' && min > max) {\n return null\n }\n\n return { min, max }\n }, {})\n}\n\nexport function getArityFromFunction(param: FunctionLike): Arity {\n return (typeof param === 'number' || isColl(param)) ? toFixedArity(1) : param.arity\n}\n\nexport function assertNumberOfParams(arity: Arity, length: number, sourceCodeInfo: SourceCodeInfo | undefined): void {\n const { min, max } = arity\n if (typeof min === 'number' && length < min) {\n throw new LitsError(\n `Wrong number of arguments, expected at least ${min}, got ${valueToString(length)}.`,\n sourceCodeInfo,\n )\n }\n\n if (typeof max === 'number' && length > max) {\n throw new LitsError(\n `Wrong number of arguments, expected at most ${max}, got ${valueToString(length)}.`,\n sourceCodeInfo,\n )\n }\n}\n\nexport function canBeOperator(count: Arity): boolean {\n if (typeof count.max === 'number' && count.max < 2) {\n return false\n }\n\n if (typeof count.min === 'number' && count.min > 2) {\n return false\n }\n\n return true\n}\n\nexport function toFixedArity(arity: number): Arity {\n return { min: arity, max: arity }\n}\n","import { assertNumber } from '../../../typeGuards/number'\nimport { toFixedArity } from '../../../utils/arity'\nimport type { BuiltinNormalExpressions } from '../../interface'\nimport type { LitsModule } from '../interface'\n\n// --- Conversion factor tables ---\n// Each category maps unit abbreviations to a factor relative to a base unit.\n// To convert from unit A to unit B: value * (factorA / factorB)\n// Temperature is special-cased (non-linear).\n\ninterface UnitCategory {\n baseUnit: string\n units: Record<string, number>\n description: string\n}\n\nconst lengthUnits: UnitCategory = {\n baseUnit: 'm',\n description: 'length',\n units: {\n angstrom: 1e-10,\n um: 0.000001,\n mm: 0.001,\n cm: 0.01,\n m: 1,\n km: 1000,\n in: 0.0254,\n ft: 0.3048,\n yd: 0.9144,\n mi: 1609.344,\n nmi: 1852,\n },\n}\n\nconst weightUnits: UnitCategory = {\n baseUnit: 'kg',\n description: 'weight',\n units: {\n mg: 0.000001,\n g: 0.001,\n kg: 1,\n t: 1000,\n oz: 0.028349523125,\n lb: 0.45359237,\n st: 6.35029318,\n },\n}\n\nconst volumeUnits: UnitCategory = {\n baseUnit: 'l',\n description: 'volume',\n units: {\n 'ml': 0.001,\n 'cl': 0.01,\n 'dl': 0.1,\n 'l': 1,\n 'tsp': 0.00492892159375,\n 'tbsp': 0.01478676478125,\n 'fl-oz': 0.0295735295625,\n 'cup': 0.2365882365,\n 'pt': 0.473176473,\n 'qt': 0.946352946,\n 'gal': 3.785411784,\n },\n}\n\nconst timeUnits: UnitCategory = {\n baseUnit: 's',\n description: 'time',\n units: {\n ms: 0.001,\n s: 1,\n min: 60,\n h: 3600,\n day: 86400,\n week: 604800,\n },\n}\n\nconst areaUnits: UnitCategory = {\n baseUnit: 'm2',\n description: 'area',\n units: {\n mm2: 0.000001,\n cm2: 0.0001,\n m2: 1,\n km2: 1000000,\n in2: 0.00064516,\n ft2: 0.09290304,\n yd2: 0.83612736,\n acre: 4046.8564224,\n hectare: 10000,\n },\n}\n\nconst speedUnits: UnitCategory = {\n baseUnit: 'm/s',\n description: 'speed',\n units: {\n 'm/s': 1,\n 'km/h': 1 / 3.6,\n 'mph': 0.44704,\n 'kn': 0.514444,\n 'ft/s': 0.3048,\n },\n}\n\nconst dataUnits: UnitCategory = {\n baseUnit: 'b',\n description: 'data',\n units: {\n b: 1,\n kb: 1000,\n mb: 1000000,\n gb: 1e9,\n tb: 1e12,\n pb: 1e15,\n },\n}\n\nconst pressureUnits: UnitCategory = {\n baseUnit: 'pa',\n description: 'pressure',\n units: {\n pa: 1,\n kpa: 1000,\n bar: 100000,\n atm: 101325,\n psi: 6894.757293168,\n mmhg: 133.322387415,\n },\n}\n\nconst energyUnits: UnitCategory = {\n baseUnit: 'j',\n description: 'energy',\n units: {\n j: 1,\n kj: 1000,\n cal: 4.184,\n kcal: 4184,\n wh: 3600,\n kwh: 3600000,\n btu: 1055.06,\n },\n}\n\nconst powerUnits: UnitCategory = {\n baseUnit: 'w',\n description: 'power',\n units: {\n w: 1,\n kw: 1000,\n mw: 1000000,\n hp: 745.7,\n },\n}\n\nconst frequencyUnits: UnitCategory = {\n baseUnit: 'hz',\n description: 'frequency',\n units: {\n hz: 1,\n khz: 1000,\n mhz: 1000000,\n ghz: 1000000000,\n },\n}\n\nconst angleUnits: UnitCategory = {\n baseUnit: 'rad',\n description: 'angle',\n units: {\n deg: Math.PI / 180,\n rad: 1,\n grad: Math.PI / 200,\n turn: 2 * Math.PI,\n },\n}\n\n// --- Temperature conversion functions ---\n\nfunction celsiusTo(unit: 'c' | 'f' | 'k', value: number): number {\n switch (unit) {\n case 'c': return value\n case 'f': return value * 9 / 5 + 32\n case 'k': return value + 273.15\n }\n}\n\nfunction toCelsius(unit: 'c' | 'f' | 'k', value: number): number {\n switch (unit) {\n case 'c': return value\n case 'f': return (value - 32) * 5 / 9\n case 'k': return value - 273.15\n }\n}\n\nconst temperatureUnits = ['c', 'f', 'k'] as const\n\nconst unitDescriptions: Record<string, string> = {\n // Length\n 'angstrom': 'ångströms',\n 'um': 'micrometers',\n 'mm': 'millimeters',\n 'cm': 'centimeters',\n 'm': 'meters',\n 'km': 'kilometers',\n 'in': 'inches',\n 'ft': 'feet',\n 'yd': 'yards',\n 'mi': 'miles',\n 'nmi': 'nautical miles',\n // Weight\n 'mg': 'milligrams',\n 'g': 'grams',\n 'kg': 'kilograms',\n 't': 'metric tons',\n 'oz': 'ounces',\n 'lb': 'pounds',\n 'st': 'stones',\n // Volume\n 'ml': 'milliliters',\n 'cl': 'centiliters',\n 'dl': 'deciliters',\n 'l': 'liters',\n 'tsp': 'teaspoons',\n 'tbsp': 'tablespoons',\n 'fl-oz': 'fluid ounces',\n 'cup': 'cups',\n 'pt': 'pints',\n 'qt': 'quarts',\n 'gal': 'gallons',\n // Time\n 'ms': 'milliseconds',\n 's': 'seconds',\n 'min': 'minutes',\n 'h': 'hours',\n 'day': 'days',\n 'week': 'weeks',\n // Area\n 'mm2': 'square millimeters',\n 'cm2': 'square centimeters',\n 'm2': 'square meters',\n 'km2': 'square kilometers',\n 'in2': 'square inches',\n 'ft2': 'square feet',\n 'yd2': 'square yards',\n 'acre': 'acres',\n 'hectare': 'hectares',\n // Speed\n 'm/s': 'meters per second',\n 'km/h': 'kilometers per hour',\n 'mph': 'miles per hour',\n 'kn': 'knots',\n 'ft/s': 'feet per second',\n // Data\n 'b': 'bytes',\n 'kb': 'kilobytes',\n 'mb': 'megabytes',\n 'gb': 'gigabytes',\n 'tb': 'terabytes',\n 'pb': 'petabytes',\n // Pressure\n 'pa': 'pascals',\n 'kpa': 'kilopascals',\n 'bar': 'bars',\n 'atm': 'atmospheres',\n 'psi': 'pounds per square inch',\n 'mmhg': 'millimeters of mercury',\n // Energy\n 'j': 'joules',\n 'kj': 'kilojoules',\n 'cal': 'calories',\n 'kcal': 'kilocalories',\n 'wh': 'watt-hours',\n 'kwh': 'kilowatt-hours',\n 'btu': 'British thermal units',\n // Power\n 'w': 'watts',\n 'kw': 'kilowatts',\n 'mw': 'megawatts',\n 'hp': 'horsepower',\n // Frequency\n 'hz': 'hertz',\n 'khz': 'kilohertz',\n 'mhz': 'megahertz',\n 'ghz': 'gigahertz',\n // Angle\n 'deg': 'degrees',\n 'rad': 'radians',\n 'grad': 'gradians',\n 'turn': 'turns',\n // Temperature\n 'c': 'Celsius',\n 'f': 'Fahrenheit',\n 'k': 'Kelvin',\n}\n\n// --- Generate linear conversion functions ---\n\nfunction generateLinearConversions(category: UnitCategory): BuiltinNormalExpressions {\n const result: BuiltinNormalExpressions = {}\n const unitNames = Object.keys(category.units)\n\n for (const from of unitNames) {\n for (const to of unitNames) {\n if (from === to)\n continue\n\n const fromFactor = category.units[from]!\n const toFactor = category.units[to]!\n const conversionFactor = fromFactor / toFactor\n const fnName = `${from}->${to}`\n const fromDesc = unitDescriptions[from]!\n const toDesc = unitDescriptions[to]!\n\n const seeAlso = [\n `convert.${to}->${from}`,\n ...unitNames\n .filter(u => u !== from && u !== to)\n .map(u => `convert.${from}->${u}`),\n ]\n\n result[fnName] = {\n evaluate: ([value], sourceCodeInfo): number => {\n assertNumber(value, sourceCodeInfo)\n return value * conversionFactor\n },\n arity: toFixedArity(1),\n docs: {\n category: 'convert',\n returns: { type: 'number' },\n args: {\n value: { type: 'number', description: `Value in ${fromDesc}` },\n },\n variants: [{ argumentNames: ['value'] }],\n description: `Converts a value from ${fromDesc} (\\`${from}\\`) to ${toDesc} (\\`${to}\\`).`,\n seeAlso,\n examples: [\n `let { ${fnName} } = import(convert);\n${fnName}(1)`,\n ],\n },\n }\n }\n }\n return result\n}\n\n// --- Generate temperature conversion functions ---\n\nfunction generateTemperatureConversions(): BuiltinNormalExpressions {\n const result: BuiltinNormalExpressions = {}\n\n for (const from of temperatureUnits) {\n for (const to of temperatureUnits) {\n if (from === to)\n continue\n\n const fnName = `${from}->${to}`\n const fromDesc = unitDescriptions[from]!\n const toDesc = unitDescriptions[to]!\n\n const seeAlso = [\n `convert.${to}->${from}`,\n ...temperatureUnits\n .filter(u => u !== from && u !== to)\n .map(u => `convert.${from}->${u}`),\n ]\n\n result[fnName] = {\n evaluate: ([value], sourceCodeInfo): number => {\n assertNumber(value, sourceCodeInfo)\n const celsius = toCelsius(from, value)\n return celsiusTo(to, celsius)\n },\n arity: toFixedArity(1),\n docs: {\n category: 'convert',\n returns: { type: 'number' },\n args: {\n value: { type: 'number', description: `Value in ${fromDesc}` },\n },\n variants: [{ argumentNames: ['value'] }],\n description: `Converts a temperature from ${fromDesc} (\\`${from}\\`) to ${toDesc} (\\`${to}\\`).`,\n seeAlso,\n examples: [\n `let { ${fnName} } = import(convert);\n${fnName}(100)`,\n ],\n },\n }\n }\n }\n return result\n}\n\n// --- Assemble all conversion functions ---\n\nconst convertFunctions: BuiltinNormalExpressions = {\n ...generateLinearConversions(lengthUnits),\n ...generateLinearConversions(weightUnits),\n ...generateLinearConversions(volumeUnits),\n ...generateLinearConversions(timeUnits),\n ...generateLinearConversions(areaUnits),\n ...generateLinearConversions(speedUnits),\n ...generateLinearConversions(dataUnits),\n ...generateLinearConversions(pressureUnits),\n ...generateLinearConversions(energyUnits),\n ...generateLinearConversions(powerUnits),\n ...generateLinearConversions(frequencyUnits),\n ...generateLinearConversions(angleUnits),\n ...generateTemperatureConversions(),\n}\n\nexport const convertModule: LitsModule = {\n name: 'convert',\n functions: convertFunctions,\n}\n"],"names":["getCodeMarker","sourceCodeInfo","position","code","leftPadding","column","rightPadding","length","repeat","Math","max","LitsError","Error","shortMessage","constructor","err","message","super","location","line","filePath","getLitsErrorMessage","this","Object","setPrototypeOf","prototype","name","NodeTypes","Number","String","NormalExpression","SpecialExpression","UserDefinedSymbol","NormalBuiltinSymbol","SpecialBuiltinSymbol","ReservedSymbol","Binding","Spread","NodeTypesSet","Set","values","functionTypeSet","isLitsFunction","func","type","functionType","has","isNode","value","Array","isArray","valueToString","keys","find","key","RegExp","toString","JSON","stringify","assertNumber","options","isNaN","integer","isInteger","finite","isFinite","zero","nonZero","positive","negative","nonPositive","nonNegative","gt","gte","lt","lte","isNumber","sign","getSignString","numberType","range","getRangeString","filter","x","join","getNumberTypeName","anyValue","getSourceCodeInfo","toFixedArity","arity","min","angleUnits","baseUnit","description","units","deg","PI","rad","grad","turn","celsiusTo","unit","toCelsius","temperatureUnits","unitDescriptions","angstrom","um","mm","cm","m","km","in","ft","yd","mi","nmi","mg","g","kg","t","oz","lb","st","ml","cl","dl","l","tsp","tbsp","cup","pt","qt","gal","ms","s","h","day","week","mm2","cm2","m2","km2","in2","ft2","yd2","acre","hectare","mph","kn","b","kb","mb","gb","tb","pb","pa","kpa","bar","atm","psi","mmhg","j","kj","cal","kcal","wh","kwh","btu","w","kw","mw","hp","hz","khz","mhz","ghz","c","f","k","generateLinearConversions","category","result","unitNames","from","to","conversionFactor","fnName","fromDesc","toDesc","seeAlso","u","map","evaluate","docs","returns","args","variants","argumentNames","examples","convertModule","functions","celsius","generateTemperatureConversions"],"mappings":"AAEM,SAAUA,EAAcC,GAC5B,IAAKA,EAAeC,WAAaD,EAAeE,KAC9C,MAAO,GAET,MAAMC,EAAcH,EAAeC,SAASG,OAAS,EAC/CC,EAAeL,EAAeE,KAAKI,OAASH,EAAc,EAChE,MAAO,GAAG,IAAII,OA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EAAkB,CACjC,GAAIgF,IAASC,EACX,SAEF,MAAME,EAAS,GAAGH,MAASC,IACrBG,EAAWnF,EAAiB+E,GAC5BK,EAASpF,EAAiBgF,GAE1BK,EAAU,CACd,WAAWL,MAAOD,OACfhF,EACArB,OAAO4G,GAAKA,IAAMP,GAAQO,IAAMN,GAChCO,IAAID,GAAK,WAAWP,MAASO,MAGlCT,EAAOK,GAAU,CACfM,SAAU,EAAEhJ,GAAQ/C,KAClB0D,EAAaX,EAAO/C,GACpB,MAAMwM,EAAUnG,EAAUiF,EAAMvI,GAChC,OAAOoD,EAAUoF,EAAIiB,IAEvBhH,MAAOD,EAAa,GACpByG,KAAM,CACJb,SAAU,UACVc,QAAS,CAAEtJ,KAAM,UACjBuJ,KAAM,CACJnJ,MAAO,CAAEJ,KAAM,SAAUiD,YAAa,YAAY8F,MAEpDS,SAAU,CAAC,CAAEC,cAAe,CAAC,WAC7BxG,YAAa,+BAA+B8F,QAAeJ,WAAcK,QAAaJ,QACtFK,UACAS,SAAU,CACR,SAASZ,2BACnBA,WAIG,CAEH,OAAOL,CACT,CAiBKqB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";function e(e){if(!e.position||!e.code)return"";const t=e.position.column-1,n=e.code.length-t-1;return`${" ".repeat(Math.max(t,0))}^${" ".repeat(Math.max(n,0))}`}class t extends Error{sourceCodeInfo;shortMessage;constructor(n,r){const s=n instanceof Error?n.message:`${n}`;super(function(t,n){if(!n)return t;const r=`${n.position.line}:${n.position.column}`;return`${t}${n.filePath?`\n${n.filePath}:${r}`:`\nLocation ${r}`}\n${n.code}\n${e(n)}`}(s,r)),this.shortMessage=s,this.sourceCodeInfo=r,Object.setPrototypeOf(this,t.prototype),this.name="LitsError"}getCodeMarker(){return this.sourceCodeInfo&&e(this.sourceCodeInfo)}}const n={Number:1,String:2,NormalExpression:3,SpecialExpression:4,UserDefinedSymbol:5,NormalBuiltinSymbol:6,SpecialBuiltinSymbol:7,ReservedSymbol:8,Binding:9,Spread:10},r=new Set(Object.values(n));const s=new Set(["UserDefined","Partial","Comp","Constantly","Juxt","Complement","EveryPred","SomePred","Fnull","Builtin","SpecialBuiltin","NativeJsFunction","Module"]);function i(e){return null!==e&&"object"==typeof e&&("^^fn^^"in e&&"functionType"in e&&("string"==typeof(t=e.functionType)&&s.has(t)));var t}function o(e){return!(!Array.isArray(e)||e.length<2)&&("number"==typeof(t=e[0])&&r.has(t));var t}function a(e){return i(e)?`<function ${e.name||"λ"}>`:o(e)?`${t=e[0],Object.keys(n).find(e=>n[e]===t)}-node`:null===e?"null":"object"==typeof e&&e instanceof RegExp?`${e}`:"object"==typeof e&&e instanceof Error?e.toString():JSON.stringify(e);var t}function u(e,n,r={}){if(!function(e,t={}){return!("number"!=typeof e||Number.isNaN(e)||t.integer&&!Number.isInteger(e)||t.finite&&!Number.isFinite(e)||t.zero&&0!==e||t.nonZero&&0===e||t.positive&&e<=0||t.negative&&e>=0||t.nonPositive&&e>0||t.nonNegative&&e<0||"number"==typeof t.gt&&e<=t.gt||"number"==typeof t.gte&&e<t.gte||"number"==typeof t.lt&&e>=t.lt||"number"==typeof t.lte&&e>t.lte)}(e,r))throw new t(`Expected ${function(e){if(e.zero)return"zero";const t=function(e){return e.positive?"positive":e.negative?"negative":e.nonNegative?"non negative":e.nonPositive?"non positive":e.nonZero?"non zero":""}(e),n=e.integer?"integer":"number",r=e.finite?"finite":"",s=function(e){return"number"!=typeof e.gt&&"number"!=typeof e.gte||"number"!=typeof e.lt&&"number"!=typeof e.lte?"number"==typeof e.gt||"number"==typeof e.gte?"number"==typeof e.gt?`n > ${e.gt}`:`n >= ${e.gte}`:"number"==typeof e.lt||"number"==typeof e.lte?"number"==typeof e.lt?`n < ${e.lt}`:`n <= ${e.lte}`:"":`${"number"==typeof e.gt?`${e.gt} < n `:`${e.gte} <= n `}${"number"==typeof e.lt?`< ${e.lt}`:`<= ${e.lte}`}`}(e);return[t,r,n,s].filter(e=>!!e).join(" ")}(r)}, got ${a(e)}.`,function(e,t){return e?.sourceCodeInfo??t}(e,n))}function c(e){return{min:e,max:e}}const m={baseUnit:"rad",description:"angle",units:{deg:Math.PI/180,rad:1,grad:Math.PI/200,turn:2*Math.PI}};function l(e,t){switch(e){case"c":return t;case"f":return 9*t/5+32;case"k":return t+273.15}}function p(e,t){switch(e){case"c":return t;case"f":return 5*(t-32)/9;case"k":return t-273.15}}const f=["c","f","k"],g={angstrom:"ångströms",um:"micrometers",mm:"millimeters",cm:"centimeters",m:"meters",km:"kilometers",in:"inches",ft:"feet",yd:"yards",mi:"miles",nmi:"nautical miles",mg:"milligrams",g:"grams",kg:"kilograms",t:"metric tons",oz:"ounces",lb:"pounds",st:"stones",ml:"milliliters",cl:"centiliters",dl:"deciliters",l:"liters",tsp:"teaspoons",tbsp:"tablespoons","fl-oz":"fluid ounces",cup:"cups",pt:"pints",qt:"quarts",gal:"gallons",ms:"milliseconds",s:"seconds",min:"minutes",h:"hours",day:"days",week:"weeks",mm2:"square millimeters",cm2:"square centimeters",m2:"square meters",km2:"square kilometers",in2:"square inches",ft2:"square feet",yd2:"square yards",acre:"acres",hectare:"hectares","m/s":"meters per second","km/h":"kilometers per hour",mph:"miles per hour",kn:"knots","ft/s":"feet per second",b:"bytes",kb:"kilobytes",mb:"megabytes",gb:"gigabytes",tb:"terabytes",pb:"petabytes",pa:"pascals",kpa:"kilopascals",bar:"bars",atm:"atmospheres",psi:"pounds per square inch",mmhg:"millimeters of mercury",j:"joules",kj:"kilojoules",cal:"calories",kcal:"kilocalories",wh:"watt-hours",kwh:"kilowatt-hours",btu:"British thermal units",w:"watts",kw:"kilowatts",mw:"megawatts",hp:"horsepower",hz:"hertz",khz:"kilohertz",mhz:"megahertz",ghz:"gigahertz",deg:"degrees",rad:"radians",grad:"gradians",turn:"turns",c:"Celsius",f:"Fahrenheit",k:"Kelvin"};function b(e){const t={},n=Object.keys(e.units);for(const r of n)for(const s of n){if(r===s)continue;const i=e.units[r]/e.units[s],o=`${r}->${s}`,a=g[r],m=g[s],l=[`convert.${s}->${r}`,...n.filter(e=>e!==r&&e!==s).map(e=>`convert.${r}->${e}`)];t[o]={evaluate:([e],t)=>(u(e,t),e*i),arity:c(1),docs:{category:"convert",returns:{type:"number"},args:{value:{type:"number",description:`Value in ${a}`}},variants:[{argumentNames:["value"]}],description:`Converts a value from ${a} (\`${r}\`) to ${m} (\`${s}\`).`,seeAlso:l,examples:[`let { ${o} } = import(convert);\n${o}(1)`]}}}return t}const d={name:"convert",functions:{...b({baseUnit:"m",description:"length",units:{angstrom:1e-10,um:1e-6,mm:.001,cm:.01,m:1,km:1e3,in:.0254,ft:.3048,yd:.9144,mi:1609.344,nmi:1852}}),...b({baseUnit:"kg",description:"weight",units:{mg:1e-6,g:.001,kg:1,t:1e3,oz:.028349523125,lb:.45359237,st:6.35029318}}),...b({baseUnit:"l",description:"volume",units:{ml:.001,cl:.01,dl:.1,l:1,tsp:.00492892159375,tbsp:.01478676478125,"fl-oz":.0295735295625,cup:.2365882365,pt:.473176473,qt:.946352946,gal:3.785411784}}),...b({baseUnit:"s",description:"time",units:{ms:.001,s:1,min:60,h:3600,day:86400,week:604800}}),...b({baseUnit:"m2",description:"area",units:{mm2:1e-6,cm2:1e-4,m2:1,km2:1e6,in2:64516e-8,ft2:.09290304,yd2:.83612736,acre:4046.8564224,hectare:1e4}}),...b({baseUnit:"m/s",description:"speed",units:{"m/s":1,"km/h":1/3.6,mph:.44704,kn:.514444,"ft/s":.3048}}),...b({baseUnit:"b",description:"data",units:{b:1,kb:1e3,mb:1e6,gb:1e9,tb:1e12,pb:1e15}}),...b({baseUnit:"pa",description:"pressure",units:{pa:1,kpa:1e3,bar:1e5,atm:101325,psi:6894.757293168,mmhg:133.322387415}}),...b({baseUnit:"j",description:"energy",units:{j:1,kj:1e3,cal:4.184,kcal:4184,wh:3600,kwh:36e5,btu:1055.06}}),...b({baseUnit:"w",description:"power",units:{w:1,kw:1e3,mw:1e6,hp:745.7}}),...b({baseUnit:"hz",description:"frequency",units:{hz:1,khz:1e3,mhz:1e6,ghz:1e9}}),...b(m),...function(){const e={};for(const t of f)for(const n of f){if(t===n)continue;const r=`${t}->${n}`,s=g[t],i=g[n],o=[`convert.${n}->${t}`,...f.filter(e=>e!==t&&e!==n).map(e=>`convert.${t}->${e}`)];e[r]={evaluate:([e],r)=>{u(e,r);const s=p(t,e);return l(n,s)},arity:c(1),docs:{category:"convert",returns:{type:"number"},args:{value:{type:"number",description:`Value in ${s}`}},variants:[{argumentNames:["value"]}],description:`Converts a temperature from ${s} (\`${t}\`) to ${i} (\`${n}\`).`,seeAlso:o,examples:[`let { ${r} } = import(convert);\n${r}(100)`]}}}return e}()}};exports.convertModule=d;
|
|
2
|
+
//# sourceMappingURL=convert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.js","sources":["../../src/utils/debug/getCodeMarker.ts","../../src/errors.ts","../../src/constants/constants.ts","../../src/utils/debug/debugTools.ts","../../src/utils/symbols.ts","../../src/typeGuards/number.ts","../../src/utils/debug/getSourceCodeInfo.ts","../../src/utils/arity.ts","../../src/builtin/modules/convert/index.ts"],"sourcesContent":["import type { SourceCodeInfo } from '../../tokenizer/token'\n\nexport function getCodeMarker(sourceCodeInfo: SourceCodeInfo): string {\n if (!sourceCodeInfo.position || !sourceCodeInfo.code)\n return ''\n\n const leftPadding = sourceCodeInfo.position.column - 1\n const rightPadding = sourceCodeInfo.code.length - leftPadding - 1\n return `${' '.repeat(Math.max(leftPadding, 0))}^${' '.repeat(Math.max(rightPadding, 0))}`\n}\n","import { getCodeMarker } from '../src/utils/debug/getCodeMarker'\nimport type { Arr } from './interface'\nimport type { SourceCodeInfo } from './tokenizer/token'\n\nfunction getLitsErrorMessage(message: string, sourceCodeInfo?: SourceCodeInfo) {\n if (!sourceCodeInfo) {\n return message\n }\n const location = `${sourceCodeInfo.position.line}:${sourceCodeInfo.position.column}`\n const filePathLine = sourceCodeInfo.filePath\n ? `\\n${sourceCodeInfo.filePath}:${location}`\n : `\\nLocation ${location}`\n const codeLine = `\\n${sourceCodeInfo.code}`\n const codeMarker = `\\n${getCodeMarker(sourceCodeInfo)}`\n return `${message}${filePathLine}${codeLine}${codeMarker}`\n}\n\nexport class RecurSignal extends Error {\n public params: Arr\n constructor(params: Arr) {\n super(`recur, params: ${params}`)\n Object.setPrototypeOf(this, RecurSignal.prototype)\n this.name = 'RecurSignal'\n this.params = params\n }\n}\n\nexport class LitsError extends Error {\n public readonly sourceCodeInfo?: SourceCodeInfo\n public readonly shortMessage: string\n constructor(err: unknown, sourceCodeInfo: SourceCodeInfo | undefined) {\n const message = err instanceof Error\n ? err.message\n : `${err}`\n\n super(getLitsErrorMessage(message, sourceCodeInfo))\n this.shortMessage = message\n this.sourceCodeInfo = sourceCodeInfo\n Object.setPrototypeOf(this, LitsError.prototype)\n this.name = 'LitsError'\n }\n\n public getCodeMarker(): string | undefined {\n return this.sourceCodeInfo && getCodeMarker(this.sourceCodeInfo)\n }\n}\n\nexport class UserDefinedError extends LitsError {\n public userMessage: string\n constructor(message: string, sourceCodeInfo?: SourceCodeInfo) {\n super(message, sourceCodeInfo)\n this.userMessage = message\n Object.setPrototypeOf(this, UserDefinedError.prototype)\n this.name = 'UserDefinedError'\n }\n}\n\nexport class AssertionError extends LitsError {\n constructor(message: string | Error, sourceCodeInfo?: SourceCodeInfo) {\n super(message, sourceCodeInfo)\n Object.setPrototypeOf(this, AssertionError.prototype)\n this.name = 'AssertionError'\n }\n}\n\nexport class UndefinedSymbolError extends LitsError {\n public symbol: string\n constructor(symbolName: string, sourceCodeInfo?: SourceCodeInfo) {\n const message = `Undefined symbol '${symbolName}'.`\n super(message, sourceCodeInfo)\n this.symbol = symbolName\n Object.setPrototypeOf(this, UndefinedSymbolError.prototype)\n this.name = 'UndefinedSymbolError'\n }\n}\n\nexport function isLitsError(error: unknown): error is LitsError {\n return error instanceof LitsError\n}\n","export const NodeTypes = {\n Number: 1,\n String: 2,\n NormalExpression: 3,\n SpecialExpression: 4,\n UserDefinedSymbol: 5,\n NormalBuiltinSymbol: 6,\n SpecialBuiltinSymbol: 7,\n ReservedSymbol: 8,\n Binding: 9,\n Spread: 10,\n} as const\n\nconst NodeTypesSet = new Set(Object.values(NodeTypes))\n\nexport type NodeType = typeof NodeTypes[keyof typeof NodeTypes]\n\nexport function getNodeTypeName(type: NodeType): keyof typeof NodeTypes {\n return Object.keys(NodeTypes).find(key => NodeTypes[key as keyof typeof NodeTypes] === type) as keyof typeof NodeTypes\n}\n\n// TODO, is this needed?\nexport function isNodeType(type: unknown): type is NodeType {\n return typeof type === 'number' && NodeTypesSet.has(type as NodeType)\n}\n\nconst functionTypes = [\n 'UserDefined',\n 'Partial',\n 'Comp',\n 'Constantly',\n 'Juxt',\n 'Complement',\n 'EveryPred',\n 'SomePred',\n 'Fnull',\n 'Builtin',\n 'SpecialBuiltin',\n 'NativeJsFunction',\n 'Module',\n] as const\n\nconst functionTypeSet = new Set(functionTypes)\n\nexport type FunctionType = typeof functionTypes[number]\n\nexport function isFunctionType(type: unknown): type is FunctionType {\n return typeof type === 'string' && functionTypeSet.has(type as FunctionType)\n}\n","import { getNodeTypeName, isFunctionType, isNodeType } from '../../constants/constants'\nimport type { AstNode, LitsFunction } from '../../parser/types'\nimport { FUNCTION_SYMBOL } from '../symbols'\n\nfunction isLitsFunction(func: unknown): func is LitsFunction {\n if (func === null || typeof func !== 'object')\n return false\n\n return FUNCTION_SYMBOL in func && 'functionType' in func && isFunctionType(func.functionType)\n}\n\nfunction isNode(value: unknown): value is AstNode {\n if (!Array.isArray(value) || value.length < 2)\n return false\n return isNodeType(value[0])\n}\n\nexport function valueToString(value: unknown): string {\n if (isLitsFunction(value))\n // eslint-disable-next-line ts/no-unsafe-member-access\n return `<function ${(value as any).name || '\\u03BB'}>`\n\n if (isNode(value))\n return `${getNodeTypeName(value[0])}-node`\n\n if (value === null)\n return 'null'\n\n if (typeof value === 'object' && value instanceof RegExp)\n return `${value}`\n\n if (typeof value === 'object' && value instanceof Error)\n return value.toString()\n\n return JSON.stringify(value)\n}\n","export const FUNCTION_SYMBOL = '^^fn^^'\nexport const REGEXP_SYMBOL = '^^re^^'\n","import { LitsError } from '../errors'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { valueToString } from '../utils/debug/debugTools'\nimport { getSourceCodeInfo } from '../utils/debug/getSourceCodeInfo'\n\ntype SignOptions =\n | {\n positive?: true\n negative?: never\n nonPositive?: never\n nonNegative?: never\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: true\n nonPositive?: never\n nonNegative?: never\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: true\n nonNegative?: never\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: never\n nonNegative?: true\n zero?: never\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: never\n nonNegative?: never\n zero?: true\n nonZero?: never\n }\n | {\n positive?: never\n negative?: never\n nonPositive?: never\n nonNegative?: never\n zero?: never\n nonZero?: true\n }\n\ntype GtOptions =\n | {\n gt?: number\n gte?: never\n }\n | {\n gt?: never\n gte?: number\n }\n\ntype LtOptions =\n | {\n lt?: number\n lte?: never\n }\n | {\n lt?: never\n lte?: number\n }\n\ntype NumberOptions = {\n integer?: true\n finite?: true\n} & SignOptions &\nGtOptions &\nLtOptions\n\nfunction getRangeString(options: NumberOptions): string {\n const hasUpperAndLowerBound\n = (typeof options.gt === 'number' || typeof options.gte === 'number')\n && (typeof options.lt === 'number' || typeof options.lte === 'number')\n if (hasUpperAndLowerBound) {\n return `${typeof options.gt === 'number' ? `${options.gt} < n ` : `${options.gte} <= n `}${\n typeof options.lt === 'number' ? `< ${options.lt}` : `<= ${options.lte}`\n }`\n }\n else if (typeof options.gt === 'number' || typeof options.gte === 'number') {\n return `${typeof options.gt === 'number' ? `n > ${options.gt}` : `n >= ${options.gte}`}`\n }\n else if (typeof options.lt === 'number' || typeof options.lte === 'number') {\n return `${typeof options.lt === 'number' ? `n < ${options.lt}` : `n <= ${options.lte}`}`\n }\n else { return '' }\n}\n\nfunction getSignString(options: NumberOptions): string {\n return options.positive\n ? 'positive'\n : options.negative\n ? 'negative'\n : options.nonNegative\n ? 'non negative'\n : options.nonPositive\n ? 'non positive'\n : options.nonZero\n ? 'non zero'\n : ''\n}\n\nfunction getNumberTypeName(options: NumberOptions): string {\n if (options.zero)\n return 'zero'\n\n const sign = getSignString(options)\n const numberType = options.integer ? 'integer' : 'number'\n const finite = options.finite ? 'finite' : ''\n const range = getRangeString(options)\n\n return [sign, finite, numberType, range].filter(x => !!x).join(' ')\n}\n\nexport function isNumber(value: unknown, options: NumberOptions = {}): value is number {\n if (typeof value !== 'number')\n return false\n\n if (Number.isNaN(value))\n return false\n\n if (options.integer && !Number.isInteger(value))\n return false\n\n if (options.finite && !Number.isFinite(value))\n return false\n\n if (options.zero && value !== 0)\n return false\n\n if (options.nonZero && value === 0)\n return false\n\n if (options.positive && value <= 0)\n return false\n\n if (options.negative && value >= 0)\n return false\n\n if (options.nonPositive && value > 0)\n return false\n\n if (options.nonNegative && value < 0)\n return false\n\n if (typeof options.gt === 'number' && value <= options.gt)\n return false\n\n if (typeof options.gte === 'number' && value < options.gte)\n return false\n\n if (typeof options.lt === 'number' && value >= options.lt)\n return false\n\n if (typeof options.lte === 'number' && value > options.lte)\n return false\n\n return true\n}\n\nexport function assertNumber(\n value: unknown,\n sourceCodeInfo?: SourceCodeInfo,\n options: NumberOptions = {},\n): asserts value is number {\n if (!isNumber(value, options)) {\n throw new LitsError(\n `Expected ${getNumberTypeName(options)}, got ${valueToString(value)}.`,\n getSourceCodeInfo(value, sourceCodeInfo),\n )\n }\n}\n\nexport function asNumber(\n value: unknown,\n sourceCodeInfo: SourceCodeInfo | undefined,\n options: NumberOptions = {},\n): number {\n assertNumber(value, sourceCodeInfo, options)\n return value\n}\n","import type { SourceCodeInfo } from '../../tokenizer/token'\n\nexport function getSourceCodeInfo(anyValue: any, sourceCodeInfo: SourceCodeInfo | undefined): SourceCodeInfo | undefined {\n // eslint-disable-next-line ts/no-unsafe-return, ts/no-unsafe-member-access\n return anyValue?.sourceCodeInfo ?? sourceCodeInfo\n}\n","import type { Arity } from '../builtin/interface'\nimport { LitsError } from '../errors'\nimport type { FunctionLike } from '../parser/types'\nimport type { SourceCodeInfo } from '../tokenizer/token'\nimport { isColl } from '../typeGuards/lits'\nimport { valueToString } from './debug/debugTools'\n\nexport function arityAccepts(arity: Arity, nbrOfParams: number): boolean {\n const { min, max } = arity\n if (typeof min === 'number' && nbrOfParams < min) {\n return false\n }\n if (typeof max === 'number' && nbrOfParams > max) {\n return false\n }\n return true\n}\n\nexport function arityAcceptsMin(arity: Arity, nbrOfParams: number): boolean {\n const { min } = arity\n if (typeof min === 'number' && nbrOfParams < min) {\n return false\n }\n return true\n}\n\nexport function getCommonArityFromFunctions(params: FunctionLike[]): Arity | null {\n return params.reduce((acc: Arity | null, param): Arity | null => {\n if (acc === null) {\n return null\n }\n const arity: Arity = (typeof param === 'number' || isColl(param)) ? toFixedArity(1) : param.arity\n const { min: aMin, max: aMax } = arity\n const { min: bMin, max: bMax } = acc\n const min = typeof aMin === 'number' && typeof bMin === 'number'\n ? Math.max(aMin, bMin)\n : typeof aMin === 'number' ? aMin : typeof bMin === 'number' ? bMin : undefined\n const max = typeof aMax === 'number' && typeof bMax === 'number'\n ? Math.min(aMax, bMax)\n : typeof aMax === 'number' ? aMax : typeof bMax === 'number' ? bMax : undefined\n\n if (typeof min === 'number' && typeof max === 'number' && min > max) {\n return null\n }\n\n return { min, max }\n }, {})\n}\n\nexport function getArityFromFunction(param: FunctionLike): Arity {\n return (typeof param === 'number' || isColl(param)) ? toFixedArity(1) : param.arity\n}\n\nexport function assertNumberOfParams(arity: Arity, length: number, sourceCodeInfo: SourceCodeInfo | undefined): void {\n const { min, max } = arity\n if (typeof min === 'number' && length < min) {\n throw new LitsError(\n `Wrong number of arguments, expected at least ${min}, got ${valueToString(length)}.`,\n sourceCodeInfo,\n )\n }\n\n if (typeof max === 'number' && length > max) {\n throw new LitsError(\n `Wrong number of arguments, expected at most ${max}, got ${valueToString(length)}.`,\n sourceCodeInfo,\n )\n }\n}\n\nexport function canBeOperator(count: Arity): boolean {\n if (typeof count.max === 'number' && count.max < 2) {\n return false\n }\n\n if (typeof count.min === 'number' && count.min > 2) {\n return false\n }\n\n return true\n}\n\nexport function toFixedArity(arity: number): Arity {\n return { min: arity, max: arity }\n}\n","import { assertNumber } from '../../../typeGuards/number'\nimport { toFixedArity } from '../../../utils/arity'\nimport type { BuiltinNormalExpressions } from '../../interface'\nimport type { LitsModule } from '../interface'\n\n// --- Conversion factor tables ---\n// Each category maps unit abbreviations to a factor relative to a base unit.\n// To convert from unit A to unit B: value * (factorA / factorB)\n// Temperature is special-cased (non-linear).\n\ninterface UnitCategory {\n baseUnit: string\n units: Record<string, number>\n description: string\n}\n\nconst lengthUnits: UnitCategory = {\n baseUnit: 'm',\n description: 'length',\n units: {\n angstrom: 1e-10,\n um: 0.000001,\n mm: 0.001,\n cm: 0.01,\n m: 1,\n km: 1000,\n in: 0.0254,\n ft: 0.3048,\n yd: 0.9144,\n mi: 1609.344,\n nmi: 1852,\n },\n}\n\nconst weightUnits: UnitCategory = {\n baseUnit: 'kg',\n description: 'weight',\n units: {\n mg: 0.000001,\n g: 0.001,\n kg: 1,\n t: 1000,\n oz: 0.028349523125,\n lb: 0.45359237,\n st: 6.35029318,\n },\n}\n\nconst volumeUnits: UnitCategory = {\n baseUnit: 'l',\n description: 'volume',\n units: {\n 'ml': 0.001,\n 'cl': 0.01,\n 'dl': 0.1,\n 'l': 1,\n 'tsp': 0.00492892159375,\n 'tbsp': 0.01478676478125,\n 'fl-oz': 0.0295735295625,\n 'cup': 0.2365882365,\n 'pt': 0.473176473,\n 'qt': 0.946352946,\n 'gal': 3.785411784,\n },\n}\n\nconst timeUnits: UnitCategory = {\n baseUnit: 's',\n description: 'time',\n units: {\n ms: 0.001,\n s: 1,\n min: 60,\n h: 3600,\n day: 86400,\n week: 604800,\n },\n}\n\nconst areaUnits: UnitCategory = {\n baseUnit: 'm2',\n description: 'area',\n units: {\n mm2: 0.000001,\n cm2: 0.0001,\n m2: 1,\n km2: 1000000,\n in2: 0.00064516,\n ft2: 0.09290304,\n yd2: 0.83612736,\n acre: 4046.8564224,\n hectare: 10000,\n },\n}\n\nconst speedUnits: UnitCategory = {\n baseUnit: 'm/s',\n description: 'speed',\n units: {\n 'm/s': 1,\n 'km/h': 1 / 3.6,\n 'mph': 0.44704,\n 'kn': 0.514444,\n 'ft/s': 0.3048,\n },\n}\n\nconst dataUnits: UnitCategory = {\n baseUnit: 'b',\n description: 'data',\n units: {\n b: 1,\n kb: 1000,\n mb: 1000000,\n gb: 1e9,\n tb: 1e12,\n pb: 1e15,\n },\n}\n\nconst pressureUnits: UnitCategory = {\n baseUnit: 'pa',\n description: 'pressure',\n units: {\n pa: 1,\n kpa: 1000,\n bar: 100000,\n atm: 101325,\n psi: 6894.757293168,\n mmhg: 133.322387415,\n },\n}\n\nconst energyUnits: UnitCategory = {\n baseUnit: 'j',\n description: 'energy',\n units: {\n j: 1,\n kj: 1000,\n cal: 4.184,\n kcal: 4184,\n wh: 3600,\n kwh: 3600000,\n btu: 1055.06,\n },\n}\n\nconst powerUnits: UnitCategory = {\n baseUnit: 'w',\n description: 'power',\n units: {\n w: 1,\n kw: 1000,\n mw: 1000000,\n hp: 745.7,\n },\n}\n\nconst frequencyUnits: UnitCategory = {\n baseUnit: 'hz',\n description: 'frequency',\n units: {\n hz: 1,\n khz: 1000,\n mhz: 1000000,\n ghz: 1000000000,\n },\n}\n\nconst angleUnits: UnitCategory = {\n baseUnit: 'rad',\n description: 'angle',\n units: {\n deg: Math.PI / 180,\n rad: 1,\n grad: Math.PI / 200,\n turn: 2 * Math.PI,\n },\n}\n\n// --- Temperature conversion functions ---\n\nfunction celsiusTo(unit: 'c' | 'f' | 'k', value: number): number {\n switch (unit) {\n case 'c': return value\n case 'f': return value * 9 / 5 + 32\n case 'k': return value + 273.15\n }\n}\n\nfunction toCelsius(unit: 'c' | 'f' | 'k', value: number): number {\n switch (unit) {\n case 'c': return value\n case 'f': return (value - 32) * 5 / 9\n case 'k': return value - 273.15\n }\n}\n\nconst temperatureUnits = ['c', 'f', 'k'] as const\n\nconst unitDescriptions: Record<string, string> = {\n // Length\n 'angstrom': 'ångströms',\n 'um': 'micrometers',\n 'mm': 'millimeters',\n 'cm': 'centimeters',\n 'm': 'meters',\n 'km': 'kilometers',\n 'in': 'inches',\n 'ft': 'feet',\n 'yd': 'yards',\n 'mi': 'miles',\n 'nmi': 'nautical miles',\n // Weight\n 'mg': 'milligrams',\n 'g': 'grams',\n 'kg': 'kilograms',\n 't': 'metric tons',\n 'oz': 'ounces',\n 'lb': 'pounds',\n 'st': 'stones',\n // Volume\n 'ml': 'milliliters',\n 'cl': 'centiliters',\n 'dl': 'deciliters',\n 'l': 'liters',\n 'tsp': 'teaspoons',\n 'tbsp': 'tablespoons',\n 'fl-oz': 'fluid ounces',\n 'cup': 'cups',\n 'pt': 'pints',\n 'qt': 'quarts',\n 'gal': 'gallons',\n // Time\n 'ms': 'milliseconds',\n 's': 'seconds',\n 'min': 'minutes',\n 'h': 'hours',\n 'day': 'days',\n 'week': 'weeks',\n // Area\n 'mm2': 'square millimeters',\n 'cm2': 'square centimeters',\n 'm2': 'square meters',\n 'km2': 'square kilometers',\n 'in2': 'square inches',\n 'ft2': 'square feet',\n 'yd2': 'square yards',\n 'acre': 'acres',\n 'hectare': 'hectares',\n // Speed\n 'm/s': 'meters per second',\n 'km/h': 'kilometers per hour',\n 'mph': 'miles per hour',\n 'kn': 'knots',\n 'ft/s': 'feet per second',\n // Data\n 'b': 'bytes',\n 'kb': 'kilobytes',\n 'mb': 'megabytes',\n 'gb': 'gigabytes',\n 'tb': 'terabytes',\n 'pb': 'petabytes',\n // Pressure\n 'pa': 'pascals',\n 'kpa': 'kilopascals',\n 'bar': 'bars',\n 'atm': 'atmospheres',\n 'psi': 'pounds per square inch',\n 'mmhg': 'millimeters of mercury',\n // Energy\n 'j': 'joules',\n 'kj': 'kilojoules',\n 'cal': 'calories',\n 'kcal': 'kilocalories',\n 'wh': 'watt-hours',\n 'kwh': 'kilowatt-hours',\n 'btu': 'British thermal units',\n // Power\n 'w': 'watts',\n 'kw': 'kilowatts',\n 'mw': 'megawatts',\n 'hp': 'horsepower',\n // Frequency\n 'hz': 'hertz',\n 'khz': 'kilohertz',\n 'mhz': 'megahertz',\n 'ghz': 'gigahertz',\n // Angle\n 'deg': 'degrees',\n 'rad': 'radians',\n 'grad': 'gradians',\n 'turn': 'turns',\n // Temperature\n 'c': 'Celsius',\n 'f': 'Fahrenheit',\n 'k': 'Kelvin',\n}\n\n// --- Generate linear conversion functions ---\n\nfunction generateLinearConversions(category: UnitCategory): BuiltinNormalExpressions {\n const result: BuiltinNormalExpressions = {}\n const unitNames = Object.keys(category.units)\n\n for (const from of unitNames) {\n for (const to of unitNames) {\n if (from === to)\n continue\n\n const fromFactor = category.units[from]!\n const toFactor = category.units[to]!\n const conversionFactor = fromFactor / toFactor\n const fnName = `${from}->${to}`\n const fromDesc = unitDescriptions[from]!\n const toDesc = unitDescriptions[to]!\n\n const seeAlso = [\n `convert.${to}->${from}`,\n ...unitNames\n .filter(u => u !== from && u !== to)\n .map(u => `convert.${from}->${u}`),\n ]\n\n result[fnName] = {\n evaluate: ([value], sourceCodeInfo): number => {\n assertNumber(value, sourceCodeInfo)\n return value * conversionFactor\n },\n arity: toFixedArity(1),\n docs: {\n category: 'convert',\n returns: { type: 'number' },\n args: {\n value: { type: 'number', description: `Value in ${fromDesc}` },\n },\n variants: [{ argumentNames: ['value'] }],\n description: `Converts a value from ${fromDesc} (\\`${from}\\`) to ${toDesc} (\\`${to}\\`).`,\n seeAlso,\n examples: [\n `let { ${fnName} } = import(convert);\n${fnName}(1)`,\n ],\n },\n }\n }\n }\n return result\n}\n\n// --- Generate temperature conversion functions ---\n\nfunction generateTemperatureConversions(): BuiltinNormalExpressions {\n const result: BuiltinNormalExpressions = {}\n\n for (const from of temperatureUnits) {\n for (const to of temperatureUnits) {\n if (from === to)\n continue\n\n const fnName = `${from}->${to}`\n const fromDesc = unitDescriptions[from]!\n const toDesc = unitDescriptions[to]!\n\n const seeAlso = [\n `convert.${to}->${from}`,\n ...temperatureUnits\n .filter(u => u !== from && u !== to)\n .map(u => `convert.${from}->${u}`),\n ]\n\n result[fnName] = {\n evaluate: ([value], sourceCodeInfo): number => {\n assertNumber(value, sourceCodeInfo)\n const celsius = toCelsius(from, value)\n return celsiusTo(to, celsius)\n },\n arity: toFixedArity(1),\n docs: {\n category: 'convert',\n returns: { type: 'number' },\n args: {\n value: { type: 'number', description: `Value in ${fromDesc}` },\n },\n variants: [{ argumentNames: ['value'] }],\n description: `Converts a temperature from ${fromDesc} (\\`${from}\\`) to ${toDesc} (\\`${to}\\`).`,\n seeAlso,\n examples: [\n `let { ${fnName} } = import(convert);\n${fnName}(100)`,\n ],\n },\n }\n }\n }\n return result\n}\n\n// --- Assemble all conversion functions ---\n\nconst convertFunctions: BuiltinNormalExpressions = {\n ...generateLinearConversions(lengthUnits),\n ...generateLinearConversions(weightUnits),\n ...generateLinearConversions(volumeUnits),\n ...generateLinearConversions(timeUnits),\n ...generateLinearConversions(areaUnits),\n ...generateLinearConversions(speedUnits),\n ...generateLinearConversions(dataUnits),\n ...generateLinearConversions(pressureUnits),\n ...generateLinearConversions(energyUnits),\n ...generateLinearConversions(powerUnits),\n ...generateLinearConversions(frequencyUnits),\n ...generateLinearConversions(angleUnits),\n ...generateTemperatureConversions(),\n}\n\nexport const convertModule: LitsModule = {\n name: 'convert',\n functions: convertFunctions,\n}\n"],"names":["getCodeMarker","sourceCodeInfo","position","code","leftPadding","column","rightPadding","length","repeat","Math","max","LitsError","Error","shortMessage","constructor","err","message","super","location","line","filePath","getLitsErrorMessage","this","Object","setPrototypeOf","prototype","name","NodeTypes","Number","String","NormalExpression","SpecialExpression","UserDefinedSymbol","NormalBuiltinSymbol","SpecialBuiltinSymbol","ReservedSymbol","Binding","Spread","NodeTypesSet","Set","values","functionTypeSet","isLitsFunction","func","type","functionType","has","isNode","value","Array","isArray","valueToString","keys","find","key","RegExp","toString","JSON","stringify","assertNumber","options","isNaN","integer","isInteger","finite","isFinite","zero","nonZero","positive","negative","nonPositive","nonNegative","gt","gte","lt","lte","isNumber","sign","getSignString","numberType","range","getRangeString","filter","x","join","getNumberTypeName","anyValue","getSourceCodeInfo","toFixedArity","arity","min","angleUnits","baseUnit","description","units","deg","PI","rad","grad","turn","celsiusTo","unit","toCelsius","temperatureUnits","unitDescriptions","angstrom","um","mm","cm","m","km","in","ft","yd","mi","nmi","mg","g","kg","t","oz","lb","st","ml","cl","dl","l","tsp","tbsp","cup","pt","qt","gal","ms","s","h","day","week","mm2","cm2","m2","km2","in2","ft2","yd2","acre","hectare","mph","kn","b","kb","mb","gb","tb","pb","pa","kpa","bar","atm","psi","mmhg","j","kj","cal","kcal","wh","kwh","btu","w","kw","mw","hp","hz","khz","mhz","ghz","c","f","k","generateLinearConversions","category","result","unitNames","from","to","conversionFactor","fnName","fromDesc","toDesc","seeAlso","u","map","evaluate","docs","returns","args","variants","argumentNames","examples","convertModule","functions","celsius","generateTemperatureConversions"],"mappings":"aAEM,SAAUA,EAAcC,GAC5B,IAAKA,EAAeC,WAAaD,EAAeE,KAC9C,MAAO,GAET,MAAMC,EAAcH,EAAeC,SAASG,OAAS,EAC/CC,EAAeL,EAAeE,KAAKI,OAASH,EAAc,EAChE,MAAO,GAAG,IAAII,OAAOC,KAAKC,IAAIN,EAAa,OAAO,IAAII,OAAOC,KAAKC,IAAIJ,EAAc,KACtF,CCkBM,MAAOK,UAAkBC,MACbX,eACAY,aAChB,WAAAC,CAAYC,EAAcd,GACxB,MAAMe,EAAUD,aAAeH,MAC3BG,EAAIC,QACJ,GAAGD,IAEPE,MA/BJ,SAA6BD,EAAiBf,GAC5C,IAAKA,EACH,OAAOe,EAET,MAAME,EAAW,GAAG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,GAAQ/C,KAClB0D,EAAaX,EAAO/C,GACpB,MAAMwM,EAAUnG,EAAUiF,EAAMvI,GAChC,OAAOoD,EAAUoF,EAAIiB,IAEvBhH,MAAOD,EAAa,GACpByG,KAAM,CACJb,SAAU,UACVc,QAAS,CAAEtJ,KAAM,UACjBuJ,KAAM,CACJnJ,MAAO,CAAEJ,KAAM,SAAUiD,YAAa,YAAY8F,MAEpDS,SAAU,CAAC,CAAEC,cAAe,CAAC,WAC7BxG,YAAa,+BAA+B8F,QAAeJ,WAAcK,QAAaJ,QACtFK,UACAS,SAAU,CACR,SAASZ,2BACnBA,WAIG,CAEH,OAAOL,CACT,CAiBKqB"}
|
package/dist/modules/grid.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function e(e){if(!e.position||!e.code)return"";const r=e.position.column-1,t=e.code.length-r-1;return`${" ".repeat(Math.max(r,0))}^${" ".repeat(Math.max(t,0))}`}class r extends Error{sourceCodeInfo;shortMessage;constructor(t,n){const i=t instanceof Error?t.message:`${t}`;super(function(r,t){if(!t)return r;const n=`${t.position.line}:${t.position.column}`;return`${r}${t.filePath?`\n${t.filePath}:${n}`:`\nLocation ${n}`}\n${t.code}\n${e(t)}`}(i,n)),this.shortMessage=i,this.sourceCodeInfo=n,Object.setPrototypeOf(this,r.prototype),this.name="LitsError"}getCodeMarker(){return this.sourceCodeInfo&&e(this.sourceCodeInfo)}}const t={Number:1,String:2,NormalExpression:3,SpecialExpression:4,UserDefinedSymbol:5,NormalBuiltinSymbol:6,SpecialBuiltinSymbol:7,ReservedSymbol:8,Binding:9,Spread:10},n=new Set(Object.values(t));const i=new Set(["UserDefined","Partial","Comp","Constantly","Juxt","Complement","EveryPred","SomePred","Fnull","Builtin","SpecialBuiltin","NativeJsFunction","Module"]);const o="^^fn^^",s="^^re^^";function a(e){return null!==e&&"object"==typeof e&&(o in e&&"functionType"in e&&("string"==typeof(r=e.functionType)&&i.has(r)));var r}function l(e){return!(!Array.isArray(e)||e.length<2)&&("number"==typeof(r=e[0])&&n.has(r));var r}function g(e){return a(e)?`<function ${e.name||"λ"}>`:l(e)?`${r=e[0],Object.keys(t).find(e=>t[e]===r)}-node`:null===e?"null":"object"==typeof e&&e instanceof RegExp?`${e}`:"object"==typeof e&&e instanceof Error?e.toString():JSON.stringify(e);var r}function c(e,r){return e?.sourceCodeInfo??r}function d(e,r={}){return"number"==typeof e&&(!Number.isNaN(e)&&(!(r.integer&&!Number.isInteger(e))&&(!(r.finite&&!Number.isFinite(e))&&((!r.zero||0===e)&&((!r.nonZero||0!==e)&&(!(r.positive&&e<=0)&&(!(r.negative&&e>=0)&&(!(r.nonPositive&&e>0)&&(!(r.nonNegative&&e<0)&&(!("number"==typeof r.gt&&e<=r.gt)&&(!("number"==typeof r.gte&&e<r.gte)&&(!("number"==typeof r.lt&&e>=r.lt)&&!("number"==typeof r.lte&&e>r.lte)))))))))))))}function u(e,t,n={}){if(!d(e,n))throw new r(`Expected ${function(e){if(e.zero)return"zero";const r=function(e){return e.positive?"positive":e.negative?"negative":e.nonNegative?"non negative":e.nonPositive?"non positive":e.nonZero?"non zero":""}(e),t=e.integer?"integer":"number",n=e.finite?"finite":"",i=function(e){return"number"!=typeof e.gt&&"number"!=typeof e.gte||"number"!=typeof e.lt&&"number"!=typeof e.lte?"number"==typeof e.gt||"number"==typeof e.gte?"number"==typeof e.gt?`n > ${e.gt}`:`n >= ${e.gte}`:"number"==typeof e.lt||"number"==typeof e.lte?"number"==typeof e.lt?`n < ${e.lt}`:`n <= ${e.lte}`:"":`${"number"==typeof e.gt?`${e.gt} < n `:`${e.gte} <= n `}${"number"==typeof e.lt?`< ${e.lt}`:`<= ${e.lte}`}`}(e);return[r,n,t,i].filter(e=>!!e).join(" ")}(n)}, got ${g(e)}.`,c(e,t))}const h=new WeakSet,p=new WeakSet,m=new WeakSet,f=new WeakSet,y=new WeakSet;function b(e,t){if(!function(e){return!(!Array.isArray(e)||!p.has(e)&&(m.has(e)||(e.every(e=>d(e))?(h.add(e),p.add(e),0):(m.add(e),1))))}(e))throw new r(`Expected a vector, but got ${e}`,t)}function v(e,t){if(!function(e){if(!Array.isArray(e))return!1;if(f.has(e))return!0;if(y.has(e))return!1;if(0===e.length)return y.add(e),!1;if(!Array.isArray(e[0]))return y.add(e),!1;const r=e[0].length;for(const t of e.slice(1)){if(!Array.isArray(t))return y.add(e),!1;if(t.length!==r)return y.add(e),!1}return h.add(e),f.add(e),!0}(e))throw new r(`Expected a grid, but got ${e}`,t)}function w(e,t,n){return new r(`Expected ${e}, got ${g(t)}.`,c(t,n))}function A(e,r){if(!Array.isArray(e))throw w("array",e,r)}function N(e){return null!==e&&"object"==typeof e&&!!e[o]}function x(e,r){return $(e,r),e}function $(e,r){if(!function(e){return void 0!==e}(e))throw w("not undefined",e,r)}function T(e){return!(null===e||"object"!=typeof e||Array.isArray(e)||e instanceof RegExp||N(e)||(r=e,null!==r&&"object"==typeof r&&r[s]));var r}function K(e){return function(e){return Array.isArray(e)||"string"==typeof e}(e)||T(e)}function C(e,r){if(!function(e){return"number"==typeof e||!!K(e)||!!N(e)}(e))throw w("FunctionLike",e,r)}function F(e){return{min:e,max:e}}function S(e,r){return e instanceof Promise?e.then(r):r(e)}function k(e,r){const t=[];for(let n=0;n<e.length;n++){const i=r(e[n],n);if(i instanceof Promise)return E(i,t,e,r,n);t.push(i)}return t}async function E(e,r,t,n,i){r.push(await e);for(let e=i+1;e<t.length;e++)r.push(await n(t[e],e));return r}function O(e,r,t){let n=t;for(let t=0;t<e.length;t++){const i=r(n,e[t],t);if(i instanceof Promise)return P(i,e,r,t);n=i}return n}async function P(e,r,t,n){let i=await e;for(let e=n+1;e<r.length;e++)i=await t(i,r[e],e);return i}function R(e,r){for(let t=0;t<e.length;t++){const n=r(e[t],t);if(n instanceof Promise)return j(n,e,r,t);if(n)return!0}return!1}async function j(e,r,t,n){if(await e)return!0;for(let e=n+1;e<r.length;e++)if(await t(r[e],e))return!0;return!1}function U(e,r){for(let t=0;t<e.length;t++){const n=r(e[t],t);if(n instanceof Promise)return z(n,e,r,t);if(!n)return!1}return!0}async function z(e,r,t,n){if(!await e)return!1;for(let e=n+1;e<r.length;e++)if(!await t(r[e],e))return!1;return!0}const I={"every?":{category:"grid",description:"Checks if all elements in a grid satisfy a predicate. Returns true only if the predicate returns true for every element in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['// Using "as" alias because "every?" shadows a builtin function\nlet { every? as grid-every? } = import(grid);\ngrid-every?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], string?)','// Using "as" alias because "every?" shadows a builtin function\nlet { every? as grid-every? } = import(grid);\ngrid-every?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], string?)','// Using "as" alias because "every?" shadows a builtin function\nlet { every? as grid-every? } = import(grid);\ngrid-every?([\n [1, 2],\n [3, 4],\n], string?)'],seeAlso:["collection.every?","grid.some?","grid.every-row?","grid.every-col?"]},"some?":{category:"grid",description:"Checks if any element in a grid satisfies a predicate. Returns true if the predicate returns true for at least one element in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { some? } = import(grid);\nsome?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], string?)','let { some? } = import(grid);\nsome?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], string?)',"let { some? } = import(grid);\nsome?([\n [1, 2],\n [3, 4],\n], string?)"],seeAlso:["collection.any?","grid.every?","grid.some-row?","grid.some-col?"]},"every-row?":{category:"grid",description:"Checks if all rows in a grid satisfy a predicate. Returns true only if the predicate returns true for every row in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { every-row? } = import(grid);\nevery-row?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> string?($[0]))','let { every-row? } = import(grid);\nevery-row?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> string?($[0]))',"let { every-row? } = import(grid);\nevery-row?([\n [1, 2],\n [3, 4],\n], -> string?($[0]))"],seeAlso:["grid.some-row?","grid.every-col?","grid.every?"]},"some-row?":{category:"grid",description:"Checks if any row in a grid satisfies a predicate. Returns true if the predicate returns true for at least one row in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { some-row? } = import(grid);\nsome-row?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> $ contains? "Albert")','let { some-row? } = import(grid);\nsome-row?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> $ contains? "Albert")','let { some-row? } = import(grid);\nsome-row?([\n [1, 2],\n [3, 4],\n], -> $ contains? "Albert")'],seeAlso:["grid.every-row?","grid.some-col?","grid.some?"]},"every-col?":{category:"grid",description:"Checks if all columns in a grid satisfy a predicate. Returns true only if the predicate returns true for every column in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { every-col? } = import(grid);\nevery-col?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> string?($[0]))','let { every-col? } = import(grid);\nevery-col?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> string?($[0]))',"let { every-col? } = import(grid);\nevery-col?([\n [1, 2],\n [3, 4],\n], -> string?($[0]))"],seeAlso:["grid.some-col?","grid.every-row?","grid.every?"]},"some-col?":{category:"grid",description:"Checks if any column in a grid satisfies a predicate. Returns true if the predicate returns true for at least one column in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { some-col? } = import(grid);\nsome-col?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> $ contains? "Albert")','let { some-col? } = import(grid);\nsome-col?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> $ contains? "Albert")','let { some-col? } = import(grid);\nsome-col?([\n [1, 2],\n [3, 4],\n], -> $ contains? "Albert")'],seeAlso:["grid.every-col?","grid.some-row?","grid.some?"]},row:{category:"grid",description:"Returns the row at index $a in the grid $b.",returns:{type:"any"},args:{a:{type:"grid"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:['let { row } = import(grid);\nrow([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 0)','let { row } = import(grid);\nrow([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)','let { row } = import(grid);\nrow([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 2)'],seeAlso:["grid.col","grid.shape"]},col:{category:"grid",description:"Returns the column at index $a in the grid $b.",returns:{type:"any"},args:{a:{type:"grid"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:['let { col } = import(grid);\ncol([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 0)','let { col } = import(grid);\ncol([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)','let { col } = import(grid);\ncol([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 2)'],seeAlso:["grid.row","grid.shape"]},shape:{category:"grid",description:"Returns the shape of the grid `g` as a `vector` of two numbers, where the first number is the number of rows and the second number is the number of columns.",returns:{type:"vector"},args:{g:{type:"grid",description:"The grid to get the shape of."}},variants:[{argumentNames:["g"]}],examples:['let { shape } = import(grid);\nshape([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { shape } = import(grid);\nshape([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])',"let { shape } = import(grid);\nshape([\n [1, 2],\n [3, 4],\n])"],seeAlso:["grid.row","grid.col","grid.reshape"]},fill:{category:"grid",description:"Creates a grid of the specified size, filled with the specified value.",returns:{type:"grid"},args:{rows:{type:"integer",description:"The number of rows in the grid."},cols:{type:"integer",description:"The number of columns in the grid."},value:{type:"any",description:"The value to fill the grid with."}},variants:[{argumentNames:["rows","cols","value"]}],examples:["let { fill } = import(grid);\nfill(2, 3, 0)",'let { fill } = import(grid);\nfill(2, 3, "x")'],seeAlso:["grid.generate","grid.from-array","vector.fill"]},generate:{category:"grid",description:"Generates a grid of the specified size, where each element is generated by the provided function.",returns:{type:"grid"},args:{rows:{type:"number",description:"The number of rows in the grid."},cols:{type:"number",description:"The number of columns in the grid."},fn:{type:"function",description:"The function to generate the grid. It takes two arguments: the row index and the column index."}},variants:[{argumentNames:["rows","cols","fn"]}],examples:["let { generate } = import(grid);\ngenerate(3, 3, (i, j) -> i + j)"],seeAlso:["grid.fill","grid.from-array","vector.generate"]},reshape:{category:"grid",description:"Reshapes the grid `a` into a new grid with the specified number of rows `b`. The number of columns is automatically calculated based on the total number of elements in the grid.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:['let { reshape } = import(grid);\nreshape([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], 2)'],seeAlso:["grid.shape","grid.from-array"]},transpose:{category:"grid",description:"Transposes the grid `g`, swapping its rows and columns.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to transpose."}},variants:[{argumentNames:["g"]}],examples:['let { transpose } = import(grid);\ntranspose([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { transpose } = import(grid);\ntranspose([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])',"let { transpose } = import(grid);\ntranspose([\n [1, 2],\n [3, 4],\n])"],seeAlso:["grid.flip-h","grid.flip-v","grid.rotate"]},"flip-h":{category:"grid",description:"Flips the grid `g` horizontally.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to flip horizontally."}},variants:[{argumentNames:["g"]}],examples:['let { flip-h } = import(grid);\nflip-h([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { flip-h } = import(grid);\nflip-h([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])',"let { flip-h } = import(grid);\nflip-h([\n [1, 2],\n [3, 4],\n])"],seeAlso:["grid.flip-v","grid.transpose","grid.rotate","grid.reverse-cols"]},"flip-v":{category:"grid",description:"Flips the grid `g` vertically.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to flip vertically."}},variants:[{argumentNames:["g"]}],examples:['let { flip-v } = import(grid);\nflip-v([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { flip-v } = import(grid);\nflip-v([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])',"let { flip-v } = import(grid);\nflip-v([\n [1, 2],\n [3, 4],\n])"],seeAlso:["grid.flip-h","grid.transpose","grid.rotate","grid.reverse-rows"]},rotate:{category:"grid",description:"Rotates the grid `g` by the specified angle. The angle is given in terms of 90-degree rotations. Positive values rotate the grid clockwise, while negative values rotate it counterclockwise.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:["let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], 1)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], 2)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], 3)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], 4)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], -1)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], -2)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], -3)"],seeAlso:["grid.transpose","grid.flip-h","grid.flip-v"]},"reverse-rows":{category:"grid",description:"Reverses the order of rows in the grid `g`.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to reverse rows."}},variants:[{argumentNames:["g"]}],examples:['let { reverse-rows } = import(grid);\nreverse-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { reverse-rows } = import(grid);\nreverse-rows([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])',"let { reverse-rows } = import(grid);\nreverse-rows([\n [1, 2],\n [3, 4],\n])"],seeAlso:["grid.reverse-cols","grid.flip-v"]},"reverse-cols":{category:"grid",description:"Reverses the order of columns in the grid `g`.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to reverse columns."}},variants:[{argumentNames:["g"]}],examples:['let { reverse-cols } = import(grid);\nreverse-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { reverse-cols } = import(grid);\nreverse-cols([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])',"let { reverse-cols } = import(grid);\nreverse-cols([\n [1, 2],\n [3, 4],\n])"],seeAlso:["grid.reverse-rows","grid.flip-h"]},slice:{category:"grid",description:"Slices the grid `g` from the starting index `begin` to the optional ending index `stop`. The slice is inclusive of the starting index and exclusive of the ending index.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to slice."},begin:{type:"vector",description:"The starting index of the slice as a vector of two numbers: `[row, col]`."},stop:{type:"vector",description:"Optional ending index of the slice as a vector of two numbers: `[row, col]`."}},variants:[{argumentNames:["g","begin"]},{argumentNames:["g","begin","stop"]}],examples:['// Using "as" alias because "slice" shadows a builtin function\nlet { slice as grid-slice } = import(grid);\ngrid-slice([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], [1, 1], [2, 2])','// Using "as" alias because "slice" shadows a builtin function\nlet { slice as grid-slice } = import(grid);\ngrid-slice([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], [1, 1])'],hideOperatorForm:!0,seeAlso:["grid.slice-rows","grid.slice-cols"]},"slice-rows":{category:"grid",description:"Slices rows of the grid `g` from the starting index `begin` to the optional ending index `stop`. The slice is inclusive of the starting index and exclusive of the ending index.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to slice."},begin:{type:"number",description:"The starting index of the slice."},stop:{type:"number",description:"Optional ending index of the slice."}},variants:[{argumentNames:["g","begin"]},{argumentNames:["g","begin","stop"]}],examples:['let { slice-rows } = import(grid);\nslice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { slice-rows } = import(grid);\nslice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)'],hideOperatorForm:!0,seeAlso:["grid.slice","grid.slice-cols","grid.splice-rows"]},"slice-cols":{category:"grid",description:"Slices columns of the grid `g` from the starting index `begin` to the optional ending index `stop`. The slice is inclusive of the starting index and exclusive of the ending index.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to slice."},begin:{type:"number",description:"The starting index of the slice."},stop:{type:"number",description:"Optional ending index of the slice."}},variants:[{argumentNames:["g","begin"]},{argumentNames:["g","begin","stop"]}],examples:['let { slice-cols } = import(grid);\nslice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { slice-cols } = import(grid);\nslice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)'],hideOperatorForm:!0,seeAlso:["grid.slice","grid.slice-rows","grid.splice-cols"]},"splice-rows":{category:"grid",description:"Splices rows of the grid `g` starting from the index `begin`. Deletes `deleteCount` rows and inserts the specified `items` at that position.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to splice."},begin:{type:"number",description:"The starting index of the splice."},deleteCount:{type:"number",description:"The number of rows to delete."},items:{type:"array",rest:!0,description:"The rows to insert."}},variants:[{argumentNames:["g","begin","deleteCount"]},{argumentNames:["g","begin","deleteCount","items"]}],examples:['let { splice-rows } = import(grid);\nsplice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { splice-rows } = import(grid);\nsplice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 1, ["Nazanin", "mother", 40])'],hideOperatorForm:!0,seeAlso:["grid.splice-cols","grid.slice-rows"]},"splice-cols":{category:"grid",description:"Splices columns of the grid `g` starting from the index `begin`. Deletes `deleteCount` columns and inserts the specified `items` at that position.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to splice."},begin:{type:"number",description:"The starting index of the splice."},deleteCount:{type:"number",description:"The number of columns to delete."},items:{type:"array",rest:!0,description:"The columns to insert."}},variants:[{argumentNames:["g","begin","deleteCount"]},{argumentNames:["g","begin","deleteCount","items"]}],examples:['let { splice-cols } = import(grid);\nsplice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { splice-cols } = import(grid);\nsplice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 1, ["f", "m", "s"])'],hideOperatorForm:!0,seeAlso:["grid.splice-rows","grid.slice-cols"]},"concat-rows":{category:"grid",description:"Concatenates two grids `a` and `b` by rows. The number of columns in both grids must be the same.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"grid"}},variants:[{argumentNames:["a","b"]}],examples:['let { concat-rows } = import(grid);\nconcat-rows([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], [\n [1, 2],\n [3, 4],\n])'],seeAlso:["grid.concat-cols","grid.push-rows"]},"concat-cols":{category:"grid",description:"Concatenates two grids `a` and `b` by columns. The number of rows in both grids must be the same.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"grid"}},variants:[{argumentNames:["a","b"]}],examples:['let { concat-cols } = import(grid);\nconcat-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], [\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])'],seeAlso:["grid.concat-rows","grid.push-cols"]},map:{category:"grid",description:"Maps a function `a` over each element of the grid `b`, returning a new grid with the results.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['// Using "as" alias because "map" shadows a builtin function\nlet { map as grid-map } = import(grid);\ngrid-map([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], str)'],seeAlso:["map","grid.mapi","grid.reduce"]},mapi:{category:"grid",description:"Maps a function `a` over each element of the grid `b`, passing the row and column index as additional arguments to the function.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['// Using "as" alias because "mapi" shadows a builtin function\nlet { mapi as grid-mapi } = import(grid);\ngrid-mapi([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> $1 ++ "(" ++ $2 ++ ", " ++ $3 ++ ")")'],seeAlso:["grid.map","grid.reducei","map"]},reduce:{category:"grid",description:"Reduces the grid `a` using the function `b`, returning a single value.",returns:{type:"any"},args:{g:{type:"grid",description:"The grid to reduce."},fn:{type:"function",description:"The function to reduce the grid. It takes two arguments: the accumulator and the current element."},"initial-value":{type:"any",description:"The initial value for the accumulator."}},variants:[{argumentNames:["g","fn","initial-value"]}],examples:['// Using "as" alias because "reduce" shadows a builtin function\nlet { reduce as grid-reduce } = import(grid);\ngrid-reduce([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ++, "")'],seeAlso:["reduce","grid.reducei","grid.map"]},reducei:{category:"grid",description:"Reduces the grid `a` using the function `b`, passing the row and column indices as additional arguments to the function.",returns:{type:"any"},args:{g:{type:"grid",description:"The grid to reduce."},fn:{type:"function",description:"The function to reduce the grid. It takes four arguments: the accumulator, the current element, the row index, and the column index."},"initial-value":{type:"any",description:"The initial value for the accumulator."}},variants:[{argumentNames:["g","fn","initial-value"]}],examples:['// Using "as" alias because "reducei" shadows a builtin function\nlet { reducei as grid-reducei } = import(grid);\ngrid-reducei([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ++, "")'],seeAlso:["grid.reduce","grid.mapi","reduce"]},"push-rows":{category:"grid",description:"Pushes the specified rows into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to push rows into."},rows:{type:"array",rest:!0,description:"The rows to push into the grid."}},variants:[{argumentNames:["g","rows"]}],examples:['let { push-rows } = import(grid);\npush-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["Nazanin", "mother", 40])'],hideOperatorForm:!0,seeAlso:["grid.unshift-rows","grid.pop-row","grid.shift-row","grid.concat-rows"]},"unshift-rows":{category:"grid",description:"Unshifts the specified rows into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to unshift rows into."},rows:{type:"array",rest:!0,description:"The rows to unshift into the grid."}},variants:[{argumentNames:["g","rows"]}],examples:['let { unshift-rows } = import(grid);\nunshift-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["Nazanin", "mother", 40])'],hideOperatorForm:!0,seeAlso:["grid.push-rows","grid.shift-row","grid.pop-row"]},"pop-row":{category:"grid",description:"Pops the last row from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to pop a row from."}},variants:[{argumentNames:["g"]}],examples:['let { pop-row } = import(grid);\npop-row([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.shift-row","grid.push-rows","grid.unshift-rows"]},"shift-row":{category:"grid",description:"Shifts the first row from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to shift a row from."}},variants:[{argumentNames:["g"]}],examples:['let { shift-row } = import(grid);\nshift-row([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.pop-row","grid.push-rows","grid.unshift-rows"]},"push-cols":{category:"grid",description:"Pushes the specified columns into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to push columns into."},cols:{type:"array",rest:!0,description:"The columns to push into the grid."}},variants:[{argumentNames:["g","cols"]}],examples:['let { push-cols } = import(grid);\npush-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["f", "m", "s"])'],hideOperatorForm:!0,seeAlso:["grid.unshift-cols","grid.pop-col","grid.shift-col","grid.concat-cols"]},"unshift-cols":{category:"grid",description:"Unshifts the specified columns into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to unshift columns into."},cols:{type:"array",rest:!0,description:"The columns to unshift into the grid."}},variants:[{argumentNames:["g","cols"]}],examples:['let { unshift-cols } = import(grid);\nunshift-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["f", "m", "s"])'],hideOperatorForm:!0,seeAlso:["grid.push-cols","grid.shift-col","grid.pop-col"]},"pop-col":{category:"grid",description:"Pops the last column from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to pop a column from."}},variants:[{argumentNames:["g"]}],examples:['let { pop-col } = import(grid);\npop-col([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.shift-col","grid.push-cols","grid.unshift-cols"]},"shift-col":{category:"grid",description:"Shifts the first column from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to shift a column from."}},variants:[{argumentNames:["g"]}],examples:['let { shift-col } = import(grid);\nshift-col([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.pop-col","grid.push-cols","grid.unshift-cols"]},"from-array":{category:"grid",description:"Creates a grid from a flat array with specified dimensions. The array is reshaped into the specified number of rows, and the number of columns is automatically calculated based on the total number of elements in the array.",returns:{type:"grid"},args:{a:{type:"array"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:["let { from-array } = import(grid);\nfrom-array([1, 2, 3, 4], 2)","let { from-array } = import(grid);\nfrom-array([1, 2, 3, 4], 4)"],seeAlso:["grid.fill","grid.generate","grid.reshape"]}};function M(e){const r=[];for(let t=0;t<e[0].length;t+=1){const n=[];for(let r=0;r<e.length;r+=1)n.push(e[r][t]);r.push(n)}return r}const B={"every?":{evaluate:([e,r],t,n,{executeFunction:i})=>{v(e,t),C(r,t);const o=[];for(const r of e)for(const e of r)o.push(e);return U(o,e=>i(r,[e],n,t))},arity:F(2)},"some?":{evaluate:([e,r],t,n,{executeFunction:i})=>{v(e,t),C(r,t);const o=[];for(const r of e)for(const e of r)o.push(e);return R(o,e=>i(r,[e],n,t))},arity:F(2)},"every-row?":{evaluate:([e,r],t,n,{executeFunction:i})=>(v(e,t),C(r,t),U(Array.from(e),e=>i(r,[e],n,t))),arity:F(2)},"some-row?":{evaluate:([e,r],t,n,{executeFunction:i})=>(v(e,t),C(r,t),R(Array.from(e),e=>i(r,[e],n,t))),arity:F(2)},"every-col?":{evaluate:([e,r],t,n,{executeFunction:i})=>{v(e,t),C(r,t);const o=M(e);return U(Array.from(o),e=>i(r,[e],n,t))},arity:F(2)},"some-col?":{evaluate:([e,r],t,n,{executeFunction:i})=>{v(e,t),C(r,t);const o=M(e);return R(Array.from(o),e=>i(r,[e],n,t))},arity:F(2)},row:{evaluate:([e,r],t)=>(v(e,t),u(r,t,{integer:!0,nonNegative:!0,lt:e.length}),e[r]),arity:F(2)},col:{evaluate:([e,r],t)=>(v(e,t),u(r,t,{integer:!0,nonNegative:!0,lt:e[0].length}),e.map(e=>e[r])),arity:F(2)},shape:{evaluate:([e],r)=>(v(e,r),[e.length,e[0].length]),arity:F(1)},fill:{evaluate:([e,r,t],n)=>{u(e,n,{integer:!0,positive:!0}),u(r,n,{integer:!0,positive:!0}),$(t,n);const i=[];for(let n=0;n<e;n+=1){const e=[];for(let n=0;n<r;n+=1)e.push(t);i.push(e)}return i},arity:F(3)},generate:{evaluate:([e,r,t],n,i,{executeFunction:o})=>(u(e,n,{integer:!0,positive:!0}),u(r,n,{integer:!0,positive:!0}),C(t,n),k(Array.from({length:e}),(e,s)=>k(Array.from({length:r}),(e,r)=>S(o(t,[s,r],i,n),e=>($(e,n),e))))),arity:F(3)},reshape:{evaluate:([e,t],n)=>{v(e,n),u(t,n,{integer:!0,positive:!0});const i=e.flat();if(i.length%t!==0)throw new r(`The number of elements in the grid must be divisible by rows, but got ${i.length} and ${t}`,n);const o=i.length/t,s=[];for(let e=0;e<t;e+=1){const r=[];for(let t=0;t<o;t+=1)r.push(i[e*o+t]);s.push(r)}return s},arity:F(2)},transpose:{evaluate:([e],r)=>(v(e,r),M(e)),arity:F(1)},"flip-h":{evaluate:([e],r)=>(v(e,r),e.map(e=>e.reverse())),arity:F(1)},"flip-v":{evaluate:([e],r)=>(v(e,r),e.reverse()),arity:F(1)},rotate:{evaluate:([e,r],t)=>{if(v(e,t),u(r,t,{integer:!0}),0===(r=(r%4+4)%4)||0===e.length)return e.map(e=>[...e]);const n=e.length,i=e[0].length;let o;switch(r){case 1:o=Array(i).fill(null).map(()=>Array(n).fill(null));for(let r=0;r<n;r++)for(let t=0;t<i;t++)o[t][n-1-r]=e[r][t];break;case 2:o=Array(n).fill(null).map(()=>Array(i).fill(null));for(let r=0;r<n;r++)for(let t=0;t<i;t++)o[n-1-r][i-1-t]=e[r][t];break;case 3:o=Array(i).fill(null).map(()=>Array(n).fill(null));for(let r=0;r<n;r++)for(let t=0;t<i;t++)o[i-1-t][r]=e[r][t]}return o},arity:F(2)},"reverse-rows":{evaluate:([e],r)=>(v(e,r),e.reverse()),arity:F(1)},"reverse-cols":{evaluate:([e],r)=>(v(e,r),e.map(e=>e.reverse())),arity:F(1)},slice:{evaluate:([e,t,n],i)=>{if(v(e,i),b(t,i),2!==t.length)throw new r(`The start vector must have 2 elements, but got ${t.length}`,i);const[o,s]=t;if(u(o,i,{integer:!0,nonNegative:!0,lt:e.length}),u(s,i,{integer:!0,nonNegative:!0,lt:e[0].length}),n??=[e.length,e[0].length],b(n,i),2!==n.length)throw new r(`The end vector must have 2 elements, but got ${n.length}`,i);const[a,l]=n;u(a,i,{gt:o,lte:e.length}),u(l,i,{gt:s,lte:e[0].length});const g=[];for(let r=o;r<a;r+=1){const t=[];for(let n=s;n<l;n+=1)t.push(e[r][n]);g.push(t)}return g},arity:{min:2,max:3}},"slice-rows":{evaluate:([e,r,t],n)=>(v(e,n),void 0===t?(u(r,n,{integer:!0,lte:e.length,gte:-e.length}),r<0?e.slice(e.length+r):e.slice(r)):(u(r,n,{integer:!0,nonNegative:!0,lte:e.length}),u(t,n,{integer:!0}),u(t=t<0?e.length+t:t,n,{gt:r,lte:e.length}),e.slice(r,t))),arity:{min:2,max:3}},"slice-cols":{evaluate:([e,r,t],n)=>{v(e,n);const i=M(e);return void 0===t?(u(r,n,{integer:!0,lte:i.length,gte:-i.length}),M(r<0?i.slice(i.length+r):i.slice(r))):(u(r,n,{integer:!0,nonNegative:!0,lte:i.length}),u(t,n,{integer:!0}),u(t=t<0?i.length+t:t,n,{gt:r,lte:i.length}),M(i.slice(r,t)))},arity:{min:2,max:3}},"splice-rows":{evaluate:([e,t,n,...i],o)=>{v(e,o),u(t,o,{integer:!0,nonNegative:!0,lte:e.length}),u(n,o,{integer:!0,nonNegative:!0}),0!==i.length&&(v(i,o),i.every(t=>{if(A(t,o),e[0].length!==t.length)throw new r(`All rows must have the same length as the number of columns in grid, but got ${t.length}`,o);return!0}));const s=[];for(let r=0;r<t;r+=1)s.push(e[r]);i.length>0&&s.push(...i);for(let r=t+n;r<e.length;r+=1)s.push(e[r]);return s},arity:{min:3}},"splice-cols":{evaluate:([e,t,n,...i],o)=>{v(e,o);const s=M(e);u(t,o,{integer:!0,nonNegative:!0,lte:s.length}),u(n,o,{integer:!0,nonNegative:!0}),0!==i.length&&(v(i,o),i.every(e=>{if(A(e,o),s[0].length!==e.length)throw new r(`All rows must have the same length as the number of rows in grid, but got ${e.length}`,o);return!0}));const a=[];for(let e=0;e<t;e+=1)a.push(s[e]);a.push(...i);for(let e=t+n;e<s.length;e+=1)a.push(s[e]);return M(a)},arity:{min:3}},"concat-rows":{evaluate:(e,t)=>{A(e,t),e.every(e=>v(e,t));const n=e[0][0].length;e.slice(1).every(e=>{if(e[0].length!==n)throw new r(`All grids must have the same number of columns, but got ${n} and ${e[0].length}`,t);return!0});const i=[];return e.forEach(e=>{e.forEach(e=>{i.push(e)})}),i},arity:{min:1}},"concat-cols":{evaluate:(e,t)=>{A(e,t),e.every(e=>v(e,t));const n=e[0].length;e.slice(1).every(e=>{if(e.length!==n)throw new r(`All grids must have the same number of rows, but got ${n} and ${e.length}`,t);return!0});const i=[];for(let r=0;r<n;r+=1){const t=[];e.forEach(e=>{t.push(...e[r])}),i.push(t)}return i},arity:{min:1}},map:{evaluate:(e,t,n,{executeFunction:i})=>{const o=function(e,r){return C(e,r),e}(e.at(-1),t),s=e.slice(0,-1);v(s[0],t);const a=s[0].length,l=s[0][0].length;return s.slice(1).forEach(e=>{if(v(e,t),e.length!==a)throw new r(`All grids must have the same number of rows, but got ${a} and ${e.length}`,t);if(e[0].length!==l)throw new r(`All grids must have the same number of columns, but got ${l} and ${e[0].length}`,t)}),k(Array.from({length:a}),(e,r)=>k(Array.from({length:l}),(e,a)=>{const l=s.map(e=>e[r][a]);return S(i(o,l,n,t),e=>x(e))}))},arity:{min:2}},mapi:{evaluate:([e,r],t,n,{executeFunction:i})=>{v(e,t),C(r,t);const o=e.length,s=e[0].length;return k(Array.from({length:o}),(o,a)=>k(Array.from({length:s}),(o,s)=>S(i(r,[e[a][s],a,s],n,t),e=>x(e))))},arity:F(2)},reduce:{evaluate:([e,r,t],n,i,{executeFunction:o})=>{v(e,n),C(r,n);const s=[];for(const r of e)for(const e of r)s.push(e);return O(s,(e,t)=>o(r,[e,t],i,n),x(t))},arity:F(3)},reducei:{evaluate:([e,r,t],n,i,{executeFunction:o})=>{v(e,n),C(r,n);const s=[];for(let r=0;r<e.length;r+=1)for(let t=0;t<e[r].length;t+=1)s.push({cell:e[r][t],i:r,j:t});return O(s,(e,{cell:t,i:s,j:a})=>o(r,[e,t,s,a],i,n),x(t))},arity:F(3)},"push-rows":{evaluate:([e,...t],n)=>{if(v(e,n),v(t,n),e[0].length!==t[0].length)throw new r(`All rows must have the same length as the number of columns in grid, but got ${e[0].length} and ${t[0].length}`,n);return[...e,...t]},arity:{min:2}},"unshift-rows":{evaluate:([e,...t],n)=>{if(v(e,n),v(t,n),e[0].length!==t[0].length)throw new r(`All rows must have the same length as the number of columns in grid, but got ${e[0].length} and ${t[0].length}`,n);return[...t,...e]},arity:{min:2}},"pop-row":{evaluate:([e],r)=>(v(e,r),1===e.length?null:e.slice(0,-1)),arity:F(1)},"shift-row":{evaluate:([e],r)=>(v(e,r),1===e.length?null:e.slice(1)),arity:F(1)},"push-cols":{evaluate:([e,...t],n)=>{if(v(e,n),v(t,n),e.length!==t[0].length)throw new r(`All columns must have the same length as the number of rows in grid, but got ${t.length}`,n);const i=[];for(let r=0;r<e.length;r+=1){const n=[];n.push(...e[r]),t.forEach(e=>{n.push(e[r])}),i.push(n)}return i},arity:{min:2}},"unshift-cols":{evaluate:([e,...t],n)=>{if(v(e,n),v(t,n),e.length!==t[0].length)throw new r(`All columns must have the same length as the number of rows in grid, but got ${t.length}`,n);const i=[];for(let r=0;r<e.length;r+=1){const n=[];t.forEach(e=>{n.push(e[r])}),n.push(...e[r]),i.push(n)}return i},arity:{min:2}},"pop-col":{evaluate:([e],r)=>(v(e,r),1===e[0].length?null:e.map(e=>e.slice(0,-1))),arity:F(1)},"shift-col":{evaluate:([e],r)=>(v(e,r),1===e[0].length?null:e.map(e=>e.slice(1))),arity:F(1)},"from-array":{evaluate:([e,t],n)=>{if(A(e,n),u(t,n,{integer:!0,positive:!0}),e.length%t!==0)throw new r(`The number of elements in the array must be divisible by rows, but got ${e.length} and ${t}`,n);return function(e,r){const t=[],n=e.length/r;for(let i=0;i<r;i++){const r=i*n,o=r+n;t.push(e.slice(r,o))}return t}(e,t)},arity:F(2)}};for(const[e,r]of Object.entries(I))B[e]&&(B[e].docs=r);const W={name:"grid",functions:B};export{W as gridModule};
|
|
1
|
+
function e(e){if(!e.position||!e.code)return"";const t=e.position.column-1,r=e.code.length-t-1;return`${" ".repeat(Math.max(t,0))}^${" ".repeat(Math.max(r,0))}`}class t extends Error{sourceCodeInfo;shortMessage;constructor(r,n){const i=r instanceof Error?r.message:`${r}`;super(function(t,r){if(!r)return t;const n=`${r.position.line}:${r.position.column}`;return`${t}${r.filePath?`\n${r.filePath}:${n}`:`\nLocation ${n}`}\n${r.code}\n${e(r)}`}(i,n)),this.shortMessage=i,this.sourceCodeInfo=n,Object.setPrototypeOf(this,t.prototype),this.name="LitsError"}getCodeMarker(){return this.sourceCodeInfo&&e(this.sourceCodeInfo)}}const r={Number:1,String:2,NormalExpression:3,SpecialExpression:4,UserDefinedSymbol:5,NormalBuiltinSymbol:6,SpecialBuiltinSymbol:7,ReservedSymbol:8,Binding:9,Spread:10},n=new Set(Object.values(r));const i=new Set(["UserDefined","Partial","Comp","Constantly","Juxt","Complement","EveryPred","SomePred","Fnull","Builtin","SpecialBuiltin","NativeJsFunction","Module"]);const o="^^fn^^",s="^^re^^";function a(e){return null!==e&&"object"==typeof e&&(o in e&&"functionType"in e&&("string"==typeof(t=e.functionType)&&i.has(t)));var t}function l(e){return!(!Array.isArray(e)||e.length<2)&&("number"==typeof(t=e[0])&&n.has(t));var t}function g(e){return a(e)?`<function ${e.name||"λ"}>`:l(e)?`${t=e[0],Object.keys(r).find(e=>r[e]===t)}-node`:null===e?"null":"object"==typeof e&&e instanceof RegExp?`${e}`:"object"==typeof e&&e instanceof Error?e.toString():JSON.stringify(e);var t}function c(e,t){return e?.sourceCodeInfo??t}function d(e,t={}){return"number"==typeof e&&(!Number.isNaN(e)&&(!(t.integer&&!Number.isInteger(e))&&(!(t.finite&&!Number.isFinite(e))&&((!t.zero||0===e)&&((!t.nonZero||0!==e)&&(!(t.positive&&e<=0)&&(!(t.negative&&e>=0)&&(!(t.nonPositive&&e>0)&&(!(t.nonNegative&&e<0)&&(!("number"==typeof t.gt&&e<=t.gt)&&(!("number"==typeof t.gte&&e<t.gte)&&(!("number"==typeof t.lt&&e>=t.lt)&&!("number"==typeof t.lte&&e>t.lte)))))))))))))}function u(e,r,n={}){if(!d(e,n))throw new t(`Expected ${function(e){if(e.zero)return"zero";const t=function(e){return e.positive?"positive":e.negative?"negative":e.nonNegative?"non negative":e.nonPositive?"non positive":e.nonZero?"non zero":""}(e),r=e.integer?"integer":"number",n=e.finite?"finite":"",i=function(e){return"number"!=typeof e.gt&&"number"!=typeof e.gte||"number"!=typeof e.lt&&"number"!=typeof e.lte?"number"==typeof e.gt||"number"==typeof e.gte?"number"==typeof e.gt?`n > ${e.gt}`:`n >= ${e.gte}`:"number"==typeof e.lt||"number"==typeof e.lte?"number"==typeof e.lt?`n < ${e.lt}`:`n <= ${e.lte}`:"":`${"number"==typeof e.gt?`${e.gt} < n `:`${e.gte} <= n `}${"number"==typeof e.lt?`< ${e.lt}`:`<= ${e.lte}`}`}(e);return[t,n,r,i].filter(e=>!!e).join(" ")}(n)}, got ${g(e)}.`,c(e,r))}const h=new WeakSet,p=new WeakSet,m=new WeakSet,f=new WeakSet,y=new WeakSet;function b(e,r){if(!function(e){return!(!Array.isArray(e)||!p.has(e)&&(m.has(e)||(e.every(e=>d(e))?(h.add(e),p.add(e),0):(m.add(e),1))))}(e))throw new t(`Expected a vector, but got ${e}`,r)}function w(e,r){if(!function(e){if(!Array.isArray(e))return!1;if(f.has(e))return!0;if(y.has(e))return!1;if(0===e.length)return y.add(e),!1;if(!Array.isArray(e[0]))return y.add(e),!1;const t=e[0].length;for(const r of e.slice(1)){if(!Array.isArray(r))return y.add(e),!1;if(r.length!==t)return y.add(e),!1}return h.add(e),f.add(e),!0}(e))throw new t(`Expected a grid, but got ${e}`,r)}function v(e,r,n){return new t(`Expected ${e}, got ${g(r)}.`,c(r,n))}function A(e,t){if(!Array.isArray(e))throw v("array",e,t)}function N(e){return null!==e&&"object"==typeof e&&!!e[o]}function x(e,t){return $(e,t),e}function $(e,t){if(!function(e){return void 0!==e}(e))throw v("not undefined",e,t)}function T(e){return!(null===e||"object"!=typeof e||Array.isArray(e)||e instanceof RegExp||N(e)||(t=e,null!==t&&"object"==typeof t&&t[s]));var t}function K(e){return function(e){return Array.isArray(e)||"string"==typeof e}(e)||T(e)}function C(e,t){if(!function(e){return"number"==typeof e||!!K(e)||!!N(e)}(e))throw v("FunctionLike",e,t)}function F(e){return{min:e,max:e}}function S(e,t){return e instanceof Promise?e.then(t):t(e)}function k(e,t){const r=[];for(let n=0;n<e.length;n++){const i=t(e[n],n);if(i instanceof Promise)return E(i,r,e,t,n);r.push(i)}return r}async function E(e,t,r,n,i){t.push(await e);for(let e=i+1;e<r.length;e++)t.push(await n(r[e],e));return t}function O(e,t,r){let n=r;for(let r=0;r<e.length;r++){const i=t(n,e[r],r);if(i instanceof Promise)return P(i,e,t,r);n=i}return n}async function P(e,t,r,n){let i=await e;for(let e=n+1;e<t.length;e++)i=await r(i,t[e],e);return i}function R(e,t){for(let r=0;r<e.length;r++){const n=t(e[r],r);if(n instanceof Promise)return j(n,e,t,r);if(n)return!0}return!1}async function j(e,t,r,n){if(await e)return!0;for(let e=n+1;e<t.length;e++)if(await r(t[e],e))return!0;return!1}function z(e,t){for(let r=0;r<e.length;r++){const n=t(e[r],r);if(n instanceof Promise)return I(n,e,t,r);if(!n)return!1}return!0}async function I(e,t,r,n){if(!await e)return!1;for(let e=n+1;e<t.length;e++)if(!await r(t[e],e))return!1;return!0}const M={"cell-every?":{category:"grid",description:"Checks if all elements in a grid satisfy a predicate. Returns true only if the predicate returns true for every element in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { cell-every? } = import(grid);\ncell-every?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], string?)','let { cell-every? } = import(grid);\ncell-every?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], string?)',"let { cell-every? } = import(grid);\ncell-every?([\n [1, 2],\n [3, 4],\n], string?)"],seeAlso:["collection.every?","grid.some?","grid.every-row?","grid.every-col?"]},"some?":{category:"grid",description:"Checks if any element in a grid satisfies a predicate. Returns true if the predicate returns true for at least one element in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { some? } = import(grid);\nsome?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], string?)','let { some? } = import(grid);\nsome?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], string?)',"let { some? } = import(grid);\nsome?([\n [1, 2],\n [3, 4],\n], string?)"],seeAlso:["collection.any?","grid.cell-every?","grid.some-row?","grid.some-col?"]},"every-row?":{category:"grid",description:"Checks if all rows in a grid satisfy a predicate. Returns true only if the predicate returns true for every row in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { every-row? } = import(grid);\nevery-row?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> string?($[0]))','let { every-row? } = import(grid);\nevery-row?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> string?($[0]))',"let { every-row? } = import(grid);\nevery-row?([\n [1, 2],\n [3, 4],\n], -> string?($[0]))"],seeAlso:["grid.some-row?","grid.every-col?","grid.cell-every?"]},"some-row?":{category:"grid",description:"Checks if any row in a grid satisfies a predicate. Returns true if the predicate returns true for at least one row in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { some-row? } = import(grid);\nsome-row?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> $ contains? "Albert")','let { some-row? } = import(grid);\nsome-row?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> $ contains? "Albert")','let { some-row? } = import(grid);\nsome-row?([\n [1, 2],\n [3, 4],\n], -> $ contains? "Albert")'],seeAlso:["grid.every-row?","grid.some-col?","grid.some?"]},"every-col?":{category:"grid",description:"Checks if all columns in a grid satisfy a predicate. Returns true only if the predicate returns true for every column in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { every-col? } = import(grid);\nevery-col?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> string?($[0]))','let { every-col? } = import(grid);\nevery-col?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> string?($[0]))',"let { every-col? } = import(grid);\nevery-col?([\n [1, 2],\n [3, 4],\n], -> string?($[0]))"],seeAlso:["grid.some-col?","grid.every-row?","grid.cell-every?"]},"some-col?":{category:"grid",description:"Checks if any column in a grid satisfies a predicate. Returns true if the predicate returns true for at least one column in the grid.",returns:{type:"boolean"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { some-col? } = import(grid);\nsome-col?([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> $ contains? "Albert")','let { some-col? } = import(grid);\nsome-col?([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], -> $ contains? "Albert")','let { some-col? } = import(grid);\nsome-col?([\n [1, 2],\n [3, 4],\n], -> $ contains? "Albert")'],seeAlso:["grid.every-col?","grid.some-row?","grid.some?"]},row:{category:"grid",description:"Returns the row at index $a in the grid $b.",returns:{type:"any"},args:{a:{type:"grid"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:['let { row } = import(grid);\nrow([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 0)','let { row } = import(grid);\nrow([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)','let { row } = import(grid);\nrow([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 2)'],seeAlso:["grid.col","grid.shape"]},col:{category:"grid",description:"Returns the column at index $a in the grid $b.",returns:{type:"any"},args:{a:{type:"grid"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:['let { col } = import(grid);\ncol([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 0)','let { col } = import(grid);\ncol([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)','let { col } = import(grid);\ncol([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 2)'],seeAlso:["grid.row","grid.shape"]},shape:{category:"grid",description:"Returns the shape of the grid `g` as a `vector` of two numbers, where the first number is the number of rows and the second number is the number of columns.",returns:{type:"vector"},args:{g:{type:"grid",description:"The grid to get the shape of."}},variants:[{argumentNames:["g"]}],examples:['let { shape } = import(grid);\nshape([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { shape } = import(grid);\nshape([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])',"let { shape } = import(grid);\nshape([\n [1, 2],\n [3, 4],\n])"],seeAlso:["grid.row","grid.col","grid.reshape"]},fill:{category:"grid",description:"Creates a grid of the specified size, filled with the specified value.",returns:{type:"grid"},args:{rows:{type:"integer",description:"The number of rows in the grid."},cols:{type:"integer",description:"The number of columns in the grid."},value:{type:"any",description:"The value to fill the grid with."}},variants:[{argumentNames:["rows","cols","value"]}],examples:["let { fill } = import(grid);\nfill(2, 3, 0)",'let { fill } = import(grid);\nfill(2, 3, "x")'],seeAlso:["grid.generate","grid.from-array"]},generate:{category:"grid",description:"Generates a grid of the specified size, where each element is generated by the provided function.",returns:{type:"grid"},args:{rows:{type:"number",description:"The number of rows in the grid."},cols:{type:"number",description:"The number of columns in the grid."},fn:{type:"function",description:"The function to generate the grid. It takes two arguments: the row index and the column index."}},variants:[{argumentNames:["rows","cols","fn"]}],examples:["let { generate } = import(grid);\ngenerate(3, 3, (i, j) -> i + j)"],seeAlso:["grid.fill","grid.from-array"]},reshape:{category:"grid",description:"Reshapes the grid `a` into a new grid with the specified number of rows `b`. The number of columns is automatically calculated based on the total number of elements in the grid.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:['let { reshape } = import(grid);\nreshape([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], 2)'],seeAlso:["grid.shape","grid.from-array"]},transpose:{category:"grid",description:"Transposes the grid `g`, swapping its rows and columns.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to transpose."}},variants:[{argumentNames:["g"]}],examples:['let { transpose } = import(grid);\ntranspose([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { transpose } = import(grid);\ntranspose([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])',"let { transpose } = import(grid);\ntranspose([\n [1, 2],\n [3, 4],\n])"],seeAlso:["grid.flip-h","grid.flip-v","grid.rotate"]},"flip-h":{category:"grid",description:"Flips the grid `g` horizontally.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to flip horizontally."}},variants:[{argumentNames:["g"]}],examples:['let { flip-h } = import(grid);\nflip-h([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { flip-h } = import(grid);\nflip-h([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])',"let { flip-h } = import(grid);\nflip-h([\n [1, 2],\n [3, 4],\n])"],seeAlso:["grid.flip-v","grid.transpose","grid.rotate"]},"flip-v":{category:"grid",description:"Flips the grid `g` vertically.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to flip vertically."}},variants:[{argumentNames:["g"]}],examples:['let { flip-v } = import(grid);\nflip-v([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])','let { flip-v } = import(grid);\nflip-v([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])',"let { flip-v } = import(grid);\nflip-v([\n [1, 2],\n [3, 4],\n])"],seeAlso:["grid.flip-h","grid.transpose","grid.rotate"]},rotate:{category:"grid",description:"Rotates the grid `g` by the specified angle. The angle is given in terms of 90-degree rotations. Positive values rotate the grid clockwise, while negative values rotate it counterclockwise.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"integer"}},variants:[{argumentNames:["a","b"]}],examples:["let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], 1)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], 2)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], 3)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], 4)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], -1)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], -2)","let { rotate } = import(grid);\nrotate([\n [1, 2],\n [3, 4],\n], -3)"],seeAlso:["grid.transpose","grid.flip-h","grid.flip-v"]},crop:{category:"grid",description:"Crops the grid `g` from the starting index `begin` to the optional ending index `stop`. The crop is inclusive of the starting index and exclusive of the ending index.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to slice."},begin:{type:"vector",description:"The starting index of the slice as a vector of two numbers: `[row, col]`."},stop:{type:"vector",description:"Optional ending index of the slice as a vector of two numbers: `[row, col]`."}},variants:[{argumentNames:["g","begin"]},{argumentNames:["g","begin","stop"]}],examples:['let { crop } = import(grid);\ncrop([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], [1, 1], [2, 2])','let { crop } = import(grid);\ncrop([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], [1, 1])'],hideOperatorForm:!0,seeAlso:["grid.slice-rows","grid.slice-cols"]},"slice-rows":{category:"grid",description:"Slices rows of the grid `g` from the starting index `begin` to the optional ending index `stop`. The slice is inclusive of the starting index and exclusive of the ending index.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to slice."},begin:{type:"number",description:"The starting index of the slice."},stop:{type:"number",description:"Optional ending index of the slice."}},variants:[{argumentNames:["g","begin"]},{argumentNames:["g","begin","stop"]}],examples:['let { slice-rows } = import(grid);\nslice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { slice-rows } = import(grid);\nslice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)'],hideOperatorForm:!0,seeAlso:["grid.crop","grid.slice-cols","grid.splice-rows"]},"slice-cols":{category:"grid",description:"Slices columns of the grid `g` from the starting index `begin` to the optional ending index `stop`. The slice is inclusive of the starting index and exclusive of the ending index.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to slice."},begin:{type:"number",description:"The starting index of the slice."},stop:{type:"number",description:"Optional ending index of the slice."}},variants:[{argumentNames:["g","begin"]},{argumentNames:["g","begin","stop"]}],examples:['let { slice-cols } = import(grid);\nslice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { slice-cols } = import(grid);\nslice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1)'],hideOperatorForm:!0,seeAlso:["grid.crop","grid.slice-rows","grid.splice-cols"]},"splice-rows":{category:"grid",description:"Splices rows of the grid `g` starting from the index `begin`. Deletes `deleteCount` rows and inserts the specified `items` at that position.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to splice."},begin:{type:"number",description:"The starting index of the splice."},deleteCount:{type:"number",description:"The number of rows to delete."},items:{type:"array",rest:!0,description:"The rows to insert."}},variants:[{argumentNames:["g","begin","deleteCount"]},{argumentNames:["g","begin","deleteCount","items"]}],examples:['let { splice-rows } = import(grid);\nsplice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { splice-rows } = import(grid);\nsplice-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 1, ["Nazanin", "mother", 40])'],hideOperatorForm:!0,seeAlso:["grid.splice-cols","grid.slice-rows"]},"splice-cols":{category:"grid",description:"Splices columns of the grid `g` starting from the index `begin`. Deletes `deleteCount` columns and inserts the specified `items` at that position.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to splice."},begin:{type:"number",description:"The starting index of the splice."},deleteCount:{type:"number",description:"The number of columns to delete."},items:{type:"array",rest:!0,description:"The columns to insert."}},variants:[{argumentNames:["g","begin","deleteCount"]},{argumentNames:["g","begin","deleteCount","items"]}],examples:['let { splice-cols } = import(grid);\nsplice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 2)','let { splice-cols } = import(grid);\nsplice-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], 1, 1, ["f", "m", "s"])'],hideOperatorForm:!0,seeAlso:["grid.splice-rows","grid.slice-cols"]},"concat-rows":{category:"grid",description:"Concatenates two grids `a` and `b` by rows. The number of columns in both grids must be the same.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"grid"}},variants:[{argumentNames:["a","b"]}],examples:['let { concat-rows } = import(grid);\nconcat-rows([\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n], [\n [1, 2],\n [3, 4],\n])'],seeAlso:["grid.concat-cols","grid.push-rows"]},"concat-cols":{category:"grid",description:"Concatenates two grids `a` and `b` by columns. The number of rows in both grids must be the same.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"grid"}},variants:[{argumentNames:["a","b"]}],examples:['let { concat-cols } = import(grid);\nconcat-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], [\n ["Albert", "father"],\n ["Nina", "mother"],\n ["Kian", "son"],\n])'],seeAlso:["grid.concat-rows","grid.push-cols"]},"cell-map":{category:"grid",description:"Maps a function `a` over each element of the grid `b`, returning a new grid with the results.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { cell-map } = import(grid);\ncell-map([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], str)'],seeAlso:["map","grid.cell-mapi","grid.cell-reduce"]},"cell-mapi":{category:"grid",description:"Maps a function `a` over each element of the grid `b`, passing the row and column index as additional arguments to the function.",returns:{type:"grid"},args:{a:{type:"grid"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],examples:['let { cell-mapi } = import(grid);\ncell-mapi([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], -> $1 ++ "(" ++ $2 ++ ", " ++ $3 ++ ")")'],seeAlso:["grid.cell-map","grid.cell-reducei","map"]},"cell-reduce":{category:"grid",description:"Reduces the grid `a` using the function `b`, returning a single value.",returns:{type:"any"},args:{g:{type:"grid",description:"The grid to reduce."},fn:{type:"function",description:"The function to reduce the grid. It takes two arguments: the accumulator and the current element."},"initial-value":{type:"any",description:"The initial value for the accumulator."}},variants:[{argumentNames:["g","fn","initial-value"]}],examples:['// Using "as" alias because "reduce" shadows a builtin function\nlet { cell-reduce } = import(grid);\ncell-reduce([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ++, "")'],seeAlso:["reduce","grid.cell-reducei","grid.cell-map"]},"cell-reducei":{category:"grid",description:"Reduces the grid `a` using the function `b`, passing the row and column indices as additional arguments to the function.",returns:{type:"any"},args:{g:{type:"grid",description:"The grid to reduce."},fn:{type:"function",description:"The function to reduce the grid. It takes four arguments: the accumulator, the current element, the row index, and the column index."},"initial-value":{type:"any",description:"The initial value for the accumulator."}},variants:[{argumentNames:["g","fn","initial-value"]}],examples:['// Using "as" alias because "reducei" shadows a builtin function\nlet { cell-reducei } = import(grid);\ncell-reducei([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ++, "")'],seeAlso:["grid.cell-reduce","grid.cell-mapi","reduce"]},"push-rows":{category:"grid",description:"Pushes the specified rows into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to push rows into."},rows:{type:"array",rest:!0,description:"The rows to push into the grid."}},variants:[{argumentNames:["g","rows"]}],examples:['let { push-rows } = import(grid);\npush-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["Nazanin", "mother", 40])'],hideOperatorForm:!0,seeAlso:["grid.unshift-rows","grid.pop-row","grid.shift-row","grid.concat-rows"]},"unshift-rows":{category:"grid",description:"Unshifts the specified rows into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to unshift rows into."},rows:{type:"array",rest:!0,description:"The rows to unshift into the grid."}},variants:[{argumentNames:["g","rows"]}],examples:['let { unshift-rows } = import(grid);\nunshift-rows([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["Nazanin", "mother", 40])'],hideOperatorForm:!0,seeAlso:["grid.push-rows","grid.shift-row","grid.pop-row"]},"pop-row":{category:"grid",description:"Pops the last row from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to pop a row from."}},variants:[{argumentNames:["g"]}],examples:['let { pop-row } = import(grid);\npop-row([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.shift-row","grid.push-rows","grid.unshift-rows"]},"shift-row":{category:"grid",description:"Shifts the first row from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to shift a row from."}},variants:[{argumentNames:["g"]}],examples:['let { shift-row } = import(grid);\nshift-row([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.pop-row","grid.push-rows","grid.unshift-rows"]},"push-cols":{category:"grid",description:"Pushes the specified columns into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to push columns into."},cols:{type:"array",rest:!0,description:"The columns to push into the grid."}},variants:[{argumentNames:["g","cols"]}],examples:['let { push-cols } = import(grid);\npush-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["f", "m", "s"])'],hideOperatorForm:!0,seeAlso:["grid.unshift-cols","grid.pop-col","grid.shift-col","grid.concat-cols"]},"unshift-cols":{category:"grid",description:"Unshifts the specified columns into the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to unshift columns into."},cols:{type:"array",rest:!0,description:"The columns to unshift into the grid."}},variants:[{argumentNames:["g","cols"]}],examples:['let { unshift-cols } = import(grid);\nunshift-cols([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n], ["f", "m", "s"])'],hideOperatorForm:!0,seeAlso:["grid.push-cols","grid.shift-col","grid.pop-col"]},"pop-col":{category:"grid",description:"Pops the last column from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to pop a column from."}},variants:[{argumentNames:["g"]}],examples:['let { pop-col } = import(grid);\npop-col([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.shift-col","grid.push-cols","grid.unshift-cols"]},"shift-col":{category:"grid",description:"Shifts the first column from the grid `g` and returns the new grid.",returns:{type:"grid"},args:{g:{type:"grid",description:"The grid to shift a column from."}},variants:[{argumentNames:["g"]}],examples:['let { shift-col } = import(grid);\nshift-col([\n ["Albert", "father", 10],\n ["Nina", "mother", 20],\n ["Kian", "son", 30],\n])'],seeAlso:["grid.pop-col","grid.push-cols","grid.unshift-cols"]},"from-array":{category:"grid",description:"Creates a grid from a flat array with specified dimensions. The array is reshaped into the specified number of rows, and the number of columns is automatically calculated based on the total number of elements in the array.",returns:{type:"grid"},args:{a:{type:"array"},b:{type:"number"}},variants:[{argumentNames:["a","b"]}],examples:["let { from-array } = import(grid);\nfrom-array([1, 2, 3, 4], 2)","let { from-array } = import(grid);\nfrom-array([1, 2, 3, 4], 4)"],seeAlso:["grid.fill","grid.generate","grid.reshape"]}};function U(e){const t=[];for(let r=0;r<e[0].length;r+=1){const n=[];for(let t=0;t<e.length;t+=1)n.push(e[t][r]);t.push(n)}return t}const B={"cell-every?":{evaluate:([e,t],r,n,{executeFunction:i})=>{w(e,r),C(t,r);const o=[];for(const t of e)for(const e of t)o.push(e);return z(o,e=>i(t,[e],n,r))},arity:F(2)},"some?":{evaluate:([e,t],r,n,{executeFunction:i})=>{w(e,r),C(t,r);const o=[];for(const t of e)for(const e of t)o.push(e);return R(o,e=>i(t,[e],n,r))},arity:F(2)},"every-row?":{evaluate:([e,t],r,n,{executeFunction:i})=>(w(e,r),C(t,r),z(Array.from(e),e=>i(t,[e],n,r))),arity:F(2)},"some-row?":{evaluate:([e,t],r,n,{executeFunction:i})=>(w(e,r),C(t,r),R(Array.from(e),e=>i(t,[e],n,r))),arity:F(2)},"every-col?":{evaluate:([e,t],r,n,{executeFunction:i})=>{w(e,r),C(t,r);const o=U(e);return z(Array.from(o),e=>i(t,[e],n,r))},arity:F(2)},"some-col?":{evaluate:([e,t],r,n,{executeFunction:i})=>{w(e,r),C(t,r);const o=U(e);return R(Array.from(o),e=>i(t,[e],n,r))},arity:F(2)},row:{evaluate:([e,t],r)=>(w(e,r),u(t,r,{integer:!0,nonNegative:!0,lt:e.length}),e[t]),arity:F(2)},col:{evaluate:([e,t],r)=>(w(e,r),u(t,r,{integer:!0,nonNegative:!0,lt:e[0].length}),e.map(e=>e[t])),arity:F(2)},shape:{evaluate:([e],t)=>(w(e,t),[e.length,e[0].length]),arity:F(1)},fill:{evaluate:([e,t,r],n)=>{u(e,n,{integer:!0,positive:!0}),u(t,n,{integer:!0,positive:!0}),$(r,n);const i=[];for(let n=0;n<e;n+=1){const e=[];for(let n=0;n<t;n+=1)e.push(r);i.push(e)}return i},arity:F(3)},generate:{evaluate:([e,t,r],n,i,{executeFunction:o})=>(u(e,n,{integer:!0,positive:!0}),u(t,n,{integer:!0,positive:!0}),C(r,n),k(Array.from({length:e}),(e,s)=>k(Array.from({length:t}),(e,t)=>S(o(r,[s,t],i,n),e=>($(e,n),e))))),arity:F(3)},reshape:{evaluate:([e,r],n)=>{w(e,n),u(r,n,{integer:!0,positive:!0});const i=e.flat();if(i.length%r!==0)throw new t(`The number of elements in the grid must be divisible by rows, but got ${i.length} and ${r}`,n);const o=i.length/r,s=[];for(let e=0;e<r;e+=1){const t=[];for(let r=0;r<o;r+=1)t.push(i[e*o+r]);s.push(t)}return s},arity:F(2)},transpose:{evaluate:([e],t)=>(w(e,t),U(e)),arity:F(1)},"flip-h":{evaluate:([e],t)=>(w(e,t),e.map(e=>e.reverse())),arity:F(1)},"flip-v":{evaluate:([e],t)=>(w(e,t),e.reverse()),arity:F(1)},rotate:{evaluate:([e,t],r)=>{if(w(e,r),u(t,r,{integer:!0}),0===(t=(t%4+4)%4)||0===e.length)return e.map(e=>[...e]);const n=e.length,i=e[0].length;let o;switch(t){case 1:o=Array(i).fill(null).map(()=>Array(n).fill(null));for(let t=0;t<n;t++)for(let r=0;r<i;r++)o[r][n-1-t]=e[t][r];break;case 2:o=Array(n).fill(null).map(()=>Array(i).fill(null));for(let t=0;t<n;t++)for(let r=0;r<i;r++)o[n-1-t][i-1-r]=e[t][r];break;case 3:o=Array(i).fill(null).map(()=>Array(n).fill(null));for(let t=0;t<n;t++)for(let r=0;r<i;r++)o[i-1-r][t]=e[t][r]}return o},arity:F(2)},crop:{evaluate:([e,r,n],i)=>{if(w(e,i),b(r,i),2!==r.length)throw new t(`The start vector must have 2 elements, but got ${r.length}`,i);const[o,s]=r;if(u(o,i,{integer:!0,nonNegative:!0,lt:e.length}),u(s,i,{integer:!0,nonNegative:!0,lt:e[0].length}),n??=[e.length,e[0].length],b(n,i),2!==n.length)throw new t(`The end vector must have 2 elements, but got ${n.length}`,i);const[a,l]=n;u(a,i,{gt:o,lte:e.length}),u(l,i,{gt:s,lte:e[0].length});const g=[];for(let t=o;t<a;t+=1){const r=[];for(let n=s;n<l;n+=1)r.push(e[t][n]);g.push(r)}return g},arity:{min:2,max:3}},"slice-rows":{evaluate:([e,t,r],n)=>(w(e,n),void 0===r?(u(t,n,{integer:!0,lte:e.length,gte:-e.length}),t<0?e.slice(e.length+t):e.slice(t)):(u(t,n,{integer:!0,nonNegative:!0,lte:e.length}),u(r,n,{integer:!0}),u(r=r<0?e.length+r:r,n,{gt:t,lte:e.length}),e.slice(t,r))),arity:{min:2,max:3}},"slice-cols":{evaluate:([e,t,r],n)=>{w(e,n);const i=U(e);return void 0===r?(u(t,n,{integer:!0,lte:i.length,gte:-i.length}),U(t<0?i.slice(i.length+t):i.slice(t))):(u(t,n,{integer:!0,nonNegative:!0,lte:i.length}),u(r,n,{integer:!0}),u(r=r<0?i.length+r:r,n,{gt:t,lte:i.length}),U(i.slice(t,r)))},arity:{min:2,max:3}},"splice-rows":{evaluate:([e,r,n,...i],o)=>{w(e,o),u(r,o,{integer:!0,nonNegative:!0,lte:e.length}),u(n,o,{integer:!0,nonNegative:!0}),0!==i.length&&(w(i,o),i.every(r=>{if(A(r,o),e[0].length!==r.length)throw new t(`All rows must have the same length as the number of columns in grid, but got ${r.length}`,o);return!0}));const s=[];for(let t=0;t<r;t+=1)s.push(e[t]);i.length>0&&s.push(...i);for(let t=r+n;t<e.length;t+=1)s.push(e[t]);return s},arity:{min:3}},"splice-cols":{evaluate:([e,r,n,...i],o)=>{w(e,o);const s=U(e);u(r,o,{integer:!0,nonNegative:!0,lte:s.length}),u(n,o,{integer:!0,nonNegative:!0}),0!==i.length&&(w(i,o),i.every(e=>{if(A(e,o),s[0].length!==e.length)throw new t(`All rows must have the same length as the number of rows in grid, but got ${e.length}`,o);return!0}));const a=[];for(let e=0;e<r;e+=1)a.push(s[e]);a.push(...i);for(let e=r+n;e<s.length;e+=1)a.push(s[e]);return U(a)},arity:{min:3}},"concat-rows":{evaluate:(e,r)=>{A(e,r),e.every(e=>w(e,r));const n=e[0][0].length;e.slice(1).every(e=>{if(e[0].length!==n)throw new t(`All grids must have the same number of columns, but got ${n} and ${e[0].length}`,r);return!0});const i=[];return e.forEach(e=>{e.forEach(e=>{i.push(e)})}),i},arity:{min:1}},"concat-cols":{evaluate:(e,r)=>{A(e,r),e.every(e=>w(e,r));const n=e[0].length;e.slice(1).every(e=>{if(e.length!==n)throw new t(`All grids must have the same number of rows, but got ${n} and ${e.length}`,r);return!0});const i=[];for(let t=0;t<n;t+=1){const r=[];e.forEach(e=>{r.push(...e[t])}),i.push(r)}return i},arity:{min:1}},"cell-map":{evaluate:(e,r,n,{executeFunction:i})=>{const o=function(e,t){return C(e,t),e}(e.at(-1),r),s=e.slice(0,-1);w(s[0],r);const a=s[0].length,l=s[0][0].length;return s.slice(1).forEach(e=>{if(w(e,r),e.length!==a)throw new t(`All grids must have the same number of rows, but got ${a} and ${e.length}`,r);if(e[0].length!==l)throw new t(`All grids must have the same number of columns, but got ${l} and ${e[0].length}`,r)}),k(Array.from({length:a}),(e,t)=>k(Array.from({length:l}),(e,a)=>{const l=s.map(e=>e[t][a]);return S(i(o,l,n,r),e=>x(e))}))},arity:{min:2}},"cell-mapi":{evaluate:([e,t],r,n,{executeFunction:i})=>{w(e,r),C(t,r);const o=e.length,s=e[0].length;return k(Array.from({length:o}),(o,a)=>k(Array.from({length:s}),(o,s)=>S(i(t,[e[a][s],a,s],n,r),e=>x(e))))},arity:F(2)},"cell-reduce":{evaluate:([e,t,r],n,i,{executeFunction:o})=>{w(e,n),C(t,n);const s=[];for(const t of e)for(const e of t)s.push(e);return O(s,(e,r)=>o(t,[e,r],i,n),x(r))},arity:F(3)},"cell-reducei":{evaluate:([e,t,r],n,i,{executeFunction:o})=>{w(e,n),C(t,n);const s=[];for(let t=0;t<e.length;t+=1)for(let r=0;r<e[t].length;r+=1)s.push({cell:e[t][r],i:t,j:r});return O(s,(e,{cell:r,i:s,j:a})=>o(t,[e,r,s,a],i,n),x(r))},arity:F(3)},"push-rows":{evaluate:([e,...r],n)=>{if(w(e,n),w(r,n),e[0].length!==r[0].length)throw new t(`All rows must have the same length as the number of columns in grid, but got ${e[0].length} and ${r[0].length}`,n);return[...e,...r]},arity:{min:2}},"unshift-rows":{evaluate:([e,...r],n)=>{if(w(e,n),w(r,n),e[0].length!==r[0].length)throw new t(`All rows must have the same length as the number of columns in grid, but got ${e[0].length} and ${r[0].length}`,n);return[...r,...e]},arity:{min:2}},"pop-row":{evaluate:([e],t)=>(w(e,t),1===e.length?null:e.slice(0,-1)),arity:F(1)},"shift-row":{evaluate:([e],t)=>(w(e,t),1===e.length?null:e.slice(1)),arity:F(1)},"push-cols":{evaluate:([e,...r],n)=>{if(w(e,n),w(r,n),e.length!==r[0].length)throw new t(`All columns must have the same length as the number of rows in grid, but got ${r.length}`,n);const i=[];for(let t=0;t<e.length;t+=1){const n=[];n.push(...e[t]),r.forEach(e=>{n.push(e[t])}),i.push(n)}return i},arity:{min:2}},"unshift-cols":{evaluate:([e,...r],n)=>{if(w(e,n),w(r,n),e.length!==r[0].length)throw new t(`All columns must have the same length as the number of rows in grid, but got ${r.length}`,n);const i=[];for(let t=0;t<e.length;t+=1){const n=[];r.forEach(e=>{n.push(e[t])}),n.push(...e[t]),i.push(n)}return i},arity:{min:2}},"pop-col":{evaluate:([e],t)=>(w(e,t),1===e[0].length?null:e.map(e=>e.slice(0,-1))),arity:F(1)},"shift-col":{evaluate:([e],t)=>(w(e,t),1===e[0].length?null:e.map(e=>e.slice(1))),arity:F(1)},"from-array":{evaluate:([e,r],n)=>{if(A(e,n),u(r,n,{integer:!0,positive:!0}),e.length%r!==0)throw new t(`The number of elements in the array must be divisible by rows, but got ${e.length} and ${r}`,n);return function(e,t){const r=[],n=e.length/t;for(let i=0;i<t;i++){const t=i*n,o=t+n;r.push(e.slice(t,o))}return r}(e,r)},arity:F(2)}};for(const[e,t]of Object.entries(M))B[e]&&(B[e].docs=t);const W={name:"grid",functions:B};export{W as gridModule};
|
|
2
2
|
//# sourceMappingURL=grid.esm.js.map
|