MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / npm_api_url

Function npm_api_url

src/packagedcode/npm.py:1508–1540  ·  view source on GitHub ↗

Return a package API data URL given a namespace, name, version and a base registry URL. Special quoting rules are applied for scoped npms. For example: >>> result = npm_api_url('@invisionag', 'eslint-config-ivx', '0.1.4', 'https://registry.yarnpkg.com') >>> assert result =

(namespace, name, version=None, registry='https://registry.npmjs.org')

Source from the content-addressed store, hash-verified

1506
1507
1508def npm_api_url(namespace, name, version=None, registry='https://registry.npmjs.org'):
1509 """
1510 Return a package API data URL given a namespace, name, version and a base
1511 registry URL.
1512
1513 Special quoting rules are applied for scoped npms.
1514
1515 For example:
1516 >>> result = npm_api_url('@invisionag', 'eslint-config-ivx', '0.1.4', 'https://registry.yarnpkg.com')
1517 >>> assert result == 'https://registry.yarnpkg.com/@invisionag%2feslint-config-ivx/0.1.4'
1518
1519 >>> result = npm_api_url('@invisionag', 'eslint-config-ivx', registry='https://registry.yarnpkg.com')
1520 >>> assert result == 'https://registry.yarnpkg.com/@invisionag%2feslint-config-ivx'
1521
1522 >>> assert npm_api_url(None, 'angular', '1.6.6') == 'https://registry.npmjs.org/angular/1.6.6'
1523 >>> assert npm_api_url(None, 'angular') == 'https://registry.npmjs.org/angular'
1524
1525 >>> assert not npm_api_url(None, None, None)
1526 """
1527 if name:
1528 if namespace:
1529 # this is a legacy wart: older registries used to always encode this /
1530 # FIXME: do NOT encode and use plain / instead
1531 ns_name = '%2f'.join([namespace, name])
1532 else:
1533 ns_name = name
1534
1535 if version:
1536 version = f'/{version}'
1537 else:
1538 version = ''
1539
1540 return f'{registry}/{ns_name}{version}'
1541
1542
1543def is_scoped_package(name):

Callers 1

get_urlsFunction · 0.85

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected