module-id
v2.0.6
Published
Parses commonjs module id into name, version and path.
Downloads
6
Maintainers
Readme
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 // '[email protected]/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'