项目作者: flexdinesh

项目描述 :
Library to check any npm module's version from browser console
高级语言: JavaScript
项目地址: git://github.com/flexdinesh/global-package-version.git
创建时间: 2018-01-20T13:57:58Z
项目社区:https://github.com/flexdinesh/global-package-version

开源协议:MIT License

下载


Global Package Version

Build Status
npm version
dependencies Status
License: MIT
npm

Look up the version of one or more npm packages in browser console.

This library sets the package version in global/window variable so it can be accessed anywhere in your code or browser console.

Install

  1. $ npm install --save global-package-version

Usage

Import

  1. // ES6 style
  2. import globalPackageVersion from 'global-package-version';
  3. // or
  4. //ES5 style
  5. var globalPackageVersion = require('global-package-version');

NPM packages

You can check the version of any of your npm packages

  1. // package name is 'lodash'
  2. globalPackageVersion(require('lodash/package.json'));
  3. // You can type 'packageVersion' in browser console to check lodash Version
  4. // => packageVersion = { lodash: '4.7.2'}

Your own library

If you are building a library, you can set the version of your published package and your users will be able to check your package’s version in their browser console.

Note: This won’t affect/override any of your other variables/methods in your library.

  1. // ''../package.json' is the location of your package json
  2. // libName will be your export
  3. // example: import libName from 'libname';
  4. globalPackageVersion(require('../package.json'), {
  5. wrapper: 'libName',
  6. customPackageName: 'version'
  7. });
  8. // Your users can type 'libName.version' in browser console to check your library version
  9. // => libName.version = '1.7.0'

Options

Pass in options param to give custom variable names

  1. // wrapper
  2. globalPackageVersion(require('trim-right/package.json'),
  3. { wrapper: 'whichVersion' }
  4. );
  5. // => whichVersion = { trimRight: '1.2.3'}
  6. // customPackageName
  7. globalPackageVersion(require('trim-right/package.json'),
  8. { customPackageName: 'trimLibrary' }
  9. );
  10. // => packageVersion = { trimLibrary: '4.7.2'}
  11. // both wrapper and customPackageName
  12. globalPackageVersion(require('trim-right/package.json'), {
  13. wrapper: 'whichVersion',
  14. customPackageName: 'trimLibrary' }
  15. );
  16. // => whichVersion = { trimLibrary: '4.7.2'}

Multiple package versions can be set to global

  1. // should require each package separately
  2. globalPackageVersion(require('lodash/package.json'));
  3. globalPackageVersion(require('left-pad/package.json'));
  4. /*
  5. packageVersion = {
  6. lodash: '4.7.2',
  7. leftPad: '2.1.0'
  8. }
  9. */

License

MIT © Dineshkumar Pandiyan