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: v2.4.5
Choose a base ref
...
head repository: eemeli/yaml
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Loading
Showing with 3,311 additions and 3,922 deletions.
  1. +0 −9 .eslintignore
  2. +0 −57 .eslintrc.yaml
  3. +24 −0 .github/workflows/deno.yml
  4. +16 −0 .github/workflows/jsr-publish.yml
  5. +1 −0 .well-known/funding-manifest-urls
  6. +46 −11 README.md
  7. +0 −22 config/babel.config.js
  8. +20 −13 config/jest.config.js
  9. +18 −7 config/rollup.browser-config.mjs
  10. +61 −3 config/rollup.node-config.mjs
  11. +1 −1 docs-slate
  12. +4 −4 docs/01_intro.md
  13. +2 −1 docs/03_options.md
  14. +10 −9 docs/06_custom_tags.md
  15. +2 −1 docs/08_errors.md
  16. +1 −0 docs/09_cli.md
  17. +93 −0 eslint.config.mjs
  18. +15 −0 jsr.jsonc
  19. +1,817 −3,076 package-lock.json
  20. +8 −10 package.json
  21. +19 −12 src/cli.ts
  22. +35 −15 src/compose/compose-collection.ts
  23. +11 −10 src/compose/compose-doc.ts
  24. +26 −12 src/compose/compose-node.ts
  25. +22 −17 src/compose/compose-scalar.ts
  26. +30 −14 src/compose/composer.ts
  27. +14 −12 src/compose/resolve-block-map.ts
  28. +5 −5 src/compose/resolve-block-scalar.ts
  29. +8 −7 src/compose/resolve-block-seq.ts
  30. +2 −2 src/compose/resolve-end.ts
  31. +18 −13 src/compose/resolve-flow-collection.ts
  32. +7 −7 src/compose/resolve-flow-scalar.ts
  33. +6 −6 src/compose/resolve-props.ts
  34. +1 −1 src/compose/util-contains-newline.ts
  35. +1 −1 src/compose/util-empty-scalar-position.ts
  36. +3 −3 src/compose/util-flow-indent-check.ts
  37. +5 −9 src/compose/util-map-includes.ts
  38. +23 −20 src/doc/Document.ts
  39. +8 −8 src/doc/anchors.ts
  40. +1 −0 src/doc/applyReviver.ts
  41. +8 −8 src/doc/createNode.ts
  42. +8 −8 src/doc/directives.ts
  43. +2 −1 src/errors.ts
  44. +26 −26 src/index.ts
  45. +3 −4 src/log.ts
  46. +15 −13 src/nodes/Alias.ts
  47. +5 −7 src/nodes/Collection.ts
  48. +23 −11 src/nodes/Node.ts
  49. +11 −9 src/nodes/Pair.ts
  50. +7 −5 src/nodes/Scalar.ts
  51. +15 −14 src/nodes/YAMLMap.ts
  52. +16 −13 src/nodes/YAMLSeq.ts
  53. +13 −56 src/nodes/addPairToJSMap.ts
  54. +7 −7 src/nodes/identity.ts
  55. +3 −3 src/nodes/toJS.ts
  56. +17 −10 src/options.ts
  57. +11 −10 src/parse/cst-scalar.ts
  58. +4 −4 src/parse/cst-stringify.ts
  59. +16 −4 src/parse/cst-visit.ts
  60. +5 −4 src/parse/cst.ts
  61. +4 −7 src/parse/lexer.ts
  62. +2 −2 src/parse/line-counter.ts
  63. +12 −10 src/parse/parser.ts
  64. +12 −9 src/public-api.ts
  65. +9 −11 src/schema/Schema.ts
  66. +3 −3 src/schema/common/map.ts
  67. +2 −2 src/schema/common/null.ts
  68. +3 −3 src/schema/common/seq.ts
  69. +2 −2 src/schema/common/string.ts
  70. +2 −2 src/schema/core/bool.ts
  71. +3 −3 src/schema/core/float.ts
  72. +4 −4 src/schema/core/int.ts
  73. +7 −7 src/schema/core/schema.ts
  74. +5 −5 src/schema/json/schema.ts
  75. +43 −28 src/schema/tags.ts
  76. +14 −12 src/schema/types.ts
  77. +4 −3 src/schema/yaml-1.1/binary.ts
  78. +3 −3 src/schema/yaml-1.1/bool.ts
  79. +3 −3 src/schema/yaml-1.1/float.ts
  80. +4 −4 src/schema/yaml-1.1/int.ts
  81. +77 −0 src/schema/yaml-1.1/merge.ts
  82. +20 −15 src/schema/yaml-1.1/omap.ts
  83. +9 −9 src/schema/yaml-1.1/pairs.ts
  84. +14 −12 src/schema/yaml-1.1/schema.ts
  85. +16 −11 src/schema/yaml-1.1/set.ts
  86. +4 −4 src/schema/yaml-1.1/timestamp.ts
  87. +2 −1 src/stringify/foldFlowLines.ts
  88. +15 −11 src/stringify/stringify.ts
  89. +5 −4 src/stringify/stringifyCollection.ts
  90. +7 −7 src/stringify/stringifyDocument.ts
  91. +2 −2 src/stringify/stringifyNumber.ts
  92. +6 −5 src/stringify/stringifyPair.ts
  93. +33 −25 src/stringify/stringifyString.ts
  94. +6 −6 src/test-events.ts
  95. +16 −12 src/util.ts
  96. +8 −8 src/visit.ts
  97. +98 −4 tests/cli.ts
  98. +3 −2 tests/clone.ts
  99. +7 −7 tests/collection-access.ts
  100. +1 −1 tests/cst.ts
  101. +3 −2 tests/directives.ts
  102. +1 −1 tests/doc/YAML-1.1.spec.ts
  103. +39 −5 tests/doc/anchors.ts
  104. +24 −1 tests/doc/comments.ts
  105. +3 −2 tests/doc/createNode.ts
  106. +26 −1 tests/doc/errors.ts
  107. +13 −2 tests/doc/foldFlowLines.ts
  108. +43 −1 tests/doc/parse.ts
  109. +14 −1 tests/doc/stringify.ts
  110. +32 −9 tests/doc/types.ts
  111. +0 −2 tests/json-test-suite.ts
  112. +13 −5 tests/lexer.ts
  113. +3 −2 tests/node-to-js.ts
  114. +2 −1 tests/stream.ts
  115. +2 −1 tests/visit.ts
  116. +3 −2 tests/yaml-test-suite.ts
  117. +1 −0 tsconfig.json
9 changes: 0 additions & 9 deletions .eslintignore

This file was deleted.

57 changes: 0 additions & 57 deletions .eslintrc.yaml

This file was deleted.

24 changes: 24 additions & 0 deletions .github/workflows/deno.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Deno

on:
pull_request:
branches: [main]
push:
branches: [main]
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
deno-version: [v1.x, v2.x]

steps:
- uses: actions/checkout@v4
with: { submodules: true }
- uses: denoland/setup-deno@v2
with:
deno-version: ${{ matrix.deno-version }}
- run: deno src/public-api.ts
16 changes: 16 additions & 0 deletions .github/workflows/jsr-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: JSR Publish
on:
push:
tags:
- v2.*
workflow_dispatch:

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- run: npx jsr publish
1 change: 1 addition & 0 deletions .well-known/funding-manifest-urls
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://eemeli.org/funding.json
57 changes: 46 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -24,15 +24,31 @@ To install:

```sh
npm install yaml
# or
deno add jsr:@eemeli/yaml
```

**Note:** These docs are for `yaml@2`. For v1, see the [v1.10.0 tag](https://github.com/eemeli/yaml/tree/v1.10.0) for the source and [eemeli.org/yaml/v1](https://eemeli.org/yaml/v1/) for the documentation.

The development and maintenance of this library is [sponsored](https://github.com/sponsors/eemeli) by:

<a href="https://www.scipress.io/">
<img width=150 src="https://eemeli.org/yaml/images/scipress.svg" alt="Scipress" />
</a>
<p align="center" width="100%">
<a href="https://www.scipress.io/"
><img
width="150"
align="top"
src="https://eemeli.org/yaml/images/scipress.svg"
alt="Scipress"
/></a>
&nbsp; &nbsp;
<a href="https://manifest.build/"
><img
width="150"
align="top"
src="https://eemeli.org/yaml/images/manifest.svg"
alt="Manifest"
/></a>
</p>

## API Overview

@@ -41,24 +57,29 @@ The first has the simplest API and "just works", the second gets you all the bel

A [command-line tool](https://eemeli.org/yaml/#command-line-tool) is also included.

### Parse & Stringify

```js
import { parse, stringify } from 'yaml'
// or
import YAML from 'yaml'
// or
const YAML = require('yaml')
```

### Parse & Stringify

- [`parse(str, reviver?, options?): value`](https://eemeli.org/yaml/#yaml-parse)
- [`stringify(value, replacer?, options?): string`](https://eemeli.org/yaml/#yaml-stringify)

### Documents

<!-- prettier-ignore -->
```js
import {
Document,
isDocument,
parseAllDocuments,
parseDocument
} from 'yaml'
```

- [`Document`](https://eemeli.org/yaml/#documents)
- [`constructor(value, replacer?, options?)`](https://eemeli.org/yaml/#creating-documents)
- [`#anchors`](https://eemeli.org/yaml/#working-with-anchors)
- [`#contents`](https://eemeli.org/yaml/#content-nodes)
- [`#directives`](https://eemeli.org/yaml/#stream-directives)
- [`#errors`](https://eemeli.org/yaml/#errors)
@@ -69,6 +90,15 @@ const YAML = require('yaml')

### Content Nodes

<!-- prettier-ignore -->
```js
import {
isAlias, isCollection, isMap, isNode,
isPair, isScalar, isSeq, Scalar,
visit, visitAsync, YAMLMap, YAMLSeq
} from 'yaml'
```

- [`isAlias(foo): boolean`](https://eemeli.org/yaml/#identifying-node-types)
- [`isCollection(foo): boolean`](https://eemeli.org/yaml/#identifying-node-types)
- [`isMap(foo): boolean`](https://eemeli.org/yaml/#identifying-node-types)
@@ -79,13 +109,18 @@ const YAML = require('yaml')
- [`new Scalar(value)`](https://eemeli.org/yaml/#scalar-values)
- [`new YAMLMap()`](https://eemeli.org/yaml/#collections)
- [`new YAMLSeq()`](https://eemeli.org/yaml/#collections)
- [`doc.createAlias(node, name?): Alias`](https://eemeli.org/yaml/#working-with-anchors)
- [`doc.createAlias(node, name?): Alias`](https://eemeli.org/yaml/#creating-nodes)
- [`doc.createNode(value, options?): Node`](https://eemeli.org/yaml/#creating-nodes)
- [`doc.createPair(key, value): Pair`](https://eemeli.org/yaml/#creating-nodes)
- [`visit(node, visitor)`](https://eemeli.org/yaml/#finding-and-modifying-nodes)
- [`visitAsync(node, visitor)`](https://eemeli.org/yaml/#finding-and-modifying-nodes)

### Parsing YAML

```js
import { Composer, Lexer, Parser } from 'yaml'
```

- [`new Lexer().lex(src)`](https://eemeli.org/yaml/#lexer)
- [`new Parser(onNewLine?).parse(src)`](https://eemeli.org/yaml/#parser)
- [`new Composer(options?).compose(tokens)`](https://eemeli.org/yaml/#composer)
22 changes: 0 additions & 22 deletions config/babel.config.js

This file was deleted.

33 changes: 20 additions & 13 deletions config/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
let moduleNameMapper

const babel = [
'babel-jest',
{
overrides: [
{
test: '**/*.ts',
plugins: [
['@babel/plugin-transform-typescript', { allowDeclareFields: true }]
]
}
],
presets: [['@babel/env', { targets: { node: 'current' } }]]
}
]

const transform = {
'[/\\\\]tests[/\\\\].*\\.(m?js|ts)$': [
'babel-jest',
{ configFile: './config/babel.config.js' }
]
'[/\\\\]tests[/\\\\].*\\.(m?js|ts)$': babel
}

// The npm script name is significant.
@@ -14,12 +27,9 @@ switch (process.env.npm_lifecycle_event) {
'^yaml$': '<rootDir>/dist/index.js',
'^yaml/cli$': '<rootDir>/dist/cli.mjs',
'^yaml/util$': '<rootDir>/dist/util.js',
'^../src/test-events$': '<rootDir>/dist/test-events.js'
'^../src/test-events.ts$': '<rootDir>/dist/test-events.js'
}
transform['[/\\\\]dist[/\\\\].*\\.mjs$'] = [
'babel-jest',
{ configFile: './config/babel.config.js' }
]
transform['[/\\\\]dist[/\\\\].*\\.mjs$'] = babel
break

case 'test':
@@ -30,10 +40,7 @@ switch (process.env.npm_lifecycle_event) {
'^yaml/cli$': '<rootDir>/src/cli.ts',
'^yaml/util$': '<rootDir>/src/util.ts'
}
transform['[/\\\\]src[/\\\\].*\\.ts$'] = [
'babel-jest',
{ configFile: './config/babel.config.js' }
]
transform['[/\\\\]src[/\\\\].*\\.ts$'] = babel
}

module.exports = {
25 changes: 18 additions & 7 deletions config/rollup.browser-config.mjs
Original file line number Diff line number Diff line change
@@ -2,24 +2,35 @@ import babel from '@rollup/plugin-babel'
import replace from '@rollup/plugin-replace'
import typescript from '@rollup/plugin-typescript'

/** @type {import('rollup').RollupOptions} */
export default {
input: {
index: 'src/index.ts',
util: 'src/util.ts'
},
output: { dir: 'browser/dist', format: 'esm', preserveModules: true },
plugins: [
replace({
preventAssignment: true,
'process.env.LOG_TOKENS': String(!!process.env.LOG_TOKENS),
'process.env.LOG_STREAM': String(!!process.env.LOG_STREAM)
}),
replace({ preventAssignment: true }),
babel({
babelHelpers: 'bundled',
configFile: './config/babel.config.js',
presets: [['@babel/env', { modules: false }]]
}),
typescript({ declaration: false, outDir: 'browser/dist' })
typescript({ declaration: false, outDir: 'browser/dist' }),
{
resolveId: source =>
['node:buffer', 'node:process'].includes(source) ? source : null,
load(id) {
switch (id) {
case 'node:buffer':
return 'export const Buffer = null;'
case 'node:process':
return (
'export const emitWarning = null;' +
`export const env = { LOG_STREAM: ${!!process.env.LOG_STREAM}, LOG_TOKENS: ${!!process.env.LOG_TOKENS} };`
)
}
}
}
],
treeshake: { moduleSideEffects: false, propertyReadSideEffects: false }
}
Loading