pax_global_header00006660000000000000000000000064142546467500014527gustar00rootroot0000000000000052 comment=41a8923ffa8571d5f613a5305b911a1b61bbd499 registry-url-6.0.1/000077500000000000000000000000001425464675000142035ustar00rootroot00000000000000registry-url-6.0.1/.editorconfig000066400000000000000000000002571425464675000166640ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 registry-url-6.0.1/.gitattributes000066400000000000000000000000231425464675000170710ustar00rootroot00000000000000* text=auto eol=lf registry-url-6.0.1/.github/000077500000000000000000000000001425464675000155435ustar00rootroot00000000000000registry-url-6.0.1/.github/funding.yml000066400000000000000000000000601425464675000177140ustar00rootroot00000000000000github: sindresorhus tidelift: npm/registry-url registry-url-6.0.1/.github/security.md000066400000000000000000000002631425464675000177350ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. registry-url-6.0.1/.github/workflows/000077500000000000000000000000001425464675000176005ustar00rootroot00000000000000registry-url-6.0.1/.github/workflows/main.yml000066400000000000000000000006451425464675000212540ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: test: name: Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: node-version: - 14 - 12 steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test registry-url-6.0.1/.gitignore000066400000000000000000000000271425464675000161720ustar00rootroot00000000000000node_modules yarn.lock registry-url-6.0.1/index.d.ts000066400000000000000000000013021425464675000161000ustar00rootroot00000000000000/** Get the set npm registry URL. @param scope - Retrieve the registry URL associated with an [npm scope](https://docs.npmjs.com/misc/scope). If the provided scope is not in the user's `.npmrc` file, then `registry-url` will check for the existence of `registry`, or if that's not set, fallback to the default npm registry. @example ``` import registryUrl from 'registry-url'; // # .npmrc // registry = 'https://custom-registry.com/' console.log(registryUrl()); //=> 'https://custom-registry.com/' // # .npmrc // @myco:registry = 'https://custom-registry.com/' console.log(registryUrl('@myco')); //=> 'https://custom-registry.com/' ``` */ export default function registryUrl(scope?: string): string; registry-url-6.0.1/index.js000066400000000000000000000004231425464675000156470ustar00rootroot00000000000000import rc from 'rc'; export default function registryUrl(scope) { const result = rc('npm', {registry: 'https://registry.npmjs.org/'}); const url = result[`${scope}:registry`] || result.config_registry || result.registry; return url.slice(-1) === '/' ? url : `${url}/`; } registry-url-6.0.1/index.test-d.ts000066400000000000000000000002241425464675000170570ustar00rootroot00000000000000import {expectType} from 'tsd'; import registryUrl from './index.js'; expectType(registryUrl()); expectType(registryUrl('@myco')); registry-url-6.0.1/license000066400000000000000000000021351425464675000155510ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. registry-url-6.0.1/package.json000066400000000000000000000013741425464675000164760ustar00rootroot00000000000000{ "name": "registry-url", "version": "6.0.1", "description": "Get the set npm registry URL", "license": "MIT", "repository": "sindresorhus/registry-url", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "type": "module", "exports": "./index.js", "engines": { "node": ">=12" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "npm", "conf", "config", "npmconf", "registry", "url", "uri", "scope" ], "dependencies": { "rc": "1.2.8" }, "devDependencies": { "ava": "^3.15.0", "tsd": "^0.14.0", "xo": "^0.38.2" }, "ava": { "serial": true } } registry-url-6.0.1/readme.md000066400000000000000000000026201425464675000157620ustar00rootroot00000000000000# registry-url > Get the set npm registry URL It's usually `https://registry.npmjs.org/`, but it's [configurable](https://docs.npmjs.com/misc/registry). Use this if you do anything with the npm registry as users will expect it to use their configured registry. ## Install ``` $ npm install registry-url ``` ## Usage ```ini # .npmrc registry = 'https://custom-registry.com/' ``` ```js import registryUrl from 'registry-url'; console.log(registryUrl()); //=> 'https://custom-registry.com/' ``` It can also retrieve the registry URL associated with an [npm scope](https://docs.npmjs.com/misc/scope). ```ini # .npmrc @myco:registry = 'https://custom-registry.com/' ``` ```js import registryUrl from 'registry-url'; console.log(registryUrl('@myco')); //=> 'https://custom-registry.com/' ``` If the provided scope is not in the user's `.npmrc` file, then `registry-url` will check for the existence of `registry`, or if that's not set, fallback to the default npm registry. ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
registry-url-6.0.1/test.js000066400000000000000000000036211425464675000155220ustar00rootroot00000000000000import {promisify} from 'util'; import fs from 'fs'; import test from 'ava'; // eslint-disable-next-line node/no-unsupported-features/es-syntax const importFresh = async modulePath => import(`${modulePath}?x=${new Date()}`); const unlinkP = promisify(fs.unlink); const writeFileP = promisify(fs.writeFile); delete process.env.npm_config_registry; test.afterEach(async () => { try { await unlinkP('.npmrc'); } catch {} }); test('get the npm registry URL globally', async t => { t.truthy((await importFresh('./index.js')).default().length); }); test('works with npm_config_registry in the environment', async t => { // eslint-disable-next-line camelcase process.env.npm_config_registry = 'http://registry.example'; t.is((await importFresh('./index.js')).default(), 'http://registry.example/'); delete process.env.npm_config_registry; }); test('get the npm registry URL locally', async t => { await writeFileP('.npmrc', 'registry=http://registry.npmjs.eu/'); t.is((await importFresh('./index.js')).default(), 'http://registry.npmjs.eu/'); }); test('get local scope registry URL', async t => { await writeFileP('.npmrc', '@myco:registry=http://reg.example.com/'); t.is((await importFresh('./index.js')).default('@myco'), 'http://reg.example.com/'); }); test('return default npm registry when scope registry is not set', async t => { await writeFileP('.npmrc', ''); t.is((await importFresh('./index.js')).default('@invalidScope'), 'https://registry.npmjs.org/'); }); test('add trailing slash to local npm registry URL', async t => { await writeFileP('.npmrc', 'registry=http://registry.npmjs.eu'); t.is((await importFresh('./index.js')).default(), 'http://registry.npmjs.eu/'); }); test('add trailing slash to local scope registry URL', async t => { await writeFileP('.npmrc', '@myco:registry=http://reg.example.com'); t.is((await importFresh('./index.js')).default('@myco'), 'http://reg.example.com/'); });