-
Notifications
You must be signed in to change notification settings - Fork 0
Ryaml
Ryaml
is an immutable Object which wraps a YAML string as source reference.
The main usage of Ryaml
is to transform the underlying YAML string into Rjson
using .toRjson()
, while literal alteration on YAML is also supported via .patch()
.
Each instantiation should be carried out using new
operator.
Parameter | Type | Description | Default Value |
---|---|---|---|
raw |
string |
YAML in Javascript string | — |
config |
Object |
Environment configuration | require('./config.js') |
Determine whenever it is a junk line according to the following rules.
- Line with only whitespaces
- Comment
- Array separator (i.e.
---
)
Parameter | Type | Description | Default Value |
---|---|---|---|
line |
string |
YAML line in Javascript string | — |
Return | Type | Description |
---|---|---|
* | boolean |
Is junk line or not |
Count number of junk lines (e.g. empty line) in YAML string. Same set of rules from Ryaml.isJunkLine({ line })
is adopted.
Parameter | Type | Description | Default Value |
---|---|---|---|
lineNo |
number |
For gettng junk line before given line number | — |
Return | Type | Description |
---|---|---|
* | number |
Number of junk lines before lineNo
|
Patch YAML string with given patcher function. The patching behaviour is performed through Regex and string processing, which means YAML string itself will not be parsed in the using of this method. Please view Patch API for usage on patcher
.
Parameter | Type | Description | Default Value |
---|---|---|---|
patcher |
Function |
For actual patching the original YAML literal string via string processing. patcher should return itself at the end of lambda function |
— |
Return | Type | Description |
---|---|---|
* | Ryaml |
Immutable Ryaml with new YAML string |
const { Ryaml } = require('reyaml-core');
const ry = new Ryaml('foo: bar');
ry.patch(p => p.removeEmptyLine().wipeSingularArray());
// or
ry.patch(p => { return p.removeEmptyLine().wipeSingularArray() });
Convert to Rjson
object. Additional behaviours can be applied to the conversion procedure by supplying profile
.
Parameter | Type | Description | Default Value |
---|---|---|---|
profile |
string |
Profile name for regarding additional behaviours | default |
Return | Type | Description |
---|---|---|
* | Rjson |
Immutable Rjson with converted JSON Object |
-
default
- Passthrough without YAML patching -
d3Tree
- Patch YAML exclusively for D3 Hierarchy. It will ...- Remove empty lines; and
- Remove singular array; and
- Wrap key pair to 2-liner; and
- Append key postfix
const { Ryaml } = require('reyaml-core');
const ry = new Ryaml('foo: bar');
ry.toRjson({ profile: 'd3Tree' }).toD3({ profile: 'd3Tree' });
REyaml-Core Wiki page is released under the same license as repository itself.