# gherkin-parse

> NPM package for converting a .feature(cucumber framework) file to a JSON file and vice versa.

Latest version **1.0.12** (published 2024-08-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install gherkin-parse
pnpm add gherkin-parse
yarn add gherkin-parse
bun add gherkin-parse
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.12 |
| Published | 2024-08-09 |
| First published | 2020-09-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 6.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Jithin Zachariah |
| Maintainers | jithin-zachariah |
| Keywords | gherkin, cucumber, featurefile, json, parse |

## Links

- npm: https://www.npmjs.com/package/gherkin-parse
- Repository: https://github.com/jithin-zac/gherkin-parse
- Homepage: https://github.com/jithin-zac/gherkin-parse#readme
- Issues: https://github.com/jithin-zac/gherkin-parse/issues
- npm.io page: https://npm.io/package/gherkin-parse

## Dependencies (2)

- [gherkin](https://npm.io/package/gherkin.md) 5.0.1
- [gherkin-assembler](https://npm.io/package/gherkin-assembler.md) 2.0.1

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.12 (latest) — 2024-08-09
- 1.0.11 — 2024-08-09
- 1.0.10 — 2024-08-09
- 1.0.9 — 2024-08-09
- 1.0.8 — 2023-12-05
- 1.0.7 — 2023-12-05
- 1.0.6 — 2021-04-24
- 1.0.5 — 2021-03-06
- 1.0.4 — 2020-09-11
- 1.0.3 — 2020-09-09
- 1.0.2 — 2020-09-09
- 1.0.1 — 2020-09-09
- 1.0.0 — 2020-09-09

## README

[![HitCount](http://hits.dwyl.com/jithin-zachariah/gherkin-parse.svg)](http://hits.dwyl.com/jithin-zachariah/gherkin-parse)
[![Say Thanks!](https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg)](https://saythanks.io/to/jithin.zachariah96@gmail.com)

[![forthebadge](https://forthebadge.com/images/badges/made-with-javascript.svg)](https://forthebadge.com)
[![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com)

# gherkin-parse

`gherkin-parse` is an NPM package designed to convert `.feature` files, commonly used in [Cucumber](https://cucumber.io/) test cases, into JSON objects and vice versa.

## Installation

```npm i gherkin-parse```

## Usage

```
const parser = require("gherkin-parse");

const jsonObject = parser.convertFeatureFileToJSON("./sample.feature");

const featurefile = parser.convertJSONToFeatureFile(jsonObject);

```

## Example

Consider the following sample feature file:

```
@tag1 @tag2
Feature: Hello world Before Edit
    this is a feature description

    @tag2 @tag3
    Scenario: this is a scenario 1
        Given this is a data
        And this is a given step too
        When this is a when step
        And this is a when step too
        Then it should be a then step
        And it should be a then step too
```

The JavaScript object returned by `convertFeatureFileToJSON` would be:

```json
{
  "type": "GherkinDocument",
  "feature": {
    "type": "Feature",
    "tags": [
      { "name": "@tag1" },
      { "name": "@tag2" }
    ],
    "location": { "line": 2, "column": 1 },
    "language": "en",
    "keyword": "Feature",
    "name": "Hello world Before Edit",
    "description": "    this is a feature description",
    "children": [
      {
        "type": "Scenario",
        "tags": [
          { "name": "@tag2" },
          { "name": "@tag3" }
        ],
        "name": "this is a scenario 1",
        "steps": [
          { "keyword": "Given", "text": "this is a data" },
          { "keyword": "And", "text": "this is a given step too" },
          { "keyword": "When", "text": "this is a when step" },
          { "keyword": "And", "text": "this is a when step too" },
          { "keyword": "Then", "text": "it should be a then step" },
          { "keyword": "And", "text": "it should be a then step too" }
        ]
      }
    ]
  },
  "comments": []
}
```

This JSON object can be used for further processing and modifications. You can convert it back into a feature file string using `convertJSONToFeatureFile`. This string can then be written back to a `.feature` file using Node's `fs` module.

```
@tag1 @tag2
Feature: Hello world After Edit
    this is a feature description

    @tag2 @tag3
    Scenario: this is a scenario 1
        Given this is a data
        And this is a given step too
        When this is a when step
        And this is a when step too
        Then it should be a then step
        And it should be a then step too
```

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