# docker-file-parser

> Parses a Dockerfile and returns an array of commands.

Latest version **1.0.7** (published 2022-01-11) · MPL license · 0 weekly downloads

## Install

```sh
npm install docker-file-parser
pnpm add docker-file-parser
yarn add docker-file-parser
bun add docker-file-parser
```

## 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.0.7 |
| Published | 2022-01-11 |
| First published | 2015-09-22 |
| Weekly downloads | 0 |
| License | MPL |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 250.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 45 |
| Author | Todd Whiteman |
| Maintainers | todd.whiteman, bahamat, michael.hicks |
| Keywords | dockerfile, docker, parser |

## Links

- npm: https://www.npmjs.com/package/docker-file-parser
- Repository: https://github.com/joyent/docker-file-parser
- Issues: https://github.com/joyent/docker-file-parser/issues
- npm.io page: https://npm.io/package/docker-file-parser

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.0.7 (latest) — 2022-01-11
- 1.0.6 — 2022-01-06
- 1.0.5 — 2020-09-09
- 1.0.4 — 2018-09-19
- 1.0.3 — 2017-11-23
- 1.0.2 — 2017-05-03
- 1.0.1 — 2017-02-17
- 0.1.0 — 2015-09-22

## README

# Docker file parser

Parses a dockerfile contents string and returns the array of commands, keeping
the original file order.

# Usage

    var parser = require('docker-file-parser');
    var options = { includeComments: false };
    var contents = 'FROM ubuntu:latest\n'
                + 'ADD . /root\n'
                + 'RUN echo done\n';

    var commands = parser.parse(contents, options);

    commands.every(function (cmd) { console.log(cmd); });

## Options

 * `includeComments` Whether to include comment commands in the returned array.
   A comment will have the command name as 'COMMENT'.

## Command entries

Each returned command entry is an object with these properties:

 * `name` The capitalized name of the command, e.g. 'FROM'.
 * `args` Arguments for the command (can be array, string or map).
 * `lineno` Line number from the contents string.
 * `error` Only if there was an error parsing command.

Example:

    {
        name: 'ADD',
        args: [ '.', '/srv/app' ],
        lineno: 5
    }


# Notes

There are other docker file parse modules for JavaScript, like
`dockerfile-parse` and `dockerfile-parser`, this module differs in the follow
aspects:

* keeps the ordering of the commands (as they occur in the dockerfile)
* written from a translation of the docker parser.go
* properly handles character escaping and quoting, e.g. ENV myName="John Doe" myDog=Rex\ The\ Dog
* handles multi-line commands (i.e. have a line continuance '\' at the end)
* can optionally include the comments

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