# sls-yaml

> Serverless framework yaml extension parser

Latest version **1.1.1** (published 2024-07-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install sls-yaml
pnpm add sls-yaml
yarn add sls-yaml
bun add sls-yaml
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2024-07-10 |
| First published | 2019-07-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 133.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Nidin Vinayakan |
| Maintainers | 01 |
| Keywords | yaml, yml, parser, sls, serverless, configuration |

## Links

- npm: https://www.npmjs.com/package/sls-yaml
- Repository: https://github.com/01alchemist/sls-yaml
- Homepage: https://github.com/01alchemist/sls-yaml#readme
- Issues: https://github.com/01alchemist/sls-yaml/issues
- npm.io page: https://npm.io/package/sls-yaml

## Dependencies (3)

- [tslib](https://npm.io/package/tslib.md) ^2.6.3
- [js-yaml](https://npm.io/package/js-yaml.md) ^4.1.0
- [source-map-support](https://npm.io/package/source-map-support.md) ^0.5.21

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

- 1.1.1 (latest) — 2024-07-10
- 1.1.0 — 2024-07-10
- 1.0.31 — 2020-05-15
- 1.0.30 — 2019-09-03
- 1.0.29 — 2019-08-29
- 1.0.28 — 2019-08-29
- 1.0.26 — 2019-08-28
- 1.0.25 — 2019-08-28
- 1.0.24 — 2019-08-28
- 1.0.23 — 2019-08-28
- 1.0.22 — 2019-08-28
- 1.0.20 — 2019-08-28
- 1.0.19 — 2019-08-28
- 1.0.18 — 2019-08-25
- 1.0.17 — 2019-08-23
- … 14 more at https://npm.io/package/sls-yaml/versions

## README

## Serverless YAML extension parser

[![CircleCI]][ci-sls-yaml] [![Maintainability]][codeclimate] [![Test Coverage]][coverage]

This tiny library will parse YAML extensions used in serverless framework.

### Usage

```bash
npm install sls-yaml
```

```js
import yaml from "sls-yaml";
const compiledYamlAsJsonObject = yaml(YAML_FILE_PATH_OR_BUFFER);
```

### Supported sls extensions

- [Include external file](#include-external-file) `${file(path/to/file.yml)}`
- [Inject environment variable](#inject-environment-variable) `${env:NODE_ENV}`
- [Inject global variables](#inject-global-variables) `${global:path.to.variable}`
- [Inject local variables](#inject-local-variables) `${self:path.to.variable}`

### New extensions\*

- [Inject current git branch](#inject-current-git-branch) `${git:branch}`
- [Inject last git commit hash](#inject-last-git-commit-hash) `${git:sha1}`
- [String replace](#string-replace) `${replace(str, searchPattern, replaceValue )}`

`* - New extension not present in serverless yaml`

### Custom extensions

```js
const context = {
  custom: ([arg]: string[]) => {
    return `${arg}-beta`;
  }
};
const result = yaml(content, null, context);
```

```yml
name: service
version: v1.0.2
subset: service@${custom(${self:version})}
```
- output
```yml
name: service
version: v1.0.2
subset: service@v1.0.2-beta
```

### Include external file

This extension will include content of external yaml files.

- config.yml

```yaml
version: 1
env: dev
config: ${file(./common.yml)}
```

- common.yml

```yaml
endpoint: http://service-url
```

- Generated final yaml

```yaml
version: 1
env: dev
config:
  endpoint: http://service-url
```

### Inject environment variable

This extension will inject envronment values

- config.yml `export NODE_ENV = development`

```yaml
version: 1
env: ${env:NODE_ENV}
```

- Generated final yaml

```yaml
version: 1
env: development
```

### Inject global variables

This extension will inject variable from global scope.

- config.yml

```yaml
version: 1
env: stage
config: ${file(./common.yml)}
```

- common.yml

```yaml
endpoint: http://service-${global:env}
```

- Generated final yaml

```yaml
version: 1
env: stage
config:
  endpoint: http://service-stage
```

### Inject local variables

This extension will inject variable from local scope.

- config.yml

```yaml
version: 1
env: stage
config: ${file(./common.yml)}
```

- common.yml

```yaml
port: 8080
endpoint: http://service:${self:port}
```

- Generated final yaml

```yaml
version: 1
env: stage
config:
  port: 8080
  endpoint: http://service:8080
```

### Inject current git branch

This extension will inject current git branch name

- config.yml

```yaml
branch: ${git:branch}
```

### Inject last git commit hash

This extension will inject last git commit hash

- config.yml

```yaml
image.tag: ${git:sha1}
```

### String replace
```ts
replace(str:string, searchPattern:RegExp|string, replaceValue:string )
```
This extension will returns a new string with some or all matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp, and the replacement can be a string or a function to be called for each match. If pattern is a string, only the first occurrence will be replaced.

- config.yml

```yaml
version: v1.0.0
name: ServiceName@${replace(${ self : version }, /\\./gi, - )}
```

- output

```yaml
version: v1.0.0
name: ServiceName@v1-0-0
```

[circleci]: https://circleci.com/gh/01alchemist/sls-yaml/tree/master.svg?style=svg
[ci-sls-yaml]: https://circleci.com/gh/01alchemist/sls-yaml/tree/master
[maintainability]: https://api.codeclimate.com/v1/badges/d3b19c4c45ebf451faf3/maintainability
[codeclimate]: https://codeclimate.com/github/01alchemist/sls-yaml/maintainability
[test coverage]: https://api.codeclimate.com/v1/badges/d3b19c4c45ebf451faf3/test_coverage
[coverage]: https://codeclimate.com/github/01alchemist/sls-yaml/test_coverage

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