IIIF Image API URI Parser
3.0
for JS/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"
);
{
"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"
}
import { parseURI } from "iiif-url";
const result = parseURI(
"https://iiif.bodleian.ox.ac.uk/iiif/image/f27e28db-0b08-4f16-9bdf-3565f591fb71/info.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"
}
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"
);
{
"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"
}
]
}
The parse result will return one of three possible structures.
Structure | Tag |
---|---|
Image Request | imageRequest |
Image Information Request | imageInformationRequest |
Parse Error | error |
The tag
can be used to discriminate between them.
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.
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: