Skip to content

Commit

Permalink
feat(new tool): Nginx Config File formatter
Browse files Browse the repository at this point in the history
Prettier for Nginx config files
  • Loading branch information
sharevb committed Apr 28, 2024
1 parent 9eac9cb commit fb15b50
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { tool as asciiTextDrawer } from './ascii-text-drawer';

import { tool as textToUnicode } from './text-to-unicode';
import { tool as safelinkDecoder } from './safelink-decoder';
import { tool as nginxFormatter } from './nginx-formatter';
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
import { tool as numeronymGenerator } from './numeronym-generator';
import { tool as macAddressGenerator } from './mac-address-generator';
Expand Down Expand Up @@ -148,6 +149,7 @@ export const toolsByCategory: ToolCategory[] = [
dockerRunToDockerComposeConverter,
xmlFormatter,
yamlViewer,
nginxFormatter,
],
},
{
Expand Down
12 changes: 12 additions & 0 deletions src/tools/nginx-formatter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Braces } from '@vicons/tabler';
import { defineTool } from '../tool';

export const tool = defineTool({
name: 'Nginx formatter',
path: '/nginx-formatter',
description: 'Format/prettify Nginx configuration files',
keywords: ['nginx', 'formatter', 'prettier'],
component: () => import('./nginx-formatter.vue'),
icon: Braces,
createdAt: new Date('2024-03-30'),
});
27 changes: 27 additions & 0 deletions src/tools/nginx-formatter/nginx-formatter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<script setup lang="ts">
import { formatContent } from 'nginx-config-formatter';

Check failure on line 2 in src/tools/nginx-formatter/nginx-formatter.vue

View workflow job for this annotation

GitHub Actions / ci

Cannot find module 'nginx-config-formatter' or its corresponding type declarations.
import type { UseValidationRule } from '@/composable/validation';
import { withDefaultOnError } from '@/utils/defaults';
const defaultValue = '{\n\t"hello": [\n\t\t"world"\n\t]\n}';
const transformer = (value: string) => withDefaultOnError(() => formatContent(value), '');
const rules: UseValidationRule<string>[] = [
{
validator: (v: string) => v === '' || formatContent(v),
message: 'Provided Nginx config is not valid.',
},
];
</script>

<template>
<format-transformer
input-label="Your Nginx config"
:input-default="defaultValue"
input-placeholder="Paste your Nginx config here..."
output-label="Prettified Nginx config"
output-language="json"
:input-validation-rules="rules"
:transformer="transformer"
/>
</template>

0 comments on commit fb15b50

Please sign in to comment.