module-id
Parse commonjs module id into name
, version
and path
.
Install
$ npm i module-id
id(module_id)
const id = const parsed = parsedname // 'a',parsedversion // undefined,parsedpath // '/abc.js' parsedid // 'a/abc.js'parsedurl // 'a/*/abc.js', the normalized url pathparsedpkg // 'a@*' // Change versionparsedversion = '1.1.0'parsedid // '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 = parsedscope // undefined parsedscope = 'facebook' parsedname // '@facebook/a'parsedid // '@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 = parsedname = '@facebook/a' parsedscope // 'facebook'