swh.indexer.metadata_dictionary.npm module

class swh.indexer.metadata_dictionary.npm.NpmMapping(log_suffix='')[source]

Bases: swh.indexer.metadata_dictionary.base.JsonMapping

dedicated class for NPM (package.json) mapping and translation

name = 'npm'
mapping = {'author': 'http://schema.org/author', 'author.email': 'http://schema.org/email', 'author.name': 'http://schema.org/name', 'bugs': 'https://codemeta.github.io/terms/issueTracker', 'contributor': 'http://schema.org/contributor', 'cpu': 'http://schema.org/processorRequirements', 'description': 'http://schema.org/description', 'engines': 'http://schema.org/processorRequirements', 'homepage': 'http://schema.org/url', 'keywords': 'http://schema.org/keywords', 'license': 'http://schema.org/license', 'name': 'http://schema.org/name', 'os': 'http://schema.org/operatingSystem', 'repository': 'http://schema.org/codeRepository', 'version': 'http://schema.org/version'}
filename = b'package.json'
string_fields = ['name', 'version', 'homepage', 'description', 'email']
normalize_repository(d)[source]

https://docs.npmjs.com/files/package.json#repository

>>> NpmMapping().normalize_repository({
...     'type': 'git',
...     'url': 'https://example.org/foo.git'
... })
{'@id': 'git+https://example.org/foo.git'}
>>> NpmMapping().normalize_repository(
...     'gitlab:foo/bar')
{'@id': 'git+https://gitlab.com/foo/bar.git'}
>>> NpmMapping().normalize_repository(
...     'foo/bar')
{'@id': 'git+https://github.com/foo/bar.git'}
normalize_bugs(d)[source]

https://docs.npmjs.com/files/package.json#bugs

>>> NpmMapping().normalize_bugs({
...     'url': 'https://example.org/bugs/',
...     'email': 'bugs@example.org'
... })
{'@id': 'https://example.org/bugs/'}
>>> NpmMapping().normalize_bugs(
...     'https://example.org/bugs/')
{'@id': 'https://example.org/bugs/'}
normalize_author(d)[source]

https://docs.npmjs.com/files/package.json#people-fields-author-contributors

>>> from pprint import pprint
>>> pprint(NpmMapping().normalize_author({
...     'name': 'John Doe',
...     'email': 'john.doe@example.org',
...     'url': 'https://example.org/~john.doe',
... }))
{'@list': [{'@type': 'http://schema.org/Person',
            'http://schema.org/email': 'john.doe@example.org',
            'http://schema.org/name': 'John Doe',
            'http://schema.org/url': {'@id': 'https://example.org/~john.doe'}}]}
>>> pprint(NpmMapping().normalize_author(
...     'John Doe <john.doe@example.org> (https://example.org/~john.doe)'
... ))
{'@list': [{'@type': 'http://schema.org/Person',
            'http://schema.org/email': 'john.doe@example.org',
            'http://schema.org/name': 'John Doe',
            'http://schema.org/url': {'@id': 'https://example.org/~john.doe'}}]}
normalize_license(s)[source]

https://docs.npmjs.com/files/package.json#license

>>> NpmMapping().normalize_license('MIT')
{'@id': 'https://spdx.org/licenses/MIT'}
normalize_homepage(s)[source]

https://docs.npmjs.com/files/package.json#homepage

>>> NpmMapping().normalize_homepage('https://example.org/~john.doe')
{'@id': 'https://example.org/~john.doe'}
normalize_keywords(lst)[source]

https://docs.npmjs.com/files/package.json#homepage

>>> NpmMapping().normalize_keywords(['foo', 'bar'])
['foo', 'bar']