module-id

2.0.6 • Public • Published

Build Status Coverage

module-id

Parse commonjs module id into name, version and path.

Install

$ npm i module-id

id(module_id)

const id = require('module-id')
 
const parsed = id('a/abc.js')
 
parsed.name     // 'a',
parsed.version  // undefined,
parsed.path     // '/abc.js'
 
parsed.id       // 'a/abc.js'
parsed.url      // 'a/*/abc.js', the normalized url path
parsed.pkg      // 'a@*'
 
// Change version
parsed.version = '1.1.0'
parsed.id       // 'a@1.1.0/abc.js'

About Scoped Packages

Getter: .name

The name of a package, i.e. the name field of package.json, supports scoped package names

Setting scope will affect the value of name

const parsed = id('a/index.js')
 
parsed.scope   // undefined
 
parsed.scope = 'facebook'
 
parsed.name    // '@facebook/a'
parsed.id      // '@facebook/a/index.js'

Setter: .name

If the given value of name is a scoped package name, it will also affect the scope property

const parsed = id('a/index.js')
parsed.name = '@facebook/a'
 
parsed.scope   // 'facebook'

License

MIT

Package Sidebar

Install

npm i module-id

Weekly Downloads

0

Version

2.0.6

License

MIT

Unpacked Size

9.99 kB

Total Files

6

Last publish

Collaborators

  • kael