hyperformula
Version:
HyperFormula is a JavaScript engine for efficient processing of spreadsheet-like data and formulas
39 lines • 1.17 kB
JavaScript
/**
* @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 CharPlugin extends FunctionPlugin {
char(ast, state) {
return this.runFunction(ast.args, state, this.metadata('CHAR'), value => {
if (value < 1 || value >= 256) {
return new CellError(ErrorType.VALUE, ErrorMessage.CharacterCodeBounds);
}
return String.fromCharCode(Math.trunc(value));
});
}
unichar(ast, state) {
return this.runFunction(ast.args, state, this.metadata('CHAR'), value => {
if (value < 1 || value >= 1114112) {
return new CellError(ErrorType.VALUE, ErrorMessage.CharacterCodeBounds);
}
return String.fromCodePoint(Math.trunc(value));
});
}
}
CharPlugin.implementedFunctions = {
'CHAR': {
method: 'char',
parameters: [{
argumentType: FunctionArgumentType.NUMBER
}]
},
'UNICHAR': {
method: 'unichar',
parameters: [{
argumentType: FunctionArgumentType.NUMBER
}]
}
};