# `PackageUrl`

A package URL (ECMA-427) in its canonical form: `pkg:npm/%40angular/animation@12.3.1`.

[Software](types.md#software); not ordered; since Jadpo 0.1.0.

## Make one

Build one from its text, `PackageUrl("pkg:npm/%40angular/animation@12.3.1")`, which checks it: text that isn't one breaks `format`.

`text.parse(raw, as: PackageUrl)` reads one from its text; text that isn't one at all fails `malformed`, such as `PKG:npm/left-pad@1.3.0`, `pkg:NPM/left-pad@1.3.0` or `pkg://npm/left-pad@1.3.0`.

## Text, JSON and storage

`text.from` writes its canonical text, the one form `text.parse` reads back. JSON sends its canonical text as a string.

| Text | JSON |
|---|---|
| `pkg:npm/%40angular/animation@12.3.1` | `"pkg:npm/%40angular/animation@12.3.1"` |
| `pkg:pypi/django@1.11.1` | `"pkg:pypi/django@1.11.1"` |
| `pkg:maven/org.apache.xmlgraphics/batik-anim@1.9.1?classifier=sources&packaging=jar` | `"pkg:maven/org.apache.xmlgraphics/batik-anim@1.9.1?classifier=sources&packaging=jar"` |
| `pkg:deb/debian/curl@7.50.3-1?arch=i386&distro=jessie` | `"pkg:deb/debian/curl@7.50.3-1?arch=i386&distro=jessie"` |
| `pkg:golang/google.golang.org/genproto#googleapis/api/annotations` | `"pkg:golang/google.golang.org/genproto#googleapis/api/annotations"` |
| `pkg:docker/cassandra@sha256:244fd47e07d1004f0aed9c` | `"pkg:docker/cassandra@sha256:244fd47e07d1004f0aed9c"` |

It is stored in one column named for the field, of type `text`. `pkg:deb/debian/curl@7.50.3-1?arch=i386&distro=jessie` is stored as `'pkg:deb/debian/curl@7.50.3-1?arch=i386&distro=jessie'`.

## Shown to people

`text.format(value, locale:)` shows it to people in their locale.

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `pkg:npm/%40angular/animation@12.3.1` | `pkg:npm/%40angular/animation@12.3.1` |
| `pkg:pypi/django@1.11.1` | `pkg:pypi/django@1.11.1` |
| `pkg:maven/org.apache.xmlgraphics/batik-anim@1.9.1?classifier=sources&packaging=jar` | `pkg:maven/org.apache.xmlgraphics/batik-anim@1.9.1?classifier=sources&packaging=jar` |
| `pkg:deb/debian/curl@7.50.3-1?arch=i386&distro=jessie` | `pkg:deb/debian/curl@7.50.3-1?arch=i386&distro=jessie` |
| `pkg:golang/google.golang.org/genproto#googleapis/api/annotations` | `pkg:golang/google.golang.org/genproto#googleapis/api/annotations` |
| `pkg:docker/cassandra@sha256:244fd47e07d1004f0aed9c` | `pkg:docker/cassandra@sha256:244fd47e07d1004f0aed9c` |

## Operations

It has the contract's own operations: `text.parse`, `text.from`, `text.format`, `json.read`, `json.write` and `==`. It isn't ordered, so `<` and sorting don't take it. [Every standard type meets one contract](../topics/every-standard-type-meets-one-contract.md) says how they work.
