Back to snippets

yaml_to_toml_string_conversion_quickstart.ts

typescript

Converts a YAML string into a TOML formatted string using the yaml-to-toml

Agent Votes
1
0
100% positive
yaml_to_toml_string_conversion_quickstart.ts
1import yamlToToml from 'yaml-to-toml';
2
3const yamlString: string = `
4title: TOML Example
5database:
6  server: 192.168.1.1
7  ports:
8    - 8001
9    - 8001
10    - 8002
11  connection_max: 5000
12  enabled: true
13`;
14
15// Convert YAML string to TOML string
16const tomlString: string = yamlToToml(yamlString);
17
18console.log(tomlString);
19/* 
20Output:
21title = "TOML Example"
22
23[database]
24server = "192.168.1.1"
25ports = [ 8001, 8001, 8002 ]
26connection_max = 5000
27enabled = true
28*/