feat(new-tool): toml to yaml
This commit is contained in:
		
							parent
							
								
									c7d4f112c0
								
							
						
					
					
						commit
						746e5bdccc
					
				| @ -1,6 +1,7 @@ | |||||||
| import { tool as base64FileConverter } from './base64-file-converter'; | import { tool as base64FileConverter } from './base64-file-converter'; | ||||||
| import { tool as base64StringConverter } from './base64-string-converter'; | import { tool as base64StringConverter } from './base64-string-converter'; | ||||||
| import { tool as basicAuthGenerator } from './basic-auth-generator'; | import { tool as basicAuthGenerator } from './basic-auth-generator'; | ||||||
|  | import { tool as tomlToYaml } from './toml-to-yaml'; | ||||||
| import { tool as tomlToJson } from './toml-to-json'; | import { tool as tomlToJson } from './toml-to-json'; | ||||||
| import { tool as jsonToCsv } from './json-to-csv'; | import { tool as jsonToCsv } from './json-to-csv'; | ||||||
| import { tool as cameraRecorder } from './camera-recorder'; | import { tool as cameraRecorder } from './camera-recorder'; | ||||||
| @ -82,6 +83,7 @@ export const toolsByCategory: ToolCategory[] = [ | |||||||
|       jsonToYaml, |       jsonToYaml, | ||||||
|       listConverter, |       listConverter, | ||||||
|       tomlToJson, |       tomlToJson, | ||||||
|  |       tomlToYaml, | ||||||
|     ], |     ], | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|  | |||||||
							
								
								
									
										12
									
								
								src/tools/toml-to-yaml/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/tools/toml-to-yaml/index.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | |||||||
|  | import { defineTool } from '../tool'; | ||||||
|  | import BracketIcon from '~icons/mdi/code-brackets'; | ||||||
|  | 
 | ||||||
|  | export const tool = defineTool({ | ||||||
|  |   name: 'TOML to YAML', | ||||||
|  |   path: '/toml-to-yaml', | ||||||
|  |   description: 'Parse and convert TOML to YAML.', | ||||||
|  |   keywords: ['toml', 'yaml', 'convert', 'online', 'transform', 'parse'], | ||||||
|  |   component: () => import('./toml-to-yaml.vue'), | ||||||
|  |   icon: BracketIcon, | ||||||
|  |   createdAt: new Date('2023-06-23'), | ||||||
|  | }); | ||||||
							
								
								
									
										36
									
								
								src/tools/toml-to-yaml/toml-to-yaml.e2e.spec.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								src/tools/toml-to-yaml/toml-to-yaml.e2e.spec.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,36 @@ | |||||||
|  | import { expect, test } from '@playwright/test'; | ||||||
|  | 
 | ||||||
|  | test.describe('Tool - TOML to YAML', () => { | ||||||
|  |   test.beforeEach(async ({ page }) => { | ||||||
|  |     await page.goto('/toml-to-yaml'); | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  |   test('Has correct title', async ({ page }) => { | ||||||
|  |     await expect(page).toHaveTitle('TOML to YAML - IT Tools'); | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  |   test('TOML is parsed and outputs clean YAML', async ({ page }) => { | ||||||
|  |     await page.getByTestId('input').fill(` | ||||||
|  | foo = "bar" | ||||||
|  | 
 | ||||||
|  | # This is a comment | ||||||
|  | 
 | ||||||
|  | [list] | ||||||
|  |   name = "item" | ||||||
|  | [list.another] | ||||||
|  |   key = "value" | ||||||
|  |     `.trim());
 | ||||||
|  | 
 | ||||||
|  |     const generatedJson = await page.getByTestId('area-content').innerText(); | ||||||
|  | 
 | ||||||
|  |     expect(generatedJson.trim()).toEqual( | ||||||
|  |       ` | ||||||
|  | foo: bar | ||||||
|  | list: | ||||||
|  |   name: item | ||||||
|  |   another: | ||||||
|  |     key: value | ||||||
|  |    `.trim(),
 | ||||||
|  |     ); | ||||||
|  |   }); | ||||||
|  | }); | ||||||
							
								
								
									
										27
									
								
								src/tools/toml-to-yaml/toml-to-yaml.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								src/tools/toml-to-yaml/toml-to-yaml.vue
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | |||||||
|  | <script setup lang="ts"> | ||||||
|  | import { parse as parseToml } from 'iarna-toml-esm'; | ||||||
|  | import { stringify as stringifyToYaml } from 'yaml'; | ||||||
|  | import { withDefaultOnError } from '../../utils/defaults'; | ||||||
|  | import { isValidToml } from '../toml-to-json/toml.services'; | ||||||
|  | import type { UseValidationRule } from '@/composable/validation'; | ||||||
|  | 
 | ||||||
|  | const transformer = (value: string) => value.trim() === '' ? '' : withDefaultOnError(() => stringifyToYaml(parseToml(value)), ''); | ||||||
|  | 
 | ||||||
|  | const rules: UseValidationRule<string>[] = [ | ||||||
|  |   { | ||||||
|  |     validator: isValidToml, | ||||||
|  |     message: 'Provided TOML is not valid.', | ||||||
|  |   }, | ||||||
|  | ]; | ||||||
|  | </script> | ||||||
|  | 
 | ||||||
|  | <template> | ||||||
|  |   <format-transformer | ||||||
|  |     input-label="Your TOML" | ||||||
|  |     input-placeholder="Paste your TOML here..." | ||||||
|  |     output-label="YAML from your TOML" | ||||||
|  |     output-language="yaml" | ||||||
|  |     :input-validation-rules="rules" | ||||||
|  |     :transformer="transformer" | ||||||
|  |   /> | ||||||
|  | </template> | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user