mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
42 lines
871 B
TypeScript
42 lines
871 B
TypeScript
import type { Extension, ExtensionMap } from './Extensions';
|
|
|
|
export function toBoolean(value: boolean) {
|
|
return value;
|
|
}
|
|
|
|
export function toInt(value: boolean) {
|
|
return value ? 1 : 0;
|
|
}
|
|
|
|
export function toDateTime() {
|
|
return undefined;
|
|
}
|
|
|
|
const toFloat = toInt;
|
|
const toNumber: Extension = toInt.bind({});
|
|
|
|
toNumber.doc = {
|
|
name: 'toNumber',
|
|
description:
|
|
'Converts <code>true</code> to <code>1</code> and <code>false</code> to <code>0</code>.',
|
|
examples: [
|
|
{ example: 'true.toNumber()', evaluated: '1' },
|
|
{ example: 'false.toNumber()', evaluated: '0' },
|
|
],
|
|
section: 'cast',
|
|
returnType: 'number',
|
|
docURL:
|
|
'https://docs.n8n.io/code/builtin/data-transformation-functions/booleans/#boolean-toNumber',
|
|
};
|
|
|
|
export const booleanExtensions: ExtensionMap = {
|
|
typeName: 'Boolean',
|
|
functions: {
|
|
toBoolean,
|
|
toInt,
|
|
toFloat,
|
|
toNumber,
|
|
toDateTime,
|
|
},
|
|
};
|