-
Notifications
You must be signed in to change notification settings - Fork 0
Ryaml
Ryaml
is an immutable class 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 | Required |
---|---|---|---|---|
raw |
string |
YAML in Javascript string | — | Yes |
config |
Object |
Environment configuration | require('./config.js') |
No |
Determine whenever it is a junk line according to the following rules. Junk line is defined as non-informative line.
- Line with only whitespaces
- Comment
- Array separator (i.e.
---
)
Parameter | Type | Description | Default | Required |
---|---|---|---|---|
line |
string |
YAML line in Javascript string | — | Yes |
Return | Type | Description |
---|---|---|
* | boolean |
Is junk line or not |
Underlying immutable YAML string (i.e. Update .raw
will not alter Ryaml
).
Accessibility | |
---|---|
Getter | Yes |
Setter | No |
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 | Required |
---|---|---|---|---|
lineNo |
number |
For getting junk line before given line number, unset to be counting all lines | — | No |
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 | Required |
---|---|---|---|---|
patcher |
Patch |
For actual patching the original YAML literal string via string processing. patcher should return itself at the end of lambda function |
— | Yes |
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 | Required |
---|---|---|---|---|
profile |
string |
Profile name for regarding additional behaviours | "default" |
No |
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
d3Tree uses the variables from config ->
blockScalarTranslation
,size.tabSize
,symbol.keyPostfix
,wrapKeyPairScalar
,appendBlockScalar
.
const { Ryaml } = require('reyaml-core');
const ry = new Ryaml('foo: bar');
console.log(ry.toRjson({ profile: 'd3Tree' }).toD3({ profile: 'd3Tree' }));
REyaml-Core Wiki page is released under the same license as repository itself.