Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: eemeli/yaml
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.9.2
Choose a base ref
...
head repository: eemeli/yaml
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.10.0
Choose a head ref

Commits on Apr 27, 2020

  1. Copy the full SHA
    6c265f6 View commit details
  2. Copy the full SHA
    970bf60 View commit details
  3. Copy the full SHA
    0b08487 View commit details
  4. Copy the full SHA
    0a1f33a View commit details
  5. Copy the full SHA
    142dd24 View commit details

Commits on Apr 28, 2020

  1. Copy the full SHA
    a028ab1 View commit details
  2. Copy the full SHA
    f45c158 View commit details

Commits on May 2, 2020

  1. Merge pull request #162 from eemeli/fix/doc-marker-scalars

    Always indent top-level scalars with lines starting with document markers
    eemeli authored May 2, 2020
    Copy the full SHA
    f19f1af View commit details
  2. Copy the full SHA
    d25f3aa View commit details
  3. Copy the full SHA
    298f2fc View commit details
  4. Copy the full SHA
    d3461d3 View commit details
  5. Copy the full SHA
    d6594ed View commit details
  6. Copy the full SHA
    868259f View commit details
  7. Copy the full SHA
    8f000c1 View commit details
  8. Copy the full SHA
    0454158 View commit details
  9. Add src/schema/index.js as re-exporter

    schema/Schema depends on tags, so they can't use the re-exporter.
    eemeli committed May 2, 2020
    Copy the full SHA
    4528dac View commit details
  10. Copy the full SHA
    87144fa View commit details

Commits on May 3, 2020

  1. Copy the full SHA
    154fe0b View commit details
  2. Copy the full SHA
    c025a11 View commit details
  3. Copy the full SHA
    74f5f81 View commit details
  4. Copy the full SHA
    50e5bfc View commit details
  5. Copy the full SHA
    29fd375 View commit details
  6. Refactor Schema.stringify into its own function

    Also refactors Schema.getTagObject & Schema.stringifyProps
    eemeli committed May 3, 2020
    Copy the full SHA
    89ac4cb View commit details
  7. Copy the full SHA
    a7bc387 View commit details
  8. Copy the full SHA
    6684ee4 View commit details
  9. Copy the full SHA
    ab79f14 View commit details
  10. Copy the full SHA
    6d70a6d View commit details
  11. Copy the full SHA
    9e29f9b View commit details
  12. Copy the full SHA
    4efcd5e View commit details
  13. Copy the full SHA
    537b76e View commit details
  14. Copy the full SHA
    cefbbd9 View commit details
  15. Copy the full SHA
    38bcf11 View commit details
  16. Copy the full SHA
    41cd7a9 View commit details
  17. Copy the full SHA
    783f6d3 View commit details
  18. Copy the full SHA
    d8e5916 View commit details
  19. Copy the full SHA
    87f66aa View commit details
  20. Copy the full SHA
    c2f1106 View commit details
  21. Copy the full SHA
    b95f2d2 View commit details
  22. Drop dependency on @babel/runtime

    For some reason, with Rollup the bundled library is _bigger_ if we leave
    in a runtime dependency on @babel/runtime. I don't know why.
    eemeli committed May 3, 2020
    Copy the full SHA
    67ba1a1 View commit details
  23. Update docs: No dependencies!

    eemeli committed May 3, 2020
    Copy the full SHA
    5abe9d8 View commit details

Commits on May 6, 2020

  1. Copy the full SHA
    5a76185 View commit details

Commits on May 7, 2020

  1. Copy the full SHA
    0426e4a View commit details

Commits on May 9, 2020

  1. Copy the full SHA
    3900895 View commit details
  2. Merge pull request #165 from eemeli/rollup

    Switch browser build to use Rollup, drop @babel/runtime dependency
    eemeli authored May 9, 2020
    Copy the full SHA
    bf0dc20 View commit details
  3. Update dev & playground dependencies, including eslint 7 & jest 26

    Also switch Jest testEnvironment to "node", due to this bug:
    jestjs/jest#9983
    eemeli committed May 9, 2020
    Copy the full SHA
    a007299 View commit details
  4. Copy the full SHA
    8dfd0be View commit details
  5. Copy the full SHA
    67ed971 View commit details
  6. Copy the full SHA
    9fe7cd3 View commit details
  7. Copy the full SHA
    665d363 View commit details
  8. Copy the full SHA
    8f3f8f1 View commit details
Showing with 3,657 additions and 3,426 deletions.
  1. +0 −15 .babelrc.js
  2. +4 −0 .travis.yml
  3. +4 −4 README.md
  4. +9 −0 babel.config.js
  5. +1 −1 browser/index.js
  6. +2 −4 browser/map.js
  7. +2 −4 browser/pair.js
  8. +1 −1 browser/parse-cst.js
  9. +2 −4 browser/scalar.js
  10. +7 −10 browser/schema.js
  11. +2 −4 browser/seq.js
  12. +1 −13 browser/types.js
  13. +7 −5 browser/types/binary.js
  14. +3 −4 browser/types/omap.js
  15. +3 −4 browser/types/pairs.js
  16. +3 −4 browser/types/set.js
  17. +9 −5 browser/types/timestamp.js
  18. +1 −18 browser/util.js
  19. +1 −1 docs-slate
  20. +1 −1 docs/01_intro.md
  21. +3 −2 docs/03_options.md
  22. +9 −8 docs/04_documents.md
  23. +1 −1 docs/05_content_nodes.md
  24. +22 −8 index.d.ts
  25. +39 −0 jest.config.js
  26. +2 −2 map.js
  27. +1,537 −1,693 package-lock.json
  28. +22 −39 package.json
  29. +2 −2 pair.js
  30. +1 −1 parse-cst.js
  31. +1 −1 playground
  32. +18 −0 rollup.browser-config.js
  33. +19 −0 rollup.node-config.js
  34. +2 −2 scalar.js
  35. +8 −6 schema.js
  36. +2 −2 seq.js
  37. +0 −638 src/Document.js
  38. +6 −6 src/{schema → ast}/Alias.js
  39. +6 −6 src/{schema → ast}/Collection.js
  40. +4 −4 src/{schema → ast}/Merge.js
  41. 0 src/{schema → ast}/Node.js
  42. +19 −15 src/{schema → ast}/Pair.js
  43. +2 −4 src/{schema → ast}/Scalar.js
  44. +3 −3 src/{schema/Map.js → ast/YAMLMap.js}
  45. +3 −5 src/{schema/Seq.js → ast/YAMLSeq.js}
  46. +10 −0 src/ast/index.js
  47. 0 src/{ → ast}/toJSON.js
  48. +7 −0 src/constants.js
  49. +2 −2 src/cst/Alias.js
  50. +3 −3 src/cst/BlankLine.js
  51. +18 −9 src/cst/BlockValue.js
  52. +25 −18 src/cst/Collection.js
  53. +5 −5 src/cst/CollectionItem.js
  54. +3 −3 src/cst/Comment.js
  55. +3 −3 src/cst/Directive.js
  56. +8 −8 src/cst/Document.js
  57. +6 −6 src/cst/FlowCollection.js
  58. +3 −3 src/cst/Node.js
  59. +16 −14 src/cst/ParseContext.js
  60. +19 −6 src/cst/PlainValue.js
  61. +3 −3 src/cst/QuoteDouble.js
  62. +3 −3 src/cst/QuoteSingle.js
  63. +2 −2 src/cst/parse.js
  64. +5 −5 src/{ → doc}/Anchors.js
  65. +270 −0 src/doc/Document.js
  66. +52 −0 src/doc/Schema.js
  67. +64 −0 src/doc/createNode.js
  68. +31 −0 src/doc/getSchemaTags.js
  69. +1 −3 src/{ → doc}/listTagNames.js
  70. +55 −0 src/doc/parseContents.js
  71. +79 −0 src/doc/parseDirectives.js
  72. +3 −3 src/errors.js
  73. +6 −60 src/index.js
  74. +7 −0 src/legacy-exports.js
  75. +83 −0 src/options.js
  76. +14 −19 src/{schema/parseUtils.js → resolve/collection-utils.js}
  77. +28 −29 src/{schema/parseMap.js → resolve/resolveMap.js}
  78. +142 −0 src/resolve/resolveNode.js
  79. +18 −0 src/resolve/resolveScalar.js
  80. +30 −12 src/{schema/parseSeq.js → resolve/resolveSeq.js}
  81. +11 −0 src/resolve/resolveString.js
  82. +69 −0 src/resolve/resolveTag.js
  83. +75 −0 src/resolve/resolveTagName.js
  84. +0 −284 src/schema/index.js
  85. 0 src/{ → stringify}/addComment.js
  86. 0 src/{ → stringify}/foldFlowLines.js
  87. +92 −0 src/stringify/stringify.js
  88. +21 −0 src/stringify/stringifyNumber.js
  89. +25 −33 src/{stringify.js → stringify/stringifyString.js}
  90. +28 −0 src/stringify/stringifyTag.js
  91. +4 −4 src/tags/core.js
  92. +3 −3 src/tags/failsafe/index.js
  93. +3 −3 src/tags/failsafe/map.js
  94. +3 −3 src/tags/failsafe/seq.js
  95. +3 −14 src/tags/failsafe/string.js
  96. +11 −11 src/tags/index.js
  97. +5 −5 src/tags/json.js
  98. +1 −1 src/tags/options.js
  99. +5 −5 src/tags/yaml-1.1/binary.js
  100. +9 −9 src/tags/yaml-1.1/index.js
  101. +7 −7 src/tags/yaml-1.1/omap.js
  102. +6 −6 src/tags/yaml-1.1/pairs.js
  103. +6 −6 src/tags/yaml-1.1/set.js
  104. +1 −1 src/tags/yaml-1.1/timestamp.js
  105. +2 −2 src/test-events.js
  106. +19 −0 src/types.js
  107. +15 −0 src/util.js
  108. +3 −3 tests/cst/Node.js
  109. +8 −8 tests/cst/YAML-1.2.spec.js
  110. +1 −1 tests/cst/common.js
  111. +1 −1 tests/cst/corner-cases.js
  112. +1 −1 tests/cst/parse.js
  113. +3 −3 tests/cst/set-value.js
  114. +2 −2 tests/cst/source-utils.js
  115. +1 −1 tests/doc/YAML-1.1.spec.js
  116. +18 −20 tests/doc/YAML-1.2.spec.js
  117. +3 −3 tests/doc/anchors.js
  118. +2 −2 tests/doc/collection-access.js
  119. +34 −2 tests/doc/comments.js
  120. +3 −6 tests/doc/createNode.js
  121. +62 −7 tests/doc/errors.js
  122. +2 −2 tests/doc/foldFlowLines.js
  123. +1 −1 tests/doc/parse.js
  124. +59 −4 tests/doc/stringify.js
  125. +5 −6 tests/doc/types.js
  126. +1 −1 tests/properties.js
  127. +8 −4 tests/typings.ts
  128. +1 −1 tests/yaml-test-suite
  129. +7 −4 tests/yaml-test-suite.js
  130. +113 −99 types.d.ts
  131. +16 −11 types.js
  132. +15 −19 types.mjs
  133. +3 −2 types/binary.js
  134. +3 −2 types/omap.js
  135. +3 −2 types/pairs.js
  136. +3 −2 types/set.js
  137. +6 −6 types/timestamp.js
  138. +14 −14 util.js
  139. +13 −20 util.mjs
15 changes: 0 additions & 15 deletions .babelrc.js

This file was deleted.

4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -3,6 +3,10 @@ node_js:
- 'node'
- 'lts/*'

script:
- npm test
- npm run test:dist

addons:
browserstack:
username: eemeliaro2
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,16 +2,16 @@

`yaml` is a JavaScript parser and stringifier for [YAML](http://yaml.org/), a human friendly data serialization standard. It supports both parsing and stringifying data using all versions of YAML, along with all common data schemas. As a particularly distinguishing feature, `yaml` fully supports reading and writing comments and blank lines in YAML documents.

The library is released under the ISC open source license, and the code is [available on GitHub](https://github.com/eemeli/yaml/). It runs on Node.js 6 and later with no external dependencies, and in browsers from IE 11 upwards (Note: `@babel/runtime` is used only by the `"browser"` entry point).
The library is released under the ISC open source license, and the code is [available on GitHub](https://github.com/eemeli/yaml/). It has no external dependencies and runs on Node.js 6 and later, and in browsers from IE 11 upwards.

For the purposes of versioning, any changes that break any of the endpoints or APIs documented here will be considered semver-major breaking changes. Undocumented library internals may change between minor versions, and previous APIs may be deprecated (but not removed).

For more information, see the project's documentation site: [**eemeli.org/yaml**](https://eemeli.org/yaml/)

> To install:
To install:

```sh
npm install yaml
# or
yarn add yaml
```

Note: `yaml` 0.x and 1.x are rather different implementations. For the earlier `yaml`, see [tj/js-yaml](https://github.com/tj/js-yaml).
9 changes: 9 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
plugins: [
'@babel/plugin-proposal-class-properties',
['babel-plugin-trace', { strip: true }]
]
}

if (process.env.NODE_ENV === 'test')
module.exports.presets = [['@babel/env', { targets: { node: 'current' } }]]
2 changes: 1 addition & 1 deletion browser/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { YAML as default } from './dist'
module.exports = require('./dist').YAML
6 changes: 2 additions & 4 deletions browser/map.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
export { YAMLMap as default } from './dist/schema/Map'

import { warnFileDeprecation } from './dist/warnings'
warnFileDeprecation(__filename)
module.exports = require('./dist/types').YAMLMap
require('./dist/legacy-exports').warnFileDeprecation(__filename)
6 changes: 2 additions & 4 deletions browser/pair.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
export { Pair as default } from './dist/schema/Pair'

import { warnFileDeprecation } from './dist/warnings'
warnFileDeprecation(__filename)
module.exports = require('./dist/types').Pair
require('./dist/legacy-exports').warnFileDeprecation(__filename)
2 changes: 1 addition & 1 deletion browser/parse-cst.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { parse as default } from './dist/cst/parse'
module.exports = require('./dist/parse-cst').parse
6 changes: 2 additions & 4 deletions browser/scalar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
export { Scalar as default } from './dist/schema/Scalar'

import { warnFileDeprecation } from './dist/warnings'
warnFileDeprecation(__filename)
module.exports = require('./dist/types').Scalar
require('./dist/legacy-exports').warnFileDeprecation(__filename)
17 changes: 7 additions & 10 deletions browser/schema.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { Schema } from './dist/schema'
import { nullOptions, strOptions } from './dist/tags/options'
import { stringifyString } from './dist/stringify'
const types = require('./dist/types')
const util = require('./dist/util')

Schema.nullOptions = nullOptions
Schema.strOptions = strOptions
Schema.stringify = stringifyString
export { Schema as default }
export { nullOptions, strOptions, stringifyString as stringify }
module.exports = types.Schema
module.exports.nullOptions = types.nullOptions
module.exports.strOptions = types.strOptions
module.exports.stringify = util.stringifyString

import { warnFileDeprecation } from './dist/warnings'
warnFileDeprecation(__filename)
require('./dist/legacy-exports').warnFileDeprecation(__filename)
6 changes: 2 additions & 4 deletions browser/seq.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
export { YAMLSeq as default } from './dist/schema/Seq'

import { warnFileDeprecation } from './dist/warnings'
warnFileDeprecation(__filename)
module.exports = require('./dist/types').YAMLSeq
require('./dist/legacy-exports').warnFileDeprecation(__filename)
14 changes: 1 addition & 13 deletions browser/types.js
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
export {
binaryOptions,
boolOptions,
intOptions,
nullOptions,
strOptions
} from './dist/tags/options'

export { Schema } from './dist/schema'
export { YAMLMap } from './dist/schema/Map'
export { YAMLSeq } from './dist/schema/Seq'
export { Pair } from './dist/schema/Pair'
export { Scalar } from './dist/schema/Scalar'
export * from './dist/types.js'
12 changes: 7 additions & 5 deletions browser/types/binary.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { binary } from '../dist/tags/yaml-1.1/binary'
export { binary }
export default [binary]
'use strict'
Object.defineProperty(exports, '__esModule', { value: true })

import { warnFileDeprecation } from './dist/warnings'
warnFileDeprecation(__filename)
const legacy = require('../dist/legacy-exports')
exports.binary = legacy.binary
exports.default = [exports.binary]

legacy.warnFileDeprecation(__filename)
7 changes: 3 additions & 4 deletions browser/types/omap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { omap as default } from '../dist/tags/yaml-1.1/omap'

import { warnFileDeprecation } from './dist/warnings'
warnFileDeprecation(__filename)
const legacy = require('../dist/legacy-exports')
module.exports = legacy.omap
legacy.warnFileDeprecation(__filename)
7 changes: 3 additions & 4 deletions browser/types/pairs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { pairs as default } from '../dist/tags/yaml-1.1/pairs'

import { warnFileDeprecation } from './dist/warnings'
warnFileDeprecation(__filename)
const legacy = require('../dist/legacy-exports')
module.exports = legacy.pairs
legacy.warnFileDeprecation(__filename)
7 changes: 3 additions & 4 deletions browser/types/set.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { set as default } from '../dist/tags/yaml-1.1/set'

import { warnFileDeprecation } from './dist/warnings'
warnFileDeprecation(__filename)
const legacy = require('../dist/legacy-exports')
module.exports = legacy.set
legacy.warnFileDeprecation(__filename)
14 changes: 9 additions & 5 deletions browser/types/timestamp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { floatTime, intTime, timestamp } from '../dist/tags/yaml-1.1/timestamp'
export { floatTime, intTime, timestamp }
export default [intTime, floatTime, timestamp]
'use strict'
Object.defineProperty(exports, '__esModule', { value: true })

import { warnFileDeprecation } from './dist/warnings'
warnFileDeprecation(__filename)
const legacy = require('../dist/legacy-exports')
exports.default = [legacy.intTime, legacy.floatTime, legacy.timestamp]
exports.floatTime = legacy.floatTime
exports.intTime = legacy.intTime
exports.timestamp = legacy.timestamp

legacy.warnFileDeprecation(__filename)
19 changes: 1 addition & 18 deletions browser/util.js
Original file line number Diff line number Diff line change
@@ -1,18 +1 @@
export { findPair } from './dist/schema/Map'
export { parseMap } from './dist/schema/parseMap'
export { parseSeq } from './dist/schema/parseSeq'

export {
stringifyNumber,
stringifyString,
toJSON,
Type
} from './dist/stringify'

export {
YAMLError,
YAMLReferenceError,
YAMLSemanticError,
YAMLSyntaxError,
YAMLWarning
} from './dist/errors'
export * from './dist/util.js'
2 changes: 1 addition & 1 deletion docs-slate
Submodule docs-slate updated 12 files
+2 −0 .dockerignore
+3 −0 .gitignore
+6 −6 .travis.yml
+15 −0 CHANGELOG.md
+21 −0 Dockerfile
+3 −3 Gemfile
+32 −34 Gemfile.lock
+198 −10 LICENSE
+5 −3 README.md
+6 −4 Vagrantfile
+0 −1 config.rb
+16 −5 deploy.sh
2 changes: 1 addition & 1 deletion docs/01_intro.md
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ yarn add yaml
- Can accept any string as input without throwing, parsing as much YAML out of it as it can, and
- Supports parsing, modifying, and writing YAML comments.

The library is released under the ISC open source license, and the code is [available on GitHub](https://github.com/eemeli/yaml/). It runs on Node.js 6 and later with no external dependencies, and in browsers from IE 11 upwards (Note: `@babel/runtime` is used only by the `"browser"` entry point).
The library is released under the ISC open source license, and the code is [available on GitHub](https://github.com/eemeli/yaml/). It has no external dependencies and runs on Node.js 6 and later, and in browsers from IE 11 upwards.

For the purposes of versioning, any changes that break any of the endpoints or APIs documented here will be considered semver-major breaking changes. Undocumented library internals may change between minor versions, and previous APIs may be deprecated (but not removed).

5 changes: 3 additions & 2 deletions docs/03_options.md
Original file line number Diff line number Diff line change
@@ -78,12 +78,13 @@ mergeResult.target
## Scalar Options

```js
YAML.stringify({ 'this is': null })
// Without simpleKeys, an all-null-values object uses explicit keys & no values
YAML.stringify({ 'this is': null }, { simpleKeys: true })
// this is: null

YAML.scalarOptions.null.nullStr = '~'
YAML.scalarOptions.str.defaultType = 'QUOTE_SINGLE'
YAML.stringify({ 'this is': null })
YAML.stringify({ 'this is': null }, { simpleKeys: true })
// 'this is': ~
```

17 changes: 9 additions & 8 deletions docs/04_documents.md
Original file line number Diff line number Diff line change
@@ -147,14 +147,15 @@ A description of [alias and merge nodes](#alias-nodes) is included in the next s

#### `YAML.Document#anchors`

| Method | Returns | Description |
| -------------------------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------- |
| createAlias(node: Node, name?: string) | `Alias` | Create a new `Alias` node, adding the required anchor for `node`. If `name` is empty, a new anchor name will be generated. |
| createMergePair(...Node) | `Merge` | Create a new `Merge` node with the given source nodes. Non-`Alias` sources will be automatically wrapped. |
| getName(node: Node) | `string?` | The anchor name associated with `node`, if set. |
| getNode(name: string) | `Node?` | The node associated with the anchor `name`, if set. |
| newName(prefix: string) | `string` | Find an available anchor name with the given `prefix` and a numerical suffix. |
| setAnchor(node: Node, name?: string) | `string?` | Associate an anchor with `node`. If `name` is empty, a new name will be generated. |
| Method | Returns | Description |
| -------------------------------------- | ---------- | -------------------------------------------------------------------------------------------------------------------------- |
| createAlias(node: Node, name?: string) | `Alias` | Create a new `Alias` node, adding the required anchor for `node`. If `name` is empty, a new anchor name will be generated. |
| createMergePair(...Node) | `Merge` | Create a new `Merge` node with the given source nodes. Non-`Alias` sources will be automatically wrapped. |
| getName(node: Node) | `string?` | The anchor name associated with `node`, if set. |
| getNames() | `string[]` | List of all defined anchor names. |
| getNode(name: string) | `Node?` | The node associated with the anchor `name`, if set. |
| newName(prefix: string) | `string` | Find an available anchor name with the given `prefix` and a numerical suffix. |
| setAnchor(node: Node, name?: string) | `string?` | Associate an anchor with `node`. If `name` is empty, a new name will be generated. |

```js
const src = '[{ a: A }, { b: B }]'
2 changes: 1 addition & 1 deletion docs/05_content_nodes.md
Original file line number Diff line number Diff line change
@@ -194,7 +194,7 @@ doc.toString()

To construct a `YAMLSeq` or `YAMLMap`, use [`YAML.createNode()`](#yaml-createnode) with array, object or iterable input, or create the collections directly by importing the classes from `yaml/types`.

Once created, normal array operations may be used to modify the `items` array. New `Pair` objects may created by importing the class from `yaml/types` and using its `new Pair(key, value)` constructor.
Once created, normal array operations may be used to modify the `items` array. New `Pair` objects may created either by importing the class from `yaml/types` and using its `new Pair(key, value)` constructor, or by using the `doc.schema.createPair(key, value)` method. The latter will recursively wrap the `key` and `value` as nodes.

## Comments

30 changes: 22 additions & 8 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { CST } from './parse-cst'
import { AST, Scalar, Schema, YAMLMap, YAMLSeq } from './types'
import {
AST,
Alias,
Collection,
Merge,
Node,
Scalar,
Schema,
YAMLMap,
YAMLSeq
} from './types'
import { Type, YAMLError, YAMLWarning } from './util'

export { AST, CST }
@@ -183,18 +193,19 @@ export namespace scalarOptions {
}
}

export class Document extends AST.Collection {
export class Document extends Collection {
cstNode?: CST.Document
constructor(options?: Options)
tag: never
directivesEndMarker?: boolean
type: Type.DOCUMENT
/**
* Anchors associated with the document's nodes;
* also provides alias & merge node creators.
*/
anchors: Document.Anchors
/** The document contents. */
contents: AST.AstNode | null
contents: any
/** Errors encountered during parsing. */
errors: YAMLError[]
/**
@@ -249,6 +260,7 @@ export class Document extends AST.Collection {

export namespace Document {
interface Parsed extends Document {
contents: Node | null
/** The schema used with the document. */
schema: Schema
}
@@ -258,16 +270,18 @@ export namespace Document {
* Create a new `Alias` node, adding the required anchor for `node`.
* If `name` is empty, a new anchor name will be generated.
*/
createAlias(node: AST.Node, name?: string): AST.Alias
createAlias(node: Node, name?: string): Alias
/**
* Create a new `Merge` node with the given source nodes.
* Non-`Alias` sources will be automatically wrapped.
*/
createMergePair(...nodes: AST.Node[]): AST.Merge
createMergePair(...nodes: Node[]): Merge
/** The anchor name associated with `node`, if set. */
getName(node: AST.Node): undefined | string
getName(node: Node): undefined | string
/** List of all defined anchor names. */
getNames(): string[]
/** The node associated with the anchor `name`, if set. */
getNode(name: string): undefined | AST.Node
getNode(name: string): undefined | Node
/**
* Find an available anchor name with the given `prefix` and a
* numerical suffix.
@@ -277,7 +291,7 @@ export namespace Document {
* Associate an anchor with `node`. If `name` is empty, a new name will be generated.
* To remove an anchor, use `setAnchor(null, name)`.
*/
setAnchor(node: AST.Node | null, name?: string): void | string
setAnchor(node: Node | null, name?: string): void | string
}

interface TagPrefix {
39 changes: 39 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
let moduleNameMapper
const testPathIgnorePatterns = ['tests/common', 'cst/common']

// The npm script name is significant.
switch (process.env.npm_lifecycle_event) {
case 'test:dist':
moduleNameMapper = {}
testPathIgnorePatterns.push(
'cst/Node',
'cst/set-value',
'cst/source-utils',
'cst/YAML-1.2',
'doc/createNode',
'doc/errors',
'doc/foldFlowLines',
'doc/types'
)
break

case 'test':
default:
process.env.TRACE_LEVEL = 'log'
moduleNameMapper = {
'^\\./dist$': '<rootDir>/src/index.js',
'^\\./dist/parse-cst(\\.js)?$': '<rootDir>/src/cst/parse.js',
'^\\./dist/types(\\.js)?$': '<rootDir>/src/types.js',
'^\\./dist/(.+)$': '<rootDir>/src/$1',
'^\\.\\./dist/test-events.js$': '<rootDir>/src/test-events.js'
}
}

module.exports = {
collectCoverageFrom: ['src/**/*.js'],
moduleNameMapper,
testEnvironment: 'node',
testMatch: ['**/tests/**/*.js'],
testPathIgnorePatterns,
transform: { '/(src|tests)/.*\\.js$': 'babel-jest' }
}
4 changes: 2 additions & 2 deletions map.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
module.exports = require('./dist/schema/Map').YAMLMap
require('./dist/warnings').warnFileDeprecation(__filename)
module.exports = require('./dist/types').YAMLMap
require('./dist/legacy-exports').warnFileDeprecation(__filename)
Loading