Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/richdouglasevans/iiif-url
IIIF Image API URI Parser for JS/TS
https://github.com/richdouglasevans/iiif-url
Last synced: 27 days ago
JSON representation
IIIF Image API URI Parser for JS/TS
- Host: GitHub
- URL: https://github.com/richdouglasevans/iiif-url
- Owner: richdouglasevans
- License: mit
- Created: 2022-12-05T14:41:05.000Z (about 2 years ago)
- Default Branch: v3
- Last Pushed: 2024-11-29T08:51:48.000Z (about 1 month ago)
- Last Synced: 2024-11-29T09:36:23.469Z (about 1 month ago)
- Language: TypeScript
- Size: 332 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# iiif-url
> IIIF Image API URI Parser `3.0` for JS/TS
## Usage
### Image Request URIs
```js
import { parseURI } from "iiif-url";const result = parseURI(
"https://iiif.bodleian.ox.ac.uk/iiif/image/f27e28db-0b08-4f16-9bdf-3565f591fb71/full/256,/0/default.jpg"
);
``````json
{
"tag": "imageRequest",
"uri": "https://iiif.bodleian.ox.ac.uk/iiif/image/f27e28db-0b08-4f16-9bdf-3565f591fb71/full/256,/0/default.jpg",
"scheme": "https",
"server": {
"host": "iiif.bodleian.ox.ac.uk"
},
"prefix": "/iiif/image",
"identifier": "f27e28db-0b08-4f16-9bdf-3565f591fb71",
"region": {
"tag": "full"
},
"size": {
"tag": "width",
"w": 256
},
"rotation": {
"tag": "clockwise",
"degrees": 0
},
"quality": "default",
"format": "jpg"
}
```### Image Information Request
```js
import { parseURI } from "iiif-url";const result = parseURI(
"https://iiif.bodleian.ox.ac.uk/iiif/image/f27e28db-0b08-4f16-9bdf-3565f591fb71/info.json"
);
``````json
{
"tag": "imageInformationRequest",
"uri": "https://iiif.bodleian.ox.ac.uk/iiif/image/f27e28db-0b08-4f16-9bdf-3565f591fb71/info.json",
"scheme": "https",
"server": {
"host": "iiif.bodleian.ox.ac.uk"
},
"prefix": "/iiif/image",
"identifier": "f27e28db-0b08-4f16-9bdf-3565f591fb71"
}
```### Parse Errors
```js
import { parseURI } from "iiif-url";const result = parseURI(
"https://iiif.bodleian.ox.ac.uk/iiif/image/f27e28db-0b08-4f16-9bdf-3565f591fb71/bingo/256,/0/default.jpg"
);
``````json
{
"tag": "error",
"uri": "https://iiif.bodleian.ox.ac.uk/iiif/image/f27e28db-0b08-4f16-9bdf-3565f591fb71/bingo/256,/0/default.jpg",
"errors": [
{
"tag": "badRegion",
"value": "bingo"
}
]
}
```### Discriminated Unions
The parse result will return one of three possible structures.
| Structure | Tag |
| ------------------------------------------------------------------------------- | ------------------------- |
| [Image Request](https://iiif.io/api/image/3.0/#4-image-requests) | `imageRequest` |
| [Image Information Request](https://iiif.io/api/image/3.0/#5-image-information) | `imageInformationRequest` |
| Parse Error | `error` |The `tag` can be used to discriminate between them.
```ts
import { parseURI } from "iiif-url";const result = parseURI(
"https://iiif.bodleian.ox.ac.uk/iiif/image/f27e28db-0b08-4f16-9bdf-3565f591fb71/full/256,/0/default.jpg"
);switch (result.tag) {
case "imageRequest": {
// do something with an image request-shaped result
}
case "imageInformationRequest": {
// do something with an image information request-shaped result
}
case "error": {
// do something with an error
}
}
```The TypeScript type definitions supplied with this package describe all the possible structures and their attendant tags.
## Versioning
This package doesn't use semantic versioning.
The **major** version number tracks the version of the IIIF Image API spec targeted by this version of the package.
You're looking at the package targeting this version of the spec:
- [Image API 3.0](https://iiif.io/api/image/3.0/)