mirror of
https://github.com/n8n-io/n8n.git
synced 2026-06-02 17:57:06 +02:00
🔥 Remove dummy extensions
This commit is contained in:
parent
b9b966c8a1
commit
e4d17f5817
|
|
@ -199,7 +199,6 @@ export function average(value: unknown[]) {
|
|||
}
|
||||
|
||||
function compact(value: unknown[]): unknown[] {
|
||||
console.log('value[4]', value[4]);
|
||||
return value
|
||||
.filter((v) => v !== null && v !== undefined && v !== 'nil' && v !== '')
|
||||
.map((v) => {
|
||||
|
|
|
|||
|
|
@ -54,18 +54,6 @@ function encrypt(value: string, extraArgs?: unknown): string {
|
|||
// return createHash(format).update(value.toString()).digest('hex');
|
||||
}
|
||||
|
||||
function getOnlyFirstCharacters(value: string, extraArgs: number[]): string {
|
||||
const [end] = extraArgs;
|
||||
|
||||
if (typeof end !== 'number') {
|
||||
throw new ExpressionError.ExpressionExtensionError(
|
||||
'getOnlyFirstCharacters() requires a argument',
|
||||
);
|
||||
}
|
||||
|
||||
return value.slice(0, end);
|
||||
}
|
||||
|
||||
function isEmpty(value: string): boolean {
|
||||
return value === '';
|
||||
}
|
||||
|
|
@ -120,10 +108,6 @@ function removeMarkdown(value: string): string {
|
|||
return output;
|
||||
}
|
||||
|
||||
function sayHi(value: string) {
|
||||
return `hi ${value}`;
|
||||
}
|
||||
|
||||
function stripTags(value: string): string {
|
||||
return value.replace(/<[^>]*>?/gm, '');
|
||||
}
|
||||
|
|
@ -256,9 +240,7 @@ export const stringExtensions: ExtensionMap = {
|
|||
functions: {
|
||||
encrypt,
|
||||
hash: encrypt,
|
||||
getOnlyFirstCharacters,
|
||||
removeMarkdown,
|
||||
sayHi,
|
||||
stripTags,
|
||||
toDate,
|
||||
toDecimalNumber: toFloat,
|
||||
|
|
|
|||
|
|
@ -12,15 +12,15 @@ describe('Expression Extension Transforms', () => {
|
|||
expect(extendTransform('"".isEmpty()')!.code).toEqual('extend("", "isEmpty", [])');
|
||||
});
|
||||
|
||||
test('Chained transform with .sayHi.getOnlyFirstCharacters', () => {
|
||||
expect(extendTransform('"".sayHi().getOnlyFirstCharacters(2)')!.code).toEqual(
|
||||
'extend(extend("", "sayHi", []), "getOnlyFirstCharacters", [2])',
|
||||
test('Chained transform with .toSnakeCase.toSentenceCase', () => {
|
||||
expect(extendTransform('"".toSnakeCase().toSentenceCase(2)')!.code).toEqual(
|
||||
'extend(extend("", "toSnakeCase", []), "toSentenceCase", [2])',
|
||||
);
|
||||
});
|
||||
|
||||
test('Chained transform with native functions .sayHi.trim.getOnlyFirstCharacters', () => {
|
||||
expect(extendTransform('"aaa ".sayHi().trim().getOnlyFirstCharacters(2)')!.code).toEqual(
|
||||
'extend(extend("aaa ", "sayHi", []).trim(), "getOnlyFirstCharacters", [2])',
|
||||
test('Chained transform with native functions .toSnakeCase.trim.toSentenceCase', () => {
|
||||
expect(extendTransform('"aaa ".toSnakeCase().trim().toSentenceCase(2)')!.code).toEqual(
|
||||
'extend(extend("aaa ", "toSnakeCase", []).trim(), "toSentenceCase", [2])',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
@ -36,19 +36,21 @@ describe('tmpl Expression Parser', () => {
|
|||
});
|
||||
|
||||
test('Multiple expression', () => {
|
||||
expect(splitExpression('{{ "test".sayHi() }} you have ${{ (100).format() }}.')).toEqual([
|
||||
{ type: 'text', text: '' },
|
||||
{ type: 'code', text: ' "test".sayHi() ', hasClosingBrackets: true },
|
||||
{ type: 'text', text: ' you have $' },
|
||||
{ type: 'code', text: ' (100).format() ', hasClosingBrackets: true },
|
||||
{ type: 'text', text: '.' },
|
||||
]);
|
||||
expect(splitExpression('{{ "test".toSnakeCase() }} you have ${{ (100).format() }}.')).toEqual(
|
||||
[
|
||||
{ type: 'text', text: '' },
|
||||
{ type: 'code', text: ' "test".toSnakeCase() ', hasClosingBrackets: true },
|
||||
{ type: 'text', text: ' you have $' },
|
||||
{ type: 'code', text: ' (100).format() ', hasClosingBrackets: true },
|
||||
{ type: 'text', text: '.' },
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
test('Unclosed expression', () => {
|
||||
expect(splitExpression('{{ "test".sayHi() }} you have ${{ (100).format()')).toEqual([
|
||||
expect(splitExpression('{{ "test".toSnakeCase() }} you have ${{ (100).format()')).toEqual([
|
||||
{ type: 'text', text: '' },
|
||||
{ type: 'code', text: ' "test".sayHi() ', hasClosingBrackets: true },
|
||||
{ type: 'code', text: ' "test".toSnakeCase() ', hasClosingBrackets: true },
|
||||
{ type: 'text', text: ' you have $' },
|
||||
{ type: 'code', text: ' (100).format()', hasClosingBrackets: false },
|
||||
]);
|
||||
|
|
@ -75,14 +77,16 @@ describe('tmpl Expression Parser', () => {
|
|||
|
||||
test('Multiple expression', () => {
|
||||
expect(
|
||||
joinExpression(splitExpression('{{ "test".sayHi() }} you have ${{ (100).format() }}.')),
|
||||
).toEqual('{{ "test".sayHi() }} you have ${{ (100).format() }}.');
|
||||
joinExpression(
|
||||
splitExpression('{{ "test".toSnakeCase() }} you have ${{ (100).format() }}.'),
|
||||
),
|
||||
).toEqual('{{ "test".toSnakeCase() }} you have ${{ (100).format() }}.');
|
||||
});
|
||||
|
||||
test('Unclosed expression', () => {
|
||||
expect(
|
||||
joinExpression(splitExpression('{{ "test".sayHi() }} you have ${{ (100).format()')),
|
||||
).toEqual('{{ "test".sayHi() }} you have ${{ (100).format()');
|
||||
joinExpression(splitExpression('{{ "test".toSnakeCase() }} you have ${{ (100).format()')),
|
||||
).toEqual('{{ "test".toSnakeCase() }} you have ${{ (100).format()');
|
||||
});
|
||||
|
||||
test('Escaped opening bracket', () => {
|
||||
|
|
|
|||
|
|
@ -51,8 +51,8 @@ describe('Data Transformation Functions', () => {
|
|||
|
||||
describe('Multiple expressions', () => {
|
||||
test('Basic multiple expressions', () => {
|
||||
expect(evaluate('={{ "Test".sayHi() }} you have ${{ (100).format() }}.')).toEqual(
|
||||
'hi Test you have $100.',
|
||||
expect(evaluate('={{ "test abc".toSnakeCase() }} you have ${{ (100).format() }}.')).toEqual(
|
||||
'test_abc you have $100.',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -16,28 +16,6 @@ describe('Data Transformation Functions', () => {
|
|||
expect(evaluate('={{"".isEmpty()}}')).toEqual(true);
|
||||
});
|
||||
|
||||
test('.getOnlyFirstCharacters() should work correctly on a string', () => {
|
||||
expect(evaluate('={{"myNewField".getOnlyFirstCharacters(5)}}')).toEqual('myNew');
|
||||
|
||||
expect(evaluate('={{"myNewField".getOnlyFirstCharacters(10)}}')).toEqual('myNewField');
|
||||
|
||||
expect(
|
||||
evaluate('={{"myNewField".getOnlyFirstCharacters(5).length >= "myNewField".length}}'),
|
||||
).toEqual(false);
|
||||
|
||||
expect(evaluate('={{DateTime.now().toLocaleString().getOnlyFirstCharacters(2)}}')).toEqual(
|
||||
stringExtensions.functions.getOnlyFirstCharacters(
|
||||
// @ts-ignore
|
||||
dateExtensions.functions.toLocaleString(new Date(), []),
|
||||
[2],
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('.sayHi() should work correctly on a string', () => {
|
||||
expect(evaluate('={{ "abc".sayHi() }}')).toEqual('hi abc');
|
||||
});
|
||||
|
||||
test('.encrypt() should work correctly on a string', () => {
|
||||
expect(evaluate('={{ "12345".encrypt("sha256") }}')).toEqual(
|
||||
stringExtensions.functions.encrypt('12345', ['sha256']),
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user