Socket
Book a DemoInstallSign in
Socket

assert-version

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assert-version

Check if version mentions match the one from package.json

0.0.3
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

assert-version

Check if version mentions match the one from package.json

Install

npm install -g assert-version

How matches work

Version could be extracted with regular expression or, if you use assert-version as Node.js module, with user-defined function.

In case of regular expression, version should present in first capture.

There are two default regular expressions. If your file has .json extension, /"version":\s*"([^"]+)/ expression is used. Otherwise, /\/\*\![\s\S]+(v?\d+\.\d+\.\d+)/ expression is used. I understand that these expressions are not great, they just seem to work for my cases. Feel free to send improvements.

Extracted version should be valid semver version.

Use as Node.js module

assertVersion = require('assert-version');

var error = assertVersion({
    'bower.json': '', // First default regular expression will be used.
    'mylib.js': '', // Second default regular expression will be used.
    'other.js': /version=([^,]+)/,
    'other2.js': function(contents) {
        // `contents` is a file contents, function should return version as
        // string.
        return contents.substring(100500, 100510);
    },
    'other3.js': [matcher1, matcher2] // If you need to check more than one place in file.
});

// `error` will have error message in case of error, `undefined` otherwise.

Optionally, you can pass path to package.json with reference version as second argument of assertVersion(). It is package.json from current working directory by default.

Use as command line tool

Same to previous example (except for function extractor):

assert-version -f bower.json -f mylib.js -f other.js='version=([^,]+)' -f other3.js=matcher1 -f other3.js=matcher2

Example (Gulp task)

Example from https://github.com/hoho/conkitty-route/blob/master/gulpfile.js.

gulp.task('assert-version', function(err) {
    var assertVersion = require('assert-version');

    err(assertVersion({
        'croute.js': '',
        'bower.json': ''
    }));
});

Example (Grunt task)

Example from https://github.com/hoho/concat.js/blob/master/Gruntfile.js.

grunt.registerTask('assert-version', function() {
    var assertVersion = require('assert-version'),
        error;

    error = assertVersion({
        'concat.js': '',
        'bower.json': ''
    });

    if (error) {
        grunt.log.error(error);
        return false;
    }
});

FAQs

Package last updated on 11 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.