npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@freddydrodev/auto-version

v0.0.4

Published

An auto version library for NPM

Downloads

2

Readme

Auto Version JS

npm version npm downloads

auto-version-js is a light & fast NPM library to automatically increase the version number of a package.

Installation

First, install the npm package :

npm i -D auto-version-js

Then to increment the version number, simply run :

npx auto-version --patch  # +0.0.1
npx auto-version --minor  # +0.1.0
npx auto-version --major  # +1.0.0
npx auto-version          # no args is equivalent to --patch

To implement it in your package.json file :

"scripts": {
    "publish": "npx auto-version && npm publish"
}

Documentation

In this library, versionString represents a version as a string : '1.2.3' and versionObject represents a version as an object : { major: 1, minor: 2, patch: 3 }

Classes

Typedefs

AutoVersion

AutoVersion.getLocalPath() ⇒ string

Return the path of the project

Returns: string - the path of the project where the package.json is located

AutoVersion.getPackageJSON([pathname]) ⇒ JSON

Return the package.json file of the project

Returns: JSON - the package.json

| Param | Type | Description | | --- | --- | --- | | [pathname] | string | the path of the package.json |

AutoVersion.getVersion([pathname]) ⇒ string

Return the current version of the project

Returns: string - the version number

| Param | Type | Description | | --- | --- | --- | | [pathname] | string | the path of the package.json |

Example

AutoVersion.getVersion()              // --> the version of the current project | ex : 0.5.2
AutoVersion.getVersion('../any/dir')  // --> the version of the project in this directory

AutoVersion.setVersion(version, [pathname], [indentation])

Write the version number into package.json

| Param | Type | Default | Description | | --- | --- | --- | --- | | version | string | | the version number | | [pathname] | string | | the path of the package.json | | [indentation] | number | 4 | the number of space to pretty print the package.json file |

Example

AutoVersion.setVersion('0.2.3')
AutoVersion.setVersion('0.2.3', '../any/dir')
AutoVersion.setVersion('0.2.3', '../any/dir', 4)  // the package.json will be indented with 4 spaces

AutoVersion.parse(versionString) ⇒ VersionObject

Extract the major, minor & patch number from a semver version number

| Param | | --- | | versionString |

Example

AutoVersion.parse('1.4.2')  // --> {major: 1, minor: 4, patch: 2}

AutoVersion.stringify(versionObject) ⇒ string

Stringify a versionObject

Returns: string - the version representation of the string

| Param | | --- | | versionObject |

Example

AutoVersion.stringify({major: 1, minor: 4, patch: 2})  // --> '1.4.2'

AutoVersion.toSemver(versionString) ⇒ string

Convert a version into semver standard

Returns: string - the semver version number

| Param | | --- | | versionString |

Example

AutoVersion.toSemver('1.3.5')      // --> '1.3.5'
AutoVersion.toSemver('1.3')        // --> '1.3.0'
AutoVersion.toSemver('v1.3.5')     // -->  '1.3.5'
AutoVersion.toSemver('version 3')  // -->  '3.0.0'

AutoVersion.increment(version, level) ⇒ string

Increment the version number

Returns: string - the incremented version number

| Param | Type | Description | | --- | --- | --- | | version | string | | | level | string | major | minor | patch |

Example

AutoVersion.increment('0.4.7', 'patch')  // --> '0.4.8'
AutoVersion.increment('0.4.7', 'minor')  // --> '0.5.0'
AutoVersion.increment('0.4.7', 'major')  // --> '1.0.0'

AutoVersion.major(version) ⇒ string

Update the version number for a major update

Returns: string - the new version number

| Param | Type | | --- | --- | | version | string |

Example

AutoVersion.major('1.0.0')  // --> '2.0.0'
AutoVersion.major('0.5.9')  // --> '1.0.0'

AutoVersion.minor(version) ⇒ string

Update the version number for a minor update

Returns: string - the new version number

| Param | Type | | --- | --- | | version | string |

Example

AutoVersion.minor('1.0.0')  // --> '1.1.0'
AutoVersion.minor('0.5.8')  // --> '0.6.0'

AutoVersion.patch(version) ⇒ string

Update the version number for a patch update

Returns: string - the new version number

| Param | Type | | --- | --- | | version | string |

Example

AutoVersion.patch('1.0.0')  // --> '1.0.1'
AutoVersion.patch('0.5.9')  // --> '0.5.10'

VersionObject : Object

Properties

| Name | Type | | --- | --- | | major | number | | minor | number | | patch | number |

Example

{major: 1, minor: 3, patch: 7}  // represents 1.3.7

2020 © Dorian Beauchesne