@qrvey/formula-lang
Version:
QFormula support for qrvey projects
45 lines • 1.08 kB
JavaScript
import { AST_PRIMITIVES, OPERATION_SCOPE } from '../constants';
import { isStringParam } from '../utils';
/**
* `TRIM` Remove leading and trailing spaces
*/
export const TRIM = {
identifier: 'TRIM',
operationScope: OPERATION_SCOPE.RAW,
functionScope: [OPERATION_SCOPE.RAW],
parameters: [
{
identifier: 'STRING',
optional: false,
expectedPrimitive: AST_PRIMITIVES.STRING,
validator: [isStringParam],
},
],
transpiler: {
elasticsearch,
snowflake,
redshift,
postgresql,
databricks,
},
primitiveResult: AST_PRIMITIVES.STRING,
};
function elasticsearch(arg) {
return `${arg}.replaceAll(/^ +| +$/, (a) -> '')`; // TRIM function exists in ES but remove tabs also
}
function sql(arg) {
return `TRIM(${arg})`;
}
function snowflake(arg) {
return sql(arg);
}
function redshift(arg) {
return sql(arg);
}
function postgresql(arg) {
return sql(arg);
}
function databricks(arg) {
return sql(arg);
}
//# sourceMappingURL=trim.js.map