feat: Convert all app files to JS

This commit is contained in:
Faruk AYDIN
2024-01-05 17:44:21 +01:00
parent b95478b635
commit 43dba351c3
1030 changed files with 5114 additions and 6436 deletions

View File

@@ -1,6 +1,5 @@
import defineAction from '../../../../helpers/define-action';
import formatDateTime from './transformers/format-date-time';
import defineAction from '../../../../helpers/define-action.js';
import formatDateTime from './transformers/format-date-time.js';
const transformers = {
formatDateTime,
@@ -14,7 +13,7 @@ export default defineAction({
{
label: 'Transform',
key: 'transform',
type: 'dropdown' as const,
type: 'dropdown',
required: true,
variables: true,
options: [{ label: 'Format Date / Time', value: 'formatDateTime' }],
@@ -36,8 +35,7 @@ export default defineAction({
],
async run($) {
const transformerName = $.step.parameters
.transform as keyof typeof transformers;
const transformerName = $.step.parameters.transform;
const output = transformers[transformerName]($);
$.setActionItem({

View File

@@ -0,0 +1,22 @@
import { DateTime } from 'luxon';
const formatDateTime = ($) => {
const input = $.step.parameters.input;
const fromFormat = $.step.parameters.fromFormat;
const fromTimezone = $.step.parameters.fromTimezone;
const inputDateTime = DateTime.fromFormat(input, fromFormat, {
zone: fromTimezone,
setZone: true,
});
const toFormat = $.step.parameters.toFormat;
const toTimezone = $.step.parameters.toTimezone;
const outputDateTime = inputDateTime.setZone(toTimezone).toFormat(toFormat);
return outputDateTime;
};
export default formatDateTime;

View File

@@ -1,23 +0,0 @@
import { IGlobalVariable } from '@automatisch/types';
import { DateTime } from 'luxon';
const formatDateTime = ($: IGlobalVariable) => {
const input = $.step.parameters.input as string;
const fromFormat = $.step.parameters.fromFormat as string;
const fromTimezone = $.step.parameters.fromTimezone as string;
const inputDateTime = DateTime.fromFormat(input, fromFormat, {
zone: fromTimezone,
setZone: true,
});
const toFormat = $.step.parameters.toFormat as string;
const toTimezone = $.step.parameters.toTimezone as string;
const outputDateTime = inputDateTime.setZone(toTimezone).toFormat(toFormat);
return outputDateTime;
};
export default formatDateTime;

View File

@@ -0,0 +1,5 @@
import text from './text/index.js';
import numbers from './numbers/index.js';
import dateTime from './date-time/index.js';
export default [text, numbers, dateTime];

View File

@@ -1,5 +0,0 @@
import text from './text';
import numbers from './numbers';
import dateTime from './date-time';
export default [text, numbers, dateTime];

View File

@@ -1,9 +1,9 @@
import defineAction from '../../../../helpers/define-action';
import defineAction from '../../../../helpers/define-action.js';
import performMathOperation from './transformers/perform-math-operation';
import randomNumber from './transformers/random-number';
import formatNumber from './transformers/format-number';
import formatPhoneNumber from './transformers/format-phone-number';
import performMathOperation from './transformers/perform-math-operation.js';
import randomNumber from './transformers/random-number.js';
import formatNumber from './transformers/format-number.js';
import formatPhoneNumber from './transformers/format-phone-number.js';
const transformers = {
performMathOperation,
@@ -21,7 +21,7 @@ export default defineAction({
{
label: 'Transform',
key: 'transform',
type: 'dropdown' as const,
type: 'dropdown',
required: true,
variables: true,
options: [
@@ -48,8 +48,7 @@ export default defineAction({
],
async run($) {
const transformerName = $.step.parameters
.transform as keyof typeof transformers;
const transformerName = $.step.parameters.transform;
const output = transformers[transformerName]($);
$.setActionItem({

View File

@@ -1,10 +1,9 @@
import { IGlobalVariable } from '@automatisch/types';
import accounting from 'accounting';
const formatNumber = ($: IGlobalVariable) => {
const input = $.step.parameters.input as string;
const inputDecimalMark = $.step.parameters.inputDecimalMark as string;
const toFormat = $.step.parameters.toFormat as string;
const formatNumber = ($) => {
const input = $.step.parameters.input;
const inputDecimalMark = $.step.parameters.inputDecimalMark;
const toFormat = $.step.parameters.toFormat;
const normalizedNumber = accounting.unformat(input, inputDecimalMark);
const decimalPart = normalizedNumber.toString().split('.')[1];

View File

@@ -1,11 +1,10 @@
import { IGlobalVariable } from '@automatisch/types';
import parsePhoneNumber, { CountryCode } from 'libphonenumber-js';
import parsePhoneNumber from 'libphonenumber-js';
const formatPhoneNumber = ($: IGlobalVariable) => {
const phoneNumber = $.step.parameters.phoneNumber as string;
const toFormat = $.step.parameters.toFormat as string;
const phoneNumberCountryCode = ($.step.parameters.phoneNumberCountryCode ||
'US') as CountryCode;
const formatPhoneNumber = ($) => {
const phoneNumber = $.step.parameters.phoneNumber;
const toFormat = $.step.parameters.toFormat;
const phoneNumberCountryCode =
$.step.parameters.phoneNumberCountryCode || 'US';
const parsedPhoneNumber = parsePhoneNumber(
phoneNumber,

View File

@@ -1,11 +1,11 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
import { add, divide, multiply, subtract } from 'lodash';
import add from 'lodash/add.js';
import divide from 'lodash/divide.js';
import multiply from 'lodash/multiply.js';
import subtract from 'lodash/subtract.js';
const mathOperation = ($: IGlobalVariable) => {
const mathOperation = $.step.parameters.mathOperation as string;
const values = ($.step.parameters.values as IJSONObject[]).map((value) =>
Number(value.input)
) as number[];
const mathOperation = ($) => {
const mathOperation = $.step.parameters.mathOperation;
const values = $.step.parameters.values.map((value) => Number(value.input));
if (mathOperation === 'add') {
return values.reduce((acc, curr) => add(acc, curr), 0);

View File

@@ -1,6 +1,4 @@
import { IGlobalVariable } from '@automatisch/types';
const randomNumber = ($: IGlobalVariable) => {
const randomNumber = ($) => {
const lowerRange = Number($.step.parameters.lowerRange);
const upperRange = Number($.step.parameters.upperRange);
const decimalPoints = Number($.step.parameters.decimalPoints) || 0;

View File

@@ -1,15 +1,15 @@
import defineAction from '../../../../helpers/define-action';
import defineAction from '../../../../helpers/define-action.js';
import capitalize from './transformers/capitalize';
import extractEmailAddress from './transformers/extract-email-address';
import extractNumber from './transformers/extract-number';
import htmlToMarkdown from './transformers/html-to-markdown';
import lowercase from './transformers/lowercase';
import markdownToHtml from './transformers/markdown-to-html';
import pluralize from './transformers/pluralize';
import replace from './transformers/replace';
import trimWhitespace from './transformers/trim-whitespace';
import useDefaultValue from './transformers/use-default-value';
import capitalize from './transformers/capitalize.js';
import extractEmailAddress from './transformers/extract-email-address.js';
import extractNumber from './transformers/extract-number.js';
import htmlToMarkdown from './transformers/html-to-markdown.js';
import lowercase from './transformers/lowercase.js';
import markdownToHtml from './transformers/markdown-to-html.js';
import pluralize from './transformers/pluralize.js';
import replace from './transformers/replace.js';
import trimWhitespace from './transformers/trim-whitespace.js';
import useDefaultValue from './transformers/use-default-value.js';
const transformers = {
capitalize,
@@ -33,7 +33,7 @@ export default defineAction({
{
label: 'Transform',
key: 'transform',
type: 'dropdown' as const,
type: 'dropdown',
required: true,
variables: true,
options: [
@@ -66,8 +66,7 @@ export default defineAction({
],
async run($) {
const transformerName = $.step.parameters
.transform as keyof typeof transformers;
const transformerName = $.step.parameters.transform;
const output = transformers[transformerName]($);
$.setActionItem({

View File

@@ -0,0 +1,10 @@
import lodashCapitalize from 'lodash/capitalize.js';
const capitalize = ($) => {
const input = $.step.parameters.input;
const capitalizedInput = input.replace(/\w+/g, lodashCapitalize);
return capitalizedInput;
};
export default capitalize;

View File

@@ -1,11 +0,0 @@
import { IGlobalVariable } from '@automatisch/types';
import { capitalize as lodashCapitalize } from 'lodash';
const capitalize = ($: IGlobalVariable) => {
const input = $.step.parameters.input as string;
const capitalizedInput = input.replace(/\w+/g, lodashCapitalize);
return capitalizedInput;
};
export default capitalize;

View File

@@ -1,7 +1,5 @@
import { IGlobalVariable } from '@automatisch/types';
const extractEmailAddress = ($: IGlobalVariable) => {
const input = $.step.parameters.input as string;
const extractEmailAddress = ($) => {
const input = $.step.parameters.input;
const emailRegexp =
/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;

View File

@@ -1,7 +1,5 @@
import { IGlobalVariable } from '@automatisch/types';
const extractNumber = ($: IGlobalVariable) => {
const input = $.step.parameters.input as string;
const extractNumber = ($) => {
const input = $.step.parameters.input;
// Example numbers that's supported:
// 123

View File

@@ -1,8 +1,7 @@
import { IGlobalVariable } from '@automatisch/types';
import { NodeHtmlMarkdown } from 'node-html-markdown';
const htmlToMarkdown = ($: IGlobalVariable) => {
const input = $.step.parameters.input as string;
const htmlToMarkdown = ($) => {
const input = $.step.parameters.input;
const markdown = NodeHtmlMarkdown.translate(input);
return markdown;

View File

@@ -0,0 +1,6 @@
const lowercase = ($) => {
const input = $.step.parameters.input;
return input.toLowerCase();
};
export default lowercase;

View File

@@ -1,8 +0,0 @@
import { IGlobalVariable } from '@automatisch/types';
const lowercase = ($: IGlobalVariable) => {
const input = $.step.parameters.input as string;
return input.toLowerCase();
};
export default lowercase;

View File

@@ -1,10 +1,9 @@
import { IGlobalVariable } from '@automatisch/types';
import showdown from 'showdown';
const converter = new showdown.Converter();
const markdownToHtml = ($: IGlobalVariable) => {
const input = $.step.parameters.input as string;
const markdownToHtml = ($) => {
const input = $.step.parameters.input;
const html = converter.makeHtml(input);
return html;

View File

@@ -0,0 +1,8 @@
import pluralizeLibrary from 'pluralize';
const pluralize = ($) => {
const input = $.step.parameters.input;
return pluralizeLibrary(input);
};
export default pluralize;

View File

@@ -1,9 +0,0 @@
import { IGlobalVariable } from '@automatisch/types';
import pluralizeLibrary from 'pluralize';
const pluralize = ($: IGlobalVariable) => {
const input = $.step.parameters.input as string;
return pluralizeLibrary(input);
};
export default pluralize;

View File

@@ -0,0 +1,10 @@
const replace = ($) => {
const input = $.step.parameters.input;
const find = $.step.parameters.find;
const replace = $.step.parameters.replace;
return input.replaceAll(find, replace);
};
export default replace;

View File

@@ -1,12 +0,0 @@
import { IGlobalVariable } from '@automatisch/types';
const replace = ($: IGlobalVariable) => {
const input = $.step.parameters.input as string;
const find = $.step.parameters.find as string;
const replace = $.step.parameters.replace as string;
return input.replaceAll(find, replace);
};
export default replace;

View File

@@ -0,0 +1,6 @@
const trimWhitespace = ($) => {
const input = $.step.parameters.input;
return input.trim();
};
export default trimWhitespace;

View File

@@ -1,8 +0,0 @@
import { IGlobalVariable } from '@automatisch/types';
const trimWhitespace = ($: IGlobalVariable) => {
const input = $.step.parameters.input as string;
return input.trim();
};
export default trimWhitespace;

View File

@@ -0,0 +1,11 @@
const useDefaultValue = ($) => {
const input = $.step.parameters.input;
if (input && input.trim().length > 0) {
return input;
}
return $.step.parameters.defaultValue;
};
export default useDefaultValue;

View File

@@ -1,13 +0,0 @@
import { IGlobalVariable } from '@automatisch/types';
const useDefaultValue = ($: IGlobalVariable) => {
const input = $.step.parameters.input as string;
if (input && input.trim().length > 0) {
return input;
}
return $.step.parameters.defaultValue as string;
};
export default useDefaultValue;

View File

@@ -0,0 +1,3 @@
import listTransformOptions from './list-transform-options/index.js';
export default [listTransformOptions];

View File

@@ -1,3 +0,0 @@
import listTransformOptions from './list-transform-options';
export default [listTransformOptions];

View File

@@ -1,11 +1,11 @@
import formatOptions from './options/format';
import timezoneOptions from './options/timezone';
import formatOptions from './options/format.js';
import timezoneOptions from './options/timezone.js';
const formatDateTime = [
{
label: 'Input',
key: 'input',
type: 'string' as const,
type: 'string',
required: true,
description: 'The datetime you want to format.',
variables: true,
@@ -13,7 +13,7 @@ const formatDateTime = [
{
label: 'From Format',
key: 'fromFormat',
type: 'dropdown' as const,
type: 'dropdown',
required: true,
description: 'The format of the input.',
variables: true,
@@ -22,7 +22,7 @@ const formatDateTime = [
{
label: 'From Timezone',
key: 'fromTimezone',
type: 'dropdown' as const,
type: 'dropdown',
required: true,
description: 'The timezone of the input.',
variables: true,
@@ -31,7 +31,7 @@ const formatDateTime = [
{
label: 'To Format',
key: 'toFormat',
type: 'dropdown' as const,
type: 'dropdown',
required: true,
description: 'The format of the output.',
variables: true,
@@ -40,7 +40,7 @@ const formatDateTime = [
{
label: 'To Timezone',
key: 'toTimezone',
type: 'dropdown' as const,
type: 'dropdown',
required: true,
description: 'The timezone of the output.',
variables: true,

View File

@@ -0,0 +1,42 @@
import capitalize from './text/capitalize.js';
import extractEmailAddress from './text/extract-email-address.js';
import extractNumber from './text/extract-number.js';
import htmlToMarkdown from './text/html-to-markdown.js';
import lowercase from './text/lowercase.js';
import markdownToHtml from './text/markdown-to-html.js';
import pluralize from './text/pluralize.js';
import replace from './text/replace.js';
import trimWhitespace from './text/trim-whitespace.js';
import useDefaultValue from './text/use-default-value.js';
import performMathOperation from './numbers/perform-math-operation.js';
import randomNumber from './numbers/random-number.js';
import formatNumber from './numbers/format-number.js';
import formatPhoneNumber from './numbers/format-phone-number.js';
import formatDateTime from './date-time/format-date-time.js';
const options = {
capitalize,
extractEmailAddress,
extractNumber,
htmlToMarkdown,
lowercase,
markdownToHtml,
pluralize,
replace,
trimWhitespace,
useDefaultValue,
performMathOperation,
randomNumber,
formatNumber,
formatPhoneNumber,
formatDateTime,
};
export default {
name: 'List fields after transform',
key: 'listTransformOptions',
async run($) {
return options[$.step.parameters.transform];
},
};

View File

@@ -1,43 +0,0 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
import capitalize from './text/capitalize';
import extractEmailAddress from './text/extract-email-address';
import extractNumber from './text/extract-number';
import htmlToMarkdown from './text/html-to-markdown';
import lowercase from './text/lowercase';
import markdownToHtml from './text/markdown-to-html';
import pluralize from './text/pluralize';
import replace from './text/replace';
import trimWhitespace from './text/trim-whitespace';
import useDefaultValue from './text/use-default-value';
import performMathOperation from './numbers/perform-math-operation';
import randomNumber from './numbers/random-number';
import formatNumber from './numbers/format-number';
import formatPhoneNumber from './numbers/format-phone-number';
import formatDateTime from './date-time/format-date-time';
const options: IJSONObject = {
capitalize,
extractEmailAddress,
extractNumber,
htmlToMarkdown,
lowercase,
markdownToHtml,
pluralize,
replace,
trimWhitespace,
useDefaultValue,
performMathOperation,
randomNumber,
formatNumber,
formatPhoneNumber,
formatDateTime,
};
export default {
name: 'List fields after transform',
key: 'listTransformOptions',
async run($: IGlobalVariable) {
return options[$.step.parameters.transform as string];
},
};

View File

@@ -2,7 +2,7 @@ const formatNumber = [
{
label: 'Input',
key: 'input',
type: 'string' as const,
type: 'string',
required: true,
description: 'The number you want to format.',
variables: true,
@@ -10,7 +10,7 @@ const formatNumber = [
{
label: 'Input Decimal Mark',
key: 'inputDecimalMark',
type: 'dropdown' as const,
type: 'dropdown',
required: true,
description: 'The decimal mark of the input number.',
variables: true,
@@ -22,7 +22,7 @@ const formatNumber = [
{
label: 'To Format',
key: 'toFormat',
type: 'dropdown' as const,
type: 'dropdown',
required: true,
description: 'The format you want to convert the number to.',
variables: true,

View File

@@ -1,10 +1,10 @@
import phoneNumberCountryCodes from '../../../common/phone-number-country-codes';
import phoneNumberCountryCodes from '../../../common/phone-number-country-codes.js';
const formatPhoneNumber = [
{
label: 'Phone Number',
key: 'phoneNumber',
type: 'string' as const,
type: 'string',
required: true,
description: 'The phone number you want to format.',
variables: true,
@@ -12,7 +12,7 @@ const formatPhoneNumber = [
{
label: 'To Format',
key: 'toFormat',
type: 'dropdown' as const,
type: 'dropdown',
required: true,
description: 'The format you want to convert the number to.',
variables: true,
@@ -25,7 +25,7 @@ const formatPhoneNumber = [
{
label: 'Phone Number Country Code',
key: 'phoneNumberCountryCode',
type: 'dropdown' as const,
type: 'dropdown',
required: true,
description: 'The country code of the phone number. The default is US.',
variables: true,

View File

@@ -2,7 +2,7 @@ const performMathOperation = [
{
label: 'Math Operation',
key: 'mathOperation',
type: 'dropdown' as const,
type: 'dropdown',
required: true,
description: 'The math operation to perform.',
variables: true,
@@ -17,14 +17,14 @@ const performMathOperation = [
{
label: 'Values',
key: 'values',
type: 'dynamic' as const,
type: 'dynamic',
required: false,
description: 'Add or remove numbers as needed.',
fields: [
{
label: 'Input',
key: 'input',
type: 'string' as const,
type: 'string',
required: true,
description: 'The number to perform the math operation on.',
variables: true,

View File

@@ -2,7 +2,7 @@ const randomNumber = [
{
label: 'Lower range',
key: 'lowerRange',
type: 'string' as const,
type: 'string',
required: true,
description: 'The lowest number to generate.',
variables: true,
@@ -10,7 +10,7 @@ const randomNumber = [
{
label: 'Upper range',
key: 'upperRange',
type: 'string' as const,
type: 'string',
required: true,
description: 'The highest number to generate.',
variables: true,
@@ -18,7 +18,7 @@ const randomNumber = [
{
label: 'Decimal points',
key: 'decimalPoints',
type: 'string' as const,
type: 'string',
required: false,
description:
'The number of digits after the decimal point. It can be an integer between 0 and 15.',

View File

@@ -2,7 +2,7 @@ const capitalize = [
{
label: 'Input',
key: 'input',
type: 'string' as const,
type: 'string',
required: true,
description: 'Text that will be capitalized.',
variables: true,

View File

@@ -2,7 +2,7 @@ const extractEmailAddress = [
{
label: 'Input',
key: 'input',
type: 'string' as const,
type: 'string',
required: true,
description: 'Text that will be searched for an email address.',
variables: true,

View File

@@ -2,7 +2,7 @@ const extractNumber = [
{
label: 'Input',
key: 'input',
type: 'string' as const,
type: 'string',
required: true,
description: 'Text that will be searched for a number.',
variables: true,

View File

@@ -2,7 +2,7 @@ const htmlToMarkdown = [
{
label: 'Input',
key: 'input',
type: 'string' as const,
type: 'string',
required: true,
description: 'HTML that will be converted to Markdown.',
variables: true,

View File

@@ -2,7 +2,7 @@ const lowercase = [
{
label: 'Input',
key: 'input',
type: 'string' as const,
type: 'string',
required: true,
description: 'Text that will be lowercased.',
variables: true,

View File

@@ -2,7 +2,7 @@ const markdownToHtml = [
{
label: 'Input',
key: 'input',
type: 'string' as const,
type: 'string',
required: true,
description: 'Markdown text that will be converted to HTML.',
variables: true,

View File

@@ -2,7 +2,7 @@ const pluralize = [
{
label: 'Input',
key: 'input',
type: 'string' as const,
type: 'string',
required: true,
description: 'Text that will be pluralized.',
variables: true,

View File

@@ -2,7 +2,7 @@ const replace = [
{
label: 'Input',
key: 'input',
type: 'string' as const,
type: 'string',
required: true,
description: 'Text that you want to search for and replace values.',
variables: true,
@@ -10,7 +10,7 @@ const replace = [
{
label: 'Find',
key: 'find',
type: 'string' as const,
type: 'string',
required: true,
description: 'Text that will be searched for.',
variables: true,
@@ -18,7 +18,7 @@ const replace = [
{
label: 'Replace',
key: 'replace',
type: 'string' as const,
type: 'string',
required: false,
description: 'Text that will replace the found text.',
variables: true,

View File

@@ -2,7 +2,7 @@ const trimWhitespace = [
{
label: 'Input',
key: 'input',
type: 'string' as const,
type: 'string',
required: true,
description: 'Text you want to remove leading and trailing spaces.',
variables: true,

View File

@@ -2,7 +2,7 @@ const useDefaultValue = [
{
label: 'Input',
key: 'input',
type: 'string' as const,
type: 'string',
required: true,
description: 'Text you want to check whether it is empty or not.',
variables: true,
@@ -10,7 +10,7 @@ const useDefaultValue = [
{
label: 'Default Value',
key: 'defaultValue',
type: 'string' as const,
type: 'string',
required: true,
description:
'Text that will be used as a default value if the input is empty.',

View File

@@ -1,6 +1,6 @@
import defineApp from '../../helpers/define-app';
import actions from './actions';
import dynamicFields from './dynamic-fields';
import defineApp from '../../helpers/define-app.js';
import actions from './actions/index.js';
import dynamicFields from './dynamic-fields/index.js';
export default defineApp({
name: 'Formatter',