feat(new-tool): yaml to toml
This commit is contained in:
		
							parent
							
								
									ea50a3fc65
								
							
						
					
					
						commit
						e29b258e90
					
				
							
								
								
									
										7
									
								
								components.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										7
									
								
								components.d.ts
									
									
									
									
										vendored
									
									
								
							| @ -83,6 +83,7 @@ declare module '@vue/runtime-core' { | |||||||
|     JsonDiff: typeof import('./src/tools/json-diff/json-diff.vue')['default'] |     JsonDiff: typeof import('./src/tools/json-diff/json-diff.vue')['default'] | ||||||
|     JsonMinify: typeof import('./src/tools/json-minify/json-minify.vue')['default'] |     JsonMinify: typeof import('./src/tools/json-minify/json-minify.vue')['default'] | ||||||
|     JsonToCsv: typeof import('./src/tools/json-to-csv/json-to-csv.vue')['default'] |     JsonToCsv: typeof import('./src/tools/json-to-csv/json-to-csv.vue')['default'] | ||||||
|  |     JsonToToml: typeof import('./src/tools/json-to-toml/json-to-toml.vue')['default'] | ||||||
|     JsonToYaml: typeof import('./src/tools/json-to-yaml-converter/json-to-yaml.vue')['default'] |     JsonToYaml: typeof import('./src/tools/json-to-yaml-converter/json-to-yaml.vue')['default'] | ||||||
|     JsonViewer: typeof import('./src/tools/json-viewer/json-viewer.vue')['default'] |     JsonViewer: typeof import('./src/tools/json-viewer/json-viewer.vue')['default'] | ||||||
|     JwtParser: typeof import('./src/tools/jwt-parser/jwt-parser.vue')['default'] |     JwtParser: typeof import('./src/tools/jwt-parser/jwt-parser.vue')['default'] | ||||||
| @ -98,7 +99,6 @@ declare module '@vue/runtime-core' { | |||||||
|     MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default'] |     MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default'] | ||||||
|     MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default'] |     MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default'] | ||||||
|     NAlert: typeof import('naive-ui')['NAlert'] |     NAlert: typeof import('naive-ui')['NAlert'] | ||||||
|     NAutoComplete: typeof import('naive-ui')['NAutoComplete'] |  | ||||||
|     NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default'] |     NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default'] | ||||||
|     NCheckbox: typeof import('naive-ui')['NCheckbox'] |     NCheckbox: typeof import('naive-ui')['NCheckbox'] | ||||||
|     NCode: typeof import('naive-ui')['NCode'] |     NCode: typeof import('naive-ui')['NCode'] | ||||||
| @ -149,8 +149,6 @@ declare module '@vue/runtime-core' { | |||||||
|     RouterLink: typeof import('vue-router')['RouterLink'] |     RouterLink: typeof import('vue-router')['RouterLink'] | ||||||
|     RouterView: typeof import('vue-router')['RouterView'] |     RouterView: typeof import('vue-router')['RouterView'] | ||||||
|     RsaKeyPairGenerator: typeof import('./src/tools/rsa-key-pair-generator/rsa-key-pair-generator.vue')['default'] |     RsaKeyPairGenerator: typeof import('./src/tools/rsa-key-pair-generator/rsa-key-pair-generator.vue')['default'] | ||||||
|     SearchBar: typeof import('./src/components/SearchBar.vue')['default'] |  | ||||||
|     SearchBarItem: typeof import('./src/components/SearchBarItem.vue')['default'] |  | ||||||
|     SlugifyString: typeof import('./src/tools/slugify-string/slugify-string.vue')['default'] |     SlugifyString: typeof import('./src/tools/slugify-string/slugify-string.vue')['default'] | ||||||
|     SpanCopyable: typeof import('./src/components/SpanCopyable.vue')['default'] |     SpanCopyable: typeof import('./src/components/SpanCopyable.vue')['default'] | ||||||
|     SqlPrettify: typeof import('./src/tools/sql-prettify/sql-prettify.vue')['default'] |     SqlPrettify: typeof import('./src/tools/sql-prettify/sql-prettify.vue')['default'] | ||||||
| @ -161,6 +159,8 @@ declare module '@vue/runtime-core' { | |||||||
|     TextToNatoAlphabet: typeof import('./src/tools/text-to-nato-alphabet/text-to-nato-alphabet.vue')['default'] |     TextToNatoAlphabet: typeof import('./src/tools/text-to-nato-alphabet/text-to-nato-alphabet.vue')['default'] | ||||||
|     TokenDisplay: typeof import('./src/tools/otp-code-generator-and-validator/token-display.vue')['default'] |     TokenDisplay: typeof import('./src/tools/otp-code-generator-and-validator/token-display.vue')['default'] | ||||||
|     'TokenGenerator.tool': typeof import('./src/tools/token-generator/token-generator.tool.vue')['default'] |     'TokenGenerator.tool': typeof import('./src/tools/token-generator/token-generator.tool.vue')['default'] | ||||||
|  |     TomlToJson: typeof import('./src/tools/toml-to-json/toml-to-json.vue')['default'] | ||||||
|  |     TomlToYaml: typeof import('./src/tools/toml-to-yaml/toml-to-yaml.vue')['default'] | ||||||
|     'Tool.layout': typeof import('./src/layouts/tool.layout.vue')['default'] |     'Tool.layout': typeof import('./src/layouts/tool.layout.vue')['default'] | ||||||
|     ToolCard: typeof import('./src/components/ToolCard.vue')['default'] |     ToolCard: typeof import('./src/components/ToolCard.vue')['default'] | ||||||
|     UrlEncoder: typeof import('./src/tools/url-encoder/url-encoder.vue')['default'] |     UrlEncoder: typeof import('./src/tools/url-encoder/url-encoder.vue')['default'] | ||||||
| @ -170,5 +170,6 @@ declare module '@vue/runtime-core' { | |||||||
|     UuidGenerator: typeof import('./src/tools/uuid-generator/uuid-generator.vue')['default'] |     UuidGenerator: typeof import('./src/tools/uuid-generator/uuid-generator.vue')['default'] | ||||||
|     XmlFormatter: typeof import('./src/tools/xml-formatter/xml-formatter.vue')['default'] |     XmlFormatter: typeof import('./src/tools/xml-formatter/xml-formatter.vue')['default'] | ||||||
|     YamlToJson: typeof import('./src/tools/yaml-to-json-converter/yaml-to-json.vue')['default'] |     YamlToJson: typeof import('./src/tools/yaml-to-json-converter/yaml-to-json.vue')['default'] | ||||||
|  |     YamlToToml: typeof import('./src/tools/yaml-to-toml/yaml-to-toml.vue')['default'] | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -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 yamlToToml } from './yaml-to-toml'; | ||||||
| import { tool as jsonToToml } from './json-to-toml'; | import { tool as jsonToToml } from './json-to-toml'; | ||||||
| import { tool as tomlToYaml } from './toml-to-yaml'; | import { tool as tomlToYaml } from './toml-to-yaml'; | ||||||
| import { tool as tomlToJson } from './toml-to-json'; | import { tool as tomlToJson } from './toml-to-json'; | ||||||
| @ -81,6 +82,7 @@ export const toolsByCategory: ToolCategory[] = [ | |||||||
|       caseConverter, |       caseConverter, | ||||||
|       textToNatoAlphabet, |       textToNatoAlphabet, | ||||||
|       yamlToJson, |       yamlToJson, | ||||||
|  |       yamlToToml, | ||||||
|       jsonToYaml, |       jsonToYaml, | ||||||
|       jsonToToml, |       jsonToToml, | ||||||
|       listConverter, |       listConverter, | ||||||
|  | |||||||
							
								
								
									
										12
									
								
								src/tools/yaml-to-toml/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/tools/yaml-to-toml/index.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | |||||||
|  | import { AlignJustified } from '@vicons/tabler'; | ||||||
|  | import { defineTool } from '../tool'; | ||||||
|  | 
 | ||||||
|  | export const tool = defineTool({ | ||||||
|  |   name: 'YAML to TOML', | ||||||
|  |   path: '/yaml-to-toml', | ||||||
|  |   description: 'Parse and convert YAML to TOML.', | ||||||
|  |   keywords: ['yaml', 'to', 'toml', 'convert', 'transform'], | ||||||
|  |   component: () => import('./yaml-to-toml.vue'), | ||||||
|  |   icon: AlignJustified, | ||||||
|  |   createdAt: new Date('2023-06-23'), | ||||||
|  | }); | ||||||
							
								
								
									
										37
									
								
								src/tools/yaml-to-toml/yaml-to-toml.e2e.spec.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/tools/yaml-to-toml/yaml-to-toml.e2e.spec.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,37 @@ | |||||||
|  | import { expect, test } from '@playwright/test'; | ||||||
|  | 
 | ||||||
|  | test.describe('Tool - YAML to TOML', () => { | ||||||
|  |   test.beforeEach(async ({ page }) => { | ||||||
|  |     await page.goto('/yaml-to-toml'); | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  |   test('Has correct title', async ({ page }) => { | ||||||
|  |     await expect(page).toHaveTitle('YAML to TOML - IT Tools'); | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  |   test('JSON is parsed and outputs clean TOML', async ({ page }) => { | ||||||
|  |     await page.getByTestId('input').fill(` | ||||||
|  | foo: bar | ||||||
|  | list: | ||||||
|  |   name: item | ||||||
|  |   another: | ||||||
|  |     key: value | ||||||
|  |     number: 1 | ||||||
|  |     `.trim());
 | ||||||
|  | 
 | ||||||
|  |     const generatedJson = await page.getByTestId('area-content').innerText(); | ||||||
|  | 
 | ||||||
|  |     expect(generatedJson.trim()).toEqual( | ||||||
|  |       ` | ||||||
|  | foo = "bar" | ||||||
|  | 
 | ||||||
|  | [list] | ||||||
|  | name = "item" | ||||||
|  | 
 | ||||||
|  |   [list.another] | ||||||
|  |   key = "value" | ||||||
|  |   number = 1 | ||||||
|  |    `.trim(),
 | ||||||
|  |     ); | ||||||
|  |   }); | ||||||
|  | }); | ||||||
							
								
								
									
										28
									
								
								src/tools/yaml-to-toml/yaml-to-toml.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/tools/yaml-to-toml/yaml-to-toml.vue
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,28 @@ | |||||||
|  | <script setup lang="ts"> | ||||||
|  | import { stringify as stringifyToml } from 'iarna-toml-esm'; | ||||||
|  | import { parse as parseYaml } from 'yaml'; | ||||||
|  | import { withDefaultOnError } from '../../utils/defaults'; | ||||||
|  | import type { UseValidationRule } from '@/composable/validation'; | ||||||
|  | 
 | ||||||
|  | const convertYamlToToml = (value: string) => [stringifyToml(parseYaml(value))].flat().join('\n').trim(); | ||||||
|  | 
 | ||||||
|  | const transformer = (value: string) => value.trim() === '' ? '' : withDefaultOnError(() => convertYamlToToml(value), ''); | ||||||
|  | 
 | ||||||
|  | const rules: UseValidationRule<string>[] = [ | ||||||
|  |   { | ||||||
|  |     validator: (v: string) => v === '' || parseYaml(v), | ||||||
|  |     message: 'Provided JSON is not valid.', | ||||||
|  |   }, | ||||||
|  | ]; | ||||||
|  | </script> | ||||||
|  | 
 | ||||||
|  | <template> | ||||||
|  |   <format-transformer | ||||||
|  |     input-label="Your YAML" | ||||||
|  |     input-placeholder="Paste your YAML here..." | ||||||
|  |     output-label="TOML from your YAML" | ||||||
|  |     output-language="toml" | ||||||
|  |     :input-validation-rules="rules" | ||||||
|  |     :transformer="transformer" | ||||||
|  |   /> | ||||||
|  | </template> | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user