normalize-shorthands
Advanced tools
Comparing version 1.0.0 to 2.0.0
54
index.js
@@ -6,27 +6,15 @@ | ||
module.exports = function (remotes) { | ||
var hostname = remotes.hostname | ||
var hostname = remotes.server | ||
// create a map lookup of remote.name => remote | ||
// to do: make registry and client's remotes objects more consistent | ||
var map = Object.create(null) | ||
if (remotes.names) { | ||
// normalize proxy | ||
remotes.names.forEach(function (name) { | ||
var remote = remotes[name] | ||
remote.aliases.forEach(function (alias) { | ||
map[alias] = remote | ||
}) | ||
Object.keys(remotes.remotes).forEach(function (name) { | ||
var remote = remotes.remotes[name] | ||
remote.aliases.forEach(function (alias) { | ||
map[alias] = remote | ||
}) | ||
} else if (Array.isArray(remotes.remotes)) { | ||
// proxy.json | ||
remotes.remotes.forEach(function (remote) { | ||
remote.aliases.forEach(function (alias) { | ||
map[alias] = remote | ||
}) | ||
}) | ||
} | ||
}) | ||
shorthand.js = js | ||
return shorthand | ||
function shorthand(uri, ext) { | ||
return function shorthand(uri, ext) { | ||
if (is.url(uri)) return null | ||
@@ -46,3 +34,3 @@ if (is.data(uri)) return null | ||
if (m = /^(?:npm\:)?([\w-.]+)(?:@([^\/]+))/.exec(uri)) { | ||
if (m = /^(?:npm\:)?([\w-.]+)(?:@([^\/]*))/.exec(uri)) { | ||
debug('got npm shorthand for: %s', uri) | ||
@@ -55,3 +43,3 @@ // (npm:)project@version | ||
uri = uri.replace(m[0], '') | ||
} else if (m = /^(?:npm\:)?(?:@([\w-]+))\/([\w-.]+)(?:@([^\/]+))?/.exec(uri)) { | ||
} else if (m = /^(?:npm\:)?(?:@([\w-]+))\/([\w-.]+)(?:@([^\/]*))?/.exec(uri)) { | ||
debug('got npm org shorthand for: %s', uri) | ||
@@ -65,3 +53,3 @@ // (npm:)@org/project@version | ||
uri = uri.replace(m[0], '') | ||
} else if (m = /^([\w-]+)\/([\w-.]+)@([^/]+)/.exec(uri)) { | ||
} else if (m = /^([\w-]+)\/([\w-.]+)@([^/]*)/.exec(uri)) { | ||
debug('got github shorthand for: %s', uri) | ||
@@ -88,3 +76,3 @@ // user/project@version, defaulting to github | ||
if (remote.namespace !== false) { | ||
if (m = /^([\w-]+)\/([\w-.]+)(?:@([^\/]+))?/.exec(uri)) { | ||
if (m = /^([\w-]+)\/([\w-.]+)(?:@([^\/]*))?/.exec(uri)) { | ||
user = m[1] | ||
@@ -99,3 +87,3 @@ project = m[2] | ||
} else { | ||
if (m = /^([\w-.]+)(?:@([^\/]+))?/.exec(uri)) { | ||
if (m = /^([\w-.]+)(?:@([^\/]*))?/.exec(uri)) { | ||
project = m[1] | ||
@@ -129,18 +117,2 @@ version = m[2] | ||
} | ||
function js(remote, user, project, version, filename) { | ||
var name = remote.name | ||
var named = name !== 'npm' && name !== 'github' | ||
var val = '' | ||
if (named) | ||
val += (remote.shorthand || name) + ':' | ||
if (user && user !== '-') | ||
val += (name === 'npm' ? '@' : '') + user + '/' | ||
val += project + '@' + (version || '*') | ||
if (!filename || filename === 'index.js') return val | ||
return val + '/' + filename | ||
.replace(/\/index\.js$/, '/') | ||
.replace(/\.js$/, '') | ||
} | ||
} |
{ | ||
"name": "normalize-shorthands", | ||
"description": "shorthand URIs for normalize", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"author": { | ||
@@ -19,8 +19,8 @@ "name": "Jonathan Ong", | ||
"istanbul-harmony": "0", | ||
"normalize-proxy": "*" | ||
"normalize-remotes": "1" | ||
}, | ||
"scripts": { | ||
"test": "node --harmony-generators test", | ||
"test-cov": "node --harmony-generators ./node_modules/.bin/istanbul cover node -- --harmony-generators test", | ||
"test-travis": "node --harmony-generators ./node_modules/.bin/istanbul cover node -- --harmony-generators test" | ||
"test-cov": "node --harmony-generators ./node_modules/.bin/istanbul cover test", | ||
"test-travis": "node --harmony-generators ./node_modules/.bin/istanbul cover test" | ||
}, | ||
@@ -27,0 +27,0 @@ "files": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6107
100