lyxaira.glass 74ca844f42 Actualizacion cambios generados: seccion #12, #14 y #15. | 4 年 前 | |
---|---|---|
.. | ||
test | 4 年 前 | |
CHANGELOG.md | 4 年 前 | |
LICENSE | 4 年 前 | |
README.md | 4 年 前 | |
base64.js | 4 年 前 | |
index.js | 4 年 前 | |
package.json | 4 年 前 | |
registry-url.js | 4 年 前 |
Get the auth token set for an npm registry from .npmrc
. Also allows fetching the configured registry URL for a given npm scope.
npm install --save registry-auth-token
Returns an object containing token
and type
, or undefined
if no token can be found. type
can be either Bearer
or Basic
.
var getAuthToken = require('registry-auth-token')
var getRegistryUrl = require('registry-auth-token/registry-url')
// Get auth token and type for default `registry` set in `.npmrc`
console.log(getAuthToken()) // {token: 'someToken', type: 'Bearer'}
// Get auth token for a specific registry URL
console.log(getAuthToken('//registry.foo.bar'))
// Find the registry auth token for a given URL (with deep path):
// If registry is at `//some.host/registry`
// URL passed is `//some.host/registry/deep/path`
// Will find token the closest matching path; `//some.host/registry`
console.log(getAuthToken('//some.host/registry/deep/path', {recursive: true}))
// Find the configured registry url for scope `@foobar`.
// Falls back to the global registry if not defined.
console.log(getRegistryUrl('@foobar'))
// Use the npm config that is passed in
console.log(getRegistryUrl('http://registry.foobar.eu/', {
npmrc: {
'registry': 'http://registry.foobar.eu/',
'//registry.foobar.eu/:_authToken': 'qar'
}
}))
// If auth info can be found:
{token: 'someToken', type: 'Bearer'}
// Or:
{token: 'someOtherToken', type: 'Basic'}
// Or, if nothing is found:
undefined
Please be careful when using this. Leaking your auth token is dangerous.
MIT-licensed. See LICENSE.