.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / registry-auth-token / README.md
1 # registry-auth-token
2
3 [![npm version](http://img.shields.io/npm/v/registry-auth-token.svg?style=flat-square)](http://browsenpm.org/package/registry-auth-token)[![Build Status](http://img.shields.io/travis/rexxars/registry-auth-token/master.svg?style=flat-square)](https://travis-ci.org/rexxars/registry-auth-token)
4
5 Get the auth token set for an npm registry from `.npmrc`. Also allows fetching the configured registry URL for a given npm scope.
6
7 ## Installing
8
9 ```
10 npm install --save registry-auth-token
11 ```
12
13 ## Usage
14
15 Returns an object containing `token` and `type`, or `undefined` if no token can be found. `type` can be either `Bearer` or `Basic`.
16
17 ```js
18 var getAuthToken = require('registry-auth-token')
19 var getRegistryUrl = require('registry-auth-token/registry-url')
20
21 // Get auth token and type for default `registry` set in `.npmrc`
22 console.log(getAuthToken()) // {token: 'someToken', type: 'Bearer'}
23
24 // Get auth token for a specific registry URL
25 console.log(getAuthToken('//registry.foo.bar'))
26
27 // Find the registry auth token for a given URL (with deep path):
28 // If registry is at `//some.host/registry`
29 // URL passed is `//some.host/registry/deep/path`
30 // Will find token the closest matching path; `//some.host/registry`
31 console.log(getAuthToken('//some.host/registry/deep/path', {recursive: true}))
32
33 // Find the configured registry url for scope `@foobar`.
34 // Falls back to the global registry if not defined.
35 console.log(getRegistryUrl('@foobar'))
36
37 // Use the npm config that is passed in
38 console.log(getRegistryUrl('http://registry.foobar.eu/', {
39   npmrc: {
40     'registry': 'http://registry.foobar.eu/',
41     '//registry.foobar.eu/:_authToken': 'qar'
42   }
43 }))
44 ```
45
46 ## Return value
47
48 ```js
49 // If auth info can be found:
50 {token: 'someToken', type: 'Bearer'}
51
52 // Or:
53 {token: 'someOtherToken', type: 'Basic'}
54
55 // Or, if nothing is found:
56 undefined
57 ```
58
59 ## Security
60
61 Please be careful when using this. Leaking your auth token is dangerous.
62
63 ## License
64
65 MIT-licensed. See LICENSE.