# yaml-ast-parser

> [![Build Status](https://travis-ci.org/mulesoft-labs/yaml-ast-parser.svg?branch=master)](https://travis-ci.org/mulesoft-labs/yaml-ast-parser)

Latest version **0.0.43** (published 2018-11-15) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install yaml-ast-parser
pnpm add yaml-ast-parser
yarn add yaml-ast-parser
bun add yaml-ast-parser
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.43 |
| Published | 2018-11-15 |
| First published | 2016-03-21 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 404.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 89 |
| Maintainers | denis.denisenko, petrochenko-pavel-a |
| Keywords | raml, ast, yaml |

## Links

- npm: https://www.npmjs.com/package/yaml-ast-parser
- Repository: https://github.com/mulesoft-labs/yaml-ast-parser
- Issues: https://github.com/mulesoft-labs/yaml-ast-parser/issues
- npm.io page: https://npm.io/package/yaml-ast-parser

## Alternatives

- [monaco-yaml](https://npm.io/package/monaco-yaml.md) — 420.1K weekly downloads
- [@crewx/workflow](https://npm.io/package/@crewx/workflow.md) — 3.1K weekly downloads
- [yaml-cat](https://npm.io/package/yaml-cat.md) — 38 weekly downloads
- [nunjucks-in-yaml](https://npm.io/package/nunjucks-in-yaml.md) — 9 weekly downloads
- [shopify-symlinks](https://npm.io/package/shopify-symlinks.md) — 3 weekly downloads

## Recent versions

- 0.0.43 (latest) — 2018-11-15
- 0.0.42 — 2018-11-15
- 0.0.41 — 2018-08-28
- 0.0.40 — 2017-12-04
- 0.0.39 — 2017-11-14
- 0.0.38 — 2017-10-24
- 0.0.37 — 2017-10-18
- 0.0.36 — 2017-10-04
- 0.0.35 — 2017-09-25
- 0.0.34 — 2017-07-13
- 0.0.33 — 2017-05-29
- 0.0.32 — 2017-05-03
- 0.0.31 — 2016-12-13
- 0.0.30 — 2016-10-11
- 0.0.29 — 2016-09-02
- … 11 more at https://npm.io/package/yaml-ast-parser/versions

## README

# yaml-ast-parser

[![Build Status](https://travis-ci.org/mulesoft-labs/yaml-ast-parser.svg?branch=master)](https://travis-ci.org/mulesoft-labs/yaml-ast-parser)

This is a fork of JS-YAML which supports parsing of YAML into AST.

In additional to parsing YAML to AST, it has following features:

* restoration after the errors and reporting errors as a part of AST nodes.
* built-in support for `!include` tag used in RAML

## Usage
The type information below is relevant when using TypeScript, if using from JavaScript only the field/method information is relevant.

`load` method can be used to load the tree and returns a `YAMLNode`.

### YAMLNode
`YAMLNode` class is an ancestor for all node kinds.
It's `kind` field determine node kind, one of `Kind` enum:
  * `SCALAR`, `MAPPING`, `MAP`, `SEQ`, `ANCHOR_REF` or `INCLUDE_REF`.
 
After node kind is determined, it can be cast to one of the `YAMLNode` descendants types:
 * `YAMLScalar`, `YAMLMapping`, `YamlMap`, `YAMLSequence` or `YAMLAnchorReference`.

| class | important members |
|-------|-------------------|
| `YAMLNode` | `startPosition` and `endPosition` provide node range.|
| `YAMLScalar` | `string` `value` field |
| `YAMLMapping` |`YAMLScalar` `key` and `YAMLNode` `value` fields | 
| `YAMLSequence` | `YAMLNode[]` `items` field|
| `YamlMap` | `YAMLMapping[]` `mappings` field|
| `YAMLAnchorReference` | `string` `referencesAnchor` and `YAMLNode` `value`|

### YAMLScalar

Scalars are [one of the three main node types defined by YAML](http://www.yaml.org/spec/1.2/spec.html#scalar//) and are effectively leaf nodes.

There are many factors that can influence the type of datum represent in scalar node (context, schema, tag, etc.).

To help inspection of a `YAMLScalar` to determine its datatype when a document uses the [Core Schema](http://www.yaml.org/spec/1.2/spec.html#id2804923), you can pass the `YAMLScalar` to the `determineScalarType` function.  It will return an enum value indicating `null`, `bool`, `int`, `float`, or `string`.

Once you know the type, there are also some helper functions to help read the value by passing them the string, `value`: `parseYamlBoolean`, `parseYamlFloat`, and `parseYamlInteger`.

---
_Source: https://npm.io/package/yaml-ast-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
