Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

changelog-parser

ungoldman108.3kISC3.0.1TypeScript support: definitely-typed

Change log parser for node.

CHANGELOG.md, changelog, parser, semantic, semver, versioning

readme

changelog-parser

npm build downloads

Change log parser for node.

Install

npm install changelog-parser

Usage

This module exports a single function. It supports both callbacks and promises.

var parseChangelog = require('changelog-parser')

Callback

If provided with a callback, parseChangelog will invoke the function with the parsed changelog.

parseChangelog('path/to/CHANGELOG.md', function (err, result) {
  if (err) throw err

  // changelog object
  console.log(result)
})

Promise

If no callback is provided, parseChangelog will return a Promise.

parseChangelog('path/to/CHANGELOG.md')
  .then(function (result) {
    // changelog object
    console.log(result)
  })
  .catch(function (err) {
    // Whoops, something went wrong!
    console.error(err)
  })

Options

You can optionally provide a configuration object parseChangelog function.

You must provide either filePath or text.

filePath

Path to changelog file.

parseChangelog({
  filePath: 'path/to/CHANGELOG.md'
})

text

Text of changelog file (you can use this instead of filePath).

parseChangelog({
  text: 'raw changelog text in string format'
})

removeMarkdown

Removes the markdown markup from the changelog entries by default. You can change its value to false to keep the markdown.

parseChangelog({
  filePath: 'path/to/CHANGELOG.md',
  removeMarkdown: false // default: true
})

Command-line interface

There is also a command-line interface available if you install it with -g.

npm install -g changelog-parser

This installs a program called changelog-parser that you simply pass a CHANGELOG.md file.

changelog-parser path/to/CHANGELOG.md

This will print the JSON object representing the change log to the terminal.

Alternately you can run it without arguments and it will look for a CHANGELOG.md file in the working directory.

Standards

This module assumes your change log is a markdown file structured roughly like so:

# changelog title

A cool description (optional).

## unreleased
* foo

## x.y.z - YYYY-MM-DD (or DD.MM.YYYY, D/M/YY, etc.)
* bar

## [a.b.c]

### Changes

* Update API
* Fix bug #1

## 2.2.3-pre.1 - 2013-02-14
* Update API

## 2.0.0-x.7.z.92 - 2013-02-14
* bark bark
* woof
* arf

## v1.3.0

* make it so

## [1.2.3](link)
* init

[a.b.c]: http://altavista.com

Parsing the above example will return the following object:

{
  title: 'changelog title',
  description: 'A cool description (optional).',
  versions: [
    { version: null,
      title: 'unreleased',
      date: null,
      body: '* foo',
      parsed: {
        _: [
          'foo'
        ]
      }
    },
    { version: 'x.y.z',
      title: 'x.y.z - YYYY-MM-DD',
      date: null,
      body: '* bar',
      parsed: {
        _: [
          'bar'
        ]
      }
    },
    { version: 'a.b.c',
      title: '[a.b.c]',
      date: null,
      body: '### Changes\n\n* Update API\n* Fix bug #1',
      parsed: {
        _: [
          'Update API',
          'Fix bug #1'
        ],
        Changes: [
          'Update API',
          'Fix bug #1'
        ]
      }
    },
    { version: '2.2.3-pre.1',
      title: '2.2.3-pre.1 - 2013-02-14',
      date: '2013-02-14',
      body: '* Update API',
      parsed: {
        _: [
          'Update API'
        ]
      }
    },
    { version: '2.0.0-x.7.z.92',
      title: '2.0.0-x.7.z.92 - 2013-02-14',
      date: '2013-02-14',
      body: '* bark bark\n* woof\n* arf',
      parsed: {
        _: [
          'bark bark',
          'woof',
          'arf'
        ]
      }
    },
    { version: '1.3.0',
      title: 'v1.3.0',
      date: null,
      body: '* make it so',
      parsed: {
        _: [
          'make it so'
        ]
      }
    },
    { version: '1.2.3',
      title: '[1.2.3](link)',
      date: null,
      body: '* init',
      parsed: {
        _: [
          'init'
        ]
      }
    }
  ]
}

Expects versions to be semver compliant, otherwise sets version to null.

Each entry is available as an object in the versions array. The body of a given entry can be accessed using the following properties:

  • body - A string containing all of the updates/changes/etc. for the current entry. This property includes both plain text and markdown.
  • parsed - An object which points to one or more arrays of data for the current entry. All data for the current entry is present in the array at key _ (eg. parsed._). If the entry contains subheadings (eg. ### Added, ### Changed), then any items underneath each subheading will be present in an array at the corresponding key (eg. parsed.Added, parsed.Changed). Each array contains plain text.

CHANGELOG.md standards are inspired by keepachangelog.com.

Contributing

Contributions welcome! Please read the contributing guidelines first.

See Also

License

ISC

Log image is from emojipedia.

changelog

Change Log

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

3.0.1 - 2022-12-23

Fixes

  • fix(pkg): specify minimum supported node version (14)

3.0.0 - 2022-12-20

Breaking Changes

  • Drop support for Node 12 (EOL)

Fixes

  • parse dates in parentheses (#49)

Misc

2.8.1 - 2022-03-13

Fixes

  • ci: drop support for non-LTS node versions (#39)
  • fix: update URLs for ownership transfer
  • ci: add dependabot.yml
  • docs: update status badges
  • deps(dev): tape@5, tap-spec@5, standard@16, gh-release@6 (#38)
  • ci: multi-arch tests (mac, windows, linux)
  • docs: add examples to options

2.8.0 - 2019-05-02

Features

  • accept input text instead of file (#32) - @jedwards1211 & @ungoldman

2.7.0 - 2019-03-07

Features

  • accept options object, add removeMarkdown option (#29) - @cironunes & @ungoldman

2.6.0 - 2018-12-18

Features

  • allow version headers in CHANGELOG to use either H1 (#) or H2 (##) headers (#14) - @eladb

2.5.1 - 2018-12-05

Fixes

  • Protect against no current value (#24) - thanks @sabrehagen

2.5.0 - 2018-05-30

Features

  • add international date format support (#25) - thanks @godban

2.4.0 - 2018-02-13

Features

  • stringify results in CLI (#22) - thanks @benmonro

2.3.0 - 2018-01-09

Features

  • add support for parsed body (#20) (#21) - thanks @jrmykolyn

2.2.0 - 2017-12-29

Features

  • add promise support (#18) (#19) - thanks @jrmykolyn

2.1.0 - 2017-12-12

Features

  • add date to version objects; update tests. (#6) (#15) - thanks @jrmykolyn

Chores

  • add release script

2.0.5 - 2017-06-28

Changes

  • chore(ci): add 8, drop .10 & .12
  • docs(readme): move badges out of title
  • lint: fix useless escapes
  • chore(pkg): bump to latest standard
  • chore(gitignore): ignore lock files
  • docs(readme): update repo web address

2.0.4

Fixes

  • reset log & current vars after each execution (#10)

2.0.3 - 2016-09-09

  • bump dev dependencies
  • update repo URL
  • update maintainer email

2.0.2 - 2015-06-15

  • readme updates
  • change log fix
  • add keywords to package.json

2.0.1 - 2015-06-07

Changes

  • use os module to support cross-platform EOL parsing (#4)

2.0.0 - 2015-04-02

Breaking Changes

  • version key of version object is now null unless semver found

Changes

Additions

  • add title key to version object
  • add a real test

1.1.0 - 2015-03-07

  • add cli support
  • remove description key if empty
  • add CONTRIBUTING.md
  • add node 0.10 to travis-ci testing environments

1.0.1 - 2015-03-02

1.0.0 - 2015-03-02

  • init