-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(new tool): Nginx Config File formatter
Prettier for Nginx config files
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 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
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 @@ | ||
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'), | ||
}); |
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,27 @@ | ||
<script setup lang="ts"> | ||
import { formatContent } from 'nginx-config-formatter'; | ||
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> |