Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A Node.js module for reading/modifying/writing package.json files
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
.gitignore
package.json
readme.md

readme.md

pkg

A Node.js module for reading/editting/writing package.json files.

Install

$ npm install pkg

Usage

var pkg = require('pkg');

var file = pkg.read(module);

file.version();  // "1.2.3-4"
file.version({ parse: true });  // {major: 1, minor: 2, patch: 3, build: 4}

file.incVersion('build');

file.version();  // "1.2.3-5"

file.writeSync();

API

pkg.read ( Mixed fileOrModule[, Function callback ])

Creates a new pkg.Package object. The fileOrModule argument can be a file path to a package.json file or a module object. If a callback is given, the file will be read async, otherwise it will be read sync.

var file1 = pkg.read(module);
var file2 = pkg.read('../foo/package.json', function() {
    // ...
});

pkg.Package ( Mixed fileOrModule )

Inherits the File constructor from json-file.

Package::version ([ Object opts ])

Reads the version property from the file data. If a {parse: true} option is given, the version will be parsed onto an object like this:

{
    "major": 1,
    "minor": 0,
    "patch": 3,
    "build": 5
}

Package::incVersion ( String release )

Increments the version in the file data. release is which part of the version to increment.

file.version();  // 1.2.3-4
file.incVersion('minor');
file.version();  // 1.3.0-0
Something went wrong with that request. Please try again.