From 6cfd2faafb1c7258b5ab4462248f25d277a64b14 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Tue, 4 Apr 2023 10:57:30 +0300 Subject: [PATCH] feat: Add export of createNode() & createPair() to yaml/util (#457) --- docs/06_custom_tags.md | 4 +++- src/util.ts | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/06_custom_tags.md b/docs/06_custom_tags.md index 7d3c7c6f..c7c6425c 100644 --- a/docs/06_custom_tags.md +++ b/docs/06_custom_tags.md @@ -99,7 +99,7 @@ stringify( In YAML-speak, a custom data type is represented by a _tag_. To define your own tag, you need to account for the ways that your data is both parsed and stringified. Furthermore, both of those processes are split into two stages by the intermediate AST node structure. -If you wish to implement your own custom tags, the [`!!binary`](https://github.com/eemeli/yaml/blob/main/src/tags/yaml-1.1/binary.js) and [`!!set`](https://github.com/eemeli/yaml/blob/main/src/tags/yaml-1.1/set.js) tags provide relatively cohesive examples to study in addition to the simple examples in the sidebar here. +If you wish to implement your own custom tags, the [`!!binary`](https://github.com/eemeli/yaml/blob/main/src/schema/yaml-1.1/binary.ts) and [`!!set`](https://github.com/eemeli/yaml/blob/main/src/schema/yaml-1.1/set.ts) tags provide relatively cohesive examples to study in addition to the simple examples in the sidebar here. ### Parsing Custom Data @@ -135,6 +135,8 @@ For collections in particular, the default stringifier should be perfectly suffi ```js import { + createNode, // (value, tagName, ctx) => Node -- Create a new node + createPair, // (key, value, ctx) => Pair -- Create a new pair debug, // (logLevel, ...messages) => void -- Log debug messages to console findPair, // (items, key) => Pair? -- Given a key, find a matching Pair foldFlowLines, // (text, indent, mode, options) => string -- Fold long lines diff --git a/src/util.ts b/src/util.ts index b0e0848e..dd92a80d 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,4 +1,6 @@ +export { createNode, CreateNodeContext } from './doc/createNode.js' export { debug, LogLevelId, warn } from './log.js' +export { createPair } from './nodes/Pair.js' export { findPair } from './nodes/YAMLMap.js' export { toJS, ToJSContext } from './nodes/toJS.js' export { map as mapTag } from './schema/common/map.js'