@mojir/lits 2.3.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -22
- package/dist/bundler.esm.js +2 -0
- package/dist/bundler.esm.js.map +1 -0
- package/dist/bundler.js +2 -0
- package/dist/bundler.js.map +1 -0
- package/dist/cli/cli/src/js-interop/Cli/Fs/index.d.ts +2 -2
- package/dist/cli/cli/src/js-interop/Cli/Proc/index.d.ts +2 -2
- package/dist/cli/cli/src/js-interop/Cli/index.d.ts +2 -3
- package/dist/cli/cli.js +2642 -2313
- package/dist/cli/reference/api.d.ts +3 -3
- package/dist/cli/reference/examples.d.ts +2 -2
- package/dist/cli/reference/index.d.ts +0 -1
- package/dist/cli/src/Lits/Lits.d.ts +6 -7
- package/dist/cli/src/builtin/index.d.ts +1 -1
- package/dist/cli/src/builtin/specialExpressionTypes.d.ts +15 -15
- package/dist/cli/src/builtin/specialExpressions/import.d.ts +6 -0
- package/dist/cli/src/bundler/index.d.ts +9 -0
- package/dist/cli/src/bundler/interface.d.ts +15 -0
- package/dist/cli/src/bundler.d.ts +3 -0
- package/dist/cli/src/evaluator/ContextStack.d.ts +10 -4
- package/dist/cli/src/index.d.ts +2 -0
- package/dist/cli/src/js-interop/Cli/Fs/index.d.ts +2 -2
- package/dist/cli/src/js-interop/Cli/Proc/index.d.ts +2 -2
- package/dist/cli/src/js-interop/Cli/index.d.ts +2 -3
- package/dist/cli/src/parser/ParserContext.d.ts +1 -1
- package/dist/cli/src/parser/getPrecedence.d.ts +3 -0
- package/dist/cli/src/parser/index.d.ts +2 -0
- package/dist/cli/src/parser/subParsers/parseExpression.d.ts +5 -0
- package/dist/cli/src/parser/types.d.ts +0 -3
- package/dist/cli/src/tokenizer/reservedNames.d.ts +0 -1
- 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/assert.esm.js +1 -1
- package/dist/modules/assert.esm.js.map +1 -1
- package/dist/modules/assert.js +1 -1
- package/dist/modules/assert.js.map +1 -1
- package/dist/modules/bitwise.esm.js +1 -1
- package/dist/modules/bitwise.esm.js.map +1 -1
- package/dist/modules/bitwise.js +1 -1
- package/dist/modules/bitwise.js.map +1 -1
- package/dist/modules/cli/src/js-interop/Cli/Fs/index.d.ts +2 -2
- package/dist/modules/cli/src/js-interop/Cli/Proc/index.d.ts +2 -2
- package/dist/modules/cli/src/js-interop/Cli/index.d.ts +2 -3
- 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/functional.esm.js +1 -1
- package/dist/modules/functional.esm.js.map +1 -1
- package/dist/modules/functional.js +1 -1
- package/dist/modules/functional.js.map +1 -1
- 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/number-theory.esm.js +1 -1
- package/dist/modules/number-theory.esm.js.map +1 -1
- package/dist/modules/number-theory.js +1 -1
- package/dist/modules/number-theory.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 +3 -3
- package/dist/modules/reference/index.d.ts +0 -1
- 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/Lits/Lits.d.ts +6 -7
- package/dist/modules/src/builtin/index.d.ts +1 -1
- package/dist/modules/src/builtin/specialExpressionTypes.d.ts +15 -15
- package/dist/modules/src/builtin/specialExpressions/import.d.ts +6 -0
- package/dist/modules/src/bundler/index.d.ts +9 -0
- package/dist/modules/src/bundler/interface.d.ts +15 -0
- package/dist/modules/src/bundler.d.ts +3 -0
- package/dist/modules/src/evaluator/ContextStack.d.ts +10 -4
- package/dist/modules/src/index.d.ts +2 -0
- package/dist/modules/src/parser/ParserContext.d.ts +1 -1
- package/dist/modules/src/parser/getPrecedence.d.ts +3 -0
- package/dist/modules/src/parser/index.d.ts +2 -0
- package/dist/modules/src/parser/subParsers/parseExpression.d.ts +5 -0
- package/dist/modules/src/parser/types.d.ts +0 -3
- package/dist/modules/src/tokenizer/reservedNames.d.ts +0 -1
- 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 +3 -3
- package/dist/reference/index.d.ts +0 -1
- package/dist/src/Lits/Lits.d.ts +6 -7
- package/dist/src/builtin/index.d.ts +1 -1
- package/dist/src/builtin/specialExpressionTypes.d.ts +15 -15
- package/dist/src/builtin/specialExpressions/import.d.ts +6 -0
- package/dist/src/bundler/index.d.ts +9 -0
- package/dist/src/bundler/interface.d.ts +15 -0
- package/dist/src/bundler.d.ts +3 -0
- package/dist/src/evaluator/ContextStack.d.ts +10 -4
- package/dist/src/index.d.ts +2 -0
- package/dist/src/parser/ParserContext.d.ts +1 -1
- package/dist/src/parser/getPrecedence.d.ts +3 -0
- package/dist/src/parser/index.d.ts +2 -0
- package/dist/src/parser/subParsers/parseExpression.d.ts +5 -0
- package/dist/src/parser/types.d.ts +0 -3
- package/dist/src/tokenizer/reservedNames.d.ts +0 -1
- 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
- package/dist/cli/cli/src/js-interop/utils.d.ts +0 -2
- package/dist/cli/src/builtin/specialExpressions/def.d.ts +0 -6
- package/dist/cli/src/js-interop/utils.d.ts +0 -2
- package/dist/cli/src/parser/subParsers/getPrecedence.d.ts +0 -3
- package/dist/modules/cli/src/js-interop/utils.d.ts +0 -2
- package/dist/modules/src/builtin/specialExpressions/def.d.ts +0 -6
- package/dist/modules/src/parser/subParsers/getPrecedence.d.ts +0 -3
- package/dist/src/builtin/specialExpressions/def.d.ts +0 -6
- package/dist/src/parser/subParsers/getPrecedence.d.ts +0 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitwise.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/bitwise/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 { Argument, BuiltinNormalExpressions } from '../../interface'\nimport type { LitsModule } from '../interface'\n\nfunction getOperatorArgs(a: 'integer', b: 'integer'): Record<string, Argument> {\n return { a: { type: a }, b: { type: b } }\n}\n\nconst bitwiseUtilsNormalExpression: BuiltinNormalExpressions = {\n 'bit-not': {\n evaluate: ([num], sourceCodeInfo): number => {\n assertNumber(num, sourceCodeInfo, { integer: true })\n return ~num\n },\n arity: toFixedArity(1),\n docs: {\n category: 'bitwise',\n returns: { type: 'integer' },\n args: { a: { type: 'integer' } },\n variants: [{ argumentNames: ['a'] }],\n description: 'Returns bitwise `not` of $a.',\n seeAlso: ['&', '|', 'xor', 'bitwise.bit-and-not'],\n examples: [\n 'let { bit-not } = import(\"bitwise\");\\nbit-not(0)',\n 'let { bit-not } = import(\"bitwise\");\\nbit-not(255)',\n ],\n },\n },\n 'bit-and-not': {\n evaluate: ([first, ...rest], sourceCodeInfo): number => {\n assertNumber(first, sourceCodeInfo, { integer: true })\n\n return rest.reduce((result: number, value) => {\n assertNumber(value, sourceCodeInfo, { integer: true })\n return result & ~value\n }, first)\n },\n arity: { min: 2 },\n docs: {\n category: 'bitwise',\n returns: { type: 'integer' },\n args: {\n ...getOperatorArgs('integer', 'integer'),\n c: { type: 'integer', rest: true },\n },\n variants: [\n { argumentNames: ['a', 'b'] },\n { argumentNames: ['a', 'b', 'c'] },\n ],\n description: 'Returns bitwise `and` with complement.',\n seeAlso: ['&', '|', 'xor', 'bitwise.bit-not'],\n examples: [\n 'let { bit-and-not } = import(\"bitwise\");\\n0b0011 bit-and-not 0b0110',\n 'let { bit-and-not } = import(\"bitwise\");\\nbit-and-not(0b0011, 0b0110)',\n 'let { bit-and-not } = import(\"bitwise\");\\nbit-and-not(0b0011, 0b0110, 0b1001)',\n ],\n },\n },\n 'bit-flip': {\n evaluate: ([num, index], sourceCodeInfo): number => {\n assertNumber(num, sourceCodeInfo, { integer: true })\n assertNumber(index, sourceCodeInfo, { integer: true, nonNegative: true })\n\n const mask = 1 << index\n return (num ^= mask)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'bitwise',\n returns: { type: 'integer' },\n args: { ...getOperatorArgs('integer', 'integer') },\n variants: [{ argumentNames: ['a', 'b'] }],\n description: 'Flips bit number $b.',\n seeAlso: ['bitwise.bit-set', 'bitwise.bit-clear', 'bitwise.bit-test'],\n examples: [\n 'let { bit-flip } = import(\"bitwise\");\\n0b0011 bit-flip 1',\n 'let { bit-flip } = import(\"bitwise\");\\nbit-flip(0b0011, 1)',\n 'let { bit-flip } = import(\"bitwise\");\\nbit-flip(0b1100, 1)',\n ],\n },\n },\n 'bit-set': {\n evaluate: ([num, index], sourceCodeInfo): number => {\n assertNumber(num, sourceCodeInfo, { integer: true })\n assertNumber(index, sourceCodeInfo, { integer: true, nonNegative: true })\n\n const mask = 1 << index\n return (num |= mask)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'bitwise',\n returns: { type: 'integer' },\n args: { ...getOperatorArgs('integer', 'integer') },\n variants: [{ argumentNames: ['a', 'b'] }],\n description: 'Sets bit number $b.',\n seeAlso: ['bitwise.bit-flip', 'bitwise.bit-clear', 'bitwise.bit-test'],\n examples: [\n 'let { bit-set } = import(\"bitwise\");\\n0b0010 bit-set 1',\n 'let { bit-set } = import(\"bitwise\");\\nbit-set(0b0011, 1)',\n 'let { bit-set } = import(\"bitwise\");\\nbit-set(0b1100, 1)',\n ],\n },\n },\n 'bit-clear': {\n evaluate: ([num, index], sourceCodeInfo): number => {\n assertNumber(num, sourceCodeInfo, { integer: true })\n assertNumber(index, sourceCodeInfo, { integer: true, nonNegative: true })\n\n const mask = 1 << index\n return (num &= ~mask)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'bitwise',\n returns: { type: 'integer' },\n args: { ...getOperatorArgs('integer', 'integer') },\n variants: [{ argumentNames: ['a', 'b'] }],\n description: 'Clears bit number $b.',\n seeAlso: ['bitwise.bit-flip', 'bitwise.bit-set', 'bitwise.bit-test'],\n examples: [\n 'let { bit-clear } = import(\"bitwise\");\\n0b0011 bit-clear 1',\n 'let { bit-clear } = import(\"bitwise\");\\nbit-clear(0b0011, 1)',\n 'let { bit-clear } = import(\"bitwise\");\\nbit-clear(0b1100, 1)',\n ],\n },\n },\n 'bit-test': {\n evaluate: ([num, index], sourceCodeInfo): boolean => {\n assertNumber(num, sourceCodeInfo, { integer: true })\n assertNumber(index, sourceCodeInfo, { integer: true, nonNegative: true })\n\n const mask = 1 << index\n return !!(num & mask)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'bitwise',\n returns: { type: 'boolean' },\n args: { ...getOperatorArgs('integer', 'integer') },\n variants: [{ argumentNames: ['a', 'b'] }],\n description: 'Checks if bit number $b is set.',\n seeAlso: ['bitwise.bit-flip', 'bitwise.bit-set', 'bitwise.bit-clear'],\n examples: [\n 'let { bit-test } = import(\"bitwise\");\\n0b0011 bit-test 1',\n 'let { bit-test } = import(\"bitwise\");\\nbit-test(0b0011, 1)',\n 'let { bit-test } = import(\"bitwise\");\\nbit-test(0b1100, 1)',\n ],\n },\n },\n}\n\nexport const bitwiseUtilsModule: LitsModule = {\n name: 'bitwise',\n functions: bitwiseUtilsNormalExpression,\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","getOperatorArgs","a","b","bitwiseUtilsModule","functions","evaluate","num","docs","category","returns","args","variants","argumentNames","description","seeAlso","examples","first","rest","reduce","result","c","index"],"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,GAAGjB,EAAeC,SAASiB,QAAQlB,EAAeC,SAASG,SAM5E,MAAO,GAAG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CAAE6D,SAAS,EAAMS,aAAa,IAGlE,OAAQ0B,IADK,GAAKe,IAGpBvB,MAAOD,EAAa,GACpBU,KAAM,CACJC,SAAU,UACVC,QAAS,CAAExD,KAAM,WACjByD,KAAM,IAAKV,EAAgB,UAAW,YACtCW,SAAU,CAAC,CAAEC,cAAe,CAAC,IAAK,OAClCC,YAAa,wBACbC,QAAS,CAAC,mBAAoB,kBAAmB,oBACjDC,SAAU,CACR,6DACA,+DACA,kEAIN,WAAY,CACVV,SAAU,EAAEC,EAAKe,GAAQ/G,KACvB0D,EAAasC,EAAKhG,EAAgB,CAAE6D,SAAS,IAC7CH,EAAaqD,EAAO/G,EAAgB,CAAE6D,SAAS,EAAMS,aAAa,IAGlE,SAAU0B,EADG,GAAKe,IAGpBvB,MAAOD,EAAa,GACpBU,KAAM,CACJC,SAAU,UACVC,QAAS,CAAExD,KAAM,WACjByD,KAAM,IAAKV,EAAgB,UAAW,YACtCW,SAAU,CAAC,CAAEC,cAAe,CAAC,IAAK,OAClCC,YAAa,kCACbC,QAAS,CAAC,mBAAoB,kBAAmB,qBACjDC,SAAU,CACR,2DACA,6DACA"}
|
|
1
|
+
{"version":3,"file":"bitwise.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/bitwise/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 { Argument, BuiltinNormalExpressions } from '../../interface'\nimport type { LitsModule } from '../interface'\n\nfunction getOperatorArgs(a: 'integer', b: 'integer'): Record<string, Argument> {\n return { a: { type: a }, b: { type: b } }\n}\n\nconst bitwiseUtilsNormalExpression: BuiltinNormalExpressions = {\n 'bit-not': {\n evaluate: ([num], sourceCodeInfo): number => {\n assertNumber(num, sourceCodeInfo, { integer: true })\n return ~num\n },\n arity: toFixedArity(1),\n docs: {\n category: 'bitwise',\n returns: { type: 'integer' },\n args: { a: { type: 'integer' } },\n variants: [{ argumentNames: ['a'] }],\n description: 'Returns bitwise `not` of $a.',\n seeAlso: ['&', '|', 'xor', 'bitwise.bit-and-not'],\n examples: [\n 'let { bit-not } = import(bitwise);\\nbit-not(0)',\n 'let { bit-not } = import(bitwise);\\nbit-not(255)',\n ],\n },\n },\n 'bit-and-not': {\n evaluate: ([first, ...rest], sourceCodeInfo): number => {\n assertNumber(first, sourceCodeInfo, { integer: true })\n\n return rest.reduce((result: number, value) => {\n assertNumber(value, sourceCodeInfo, { integer: true })\n return result & ~value\n }, first)\n },\n arity: { min: 2 },\n docs: {\n category: 'bitwise',\n returns: { type: 'integer' },\n args: {\n ...getOperatorArgs('integer', 'integer'),\n c: { type: 'integer', rest: true },\n },\n variants: [\n { argumentNames: ['a', 'b'] },\n { argumentNames: ['a', 'b', 'c'] },\n ],\n description: 'Returns bitwise `and` with complement.',\n seeAlso: ['&', '|', 'xor', 'bitwise.bit-not'],\n examples: [\n 'let { bit-and-not } = import(bitwise);\\n0b0011 bit-and-not 0b0110',\n 'let { bit-and-not } = import(bitwise);\\nbit-and-not(0b0011, 0b0110)',\n 'let { bit-and-not } = import(bitwise);\\nbit-and-not(0b0011, 0b0110, 0b1001)',\n ],\n },\n },\n 'bit-flip': {\n evaluate: ([num, index], sourceCodeInfo): number => {\n assertNumber(num, sourceCodeInfo, { integer: true })\n assertNumber(index, sourceCodeInfo, { integer: true, nonNegative: true })\n\n const mask = 1 << index\n return (num ^= mask)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'bitwise',\n returns: { type: 'integer' },\n args: { ...getOperatorArgs('integer', 'integer') },\n variants: [{ argumentNames: ['a', 'b'] }],\n description: 'Flips bit number $b.',\n seeAlso: ['bitwise.bit-set', 'bitwise.bit-clear', 'bitwise.bit-test'],\n examples: [\n 'let { bit-flip } = import(bitwise);\\n0b0011 bit-flip 1',\n 'let { bit-flip } = import(bitwise);\\nbit-flip(0b0011, 1)',\n 'let { bit-flip } = import(bitwise);\\nbit-flip(0b1100, 1)',\n ],\n },\n },\n 'bit-set': {\n evaluate: ([num, index], sourceCodeInfo): number => {\n assertNumber(num, sourceCodeInfo, { integer: true })\n assertNumber(index, sourceCodeInfo, { integer: true, nonNegative: true })\n\n const mask = 1 << index\n return (num |= mask)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'bitwise',\n returns: { type: 'integer' },\n args: { ...getOperatorArgs('integer', 'integer') },\n variants: [{ argumentNames: ['a', 'b'] }],\n description: 'Sets bit number $b.',\n seeAlso: ['bitwise.bit-flip', 'bitwise.bit-clear', 'bitwise.bit-test'],\n examples: [\n 'let { bit-set } = import(bitwise);\\n0b0010 bit-set 1',\n 'let { bit-set } = import(bitwise);\\nbit-set(0b0011, 1)',\n 'let { bit-set } = import(bitwise);\\nbit-set(0b1100, 1)',\n ],\n },\n },\n 'bit-clear': {\n evaluate: ([num, index], sourceCodeInfo): number => {\n assertNumber(num, sourceCodeInfo, { integer: true })\n assertNumber(index, sourceCodeInfo, { integer: true, nonNegative: true })\n\n const mask = 1 << index\n return (num &= ~mask)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'bitwise',\n returns: { type: 'integer' },\n args: { ...getOperatorArgs('integer', 'integer') },\n variants: [{ argumentNames: ['a', 'b'] }],\n description: 'Clears bit number $b.',\n seeAlso: ['bitwise.bit-flip', 'bitwise.bit-set', 'bitwise.bit-test'],\n examples: [\n 'let { bit-clear } = import(bitwise);\\n0b0011 bit-clear 1',\n 'let { bit-clear } = import(bitwise);\\nbit-clear(0b0011, 1)',\n 'let { bit-clear } = import(bitwise);\\nbit-clear(0b1100, 1)',\n ],\n },\n },\n 'bit-test': {\n evaluate: ([num, index], sourceCodeInfo): boolean => {\n assertNumber(num, sourceCodeInfo, { integer: true })\n assertNumber(index, sourceCodeInfo, { integer: true, nonNegative: true })\n\n const mask = 1 << index\n return !!(num & mask)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'bitwise',\n returns: { type: 'boolean' },\n args: { ...getOperatorArgs('integer', 'integer') },\n variants: [{ argumentNames: ['a', 'b'] }],\n description: 'Checks if bit number $b is set.',\n seeAlso: ['bitwise.bit-flip', 'bitwise.bit-set', 'bitwise.bit-clear'],\n examples: [\n 'let { bit-test } = import(bitwise);\\n0b0011 bit-test 1',\n 'let { bit-test } = import(bitwise);\\nbit-test(0b0011, 1)',\n 'let { bit-test } = import(bitwise);\\nbit-test(0b1100, 1)',\n ],\n },\n },\n}\n\nexport const bitwiseUtilsModule: LitsModule = {\n name: 'bitwise',\n functions: bitwiseUtilsNormalExpression,\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","getOperatorArgs","a","b","bitwiseUtilsModule","functions","evaluate","num","docs","category","returns","args","variants","argumentNames","description","seeAlso","examples","first","rest","reduce","result","c","index"],"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,GAAGjB,EAAeC,SAASiB,QAAQlB,EAAeC,SAASG,SAM5E,MAAO,GAAGW,IALWf,EAAemB,SAChC,KAAKnB,EAAemB,YAAYF,IAChC,cAAcA,QACIjB,EAAeE,SACbH,EAAcC,IAExC,CAoBUoB,CAAoBL,EAASf,IAC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AAExD,KAAM,WACjByD,KAAM,IAAKV,EAAgB,UAAW,YACtCW,SAAU,CAAC,CAAEC,cAAe,CAAC,IAAK,OAClCC,YAAa,wBACbC,QAAS,CAAC,mBAAoB,kBAAmB,oBACjDC,SAAU,CACR,2DACA,6DACA,gEAIN,WAAY,CACVV,SAAU,EAAEC,EAAKe,GAAQ/G,KACvB0D,EAAasC,EAAKhG,EAAgB,CAAE6D,SAAS,IAC7CH,EAAaqD,EAAO/G,EAAgB,CAAE6D,SAAS,EAAMS,aAAa,IAGlE,SAAU0B,EADG,GAAKe,IAGpBvB,MAAOD,EAAa,GACpBU,KAAM,CACJC,SAAU,UACVC,QAAS,CAAExD,KAAM,WACjByD,KAAM,IAAKV,EAAgB,UAAW,YACtCW,SAAU,CAAC,CAAEC,cAAe,CAAC,IAAK,OAClCC,YAAa,kCACbC,QAAS,CAAC,mBAAoB,kBAAmB,qBACjDC,SAAU,CACR,yDACA,2DACA"}
|
package/dist/modules/bitwise.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";function t(t){if(!t.position||!t.code)return"";const e=t.position.column-1,i=t.code.length-e-1;return`${" ".repeat(Math.max(e,0))}^${" ".repeat(Math.max(i,0))}`}class e extends Error{sourceCodeInfo;shortMessage;constructor(i,n){const r=i instanceof Error?i.message:`${i}`;super(function(e,i){if(!i)return e;const n=`${i.position.line}:${i.position.column}`;return`${e}${i.filePath?`\n${i.filePath}:${n}`:`\nLocation ${n}`}\n${i.code}\n${t(i)}`}(r,n)),this.shortMessage=r,this.sourceCodeInfo=n,Object.setPrototypeOf(this,e.prototype),this.name="LitsError"}getCodeMarker(){return this.sourceCodeInfo&&t(this.sourceCodeInfo)}}const i={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(i));const r=new Set(["UserDefined","Partial","Comp","Constantly","Juxt","Complement","EveryPred","SomePred","Fnull","Builtin","SpecialBuiltin","NativeJsFunction","Module"]);function o(t){return null!==t&&"object"==typeof t&&("^^fn^^"in t&&"functionType"in t&&("string"==typeof(e=t.functionType)&&r.has(e)));var e}function s(t){return!(!Array.isArray(t)||t.length<2)&&("number"==typeof(e=t[0])&&n.has(e));var e}function b(t){return o(t)?`<function ${t.name||"λ"}>`:s(t)?`${e=t[0],Object.keys(i).find(t=>i[t]===e)}-node`:null===t?"null":"object"==typeof t&&t instanceof RegExp?`${t}`:"object"==typeof t&&t instanceof Error?t.toString():JSON.stringify(t);var e}function a(t,i,n={}){if(!function(t,e={}){return!("number"!=typeof t||Number.isNaN(t)||e.integer&&!Number.isInteger(t)||e.finite&&!Number.isFinite(t)||e.zero&&0!==t||e.nonZero&&0===t||e.positive&&t<=0||e.negative&&t>=0||e.nonPositive&&t>0||e.nonNegative&&t<0||"number"==typeof e.gt&&t<=e.gt||"number"==typeof e.gte&&t<e.gte||"number"==typeof e.lt&&t>=e.lt||"number"==typeof e.lte&&t>e.lte)}(t,n))throw new e(`Expected ${function(t){if(t.zero)return"zero";const e=function(t){return t.positive?"positive":t.negative?"negative":t.nonNegative?"non negative":t.nonPositive?"non positive":t.nonZero?"non zero":""}(t),i=t.integer?"integer":"number",n=t.finite?"finite":"",r=function(t){return"number"!=typeof t.gt&&"number"!=typeof t.gte||"number"!=typeof t.lt&&"number"!=typeof t.lte?"number"==typeof t.gt||"number"==typeof t.gte?"number"==typeof t.gt?`n > ${t.gt}`:`n >= ${t.gte}`:"number"==typeof t.lt||"number"==typeof t.lte?"number"==typeof t.lt?`n < ${t.lt}`:`n <= ${t.lte}`:"":`${"number"==typeof t.gt?`${t.gt} < n `:`${t.gte} <= n `}${"number"==typeof t.lt?`< ${t.lt}`:`<= ${t.lte}`}`}(t);return[e,n,i,r].filter(t=>!!t).join(" ")}(n)}, got ${b(t)}.`,function(t,e){return t?.sourceCodeInfo??e}(t,i))}function l(t){return{min:t,max:t}}function u(t,e){return{a:{type:t},b:{type:e}}}const p={name:"bitwise",functions:{"bit-not":{evaluate:([t],e)=>(a(t,e,{integer:!0}),~t),arity:l(1),docs:{category:"bitwise",returns:{type:"integer"},args:{a:{type:"integer"}},variants:[{argumentNames:["a"]}],description:"Returns bitwise `not` of $a.",seeAlso:["&","|","xor","bitwise.bit-and-not"],examples:[
|
|
1
|
+
"use strict";function t(t){if(!t.position||!t.code)return"";const e=t.position.column-1,i=t.code.length-e-1;return`${" ".repeat(Math.max(e,0))}^${" ".repeat(Math.max(i,0))}`}class e extends Error{sourceCodeInfo;shortMessage;constructor(i,n){const r=i instanceof Error?i.message:`${i}`;super(function(e,i){if(!i)return e;const n=`${i.position.line}:${i.position.column}`;return`${e}${i.filePath?`\n${i.filePath}:${n}`:`\nLocation ${n}`}\n${i.code}\n${t(i)}`}(r,n)),this.shortMessage=r,this.sourceCodeInfo=n,Object.setPrototypeOf(this,e.prototype),this.name="LitsError"}getCodeMarker(){return this.sourceCodeInfo&&t(this.sourceCodeInfo)}}const i={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(i));const r=new Set(["UserDefined","Partial","Comp","Constantly","Juxt","Complement","EveryPred","SomePred","Fnull","Builtin","SpecialBuiltin","NativeJsFunction","Module"]);function o(t){return null!==t&&"object"==typeof t&&("^^fn^^"in t&&"functionType"in t&&("string"==typeof(e=t.functionType)&&r.has(e)));var e}function s(t){return!(!Array.isArray(t)||t.length<2)&&("number"==typeof(e=t[0])&&n.has(e));var e}function b(t){return o(t)?`<function ${t.name||"λ"}>`:s(t)?`${e=t[0],Object.keys(i).find(t=>i[t]===e)}-node`:null===t?"null":"object"==typeof t&&t instanceof RegExp?`${t}`:"object"==typeof t&&t instanceof Error?t.toString():JSON.stringify(t);var e}function a(t,i,n={}){if(!function(t,e={}){return!("number"!=typeof t||Number.isNaN(t)||e.integer&&!Number.isInteger(t)||e.finite&&!Number.isFinite(t)||e.zero&&0!==t||e.nonZero&&0===t||e.positive&&t<=0||e.negative&&t>=0||e.nonPositive&&t>0||e.nonNegative&&t<0||"number"==typeof e.gt&&t<=e.gt||"number"==typeof e.gte&&t<e.gte||"number"==typeof e.lt&&t>=e.lt||"number"==typeof e.lte&&t>e.lte)}(t,n))throw new e(`Expected ${function(t){if(t.zero)return"zero";const e=function(t){return t.positive?"positive":t.negative?"negative":t.nonNegative?"non negative":t.nonPositive?"non positive":t.nonZero?"non zero":""}(t),i=t.integer?"integer":"number",n=t.finite?"finite":"",r=function(t){return"number"!=typeof t.gt&&"number"!=typeof t.gte||"number"!=typeof t.lt&&"number"!=typeof t.lte?"number"==typeof t.gt||"number"==typeof t.gte?"number"==typeof t.gt?`n > ${t.gt}`:`n >= ${t.gte}`:"number"==typeof t.lt||"number"==typeof t.lte?"number"==typeof t.lt?`n < ${t.lt}`:`n <= ${t.lte}`:"":`${"number"==typeof t.gt?`${t.gt} < n `:`${t.gte} <= n `}${"number"==typeof t.lt?`< ${t.lt}`:`<= ${t.lte}`}`}(t);return[e,n,i,r].filter(t=>!!t).join(" ")}(n)}, got ${b(t)}.`,function(t,e){return t?.sourceCodeInfo??e}(t,i))}function l(t){return{min:t,max:t}}function u(t,e){return{a:{type:t},b:{type:e}}}const p={name:"bitwise",functions:{"bit-not":{evaluate:([t],e)=>(a(t,e,{integer:!0}),~t),arity:l(1),docs:{category:"bitwise",returns:{type:"integer"},args:{a:{type:"integer"}},variants:[{argumentNames:["a"]}],description:"Returns bitwise `not` of $a.",seeAlso:["&","|","xor","bitwise.bit-and-not"],examples:["let { bit-not } = import(bitwise);\nbit-not(0)","let { bit-not } = import(bitwise);\nbit-not(255)"]}},"bit-and-not":{evaluate:([t,...e],i)=>(a(t,i,{integer:!0}),e.reduce((t,e)=>(a(e,i,{integer:!0}),t&~e),t)),arity:{min:2},docs:{category:"bitwise",returns:{type:"integer"},args:{...u("integer","integer"),c:{type:"integer",rest:!0}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","c"]}],description:"Returns bitwise `and` with complement.",seeAlso:["&","|","xor","bitwise.bit-not"],examples:["let { bit-and-not } = import(bitwise);\n0b0011 bit-and-not 0b0110","let { bit-and-not } = import(bitwise);\nbit-and-not(0b0011, 0b0110)","let { bit-and-not } = import(bitwise);\nbit-and-not(0b0011, 0b0110, 0b1001)"]}},"bit-flip":{evaluate:([t,e],i)=>{a(t,i,{integer:!0}),a(e,i,{integer:!0,nonNegative:!0});return t^1<<e},arity:l(2),docs:{category:"bitwise",returns:{type:"integer"},args:{...u("integer","integer")},variants:[{argumentNames:["a","b"]}],description:"Flips bit number $b.",seeAlso:["bitwise.bit-set","bitwise.bit-clear","bitwise.bit-test"],examples:["let { bit-flip } = import(bitwise);\n0b0011 bit-flip 1","let { bit-flip } = import(bitwise);\nbit-flip(0b0011, 1)","let { bit-flip } = import(bitwise);\nbit-flip(0b1100, 1)"]}},"bit-set":{evaluate:([t,e],i)=>{a(t,i,{integer:!0}),a(e,i,{integer:!0,nonNegative:!0});return t|1<<e},arity:l(2),docs:{category:"bitwise",returns:{type:"integer"},args:{...u("integer","integer")},variants:[{argumentNames:["a","b"]}],description:"Sets bit number $b.",seeAlso:["bitwise.bit-flip","bitwise.bit-clear","bitwise.bit-test"],examples:["let { bit-set } = import(bitwise);\n0b0010 bit-set 1","let { bit-set } = import(bitwise);\nbit-set(0b0011, 1)","let { bit-set } = import(bitwise);\nbit-set(0b1100, 1)"]}},"bit-clear":{evaluate:([t,e],i)=>{a(t,i,{integer:!0}),a(e,i,{integer:!0,nonNegative:!0});return t&~(1<<e)},arity:l(2),docs:{category:"bitwise",returns:{type:"integer"},args:{...u("integer","integer")},variants:[{argumentNames:["a","b"]}],description:"Clears bit number $b.",seeAlso:["bitwise.bit-flip","bitwise.bit-set","bitwise.bit-test"],examples:["let { bit-clear } = import(bitwise);\n0b0011 bit-clear 1","let { bit-clear } = import(bitwise);\nbit-clear(0b0011, 1)","let { bit-clear } = import(bitwise);\nbit-clear(0b1100, 1)"]}},"bit-test":{evaluate:([t,e],i)=>{a(t,i,{integer:!0}),a(e,i,{integer:!0,nonNegative:!0});return!!(t&1<<e)},arity:l(2),docs:{category:"bitwise",returns:{type:"boolean"},args:{...u("integer","integer")},variants:[{argumentNames:["a","b"]}],description:"Checks if bit number $b is set.",seeAlso:["bitwise.bit-flip","bitwise.bit-set","bitwise.bit-clear"],examples:["let { bit-test } = import(bitwise);\n0b0011 bit-test 1","let { bit-test } = import(bitwise);\nbit-test(0b0011, 1)","let { bit-test } = import(bitwise);\nbit-test(0b1100, 1)"]}}}};exports.bitwiseUtilsModule=p;
|
|
2
2
|
//# sourceMappingURL=bitwise.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitwise.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/bitwise/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 { Argument, BuiltinNormalExpressions } from '../../interface'\nimport type { LitsModule } from '../interface'\n\nfunction getOperatorArgs(a: 'integer', b: 'integer'): Record<string, Argument> {\n return { a: { type: a }, b: { type: b } }\n}\n\nconst bitwiseUtilsNormalExpression: BuiltinNormalExpressions = {\n 'bit-not': {\n evaluate: ([num], sourceCodeInfo): number => {\n assertNumber(num, sourceCodeInfo, { integer: true })\n return ~num\n },\n arity: toFixedArity(1),\n docs: {\n category: 'bitwise',\n returns: { type: 'integer' },\n args: { a: { type: 'integer' } },\n variants: [{ argumentNames: ['a'] }],\n description: 'Returns bitwise `not` of $a.',\n seeAlso: ['&', '|', 'xor', 'bitwise.bit-and-not'],\n examples: [\n 'let { bit-not } = import(\"bitwise\");\\nbit-not(0)',\n 'let { bit-not } = import(\"bitwise\");\\nbit-not(255)',\n ],\n },\n },\n 'bit-and-not': {\n evaluate: ([first, ...rest], sourceCodeInfo): number => {\n assertNumber(first, sourceCodeInfo, { integer: true })\n\n return rest.reduce((result: number, value) => {\n assertNumber(value, sourceCodeInfo, { integer: true })\n return result & ~value\n }, first)\n },\n arity: { min: 2 },\n docs: {\n category: 'bitwise',\n returns: { type: 'integer' },\n args: {\n ...getOperatorArgs('integer', 'integer'),\n c: { type: 'integer', rest: true },\n },\n variants: [\n { argumentNames: ['a', 'b'] },\n { argumentNames: ['a', 'b', 'c'] },\n ],\n description: 'Returns bitwise `and` with complement.',\n seeAlso: ['&', '|', 'xor', 'bitwise.bit-not'],\n examples: [\n 'let { bit-and-not } = import(\"bitwise\");\\n0b0011 bit-and-not 0b0110',\n 'let { bit-and-not } = import(\"bitwise\");\\nbit-and-not(0b0011, 0b0110)',\n 'let { bit-and-not } = import(\"bitwise\");\\nbit-and-not(0b0011, 0b0110, 0b1001)',\n ],\n },\n },\n 'bit-flip': {\n evaluate: ([num, index], sourceCodeInfo): number => {\n assertNumber(num, sourceCodeInfo, { integer: true })\n assertNumber(index, sourceCodeInfo, { integer: true, nonNegative: true })\n\n const mask = 1 << index\n return (num ^= mask)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'bitwise',\n returns: { type: 'integer' },\n args: { ...getOperatorArgs('integer', 'integer') },\n variants: [{ argumentNames: ['a', 'b'] }],\n description: 'Flips bit number $b.',\n seeAlso: ['bitwise.bit-set', 'bitwise.bit-clear', 'bitwise.bit-test'],\n examples: [\n 'let { bit-flip } = import(\"bitwise\");\\n0b0011 bit-flip 1',\n 'let { bit-flip } = import(\"bitwise\");\\nbit-flip(0b0011, 1)',\n 'let { bit-flip } = import(\"bitwise\");\\nbit-flip(0b1100, 1)',\n ],\n },\n },\n 'bit-set': {\n evaluate: ([num, index], sourceCodeInfo): number => {\n assertNumber(num, sourceCodeInfo, { integer: true })\n assertNumber(index, sourceCodeInfo, { integer: true, nonNegative: true })\n\n const mask = 1 << index\n return (num |= mask)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'bitwise',\n returns: { type: 'integer' },\n args: { ...getOperatorArgs('integer', 'integer') },\n variants: [{ argumentNames: ['a', 'b'] }],\n description: 'Sets bit number $b.',\n seeAlso: ['bitwise.bit-flip', 'bitwise.bit-clear', 'bitwise.bit-test'],\n examples: [\n 'let { bit-set } = import(\"bitwise\");\\n0b0010 bit-set 1',\n 'let { bit-set } = import(\"bitwise\");\\nbit-set(0b0011, 1)',\n 'let { bit-set } = import(\"bitwise\");\\nbit-set(0b1100, 1)',\n ],\n },\n },\n 'bit-clear': {\n evaluate: ([num, index], sourceCodeInfo): number => {\n assertNumber(num, sourceCodeInfo, { integer: true })\n assertNumber(index, sourceCodeInfo, { integer: true, nonNegative: true })\n\n const mask = 1 << index\n return (num &= ~mask)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'bitwise',\n returns: { type: 'integer' },\n args: { ...getOperatorArgs('integer', 'integer') },\n variants: [{ argumentNames: ['a', 'b'] }],\n description: 'Clears bit number $b.',\n seeAlso: ['bitwise.bit-flip', 'bitwise.bit-set', 'bitwise.bit-test'],\n examples: [\n 'let { bit-clear } = import(\"bitwise\");\\n0b0011 bit-clear 1',\n 'let { bit-clear } = import(\"bitwise\");\\nbit-clear(0b0011, 1)',\n 'let { bit-clear } = import(\"bitwise\");\\nbit-clear(0b1100, 1)',\n ],\n },\n },\n 'bit-test': {\n evaluate: ([num, index], sourceCodeInfo): boolean => {\n assertNumber(num, sourceCodeInfo, { integer: true })\n assertNumber(index, sourceCodeInfo, { integer: true, nonNegative: true })\n\n const mask = 1 << index\n return !!(num & mask)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'bitwise',\n returns: { type: 'boolean' },\n args: { ...getOperatorArgs('integer', 'integer') },\n variants: [{ argumentNames: ['a', 'b'] }],\n description: 'Checks if bit number $b is set.',\n seeAlso: ['bitwise.bit-flip', 'bitwise.bit-set', 'bitwise.bit-clear'],\n examples: [\n 'let { bit-test } = import(\"bitwise\");\\n0b0011 bit-test 1',\n 'let { bit-test } = import(\"bitwise\");\\nbit-test(0b0011, 1)',\n 'let { bit-test } = import(\"bitwise\");\\nbit-test(0b1100, 1)',\n ],\n },\n },\n}\n\nexport const bitwiseUtilsModule: LitsModule = {\n name: 'bitwise',\n functions: bitwiseUtilsNormalExpression,\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","getOperatorArgs","a","b","bitwiseUtilsModule","functions","evaluate","num","docs","category","returns","args","variants","argumentNames","description","seeAlso","examples","first","rest","reduce","result","c","index"],"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,GAAGjB,EAAeC,SAASiB,QAAQlB,EAAeC,SAASG,SAM5E,MAAO,GAAGW,IALWf,EAAemB,SAChC,KAAKnB,EAAemB,YAAYF,IAChC,cAAcA,QACIjB,EAAeE,SACbH,EAAcC,IAExC,CAoBUoB,CAAoBL,EAASf,IACnCqB,KAAKT,aAAeG,EACpBM,KAAKrB,eAAiBA,EACtBsB,OAAOC,eAAeF,KAAMX,EAAUc,WACtCH,KAAKI,KAAO,WACb,CAEM,aAAA1B,GACL,OAAOsB,KAAKrB,gBAAkBD,EAAcsB,KAAKrB,eA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EAIN,WAAY,CACVV,SAAU,EAAEC,EAAKe,GAAQ/G,KACvB0D,EAAasC,EAAKhG,EAAgB,CAAE6D,SAAS,IAC7CH,EAAaqD,EAAO/G,EAAgB,CAAE6D,SAAS,EAAMS,aAAa,IAGlE,SAAU0B,EADG,GAAKe,IAGpBvB,MAAOD,EAAa,GACpBU,KAAM,CACJC,SAAU,UACVC,QAAS,CAAExD,KAAM,WACjByD,KAAM,IAAKV,EAAgB,UAAW,YACtCW,SAAU,CAAC,CAAEC,cAAe,CAAC,IAAK,OAClCC,YAAa,kCACbC,QAAS,CAAC,mBAAoB,kBAAmB,qBACjDC,SAAU,CACR,2DACA,6DACA"}
|
|
1
|
+
{"version":3,"file":"bitwise.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/bitwise/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 { Argument, BuiltinNormalExpressions } from '../../interface'\nimport type { LitsModule } from '../interface'\n\nfunction getOperatorArgs(a: 'integer', b: 'integer'): Record<string, Argument> {\n return { a: { type: a }, b: { type: b } }\n}\n\nconst bitwiseUtilsNormalExpression: BuiltinNormalExpressions = {\n 'bit-not': {\n evaluate: ([num], sourceCodeInfo): number => {\n assertNumber(num, sourceCodeInfo, { integer: true })\n return ~num\n },\n arity: toFixedArity(1),\n docs: {\n category: 'bitwise',\n returns: { type: 'integer' },\n args: { a: { type: 'integer' } },\n variants: [{ argumentNames: ['a'] }],\n description: 'Returns bitwise `not` of $a.',\n seeAlso: ['&', '|', 'xor', 'bitwise.bit-and-not'],\n examples: [\n 'let { bit-not } = import(bitwise);\\nbit-not(0)',\n 'let { bit-not } = import(bitwise);\\nbit-not(255)',\n ],\n },\n },\n 'bit-and-not': {\n evaluate: ([first, ...rest], sourceCodeInfo): number => {\n assertNumber(first, sourceCodeInfo, { integer: true })\n\n return rest.reduce((result: number, value) => {\n assertNumber(value, sourceCodeInfo, { integer: true })\n return result & ~value\n }, first)\n },\n arity: { min: 2 },\n docs: {\n category: 'bitwise',\n returns: { type: 'integer' },\n args: {\n ...getOperatorArgs('integer', 'integer'),\n c: { type: 'integer', rest: true },\n },\n variants: [\n { argumentNames: ['a', 'b'] },\n { argumentNames: ['a', 'b', 'c'] },\n ],\n description: 'Returns bitwise `and` with complement.',\n seeAlso: ['&', '|', 'xor', 'bitwise.bit-not'],\n examples: [\n 'let { bit-and-not } = import(bitwise);\\n0b0011 bit-and-not 0b0110',\n 'let { bit-and-not } = import(bitwise);\\nbit-and-not(0b0011, 0b0110)',\n 'let { bit-and-not } = import(bitwise);\\nbit-and-not(0b0011, 0b0110, 0b1001)',\n ],\n },\n },\n 'bit-flip': {\n evaluate: ([num, index], sourceCodeInfo): number => {\n assertNumber(num, sourceCodeInfo, { integer: true })\n assertNumber(index, sourceCodeInfo, { integer: true, nonNegative: true })\n\n const mask = 1 << index\n return (num ^= mask)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'bitwise',\n returns: { type: 'integer' },\n args: { ...getOperatorArgs('integer', 'integer') },\n variants: [{ argumentNames: ['a', 'b'] }],\n description: 'Flips bit number $b.',\n seeAlso: ['bitwise.bit-set', 'bitwise.bit-clear', 'bitwise.bit-test'],\n examples: [\n 'let { bit-flip } = import(bitwise);\\n0b0011 bit-flip 1',\n 'let { bit-flip } = import(bitwise);\\nbit-flip(0b0011, 1)',\n 'let { bit-flip } = import(bitwise);\\nbit-flip(0b1100, 1)',\n ],\n },\n },\n 'bit-set': {\n evaluate: ([num, index], sourceCodeInfo): number => {\n assertNumber(num, sourceCodeInfo, { integer: true })\n assertNumber(index, sourceCodeInfo, { integer: true, nonNegative: true })\n\n const mask = 1 << index\n return (num |= mask)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'bitwise',\n returns: { type: 'integer' },\n args: { ...getOperatorArgs('integer', 'integer') },\n variants: [{ argumentNames: ['a', 'b'] }],\n description: 'Sets bit number $b.',\n seeAlso: ['bitwise.bit-flip', 'bitwise.bit-clear', 'bitwise.bit-test'],\n examples: [\n 'let { bit-set } = import(bitwise);\\n0b0010 bit-set 1',\n 'let { bit-set } = import(bitwise);\\nbit-set(0b0011, 1)',\n 'let { bit-set } = import(bitwise);\\nbit-set(0b1100, 1)',\n ],\n },\n },\n 'bit-clear': {\n evaluate: ([num, index], sourceCodeInfo): number => {\n assertNumber(num, sourceCodeInfo, { integer: true })\n assertNumber(index, sourceCodeInfo, { integer: true, nonNegative: true })\n\n const mask = 1 << index\n return (num &= ~mask)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'bitwise',\n returns: { type: 'integer' },\n args: { ...getOperatorArgs('integer', 'integer') },\n variants: [{ argumentNames: ['a', 'b'] }],\n description: 'Clears bit number $b.',\n seeAlso: ['bitwise.bit-flip', 'bitwise.bit-set', 'bitwise.bit-test'],\n examples: [\n 'let { bit-clear } = import(bitwise);\\n0b0011 bit-clear 1',\n 'let { bit-clear } = import(bitwise);\\nbit-clear(0b0011, 1)',\n 'let { bit-clear } = import(bitwise);\\nbit-clear(0b1100, 1)',\n ],\n },\n },\n 'bit-test': {\n evaluate: ([num, index], sourceCodeInfo): boolean => {\n assertNumber(num, sourceCodeInfo, { integer: true })\n assertNumber(index, sourceCodeInfo, { integer: true, nonNegative: true })\n\n const mask = 1 << index\n return !!(num & mask)\n },\n arity: toFixedArity(2),\n docs: {\n category: 'bitwise',\n returns: { type: 'boolean' },\n args: { ...getOperatorArgs('integer', 'integer') },\n variants: [{ argumentNames: ['a', 'b'] }],\n description: 'Checks if bit number $b is set.',\n seeAlso: ['bitwise.bit-flip', 'bitwise.bit-set', 'bitwise.bit-clear'],\n examples: [\n 'let { bit-test } = import(bitwise);\\n0b0011 bit-test 1',\n 'let { bit-test } = import(bitwise);\\nbit-test(0b0011, 1)',\n 'let { bit-test } = import(bitwise);\\nbit-test(0b1100, 1)',\n ],\n },\n },\n}\n\nexport const bitwiseUtilsModule: LitsModule = {\n name: 'bitwise',\n functions: bitwiseUtilsNormalExpression,\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","getOperatorArgs","a","b","bitwiseUtilsModule","functions","evaluate","num","docs","category","returns","args","variants","argumentNames","description","seeAlso","examples","first","rest","reduce","result","c","index"],"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,GAAGjB,EAAeC,SAASiB,QAAQlB,EAAeC,SAASG,SAM5E,MAAO,GAAGW,IALWf,EAAemB,SAChC,KAAKnB,EAAemB,YAAYF,IAChC,cAAcA,QACIjB,EAAeE,SACbH,EAAcC,IAExC,CAoBUoB,CAAoBL,EAASf,IACnCqB,KAAKT,aAAeG,EACpBM,KAAKrB,eAAiBA,EACtBsB,OAAOC,eAAeF,KAAMX,EAAUc,WACtCH,KAAKI,KAAO,WACb,CAEM,aAAA1B,GACL,OAAOsB,KAAKrB,gBAAkBD,EAAcsB,KAAKrB,eAClD,EC5CI,MAAM0B,EAAY,CACvBC,OAAQ,EACRC,OAAQ,EACRC,iBAAkB,EAClBC,kBAAmB,EACnBC,kBAAmB,EACnBC,oBAAqB,EACrBC,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AgB,CAAE6D,SAAS,EAAMS,aAAa,IAGlE,SAAU0B,EADG,GAAKe,IAGpBvB,MAAOD,EAAa,GACpBU,KAAM,CACJC,SAAU,UACVC,QAAS,CAAExD,KAAM,WACjByD,KAAM,IAAKV,EAAgB,UAAW,YACtCW,SAAU,CAAC,CAAEC,cAAe,CAAC,IAAK,OAClCC,YAAa,kCACbC,QAAS,CAAC,mBAAoB,kBAAmB,qBACjDC,SAAU,CACR,yDACA,2DACA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare
|
|
1
|
+
import type { LitsModule } from '../../../../../src/builtin/modules/interface';
|
|
2
|
+
export declare function getFsModule(): LitsModule;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LitsModule } from '../../../../../src/builtin/modules/interface';
|
|
2
2
|
export declare function sys_cwd(): string;
|
|
3
|
-
export declare
|
|
3
|
+
export declare function getProcModule(): LitsModule;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
};
|
|
1
|
+
import type { LitsModule } from '../../../../src/builtin/modules/interface';
|
|
2
|
+
export declare function getCliModules(): LitsModule[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
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,o){const r=n instanceof Error?n.message:`${n}`;super(function(t,n){if(!n)return t;const o=`${n.position.line}:${n.position.column}`;return`${t}${n.filePath?`\n${n.filePath}:${o}`:`\nLocation ${o}`}\n${n.code}\n${e(n)}`}(r,o)),this.shortMessage=r,this.sourceCodeInfo=o,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},o=new Set(Object.values(n));const r=new Set(["UserDefined","Partial","Comp","Constantly","Juxt","Complement","EveryPred","SomePred","Fnull","Builtin","SpecialBuiltin","NativeJsFunction","Module"]);const i="^^fn^^",c="^^re^^";function l(e){return null!==e&&"object"==typeof e&&(i in e&&"functionType"in e&&("string"==typeof(t=e.functionType)&&r.has(t)));var t}function a(e){return!(!Array.isArray(e)||e.length<2)&&("number"==typeof(t=e[0])&&o.has(t));var t}function u(e){return l(e)?`<function ${e.name||"λ"}>`:a(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 s(e,t){return e?.sourceCodeInfo??t}function p(e,n,o){return new t(`Expected ${e}, got ${u(n)}.`,s(n,o))}function y(e){return null!==e&&"object"==typeof e&&!!e[i]}function m(e,t){if(!function(e){return void 0!==e}(e))throw p("not undefined",e,t)}function f(e){return!(null===e||"object"!=typeof e||Array.isArray(e)||e instanceof RegExp||y(e)||(t=e,null!==t&&"object"==typeof t&&t[c]));var t}function h(e){return function(e){return Array.isArray(e)||"string"==typeof e}(e)||f(e)}function g(e,t){return d(e,t),e}function d(e,t){if(!h(e))throw p("string, array or object",e,t)}function b(e,t){if(!function(e){return"number"==typeof e||!!h(e)||!!y(e)}(e))throw p("FunctionLike",e,t)}function v(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 x(e,n,o={}){if(!v(e,o))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",o=e.finite?"finite":"",r=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,o,n,r].filter(e=>!!e).join(" ")}(o)}, got ${u(e)}.`,s(e,n))}function $(e,t,n={}){if(!function(e,t={}){return!("string"!=typeof e||t.nonEmpty&&0===e.length||t.char&&1!==e.length)}(e,n))throw p(""+(n.nonEmpty?"non empty string":n.char?"character":"string"),e,t)}function A(e,t){return w(e,t),e}function w(e,t){if(!function(e){return"string"==typeof e||"number"==typeof e}(e))throw p("string or number",e,t)}function j(e,t){return!!h(e)&&("string"==typeof e||Array.isArray(e)?!!v(t,{integer:!0})&&(t>=0&&t<e.length):!!Object.getOwnPropertyDescriptor(e,t))}function k(e){return e??null}function N(e){return f(e)?Object.entries(e).reduce((e,t)=>{const[n,o]=t;return e[n]=N(o),e},{}):Array.isArray(e)?e.map(e=>N(e)):e}function O(e){return N(e)}function T(e,t){if(!Array.isArray(e))throw p("array",e,t)}function F(e){return{min:e,max:e}}function C(e,t){return e instanceof Promise?e.then(t):t(e)}function M(e,t){const n=[];for(let o=0;o<e.length;o++){const r=t(e[o],o);if(r instanceof Promise)return P(r,n,e,t,o);n.push(r)}return n}async function P(e,t,n,o,r){t.push(await e);for(let e=r+1;e<n.length;e++)t.push(await o(n[e],e));return t}function R(e,t,n){let o=n;for(let n=0;n<e.length;n++){const r=t(o,e[n],n);if(r instanceof Promise)return S(r,e,t,n);o=r}return o}async function S(e,t,n,o){let r=await e;for(let e=o+1;e<t.length;e++)r=await n(r,t[e],e);return r}function E(e,t){for(let n=0;n<e.length;n++){const o=t(e[n],n);if(o instanceof Promise)return I(o,e,t,n);if(o)return!0}return!1}async function I(e,t,n,o){if(await e)return!0;for(let e=o+1;e<t.length;e++)if(await n(t[e],e))return!0;return!1}function B(e,t){for(let n=0;n<e.length;n++){const o=t(e[n],n);if(o instanceof Promise)return z(o,e,t,n);if(!o)return!1}return!0}async function z(e,t,n,o){if(!await e)return!1;for(let e=o+1;e<t.length;e++)if(!await n(t[e],e))return!1;return!0}function L(e,t){const n=[];for(let o=0;o<e.length;o++){const r=t(e[o],o);if(r instanceof Promise)return U(r,n,e,t,o);r&&n.push(e[o])}return n}async function U(e,t,n,o,r){await e&&t.push(n[r]);for(let e=r+1;e<n.length;e++)await o(n[e],e)&&t.push(n[e]);return t}function D(e,t){if(f(e)){if("string"==typeof t&&j(e,t))return k(e[t])}else if(v(t,{nonNegative:!0,integer:!0})&&t>=0&&t<e.length)return k(e[t])}function J(e,t,n,o){if(d(e,o),Array.isArray(e)||"string"==typeof e){if(x(t,o,{integer:!0}),x(t,o,{gte:0}),x(t,o,{lte:e.length}),"string"==typeof e)return $(n,o,{char:!0}),`${e.slice(0,t)}${n}${e.slice(t+1)}`;const r=[...e];return r[t]=n,r}$(t,o);const r={...e};return r[t]=n,r}function K(e,t,n,o,r,i,c){if(f(e)){$(t,c);const l={...e};return C(i(n,[l[t],...o],r,c),e=>(l[t]=e,l))}{x(t,c);const a=(l=t,Math.max(0,Math.ceil(l)));if(x(a,c,{lte:e.length}),Array.isArray(e))return C(M(Array.from({length:e.length+(a===e.length?1:0)}),(t,l)=>a===l?i(n,[e[l],...o],r,c):e[l]),e=>e);{const t=e.split("");return C(M(Array.from({length:t.length+(a===t.length?1:0)}),(e,l)=>a===l?C(i(n,[t[l],...o],r,c),e=>function(e,t,n={}){return $(e,t,n),e}(e,c,{char:!0})):t[l]),e=>e.join(""))}}var l}function Z(e,t,n){const o=O(e);return{coll:o,innerCollMeta:t.slice(0,t.length-1).reduce((e,t)=>{const o=e.coll;let r;return Array.isArray(o)?(x(t,n),r=g(o[t],n)):(!function(e,t){if(!f(e))throw p("object",e,t)}(o,n),$(t,n),j(e.coll,t)||(o[t]={}),r=g(o[t],n)),{coll:r,parent:o}},{coll:o,parent:{}})}}const q={name:"collection",functions:{"get-in":{evaluate:(e,t)=>{let n=k(e[0]);const o=e[1]??[],r=k(e[2]);T(o,t);for(const e of o){if(w(e,t),!h(n))return r;{const t=D(n,e);if(void 0===t)return r;n=t}}return n},arity:{min:2,max:3},docs:{category:"collection",returns:{type:"any"},args:{a:{type:"collection"},b:{type:"array"},"not-found":{type:"any"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","not-found"]}],description:"Returns the value in a nested collection, where $b is an array of keys. Returns $not-found if the key is not present. If $not-found is not set, `null` is returned.",seeAlso:["get","collection.assoc-in","collection.update-in"],examples:['\nlet cu = import("collection");\ncu.get-in(\n [[1, 2, 3], [4, { a: "Kalle" }, 6]],\n [1, 1, "a", 0]\n)','\nlet cu = import("collection");\ncu.get-in(\n [[1, 2, 3], [4, { a: "Kalle" }, 6]],\n [1, 1, "b", 0]\n)','\nlet cu = import("collection");\ncu.get-in(\n [[1, 2, 3], [4, { a: "Kalle" }, 6]],\n [1, 1, "b", 0],\n "Lisa"\n)']}},"assoc-in":{evaluate:([e,t,n],o)=>{if(d(e,o),T(t,o),m(n,o),1===t.length)return w(t[0],o),J(e,t[0],n,o);const{coll:r,innerCollMeta:i}=Z(e,t,o),c=A(t[t.length-1],o),l=A(t[t.length-2],o);return Array.isArray(i.parent)?(x(l,o),i.parent[l]=J(i.coll,c,n,o)):($(l,o),i.parent[l]=J(i.coll,c,n,o)),r},arity:F(3),docs:{category:"collection",returns:{type:"collection"},args:{coll:{type:"collection"},ks:{type:["number","string"],array:!0},value:{type:"any"}},variants:[{argumentNames:["coll","ks","value"]}],description:"\nAssociates a value in the nested collection $coll, where $ks is an array of keys and $value is the new value.\n\nIf any levels do not exist, objects will be created - and the corresponding keys must be of type string.",seeAlso:["assoc","collection.get-in","collection.update-in"],examples:['\nlet cu = import("collection");\ncu.assoc-in(\n {},\n ["a", "b", "c"],\n "Albert"\n)','\nlet cu = import("collection");\ncu.assoc-in(\n [1, 2, [1, 2, 3]],\n [2, 1],\n "Albert"\n)','\nlet cu = import("collection");\ncu.assoc-in(\n [1, 2, { name: "albert" }],\n [2, "name", 0],\n "A"\n)']}},update:{evaluate:([e,t,n,...o],r,i,{executeFunction:c})=>(d(e,r),w(t,r),b(n,r),K(e,t,n,o,i,c,r)),arity:{min:3},docs:{category:"collection",returns:{type:"collection"},args:{coll:{type:"collection"},key:{type:["string","number"]},fun:{type:"function"},"fun-args":{type:"any",rest:!0}},variants:[{argumentNames:["coll","value","fun"]},{argumentNames:["coll","value","fun","fun-args"]}],description:"\nUpdates a value in the $coll collection, where $key is a key. $fun is a function\nthat will take the old value and any supplied $fun-args and\nreturn the new value.\nIf the key does not exist, `null` is passed as the old value.",seeAlso:["collection.update-in","assoc"],examples:['\nlet cu = import("collection");\nlet x = { a: 1, b: 2 };\ncu.update(x, "a", inc)','\nlet cu = import("collection");\nlet x = { a: 1, b: 2 };\ncu.update(\n x,\n "c",\n val -> null?(val) ? 0 : inc(val)\n)']}},"update-in":{evaluate:([e,t,n,...o],r,i,{executeFunction:c})=>{if(d(e,r),T(t,r),b(n,r),1===t.length)return w(t[0],r),K(e,t[0],n,o,i,c,r);const{coll:l,innerCollMeta:a}=Z(e,t,r),u=A(t[t.length-1],r),s=A(t[t.length-2],r);return Array.isArray(a.parent)?(x(s,r),C(K(a.coll,u,n,o,i,c,r),e=>(a.parent[s]=e,l))):($(s,r),C(K(a.coll,u,n,o,i,c,r),e=>(a.parent[s]=e,l)))},arity:{min:3},docs:{category:"collection",returns:{type:"collection"},args:{coll:{type:"collection"},ks:{type:"array"},fun:{type:"function"},"fun-args":{type:"any",rest:!0}},variants:[{argumentNames:["coll","ks","fun"]},{argumentNames:["coll","ks","fun","fun-args"]}],description:"Updates a value in the $coll collection, where $ks is an array of\nkeys and $fun is a function that will take the old value and\nany supplied $fun-args and return the new value. If any levels do not exist,\nobjects will be created - and the corresponding keys must be of type string.",seeAlso:["collection.update","collection.assoc-in","collection.get-in"],examples:['\nlet cu = import("collection");\ncu.update-in(\n { a: [1, 2, 3] },\n ["a", 1],\n -> null?($) ? 0 : inc($)\n)','\nlet cu = import("collection");\ncu.update-in(\n { a: { foo: "bar"} },\n ["a", "foo"],\n -> null?($) ? "?" : "!"\n)','\nlet cu = import("collection");\ncu.update-in(\n { a: { foo: "bar"} },\n ["a", "baz"],\n -> null?($) ? "?" : "!"\n)','\nlet cu = import("collection");\ncu.update-in(\n { a: [1, 2, 3] },\n ["a", 1],\n *,\n 10,\n 10,\n 10,\n)']}},filteri:{evaluate:([e,t],n,o,{executeFunction:r})=>(d(e,n),b(t,n),Array.isArray(e)?L(e,(e,i)=>r(t,[e,i],o,n)):"string"==typeof e?C(L(e.split(""),(e,i)=>r(t,[e,i],o,n)),e=>e.join("")):C(L(Object.entries(e),([e,i])=>r(t,[i,e],o,n)),e=>e.reduce((e,[t,n])=>(e[t]=n,e),{}))),arity:F(2),docs:{category:"collection",returns:{type:"collection"},args:{a:{type:"collection"},b:{type:"function",description:"The function to call for each element in the collection. The function should take two arguments: the element itself and the index."}},variants:[{argumentNames:["a","b"]}],description:"Creates a new collection with all elements that pass the test implemented by $b. The function is called for each element in the collection, and it should take two arguments: the element itself and the index.",seeAlso:["filter","collection.mapi"],examples:['let cu = import("collection"); cu.filteri([1, 2, 3], (x, i) -> i % 2 == 0)','let cu = import("collection"); cu.filteri([1, 2, 3], (x, i) -> x % 2 == 0)','let cu = import("collection"); cu.filteri([1, 2, 3], (x, i) -> x + i > 3)']}},mapi:{evaluate:([e,t],n,o,{executeFunction:r})=>{if(d(e,n),b(t,n),Array.isArray(e))return M(e,(e,i)=>r(t,[e,i],o,n));if("string"==typeof e)return C(M(e.split(""),(e,i)=>r(t,[e,i],o,n)),e=>e.join(""));return R(Object.entries(e),(e,[i,c])=>C(r(t,[c,i],o,n),t=>(e[i]=t,e)),{})},arity:F(2),docs:{category:"collection",returns:{type:"collection"},args:{a:{type:"collection"},b:{type:"function",description:"The function to call for each element in the collection. The function should take two arguments: the element itself and the index."}},variants:[{argumentNames:["a","b"]}],description:"Creates a new collection populated with the results of calling $b on every element in $a. The function is called for each element in the collection, and it should take two arguments: the element itself and the index.",seeAlso:["map","collection.filteri"],examples:['let cu = import("collection"); cu.mapi([1, 2, 3], (x, i) -> x + i)','let cu = import("collection"); cu.mapi([1, 2, 3], (x, i) -> x * i)','let cu = import("collection"); cu.mapi([1, 2, 3], (x, i) -> x - i)','let cu = import("collection"); cu.mapi([1, 2, 3], (x, i) -> x / i)','let cu = import("collection"); cu.mapi([1, 2, 3], (x, i) -> x % inc(i))']}},reducei:{evaluate:([e,t,n],o,r,{executeFunction:i})=>(d(e,o),b(t,o),m(n,o),"string"==typeof e?($(n,o),0===e.length?n:R(e.split("").map((e,t)=>({elem:e,index:t})),(e,{elem:n,index:c})=>i(t,[e,n,c],r,o),n)):Array.isArray(e)?0===e.length?n:R(e.map((e,t)=>({elem:e,index:t})),(e,{elem:n,index:c})=>i(t,[e,n,c],r,o),n):0===Object.keys(e).length?n:R(Object.entries(e),(e,[n,c])=>i(t,[e,c,n],r,o),n)),arity:F(3),docs:{category:"collection",returns:{type:"any"},args:{coll:{type:"collection"},fun:{type:"function",description:"The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index."},initial:{type:"any",description:"The initial value to use as the accumulator."}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Runs $fun function on each element of the $coll, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.",seeAlso:["reduce","collection.reducei-right","collection.reductionsi"],examples:['let cu = import("collection"); cu.reducei([1, 2, 3], (acc, x, i) -> acc + x + i, 0)','let cu = import("collection"); cu.reducei("Albert", (acc, x, i) -> acc ++ x ++ i, "")','let cu = import("collection"); cu.reducei({ a: 1, b: 2 }, -> $1 ++ $3, "")']}},"reduce-right":{evaluate:([e,t,n],o,r,{executeFunction:i})=>(d(e,o),b(t,o),m(n,o),"string"==typeof e?0===e.length?n:R(Array.from(e.split("")).reverse(),(e,n)=>i(t,[e,n],r,o),n):Array.isArray(e)?0===e.length?n:R(Array.from(e).reverse(),(e,n)=>i(t,[e,n],r,o),n):0===Object.keys(e).length?n:R(Object.entries(e).reverse(),(e,[,n])=>i(t,[e,n],r,o),n)),arity:F(3),docs:{category:"collection",returns:{type:"any"},args:{fun:{type:"function"},coll:{type:"collection"},initial:{type:"any"}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Runs $fun function on each element of the $coll (starting from the last item), passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value.",seeAlso:["reduce","collection.reducei-right"],examples:['let cu = import("collection"); cu.reduce-right(["A", "B", "C"], str, "")','let cu = import("collection"); cu.reduce-right({ a: 1, b: 2 }, +, 0)']}},"reducei-right":{evaluate:([e,t,n],o,r,{executeFunction:i})=>(d(e,o),b(t,o),m(n,o),"string"==typeof e?0===e.length?n:R(Array.from(e.split("")).reverse().map((e,t,n)=>({elem:e,index:n.length-1-t})),(e,{elem:n,index:c})=>i(t,[e,n,c],r,o),n):Array.isArray(e)?0===e.length?n:R(Array.from(e).reverse().map((e,t,n)=>({elem:e,index:n.length-1-t})),(e,{elem:n,index:c})=>i(t,[e,n,c],r,o),n):0===Object.keys(e).length?n:R(Object.entries(e).reverse(),(e,[n,c])=>i(t,[e,c,n],r,o),n)),arity:F(3),docs:{category:"collection",returns:{type:"any"},args:{coll:{type:"collection"},fun:{type:"function",description:"The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index."},initial:{type:"any",description:"The initial value to use as the accumulator."}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Runs $fun function on each element of the $coll (starting from the last item), passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.",seeAlso:["collection.reducei","collection.reduce-right"],examples:['let cu = import("collection"); cu.reducei-right([1, 2, 3], (acc, x, i) -> acc + x + i, 0)','let cu = import("collection"); cu.reducei-right("Albert", (acc, x, i) -> acc ++ x ++ i, "")','let cu = import("collection"); cu.reducei-right({ a: 1, b: 2 }, -> $1 ++ $3, "")']}},reductions:{evaluate:([e,t,n],o,r,{executeFunction:i})=>{d(e,o),b(t,o),m(n,o),m(n,o);const c="string"==typeof e?($(n,o),0===e.length?[]:e.split("")):Array.isArray(e)?0===e.length?[]:Array.from(e):0===Object.keys(e).length?[]:Object.entries(e).map(([,e])=>e);if(0===c.length)return[n];const l=[n];return C(R(c,(e,n)=>C(i(t,[e,n],r,o),e=>(l.push(e),e)),n),()=>l)},arity:F(3),docs:{category:"collection",returns:{type:"any",array:!0},args:{fun:{type:"function"},coll:{type:"collection"},initial:{type:"any"}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Returns an array of the intermediate values of the reduction (see `reduce`) of $coll by $fun.",seeAlso:["reduce","collection.reductionsi"],examples:['let cu = import("collection"); cu.reductions([1, 2, 3], +, 0)','let cu = import("collection"); cu.reductions([1, 2, 3], +, 10)','let cu = import("collection"); cu.reductions([], +, 0)','let cu = import("collection"); cu.reductions({ a: 1, b: 2 }, +, 0)','\nlet cu = import("collection");\ncu.reductions(\n [1, 2, 3, 4, 5, 6, 7, 8, 9],\n (result, value) -> result + (even?(value) ? value : 0),\n 0\n)']}},reductionsi:{evaluate:([e,t,n],o,r,{executeFunction:i})=>{d(e,o),b(t,o),m(n,o),m(n,o);const c=(e,t)=>({elem:e,key:t}),l="string"==typeof e?($(n,o),0===e.length?[]:e.split("").map((e,t)=>c(e,t))):Array.isArray(e)?0===e.length?[]:e.map((e,t)=>c(e,t)):0===Object.keys(e).length?[]:Object.entries(e).map(([e,t])=>c(t,e));if(0===l.length)return[n];const a=[n];return C(R(l,(e,{elem:n,key:c})=>C(i(t,[e,n,c],r,o),e=>(a.push(e),e)),n),()=>a)},arity:F(3),docs:{category:"collection",returns:{type:"any",array:!0},args:{coll:{type:"collection"},fun:{type:"function",description:"The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index."},initial:{type:"any",description:"The initial value to use as the accumulator."}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Returns an array of the intermediate values of the reduction (see `reduce`) of $coll by $fun. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.",seeAlso:["collection.reductions","collection.reducei"],examples:['let cu = import("collection"); cu.reductionsi([1, 2, 3], (acc, x, i) -> acc + x + i, 0)','let cu = import("collection"); cu.reductionsi("Albert", (acc, x, i) -> acc ++ x ++ i, "")','let cu = import("collection"); cu.reductionsi({ a: 1, b: 2 }, -> $1 ++ $3, "")']}},"not-empty":{evaluate:([e],t)=>null===e?null:(d(e,t),"string"==typeof e||Array.isArray(e)?e.length>0?e:null:Object.keys(e).length>0?e:null),arity:F(1),docs:{category:"collection",returns:{type:"boolean"},args:{coll:{type:["collection","null"]}},variants:[{argumentNames:["coll"]}],description:"Returns `null` if $coll is empty or `null`, otherwise $coll.",seeAlso:["empty?","not-empty?"],examples:['let cu = import("collection"); cu.not-empty([])','let cu = import("collection"); cu.not-empty([1, 2, 3])','let cu = import("collection"); cu.not-empty({})','let cu = import("collection"); cu.not-empty({ a: 2 })','let cu = import("collection"); cu.not-empty("")','let cu = import("collection"); cu.not-empty("Albert")','let cu = import("collection"); cu.not-empty(null)']}},"every?":{evaluate:([e,t],n,o,{executeFunction:r})=>{d(e,n),b(t,n);return B(Array.isArray(e)?e:"string"==typeof e?e.split(""):Object.entries(e),e=>r(t,[e],o,n))},arity:F(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:"collection"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns `true` if all entries in $a pass the test implemented by $b, otherwise returns `false`.",seeAlso:["collection.any?","collection.not-every?","collection.not-any?","functional.every-pred","grid.every?"],examples:['let cu = import("collection"); cu.every?([1, 2, 3], number?)','let cu = import("collection"); cu.every?([1, 2, 3], even?)','\nlet cu = import("collection");\ncu.every?(\n ["Albert", "Mojir", 160, [1, 2]],\n string?,\n)','\nlet cu = import("collection");\ncu.every?(\n [50, 100, 150, 200],\n -> $ > 10,\n)','let cu = import("collection"); cu.every?([], number?)','let cu = import("collection"); cu.every?("", number?)','let cu = import("collection"); cu.every?({}, number?)','\nlet cu = import("collection");\ncu.every?(\n { a: 2, b: 4},\n -> even?(second($))\n)','\nlet cu = import("collection");\ncu.every?(\n { a: 2, b: 3 },\n -> even?(second($))\n)']}},"any?":{evaluate:([e,t],n,o,{executeFunction:r})=>{b(t,n),d(e,n);return E(Array.isArray(e)?e:"string"==typeof e?e.split(""):Object.entries(e),e=>r(t,[e],o,n))},arity:F(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:"collection"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns `true` if any element in $a pass the test implemented by $b, otherwise returns `false`.",seeAlso:["collection.every?","collection.not-any?","collection.not-every?","functional.some-pred","some","grid.some?"],examples:['\nlet cu = import("collection");\ncu.any?(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)','\nlet cu = import("collection");\ncu.any?(\n [50, 100, 150, 200],\n x -> x > 10\n)','let cu = import("collection"); cu.any?([], number?)','let cu = import("collection"); cu.any?("", number?)','let cu = import("collection"); cu.any?({}, number?)','\nlet cu = import("collection");\ncu.any?(\n { a: 2, b: 3 },\n -> even?(second($))\n)','\nlet cu = import("collection");\ncu.any?(\n { a: 1, b: 3 },\n -> even?(second($))\n)']}},"not-any?":{evaluate:([e,t],n,o,{executeFunction:r})=>{b(t,n),d(e,n);return C(E(Array.isArray(e)?e:"string"==typeof e?e.split(""):Object.entries(e),e=>r(t,[e],o,n)),e=>!e)},arity:F(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:"collection"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns `false` if any element in $a pass the test implemented by $b, otherwise returns `true`.",seeAlso:["collection.any?","collection.every?","collection.not-every?"],examples:['\nlet cu = import("collection");\ncu.not-any?(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)','\nlet cu = import("collection");\ncu.not-any?(\n [50, 100, 150, 200],\n x -> x > 10\n)','let cu = import("collection"); cu.not-any?([], number?)','let cu = import("collection"); cu.not-any?("", number?)','let cu = import("collection"); cu.not-any?({}, number?)','\nlet cu = import("collection");\ncu.not-any?(\n { a: 2, b: 3 },\n -> even?(second($))\n)','\nlet cu = import("collection");\ncu.not-any?(\n { a: 1, b: 3 },\n -> even?(second($))\n)']}},"not-every?":{evaluate:([e,t],n,o,{executeFunction:r})=>{b(t,n),d(e,n);return C(B(Array.isArray(e)?e:"string"==typeof e?e.split(""):Object.entries(e),e=>r(t,[e],o,n)),e=>!e)},arity:F(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:"collection"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns `true` if at least one element in $a does not pass the test implemented by $b, otherwise returns `false`.",seeAlso:["collection.every?","collection.any?","collection.not-any?"],examples:['\nlet cu = import("collection");\ncu.not-every?(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)','\nlet cu = import("collection");\ncu.not-every?(\n [50, 100, 150, 200],\n x -> x > 10\n)','let cu = import("collection"); cu.not-every?([], number?)','let cu = import("collection"); cu.not-every?("", number?)','let cu = import("collection"); cu.not-every?({}, number?)','\nlet cu = import("collection");\ncu.not-every?(\n { a: 2, b: 4 },\n -> even?(second($))\n)','\nlet cu = import("collection");\ncu.not-every?(\n { a: 2, b: 3 },\n -> even?(second($))\n)']}}}};export{q as collectionUtilsModule};
|
|
1
|
+
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,o){const r=n instanceof Error?n.message:`${n}`;super(function(t,n){if(!n)return t;const o=`${n.position.line}:${n.position.column}`;return`${t}${n.filePath?`\n${n.filePath}:${o}`:`\nLocation ${o}`}\n${n.code}\n${e(n)}`}(r,o)),this.shortMessage=r,this.sourceCodeInfo=o,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},o=new Set(Object.values(n));const r=new Set(["UserDefined","Partial","Comp","Constantly","Juxt","Complement","EveryPred","SomePred","Fnull","Builtin","SpecialBuiltin","NativeJsFunction","Module"]);const i="^^fn^^",c="^^re^^";function l(e){return null!==e&&"object"==typeof e&&(i in e&&"functionType"in e&&("string"==typeof(t=e.functionType)&&r.has(t)));var t}function a(e){return!(!Array.isArray(e)||e.length<2)&&("number"==typeof(t=e[0])&&o.has(t));var t}function u(e){return l(e)?`<function ${e.name||"λ"}>`:a(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 s(e,t){return e?.sourceCodeInfo??t}function p(e,n,o){return new t(`Expected ${e}, got ${u(n)}.`,s(n,o))}function y(e){return null!==e&&"object"==typeof e&&!!e[i]}function m(e,t){if(!function(e){return void 0!==e}(e))throw p("not undefined",e,t)}function f(e){return!(null===e||"object"!=typeof e||Array.isArray(e)||e instanceof RegExp||y(e)||(t=e,null!==t&&"object"==typeof t&&t[c]));var t}function h(e){return function(e){return Array.isArray(e)||"string"==typeof e}(e)||f(e)}function g(e,t){return d(e,t),e}function d(e,t){if(!h(e))throw p("string, array or object",e,t)}function b(e,t){if(!function(e){return"number"==typeof e||!!h(e)||!!y(e)}(e))throw p("FunctionLike",e,t)}function v(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 x(e,n,o={}){if(!v(e,o))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",o=e.finite?"finite":"",r=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,o,n,r].filter(e=>!!e).join(" ")}(o)}, got ${u(e)}.`,s(e,n))}function $(e,t,n={}){if(!function(e,t={}){return!("string"!=typeof e||t.nonEmpty&&0===e.length||t.char&&1!==e.length)}(e,n))throw p(""+(n.nonEmpty?"non empty string":n.char?"character":"string"),e,t)}function A(e,t){return w(e,t),e}function w(e,t){if(!function(e){return"string"==typeof e||"number"==typeof e}(e))throw p("string or number",e,t)}function j(e,t){return!!h(e)&&("string"==typeof e||Array.isArray(e)?!!v(t,{integer:!0})&&(t>=0&&t<e.length):!!Object.getOwnPropertyDescriptor(e,t))}function k(e){return e??null}function N(e){return f(e)?Object.entries(e).reduce((e,t)=>{const[n,o]=t;return e[n]=N(o),e},{}):Array.isArray(e)?e.map(e=>N(e)):e}function O(e){return N(e)}function T(e,t){if(!Array.isArray(e))throw p("array",e,t)}function F(e){return{min:e,max:e}}function C(e,t){return e instanceof Promise?e.then(t):t(e)}function M(e,t){const n=[];for(let o=0;o<e.length;o++){const r=t(e[o],o);if(r instanceof Promise)return P(r,n,e,t,o);n.push(r)}return n}async function P(e,t,n,o,r){t.push(await e);for(let e=r+1;e<n.length;e++)t.push(await o(n[e],e));return t}function R(e,t,n){let o=n;for(let n=0;n<e.length;n++){const r=t(o,e[n],n);if(r instanceof Promise)return S(r,e,t,n);o=r}return o}async function S(e,t,n,o){let r=await e;for(let e=o+1;e<t.length;e++)r=await n(r,t[e],e);return r}function E(e,t){for(let n=0;n<e.length;n++){const o=t(e[n],n);if(o instanceof Promise)return I(o,e,t,n);if(o)return!0}return!1}async function I(e,t,n,o){if(await e)return!0;for(let e=o+1;e<t.length;e++)if(await n(t[e],e))return!0;return!1}function B(e,t){for(let n=0;n<e.length;n++){const o=t(e[n],n);if(o instanceof Promise)return z(o,e,t,n);if(!o)return!1}return!0}async function z(e,t,n,o){if(!await e)return!1;for(let e=o+1;e<t.length;e++)if(!await n(t[e],e))return!1;return!0}function L(e,t){const n=[];for(let o=0;o<e.length;o++){const r=t(e[o],o);if(r instanceof Promise)return U(r,n,e,t,o);r&&n.push(e[o])}return n}async function U(e,t,n,o,r){await e&&t.push(n[r]);for(let e=r+1;e<n.length;e++)await o(n[e],e)&&t.push(n[e]);return t}function D(e,t){if(f(e)){if("string"==typeof t&&j(e,t))return k(e[t])}else if(v(t,{nonNegative:!0,integer:!0})&&t>=0&&t<e.length)return k(e[t])}function J(e,t,n,o){if(d(e,o),Array.isArray(e)||"string"==typeof e){if(x(t,o,{integer:!0}),x(t,o,{gte:0}),x(t,o,{lte:e.length}),"string"==typeof e)return $(n,o,{char:!0}),`${e.slice(0,t)}${n}${e.slice(t+1)}`;const r=[...e];return r[t]=n,r}$(t,o);const r={...e};return r[t]=n,r}function K(e,t,n,o,r,i,c){if(f(e)){$(t,c);const l={...e};return C(i(n,[l[t],...o],r,c),e=>(l[t]=e,l))}{x(t,c);const a=(l=t,Math.max(0,Math.ceil(l)));if(x(a,c,{lte:e.length}),Array.isArray(e))return C(M(Array.from({length:e.length+(a===e.length?1:0)}),(t,l)=>a===l?i(n,[e[l],...o],r,c):e[l]),e=>e);{const t=e.split("");return C(M(Array.from({length:t.length+(a===t.length?1:0)}),(e,l)=>a===l?C(i(n,[t[l],...o],r,c),e=>function(e,t,n={}){return $(e,t,n),e}(e,c,{char:!0})):t[l]),e=>e.join(""))}}var l}function Z(e,t,n){const o=O(e);return{coll:o,innerCollMeta:t.slice(0,t.length-1).reduce((e,t)=>{const o=e.coll;let r;return Array.isArray(o)?(x(t,n),r=g(o[t],n)):(!function(e,t){if(!f(e))throw p("object",e,t)}(o,n),$(t,n),j(e.coll,t)||(o[t]={}),r=g(o[t],n)),{coll:r,parent:o}},{coll:o,parent:{}})}}const q={name:"collection",functions:{"get-in":{evaluate:(e,t)=>{let n=k(e[0]);const o=e[1]??[],r=k(e[2]);T(o,t);for(const e of o){if(w(e,t),!h(n))return r;{const t=D(n,e);if(void 0===t)return r;n=t}}return n},arity:{min:2,max:3},docs:{category:"collection",returns:{type:"any"},args:{a:{type:"collection"},b:{type:"array"},"not-found":{type:"any"}},variants:[{argumentNames:["a","b"]},{argumentNames:["a","b","not-found"]}],description:"Returns the value in a nested collection, where $b is an array of keys. Returns $not-found if the key is not present. If $not-found is not set, `null` is returned.",seeAlso:["get","collection.assoc-in","collection.update-in"],examples:['\nlet cu = import(collection);\ncu.get-in(\n [[1, 2, 3], [4, { a: "Kalle" }, 6]],\n [1, 1, "a", 0]\n)','\nlet cu = import(collection);\ncu.get-in(\n [[1, 2, 3], [4, { a: "Kalle" }, 6]],\n [1, 1, "b", 0]\n)','\nlet cu = import(collection);\ncu.get-in(\n [[1, 2, 3], [4, { a: "Kalle" }, 6]],\n [1, 1, "b", 0],\n "Lisa"\n)']}},"assoc-in":{evaluate:([e,t,n],o)=>{if(d(e,o),T(t,o),m(n,o),1===t.length)return w(t[0],o),J(e,t[0],n,o);const{coll:r,innerCollMeta:i}=Z(e,t,o),c=A(t[t.length-1],o),l=A(t[t.length-2],o);return Array.isArray(i.parent)?(x(l,o),i.parent[l]=J(i.coll,c,n,o)):($(l,o),i.parent[l]=J(i.coll,c,n,o)),r},arity:F(3),docs:{category:"collection",returns:{type:"collection"},args:{coll:{type:"collection"},ks:{type:["number","string"],array:!0},value:{type:"any"}},variants:[{argumentNames:["coll","ks","value"]}],description:"\nAssociates a value in the nested collection $coll, where $ks is an array of keys and $value is the new value.\n\nIf any levels do not exist, objects will be created - and the corresponding keys must be of type string.",seeAlso:["assoc","collection.get-in","collection.update-in"],examples:['\nlet cu = import(collection);\ncu.assoc-in(\n {},\n ["a", "b", "c"],\n "Albert"\n)','\nlet cu = import(collection);\ncu.assoc-in(\n [1, 2, [1, 2, 3]],\n [2, 1],\n "Albert"\n)','\nlet cu = import(collection);\ncu.assoc-in(\n [1, 2, { name: "albert" }],\n [2, "name", 0],\n "A"\n)']}},update:{evaluate:([e,t,n,...o],r,i,{executeFunction:c})=>(d(e,r),w(t,r),b(n,r),K(e,t,n,o,i,c,r)),arity:{min:3},docs:{category:"collection",returns:{type:"collection"},args:{coll:{type:"collection"},key:{type:["string","number"]},fun:{type:"function"},"fun-args":{type:"any",rest:!0}},variants:[{argumentNames:["coll","value","fun"]},{argumentNames:["coll","value","fun","fun-args"]}],description:"\nUpdates a value in the $coll collection, where $key is a key. $fun is a function\nthat will take the old value and any supplied $fun-args and\nreturn the new value.\nIf the key does not exist, `null` is passed as the old value.",seeAlso:["collection.update-in","assoc"],examples:['\nlet cu = import(collection);\nlet x = { a: 1, b: 2 };\ncu.update(x, "a", inc)','\nlet cu = import(collection);\nlet x = { a: 1, b: 2 };\ncu.update(\n x,\n "c",\n val -> null?(val) ? 0 : inc(val)\n)']}},"update-in":{evaluate:([e,t,n,...o],r,i,{executeFunction:c})=>{if(d(e,r),T(t,r),b(n,r),1===t.length)return w(t[0],r),K(e,t[0],n,o,i,c,r);const{coll:l,innerCollMeta:a}=Z(e,t,r),u=A(t[t.length-1],r),s=A(t[t.length-2],r);return Array.isArray(a.parent)?(x(s,r),C(K(a.coll,u,n,o,i,c,r),e=>(a.parent[s]=e,l))):($(s,r),C(K(a.coll,u,n,o,i,c,r),e=>(a.parent[s]=e,l)))},arity:{min:3},docs:{category:"collection",returns:{type:"collection"},args:{coll:{type:"collection"},ks:{type:"array"},fun:{type:"function"},"fun-args":{type:"any",rest:!0}},variants:[{argumentNames:["coll","ks","fun"]},{argumentNames:["coll","ks","fun","fun-args"]}],description:"Updates a value in the $coll collection, where $ks is an array of\nkeys and $fun is a function that will take the old value and\nany supplied $fun-args and return the new value. If any levels do not exist,\nobjects will be created - and the corresponding keys must be of type string.",seeAlso:["collection.update","collection.assoc-in","collection.get-in"],examples:['\nlet cu = import(collection);\ncu.update-in(\n { a: [1, 2, 3] },\n ["a", 1],\n -> null?($) ? 0 : inc($)\n)','\nlet cu = import(collection);\ncu.update-in(\n { a: { foo: "bar"} },\n ["a", "foo"],\n -> null?($) ? "?" : "!"\n)','\nlet cu = import(collection);\ncu.update-in(\n { a: { foo: "bar"} },\n ["a", "baz"],\n -> null?($) ? "?" : "!"\n)','\nlet cu = import(collection);\ncu.update-in(\n { a: [1, 2, 3] },\n ["a", 1],\n *,\n 10,\n 10,\n 10,\n)']}},filteri:{evaluate:([e,t],n,o,{executeFunction:r})=>(d(e,n),b(t,n),Array.isArray(e)?L(e,(e,i)=>r(t,[e,i],o,n)):"string"==typeof e?C(L(e.split(""),(e,i)=>r(t,[e,i],o,n)),e=>e.join("")):C(L(Object.entries(e),([e,i])=>r(t,[i,e],o,n)),e=>e.reduce((e,[t,n])=>(e[t]=n,e),{}))),arity:F(2),docs:{category:"collection",returns:{type:"collection"},args:{a:{type:"collection"},b:{type:"function",description:"The function to call for each element in the collection. The function should take two arguments: the element itself and the index."}},variants:[{argumentNames:["a","b"]}],description:"Creates a new collection with all elements that pass the test implemented by $b. The function is called for each element in the collection, and it should take two arguments: the element itself and the index.",seeAlso:["filter","collection.mapi"],examples:["let cu = import(collection); cu.filteri([1, 2, 3], (x, i) -> i % 2 == 0)","let cu = import(collection); cu.filteri([1, 2, 3], (x, i) -> x % 2 == 0)","let cu = import(collection); cu.filteri([1, 2, 3], (x, i) -> x + i > 3)"]}},mapi:{evaluate:([e,t],n,o,{executeFunction:r})=>{if(d(e,n),b(t,n),Array.isArray(e))return M(e,(e,i)=>r(t,[e,i],o,n));if("string"==typeof e)return C(M(e.split(""),(e,i)=>r(t,[e,i],o,n)),e=>e.join(""));return R(Object.entries(e),(e,[i,c])=>C(r(t,[c,i],o,n),t=>(e[i]=t,e)),{})},arity:F(2),docs:{category:"collection",returns:{type:"collection"},args:{a:{type:"collection"},b:{type:"function",description:"The function to call for each element in the collection. The function should take two arguments: the element itself and the index."}},variants:[{argumentNames:["a","b"]}],description:"Creates a new collection populated with the results of calling $b on every element in $a. The function is called for each element in the collection, and it should take two arguments: the element itself and the index.",seeAlso:["map","collection.filteri"],examples:["let cu = import(collection); cu.mapi([1, 2, 3], (x, i) -> x + i)","let cu = import(collection); cu.mapi([1, 2, 3], (x, i) -> x * i)","let cu = import(collection); cu.mapi([1, 2, 3], (x, i) -> x - i)","let cu = import(collection); cu.mapi([1, 2, 3], (x, i) -> x / i)","let cu = import(collection); cu.mapi([1, 2, 3], (x, i) -> x % inc(i))"]}},reducei:{evaluate:([e,t,n],o,r,{executeFunction:i})=>(d(e,o),b(t,o),m(n,o),"string"==typeof e?($(n,o),0===e.length?n:R(e.split("").map((e,t)=>({elem:e,index:t})),(e,{elem:n,index:c})=>i(t,[e,n,c],r,o),n)):Array.isArray(e)?0===e.length?n:R(e.map((e,t)=>({elem:e,index:t})),(e,{elem:n,index:c})=>i(t,[e,n,c],r,o),n):0===Object.keys(e).length?n:R(Object.entries(e),(e,[n,c])=>i(t,[e,c,n],r,o),n)),arity:F(3),docs:{category:"collection",returns:{type:"any"},args:{coll:{type:"collection"},fun:{type:"function",description:"The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index."},initial:{type:"any",description:"The initial value to use as the accumulator."}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Runs $fun function on each element of the $coll, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.",seeAlso:["reduce","collection.reducei-right","collection.reductionsi"],examples:["let cu = import(collection); cu.reducei([1, 2, 3], (acc, x, i) -> acc + x + i, 0)",'let cu = import(collection); cu.reducei("Albert", (acc, x, i) -> acc ++ x ++ i, "")','let cu = import(collection); cu.reducei({ a: 1, b: 2 }, -> $1 ++ $3, "")']}},"reduce-right":{evaluate:([e,t,n],o,r,{executeFunction:i})=>(d(e,o),b(t,o),m(n,o),"string"==typeof e?0===e.length?n:R(Array.from(e.split("")).reverse(),(e,n)=>i(t,[e,n],r,o),n):Array.isArray(e)?0===e.length?n:R(Array.from(e).reverse(),(e,n)=>i(t,[e,n],r,o),n):0===Object.keys(e).length?n:R(Object.entries(e).reverse(),(e,[,n])=>i(t,[e,n],r,o),n)),arity:F(3),docs:{category:"collection",returns:{type:"any"},args:{fun:{type:"function"},coll:{type:"collection"},initial:{type:"any"}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Runs $fun function on each element of the $coll (starting from the last item), passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value.",seeAlso:["reduce","collection.reducei-right"],examples:['let cu = import(collection); cu.reduce-right(["A", "B", "C"], str, "")',"let cu = import(collection); cu.reduce-right({ a: 1, b: 2 }, +, 0)"]}},"reducei-right":{evaluate:([e,t,n],o,r,{executeFunction:i})=>(d(e,o),b(t,o),m(n,o),"string"==typeof e?0===e.length?n:R(Array.from(e.split("")).reverse().map((e,t,n)=>({elem:e,index:n.length-1-t})),(e,{elem:n,index:c})=>i(t,[e,n,c],r,o),n):Array.isArray(e)?0===e.length?n:R(Array.from(e).reverse().map((e,t,n)=>({elem:e,index:n.length-1-t})),(e,{elem:n,index:c})=>i(t,[e,n,c],r,o),n):0===Object.keys(e).length?n:R(Object.entries(e).reverse(),(e,[n,c])=>i(t,[e,c,n],r,o),n)),arity:F(3),docs:{category:"collection",returns:{type:"any"},args:{coll:{type:"collection"},fun:{type:"function",description:"The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index."},initial:{type:"any",description:"The initial value to use as the accumulator."}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Runs $fun function on each element of the $coll (starting from the last item), passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.",seeAlso:["collection.reducei","collection.reduce-right"],examples:["let cu = import(collection); cu.reducei-right([1, 2, 3], (acc, x, i) -> acc + x + i, 0)",'let cu = import(collection); cu.reducei-right("Albert", (acc, x, i) -> acc ++ x ++ i, "")','let cu = import(collection); cu.reducei-right({ a: 1, b: 2 }, -> $1 ++ $3, "")']}},reductions:{evaluate:([e,t,n],o,r,{executeFunction:i})=>{d(e,o),b(t,o),m(n,o),m(n,o);const c="string"==typeof e?($(n,o),0===e.length?[]:e.split("")):Array.isArray(e)?0===e.length?[]:Array.from(e):0===Object.keys(e).length?[]:Object.entries(e).map(([,e])=>e);if(0===c.length)return[n];const l=[n];return C(R(c,(e,n)=>C(i(t,[e,n],r,o),e=>(l.push(e),e)),n),()=>l)},arity:F(3),docs:{category:"collection",returns:{type:"any",array:!0},args:{fun:{type:"function"},coll:{type:"collection"},initial:{type:"any"}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Returns an array of the intermediate values of the reduction (see `reduce`) of $coll by $fun.",seeAlso:["reduce","collection.reductionsi"],examples:["let cu = import(collection); cu.reductions([1, 2, 3], +, 0)","let cu = import(collection); cu.reductions([1, 2, 3], +, 10)","let cu = import(collection); cu.reductions([], +, 0)","let cu = import(collection); cu.reductions({ a: 1, b: 2 }, +, 0)","\nlet cu = import(collection);\ncu.reductions(\n [1, 2, 3, 4, 5, 6, 7, 8, 9],\n (result, value) -> result + (even?(value) ? value : 0),\n 0\n)"]}},reductionsi:{evaluate:([e,t,n],o,r,{executeFunction:i})=>{d(e,o),b(t,o),m(n,o),m(n,o);const c=(e,t)=>({elem:e,key:t}),l="string"==typeof e?($(n,o),0===e.length?[]:e.split("").map((e,t)=>c(e,t))):Array.isArray(e)?0===e.length?[]:e.map((e,t)=>c(e,t)):0===Object.keys(e).length?[]:Object.entries(e).map(([e,t])=>c(t,e));if(0===l.length)return[n];const a=[n];return C(R(l,(e,{elem:n,key:c})=>C(i(t,[e,n,c],r,o),e=>(a.push(e),e)),n),()=>a)},arity:F(3),docs:{category:"collection",returns:{type:"any",array:!0},args:{coll:{type:"collection"},fun:{type:"function",description:"The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index."},initial:{type:"any",description:"The initial value to use as the accumulator."}},variants:[{argumentNames:["coll","fun","initial"]}],description:"Returns an array of the intermediate values of the reduction (see `reduce`) of $coll by $fun. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.",seeAlso:["collection.reductions","collection.reducei"],examples:["let cu = import(collection); cu.reductionsi([1, 2, 3], (acc, x, i) -> acc + x + i, 0)",'let cu = import(collection); cu.reductionsi("Albert", (acc, x, i) -> acc ++ x ++ i, "")','let cu = import(collection); cu.reductionsi({ a: 1, b: 2 }, -> $1 ++ $3, "")']}},"not-empty":{evaluate:([e],t)=>null===e?null:(d(e,t),"string"==typeof e||Array.isArray(e)?e.length>0?e:null:Object.keys(e).length>0?e:null),arity:F(1),docs:{category:"collection",returns:{type:"boolean"},args:{coll:{type:["collection","null"]}},variants:[{argumentNames:["coll"]}],description:"Returns `null` if $coll is empty or `null`, otherwise $coll.",seeAlso:["empty?","not-empty?"],examples:["let cu = import(collection); cu.not-empty([])","let cu = import(collection); cu.not-empty([1, 2, 3])","let cu = import(collection); cu.not-empty({})","let cu = import(collection); cu.not-empty({ a: 2 })",'let cu = import(collection); cu.not-empty("")','let cu = import(collection); cu.not-empty("Albert")',"let cu = import(collection); cu.not-empty(null)"]}},"every?":{evaluate:([e,t],n,o,{executeFunction:r})=>{d(e,n),b(t,n);return B(Array.isArray(e)?e:"string"==typeof e?e.split(""):Object.entries(e),e=>r(t,[e],o,n))},arity:F(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:"collection"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns `true` if all entries in $a pass the test implemented by $b, otherwise returns `false`.",seeAlso:["collection.any?","collection.not-every?","collection.not-any?","functional.every-pred","grid.every?"],examples:["let cu = import(collection); cu.every?([1, 2, 3], number?)","let cu = import(collection); cu.every?([1, 2, 3], even?)",'\nlet cu = import(collection);\ncu.every?(\n ["Albert", "Mojir", 160, [1, 2]],\n string?,\n)',"\nlet cu = import(collection);\ncu.every?(\n [50, 100, 150, 200],\n -> $ > 10,\n)","let cu = import(collection); cu.every?([], number?)",'let cu = import(collection); cu.every?("", number?)',"let cu = import(collection); cu.every?({}, number?)","\nlet cu = import(collection);\ncu.every?(\n { a: 2, b: 4},\n -> even?(second($))\n)","\nlet cu = import(collection);\ncu.every?(\n { a: 2, b: 3 },\n -> even?(second($))\n)"]}},"any?":{evaluate:([e,t],n,o,{executeFunction:r})=>{b(t,n),d(e,n);return E(Array.isArray(e)?e:"string"==typeof e?e.split(""):Object.entries(e),e=>r(t,[e],o,n))},arity:F(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:"collection"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns `true` if any element in $a pass the test implemented by $b, otherwise returns `false`.",seeAlso:["collection.every?","collection.not-any?","collection.not-every?","functional.some-pred","some","grid.some?"],examples:['\nlet cu = import(collection);\ncu.any?(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)',"\nlet cu = import(collection);\ncu.any?(\n [50, 100, 150, 200],\n x -> x > 10\n)","let cu = import(collection); cu.any?([], number?)",'let cu = import(collection); cu.any?("", number?)',"let cu = import(collection); cu.any?({}, number?)","\nlet cu = import(collection);\ncu.any?(\n { a: 2, b: 3 },\n -> even?(second($))\n)","\nlet cu = import(collection);\ncu.any?(\n { a: 1, b: 3 },\n -> even?(second($))\n)"]}},"not-any?":{evaluate:([e,t],n,o,{executeFunction:r})=>{b(t,n),d(e,n);return C(E(Array.isArray(e)?e:"string"==typeof e?e.split(""):Object.entries(e),e=>r(t,[e],o,n)),e=>!e)},arity:F(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:"collection"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns `false` if any element in $a pass the test implemented by $b, otherwise returns `true`.",seeAlso:["collection.any?","collection.every?","collection.not-every?"],examples:['\nlet cu = import(collection);\ncu.not-any?(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)',"\nlet cu = import(collection);\ncu.not-any?(\n [50, 100, 150, 200],\n x -> x > 10\n)","let cu = import(collection); cu.not-any?([], number?)",'let cu = import(collection); cu.not-any?("", number?)',"let cu = import(collection); cu.not-any?({}, number?)","\nlet cu = import(collection);\ncu.not-any?(\n { a: 2, b: 3 },\n -> even?(second($))\n)","\nlet cu = import(collection);\ncu.not-any?(\n { a: 1, b: 3 },\n -> even?(second($))\n)"]}},"not-every?":{evaluate:([e,t],n,o,{executeFunction:r})=>{b(t,n),d(e,n);return C(B(Array.isArray(e)?e:"string"==typeof e?e.split(""):Object.entries(e),e=>r(t,[e],o,n)),e=>!e)},arity:F(2),docs:{category:"collection",returns:{type:"boolean"},args:{a:{type:"collection"},b:{type:"function"}},variants:[{argumentNames:["a","b"]}],description:"Returns `true` if at least one element in $a does not pass the test implemented by $b, otherwise returns `false`.",seeAlso:["collection.every?","collection.any?","collection.not-any?"],examples:['\nlet cu = import(collection);\ncu.not-every?(\n ["Albert", "Mojir", 160, [1, 2]],\n string?\n)',"\nlet cu = import(collection);\ncu.not-every?(\n [50, 100, 150, 200],\n x -> x > 10\n)","let cu = import(collection); cu.not-every?([], number?)",'let cu = import(collection); cu.not-every?("", number?)',"let cu = import(collection); cu.not-every?({}, number?)","\nlet cu = import(collection);\ncu.not-every?(\n { a: 2, b: 4 },\n -> even?(second($))\n)","\nlet cu = import(collection);\ncu.not-every?(\n { a: 2, b: 3 },\n -> even?(second($))\n)"]}}}};export{q as collectionUtilsModule};
|
|
2
2
|
//# sourceMappingURL=collection.esm.js.map
|