feat(formatter): add extract number transform to text action (#1255)

This commit is contained in:
Ömer Faruk Aydın
2023-08-31 16:35:28 +02:00
committed by GitHub
parent 8074f9146b
commit e2dcdd2811
4 changed files with 43 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ import htmlToMarkdown from './transformers/html-to-markdown';
import markdownToHtml from './transformers/markdown-to-html';
import useDefaultValue from './transformers/use-default-value';
import extractEmailAddress from './transformers/extract-email-address';
import extractNumber from './transformers/extract-number';
const transformers = {
capitalize,
@@ -11,6 +12,7 @@ const transformers = {
markdownToHtml,
useDefaultValue,
extractEmailAddress,
extractNumber,
};
export default defineAction({
@@ -32,6 +34,7 @@ export default defineAction({
{ label: 'Convert Markdown to HTML', value: 'markdownToHtml' },
{ label: 'Use Default Value', value: 'useDefaultValue' },
{ label: 'Extract Email Address', value: 'extractEmailAddress' },
{ label: 'Extract Number', value: 'extractNumber' },
],
additionalFields: {
type: 'query',

View File

@@ -0,0 +1,26 @@
import { IGlobalVariable } from '@automatisch/types';
const extractNumber = ($: IGlobalVariable) => {
const input = $.step.parameters.input as string;
// Example numbers that's supported:
// 123
// -123
// 123456
// -123456
// 121,234
// -121,234
// 121.234
// -121.234
// 1,234,567.89
// -1,234,567.89
// 1.234.567,89
// -1.234.567,89
const numberRegexp = /-?((\d{1,3})+\.?,?)+/g;
const numbers = input.match(numberRegexp);
return numbers ? numbers[0] : '';
};
export default extractNumber;

View File

@@ -4,6 +4,7 @@ import htmlToMarkdown from './options/html-to-markdown';
import markdownToHtml from './options/markdown-to-html';
import useDefaultValue from './options/use-default-value';
import extractEmailAddress from './options/extract-email-address';
import extractNumber from './options/extract-number';
const options: IJSONObject = {
capitalize,
@@ -11,6 +12,7 @@ const options: IJSONObject = {
markdownToHtml,
useDefaultValue,
extractEmailAddress,
extractNumber,
};
export default {

View File

@@ -0,0 +1,12 @@
const extractNumber = [
{
label: 'Input',
key: 'input',
type: 'string' as const,
required: true,
description: 'Text that will be searched for a number.',
variables: true,
},
];
export default extractNumber;