mirror of
https://github.com/Fechin/reference.git
synced 2026-11-21 13:34:06 +03:00
Add yaml and toml cheatsheet
This commit is contained in:
1 parent
f243232e70
commit
b8445f3b66
2 files changed
+557
No files matched your search
@@ -0,0 +1,266 @@
|
||||
---
|
||||
title: TOML
|
||||
date: 2020-12-29 20:36:35
|
||||
icon: icon-toml
|
||||
background: bg-red-700
|
||||
tags:
|
||||
categories:
|
||||
- Programming
|
||||
intro: |
|
||||
This is a quick reference cheat sheet to the toml file syntax.
|
||||
---
|
||||
|
||||
|
||||
Getting started {.cols-3}
|
||||
---------------
|
||||
|
||||
### Introduction
|
||||
[TOML](https://toml.io/en/) is a minimal configuration file format that's easy to read due to obvious semantics.
|
||||
- [Document](https://toml.io/en/latest) _(yaml.org)_
|
||||
- [Learn X in Y minutes](https://learnxinyminutes.com/docs/toml/) _(learnxinyminutes.com)_
|
||||
|
||||
|
||||
|
||||
|
||||
### Examples
|
||||
```toml
|
||||
bool = true
|
||||
date = 2006-05-27T07:32:00Z
|
||||
string = "hello"
|
||||
number = 42
|
||||
float = 3.14
|
||||
scientificNotation = 1e+12
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Comments
|
||||
```yaml
|
||||
# A single line comment example
|
||||
|
||||
# block level comment example
|
||||
# comment line 1
|
||||
# comment line 2
|
||||
# comment line 3
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Integer
|
||||
```toml
|
||||
int1 = +42
|
||||
int2 = 0
|
||||
int3 = -21
|
||||
integerRange = 64
|
||||
```
|
||||
|
||||
|
||||
### Float
|
||||
```toml
|
||||
float2 = 3.1415
|
||||
float4 = 5e+22
|
||||
float7 = 6.626e-34
|
||||
```
|
||||
|
||||
|
||||
### Boolean
|
||||
```toml
|
||||
bool1 = true
|
||||
bool2 = false
|
||||
boolMustBeLowercase = true
|
||||
```
|
||||
|
||||
|
||||
### Datetime
|
||||
```toml
|
||||
date1 = 1989-05-27T07:32:00Z
|
||||
date2 = 1989-05-26T15:32:00-07:00
|
||||
date3 = 1989-05-27T07:32:00
|
||||
date4 = 1989-05-27
|
||||
time1 = 07:32:00
|
||||
time2 = 00:32:00.999999
|
||||
```
|
||||
|
||||
|
||||
### String
|
||||
```toml
|
||||
str1 = "I'm a string."
|
||||
str2 = "You can \"quote\" me."
|
||||
str3 = "Name\tJos\u00E9\nLoc\tSF."
|
||||
```
|
||||
See: [Strings](#strings)
|
||||
|
||||
|
||||
|
||||
|
||||
### Table
|
||||
```toml
|
||||
[owner]
|
||||
name = "Tom Preston-Werner"
|
||||
dob = 1979-05-27T07:32:00-08:00
|
||||
```
|
||||
See: [Tables](#tables)
|
||||
|
||||
|
||||
### Array
|
||||
```toml
|
||||
array1 = [1, 2, 3]
|
||||
array2 = ["Commas", "are", "delimiter"]
|
||||
array3 = [8001, 8001, 8002]
|
||||
```
|
||||
|
||||
### Friendly Array {.col-span-2}
|
||||
```toml
|
||||
array1 = [ "Don't mix", "different", "types" ]
|
||||
array2 = [ [ 1.2, 2.4 ], ["all", 'strings', """are the same""", '''type'''] ]
|
||||
array3 = [
|
||||
"Whitespace", "is",
|
||||
"ignored"
|
||||
]
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Strings {.cols-3}
|
||||
-----
|
||||
|
||||
|
||||
|
||||
### Multiline String
|
||||
```toml
|
||||
multiLineString = """
|
||||
are surrounded by three quotation marks
|
||||
on each side and allow newlines."""
|
||||
```
|
||||
|
||||
|
||||
### Literal String
|
||||
```toml {.wrap}
|
||||
path = 'C:\Users\nodejs\templates'
|
||||
path2 = '\\User\admin$\system32'
|
||||
quoted = 'Tom "Dubs" Preston-Werner'
|
||||
regex = '<\i\c*\s*>'
|
||||
```
|
||||
Surrounded by single quotes. Escaping are not allowed.
|
||||
|
||||
|
||||
### MultiLine Literal String
|
||||
```toml
|
||||
re = '''\d{2} apps is t[wo]o many'''
|
||||
lines = '''
|
||||
The first newline is
|
||||
trimmed in raw strings.
|
||||
All other whitespace
|
||||
is preserved.
|
||||
'''
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
Tables {.cols-3}
|
||||
-----
|
||||
### Basic
|
||||
```toml
|
||||
[name]
|
||||
foo = 1
|
||||
bar = 2
|
||||
```
|
||||
`foo` and `bar` are keys in the table called `name`
|
||||
|
||||
|
||||
### Nested
|
||||
```toml
|
||||
[table1]
|
||||
foo = "bar"
|
||||
|
||||
[table1.nested_table]
|
||||
baz = "bat"
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
### Array-like {.row-span-2}
|
||||
```toml
|
||||
[[comments]]
|
||||
author = "Nate"
|
||||
text = "Great Article!"
|
||||
|
||||
[[comments]]
|
||||
author = "Anonymous"
|
||||
text = "Love it!"
|
||||
```
|
||||
#### Equivalent JSON
|
||||
```json
|
||||
{
|
||||
"comments" : [
|
||||
{
|
||||
"author" : "Nate",
|
||||
"text" : "Great Article!"
|
||||
},
|
||||
{
|
||||
"author" : "Anonymous",
|
||||
"text" : "Love It!"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Dot separated
|
||||
```toml
|
||||
[dog."tater.man"]
|
||||
type = "pug"
|
||||
```
|
||||
#### Equivalent JSON
|
||||
```json
|
||||
{
|
||||
"dog": {
|
||||
"tater.man": {
|
||||
"type": "pug"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
### Multi-nested
|
||||
```toml
|
||||
[foo.bar.baz]
|
||||
bat = "hi"
|
||||
```
|
||||
#### Equivalent JSON
|
||||
```json
|
||||
{
|
||||
"foo" : {
|
||||
"bar" : {
|
||||
"baz" : {
|
||||
"bat" : "hi"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Ignore whitespace
|
||||
```toml
|
||||
[a.b.c] # this is best practice
|
||||
[ d.e.f ] # same as [d.e.f]
|
||||
[ g . h .i ] # same as [g.h.i]
|
||||
[ j . "ʞ" .'l' ] # same as [j."ʞ".'l']
|
||||
```
|
||||
|
||||
### Inline Table {.col-span-2}
|
||||
```toml
|
||||
name = { first = "Tom", last = "Preston-Werner" }
|
||||
point = { x = 1, y = 2 }
|
||||
animal = { type.name = "pug" }
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,291 @@
|
||||
---
|
||||
title: YAML
|
||||
date: 2020-12-29 18:26:55
|
||||
icon: icon-yaml
|
||||
background: bg-gray-700
|
||||
tags:
|
||||
categories:
|
||||
- Programming
|
||||
intro: |
|
||||
This is a quick reference cheat sheet for understanding and writing in YAML.
|
||||
---
|
||||
|
||||
Getting started {.cols-3}
|
||||
---------------
|
||||
|
||||
### Introduction
|
||||
[YAML](https://yaml.org/) is a data serialisation language designed to be directly writable and readable by humans
|
||||
- [Refcard](https://yaml.org/refcard.html) _(yaml.org)_
|
||||
- [Learn X in Y minutes](https://learnxinyminutes.com/docs/yaml/) _(learnxinyminutes.com)_
|
||||
- [YAML lint](http://www.yamllint.com/) _(yamllint.com)_
|
||||
|
||||
|
||||
### Scalar types {.row-span-2}
|
||||
```yaml
|
||||
n1: 1 # integer
|
||||
n2: 1.234 # float
|
||||
|
||||
s1: 'abc' # string
|
||||
s2: "abc" # string
|
||||
s3: abc # string
|
||||
|
||||
b: false # boolean type
|
||||
|
||||
d: 2015-04-05 # date type
|
||||
```
|
||||
#### Equavalent JSON
|
||||
```json {.wrap}
|
||||
{
|
||||
"n1": 1,
|
||||
"n2": 1.234,
|
||||
"s1": "abc",
|
||||
"s2": "abc",
|
||||
"s3": "abc",
|
||||
"b": false,
|
||||
"d": "2015-04-05"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
### Variables
|
||||
```yaml
|
||||
some_thing: &VAR_NAME foobar
|
||||
other_thing: *VAR_NAME
|
||||
```
|
||||
#### Equavalent JSON
|
||||
```json {.wrap}
|
||||
{
|
||||
"some_thing": "foobar",
|
||||
"other_thing": "foobar"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Sequence
|
||||
```yaml
|
||||
object:
|
||||
attributes:
|
||||
- a1
|
||||
- a2
|
||||
- a3
|
||||
methods: [getter, setter]
|
||||
```
|
||||
#### Equavalent JSON
|
||||
```json {.wrap}
|
||||
{
|
||||
"object": {
|
||||
"attributes": ["a1", "a2", "a3"],
|
||||
"methods": ["getter", "setter"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Sequence of sequences
|
||||
```yaml
|
||||
my_sequences:
|
||||
- [1, 2, 3]
|
||||
- [4, 5, 6]
|
||||
```
|
||||
#### Equavalent JSON
|
||||
```json {.wrap}
|
||||
{
|
||||
"my_sequences": [
|
||||
[1, 2, 3],
|
||||
[4, 5, 6]
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Comments
|
||||
```yaml
|
||||
# A single line comment example
|
||||
|
||||
# block level comment example
|
||||
# comment line 1
|
||||
# comment line 2
|
||||
# comment line 3
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Multiline strings
|
||||
```yaml
|
||||
description: |
|
||||
hello
|
||||
world
|
||||
```
|
||||
#### Equavalent JSON
|
||||
```json {.wrap}
|
||||
{"description": "hello\nworld\n"}
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Folded text
|
||||
```yaml
|
||||
description: >
|
||||
hello
|
||||
world
|
||||
```
|
||||
#### Equavalent JSON
|
||||
```json {.wrap}
|
||||
{"description": "hello world\n"}
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Hashes
|
||||
```yaml
|
||||
jack:
|
||||
id: 1
|
||||
name: Franc
|
||||
salary: 5000
|
||||
hobby:
|
||||
- a
|
||||
- b
|
||||
loc: {country: "A", city: "A-A"}
|
||||
```
|
||||
#### Equavalent JSON
|
||||
```json {.wrap}
|
||||
{
|
||||
"jack": {
|
||||
"id": 1,
|
||||
"name": "Franc",
|
||||
"salary": 5000,
|
||||
"hobby": ["a", "b"],
|
||||
"loc": {
|
||||
"country": "A", "city": "A-A"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Nested dictionaries
|
||||
```yaml
|
||||
Employee:
|
||||
id: 1
|
||||
name: "Franc"
|
||||
department:
|
||||
name: "Sales"
|
||||
depid: "11"
|
||||
```
|
||||
#### Equavalent JSON
|
||||
```json {.wrap}
|
||||
{
|
||||
"Employee": {
|
||||
"id": 1,
|
||||
"name": "Franc",
|
||||
"department": {
|
||||
"name": "Sales",
|
||||
"depid": "11"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
### Sequence of dictionaries
|
||||
```yaml
|
||||
children:
|
||||
- name: Jimmy Smith
|
||||
age: 15
|
||||
- name: Jenny Smith
|
||||
age: 12
|
||||
```
|
||||
#### Equavalent JSON
|
||||
```json {.wrap}
|
||||
{
|
||||
"children": [
|
||||
{"name": "Jimmy Smith", "age": 15},
|
||||
{"name": "Jenny Smith", "age": 12}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Set
|
||||
```yaml
|
||||
set1: !!set
|
||||
? one
|
||||
? two
|
||||
set2: !!set {'one', "two"}
|
||||
```
|
||||
#### Equavalent JSON
|
||||
```json {.wrap}
|
||||
{
|
||||
"set1": {"one": null, "two": null},
|
||||
"set2": {"one": null, "two": null}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Inheritance {.row-span-2}
|
||||
```yaml
|
||||
parent: &defaults
|
||||
a: 2
|
||||
b: 3
|
||||
|
||||
child:
|
||||
<<: *defaults
|
||||
b: 4
|
||||
```
|
||||
#### Equavalent JSON
|
||||
```json {.wrap}
|
||||
{
|
||||
"parent": {"a": 2, "b": 3},
|
||||
"child": {"a": 2, "b": 4}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Reference {.row-span-2}
|
||||
```yaml
|
||||
values: &ref
|
||||
- These values
|
||||
- will be reused below
|
||||
|
||||
other_values:
|
||||
i_am_ref: *ref
|
||||
```
|
||||
#### Equavalent JSON
|
||||
```json {.wrap}
|
||||
{
|
||||
"values": [
|
||||
"These values",
|
||||
"will be reused below"
|
||||
],
|
||||
"other_values": {
|
||||
"i_am_ref": [
|
||||
"These values",
|
||||
"will be reused below"
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
### Documents
|
||||
```yaml
|
||||
---
|
||||
document: this is doc 1
|
||||
---
|
||||
document: this is doc 2
|
||||
...
|
||||
```
|
||||
|
||||
Reference in new issue
Block a user