Query npm registry for a package's license.
(name: str, version: str)
| 253 | |
| 254 | |
| 255 | def lookup_npm(name: str, version: str) -> str | None: |
| 256 | """Query npm registry for a package's license.""" |
| 257 | encoded = urllib.parse.quote(name, safe="") |
| 258 | data = _get_json( |
| 259 | f"https://registry.npmjs.org/{encoded}/{version}", "registry.npmjs.org" |
| 260 | ) |
| 261 | if data: |
| 262 | lic = data.get("license") |
| 263 | if isinstance(lic, dict): |
| 264 | return lic.get("type") |
| 265 | if isinstance(lic, str): |
| 266 | return lic |
| 267 | return None |
| 268 | |
| 269 | |
| 270 | def lookup_pypi(name: str, version: str) -> str | None: |
no test coverage detected