-
Notifications
You must be signed in to change notification settings - Fork 16.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add new
@n8n/utils
package (no-changelog) (#13536)
- Loading branch information
1 parent
ebaaf0e
commit 7fb88e6
Showing
125 changed files
with
379 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const sharedOptions = require('@n8n/eslint-config/shared'); | ||
|
||
/** | ||
* @type {import('@types/eslint').ESLint.ConfigData} | ||
*/ | ||
module.exports = { | ||
extends: ['@n8n/eslint-config/node'], | ||
|
||
...sharedOptions(__dirname), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# @n8n/utils | ||
|
||
A collection of utility functions that provide common functionality for both Front-End and Back-End packages. | ||
|
||
## Table of Contents | ||
|
||
- [Features](#features) | ||
- [Contributing](#contributing) | ||
- [License](#license) | ||
|
||
## Features | ||
|
||
- **Reusable Logic**: Build complex, stateful functionality using modular composable functions that you can easily reuse. | ||
- **Consistent Patterns**: Enjoy a unified approach across n8n packages, making integration and maintenance a breeze. | ||
- **Type-Safe & Reliable**: Benefit from TypeScript support, which improves the developer experience and code robustness. | ||
- **Universal Functionality**: Designed to work seamlessly on both the front-end and back-end. | ||
- **Easily Testable**: A modular design that simplifies testing, maintenance, and rapid development. | ||
|
||
## Contributing | ||
|
||
For more details, please read our [CONTRIBUTING.md](CONTRIBUTING.md). | ||
|
||
## License | ||
|
||
For more details, please read our [LICENSE.md](LICENSE.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"$schema": "../../../node_modules/@biomejs/biome/configuration_schema.json", | ||
"extends": ["../../../biome.jsonc"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "@n8n/utils", | ||
"type": "module", | ||
"version": "1.2.0", | ||
"files": [ | ||
"dist" | ||
], | ||
"exports": { | ||
"./*": { | ||
"types": "./dist/*.d.ts", | ||
"import": "./dist/*.js", | ||
"require": "./dist/*.cjs" | ||
} | ||
}, | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "pnpm run typecheck && tsup", | ||
"preview": "vite preview", | ||
"typecheck": "tsc --noEmit", | ||
"test": "vitest run", | ||
"test:dev": "vitest --silent=false", | ||
"lint": "eslint src --ext .js,.ts,.vue --quiet", | ||
"lintfix": "eslint src --ext .js,.ts,.vue --fix", | ||
"format": "biome format --write . && prettier --write . --ignore-path ../../../.prettierignore", | ||
"format:check": "biome ci . && prettier --check . --ignore-path ../../../.prettierignore" | ||
}, | ||
"devDependencies": { | ||
"@n8n/eslint-config": "workspace:*", | ||
"@n8n/typescript-config": "workspace:*", | ||
"@n8n/vitest-config": "workspace:*", | ||
"@testing-library/jest-dom": "catalog:frontend", | ||
"@testing-library/user-event": "catalog:frontend", | ||
"tsup": "catalog:frontend", | ||
"typescript": "catalog:frontend", | ||
"vite": "catalog:frontend", | ||
"vite-plugin-dts": "catalog:frontend", | ||
"vitest": "catalog:frontend" | ||
}, | ||
"license": "See LICENSE.md file in the root of the repository" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import '@testing-library/jest-dom'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="vite/client" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const sortByProperty = <T>( | ||
property: keyof T, | ||
arr: T[], | ||
order: 'asc' | 'desc' = 'asc', | ||
): T[] => | ||
arr.sort((a, b) => { | ||
const result = String(a[property]).localeCompare(String(b[property]), undefined, { | ||
numeric: true, | ||
sensitivity: 'base', | ||
}); | ||
return order === 'asc' ? result : -result; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { truncate } from './truncate'; | ||
|
||
describe('truncate', () => { | ||
it('should truncate text to 30 chars by default', () => { | ||
expect(truncate('This is a very long text that should be truncated')).toBe( | ||
'This is a very long text that ...', | ||
); | ||
}); | ||
|
||
it('should truncate text to given length', () => { | ||
expect(truncate('This is a very long text that should be truncated', 25)).toBe( | ||
'This is a very long text ...', | ||
); | ||
}); | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "@n8n/typescript-config/tsconfig.frontend.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"rootDir": ".", | ||
"outDir": "dist", | ||
"types": ["vite/client", "vitest/globals"], | ||
"isolatedModules": true | ||
}, | ||
"include": ["src/**/*.ts", "src/**/*.vue", "vite.config.ts", "tsup.config.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { defineConfig } from 'tsup'; | ||
|
||
export default defineConfig({ | ||
entry: ['src/**/*.ts', '!src/**/*.test.ts', '!src/**/*.d.ts', '!src/__tests__**/*'], | ||
format: ['cjs', 'esm'], | ||
clean: true, | ||
dts: true, | ||
cjsInterop: true, | ||
splitting: true, | ||
sourcemap: true, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { defineConfig, mergeConfig } from 'vite'; | ||
import { vitestConfig } from '@n8n/vitest-config/frontend'; | ||
|
||
export default mergeConfig(defineConfig({}), vitestConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.