-
Notifications
You must be signed in to change notification settings - Fork 0
Patch
patch(yamlString)
is an immutable class function to patch yamlString
according to its object methods. This class is used in Ryaml.patch()
Each object methods will return a new patch(yamlString)
with updated YAML string.
Each instantiation should be carried out using ordinary function call.
Parameter | Type | Description | Default | Required |
---|---|---|---|---|
yamlString |
string |
YAML in Javascript string | — | Yes |
Keypairs will be wrapped into 2 lines, trailed with trailingScalar
for the interconnection in-between.
It will wrap from
foo: bar
to
foo: _trailingScalar_
bar
Parameter | Type | Description | Default | Required |
---|---|---|---|---|
tabSize |
number |
Size of tab, meant to be soft tab | — | Yes |
trailingScalar |
string |
String appending after key and colon | "" |
No |
Return | Type | Description |
---|---|---|
* | Patch |
Immutable patcher object |
const { Ryaml } = require('reyaml-core');
console.log(new Ryaml('foo: bar')
.patch(p => p.wrapKeyPair({
tabSize: 2,
trailingScalar: '|-'
}))
.raw);
// foo: |-\n bar\n
Append block scalar to YAML line with key & colon only
foo: _blockScalar_
bar
Parameter | Type | Description | Default | Required |
---|---|---|---|---|
blockScalar |
string |
Block scalar to be appended | — | Yes |
Return | Type | Description |
---|---|---|
* | Patch |
Immutable patcher object |
const { Ryaml } = require('reyaml-core');
console.log(new Ryaml('foo:\n bar')
.patch(p => p.appendBlockScalar({
blockScalar: '|-'
}))
.raw);
// foo: |-\n bar\n
Remove all empty lines matching the following rules. Empty lines are defined as lines not affecting parsing in js-yaml
.
- Line with only whitespaces
- Comment
Return | Type | Description |
---|---|---|
* | Patch |
Immutable patcher object |
const { Ryaml } = require('reyaml-core');
console.log(new Ryaml('foo:\n\n\t\n\n bar').patch(p => p.removeEmptyLine()).raw);
// foo:\n bar\n
Transform all matching block scalars in blockScalarMap
into destinating block scalar universally. This transformation will be applied to all lines without exception.
blockScalarMap
{
"|-": ">-", /* Convert from literal-strip to folded-strip */
"|+": ">+", /* Convert from literal-keep to folded-keep */
}
Parameter | Type | Description | Default | Required |
---|---|---|---|---|
blockScalarMap |
Object |
Map between transformee and transformer | — | Yes |
Return | Type | Description |
---|---|---|
* | Patch |
Immutable patcher object |
const { Ryaml } = require('reyaml-core');
console.log(new Ryaml('foo: |-\n bar')
.patch(p => p.unifyBlockScalar({
blockScalarMap: { '|-': '>-' }
}))
.raw);
// foo: >-\n bar\n
Patch each key with postfix
.
foo_postfix_: bar
lorem_postfix_:
ipsum
Parameter | Type | Description | Default | Required |
---|---|---|---|---|
postfix |
string |
Postfix for each key | — | Yes |
Return | Type | Description |
---|---|---|
* | Patch |
Immutable patcher object |
const { Ryaml } = require('reyaml-core');
console.log(new Ryaml('foo: bar')
.patch(p => p.appendKey({
postfix: '_POSTFIX_'
}))
.raw);
// foo_POSTFIX_: bar
Delete all array in YAML with size 1.
It will change from
foo:
- lorem: ipsum
reyaml: core
to
foo:
lorem: ipsum
reyaml: core
Return | Type | Description |
---|---|---|
* | Patch |
Immutable patcher object |
const { Ryaml } = require('reyaml-core');
console.log(new Ryaml('foo:\n - lorem: ipsum\n reyaml: core')
.patch(p => p.wipeSingularArray())
.raw);
// foo:\n lorem: ipsum\n reyaml: core
Get underlying YAML string as result.
End of
.patch(p => p)
inRyaml
should returnp
but notp.result()
Return | Type | Description |
---|---|---|
* | string |
Underlying YAML string |
REyaml-Core Wiki page is released under the same license as repository itself.