UNPKG

hyperformula

Version:

HyperFormula is a JavaScript engine for efficient processing of spreadsheet-like data and formulas

37 lines 1.11 kB
/** * @license * Copyright (c) 2025 Handsoncode. All rights reserved. */ import { CellError, ErrorType } from "../../Cell.mjs"; import { ErrorMessage } from "../../error-message.mjs"; import { FunctionArgumentType, FunctionPlugin } from "./FunctionPlugin.mjs"; export class CodePlugin extends FunctionPlugin { code(ast, state) { return this.runFunction(ast.args, state, this.metadata('CODE'), value => { if (value.length === 0) { return new CellError(ErrorType.VALUE, ErrorMessage.EmptyString); } return value.charCodeAt(0); }); } unicode(ast, state) { return this.runFunction(ast.args, state, this.metadata('UNICODE'), value => { var _a; return (_a = value.codePointAt(0)) !== null && _a !== void 0 ? _a : new CellError(ErrorType.VALUE, ErrorMessage.EmptyString); }); } } CodePlugin.implementedFunctions = { 'CODE': { method: 'code', parameters: [{ argumentType: FunctionArgumentType.STRING }] }, 'UNICODE': { method: 'unicode', parameters: [{ argumentType: FunctionArgumentType.STRING }] } };