# @stoplight/yaml

> Useful functions when working with YAML.

Latest version **4.3.0** (published 2024-03-04) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @stoplight/yaml
pnpm add @stoplight/yaml
yarn add @stoplight/yaml
bun add @stoplight/yaml
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.3.0 |
| Published | 2024-03-04 |
| First published | 2018-11-14 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=10.8 |
| Dependencies | 4 |
| Unpacked size | 79.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Author | Stoplight |
| Maintainers | stoplight-devops |
| Keywords | yaml, yaml parser, yaml.parse, parser, sourcemap |

## Links

- npm: https://www.npmjs.com/package/@stoplight/yaml
- Repository: https://github.com/stoplightio/yaml
- Homepage: https://github.com/stoplightio/yaml#readme
- Issues: https://github.com/stoplightio/yaml/issues
- npm.io page: https://npm.io/package/@stoplight/yaml

## Dependencies (4)

- [tslib](https://npm.io/package/tslib.md) ^2.2.0
- [@stoplight/types](https://npm.io/package/@stoplight/types.md) ^14.1.1
- [@stoplight/yaml-ast-parser](https://npm.io/package/@stoplight/yaml-ast-parser.md) 0.0.50
- [@stoplight/ordered-object-literal](https://npm.io/package/@stoplight/ordered-object-literal.md) ^1.0.5

## 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

- 4.3.0 (latest) — 2024-03-04
- 4.2.3 — 2022-04-15
- 4.2.2 — 2021-04-21
- 4.2.1 — 2020-07-06
- 4.2.0 — 2020-06-24
- 4.1.0 — 2020-06-22
- 4.0.2 — 2020-05-20
- 4.0.1 — 2020-05-14
- 4.0.0 — 2020-05-13
- 3.8.1 — 2020-04-20
- 3.8.0 — 2020-04-17
- 3.7.1 — 2020-03-23
- 3.7.0 — 2020-03-17
- 3.6.0 — 2020-03-11
- 3.5.2 — 2020-02-25
- … 31 more at https://npm.io/package/@stoplight/yaml/versions

## README

# @stoplight/yaml

[![Maintainability](https://api.codeclimate.com/v1/badges/5c6d61926d8f87b38b39/maintainability)](https://codeclimate.com/github/stoplightio/yaml/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/5c6d61926d8f87b38b39/test_coverage)](https://codeclimate.com/github/stoplightio/yaml/test_coverage)

Useful functions when working with YAML.

- Explore the interfaces: [TSDoc](https://stoplightio.github.io/yaml)
- View the changelog: [Releases](https://github.com/stoplightio/yaml/releases)

### Installation

Supported in modern browsers and node.

```bash
# latest stable
yarn add @stoplight/yaml
```

### Usage

- **[getJsonPathForPosition](./src/getJsonPathForPosition.ts)**: Computes JSON path for given position.
- **[getLocationForJsonPath](./src/getLocationForJsonPath.ts)**: Retrieves location of node matching given JSON path.
- **[parseWithPointers](./src/parseWithPointers.ts)**: Parses YAML into JSON and also returns diagnostics as well as full ast with line information.

```ts
// basic example of parseWithPointers
import { parseWithPointers } from "@stoplight/yaml";

const result = parseWithPointers("foo: bar");

console.log(result.data); // => the {foo: "bar"} JS object
```

```ts
// basic example of getJsonPathForPosition and getLocationForJsonPath
import { getJsonPathForPosition, getLocationForJsonPath, parseWithPointers } from "@stoplight/yaml";

const result = parseWithPointers(`hello: world
address:
    street: 123`
);

const path = getJsonPathForPosition(result, { line: 2, character: 7 }); // line and character are 0-based
console.log(path); // -> ["address", "street"];

const position = getLocationForJsonPath(result, ['address']);
console.log(position.range.start); // { line: 1, character: 8 } line and character are 0-based
console.log(position.range.end); // { line: 2, character: 15 } line and character are 0-based
```

### Contributing

1. Clone repo.
2. Create / checkout `feature/{name}`, `chore/{name}`, or `fix/{name}` branch.
3. Install deps: `yarn`.
4. Make your changes.
5. Run tests: `yarn test.prod`.
6. Stage relevant files to git.
7. Commit: `yarn commit`. _NOTE: Commits that don't follow the [conventional](https://github.com/marionebl/commitlint/tree/master/%40commitlint/config-conventional) format will be rejected. `yarn commit` creates this format for you, or you can put it together manually and then do a regular `git commit`._
8. Push: `git push`.
9. Open PR targeting the `next` branch.

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