Make code prettier

This updates ESLint and our shared eslint-config-openlayers to use Prettier.  Most formatting changes were automatically applied with this:

    npm run lint -- --fix

A few manual changes were required:

 * In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
 * In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason.  While editing this, I reworked `ExampleBuilder` to be a class.
 * In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
Tim Schaub
2020-04-06 12:25:12 -06:00
parent 53b48baf62
commit 054af09032
790 changed files with 46833 additions and 33765 deletions

View File

@@ -1,169 +1,163 @@
import IIIFInfo from '../../../../src/ol/format/IIIFInfo.js';
import {Versions} from '../../../../src/ol/format/IIIFInfo.js';
describe('ol.format.IIIFInfo', function() {
describe('ol.format.IIIFInfo', function () {
const iiifInfo = new IIIFInfo();
describe('setImageInfo', function() {
it('can handle image info JSON as object or as string serialization', function() {
describe('setImageInfo', function () {
it('can handle image info JSON as object or as string serialization', function () {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
'@id': 'http://iiif.test/id'
'@id': 'http://iiif.test/id',
});
expect(iiifInfo.getImageApiVersion()).to.be(Versions.VERSION3);
iiifInfo.setImageInfo('{"@context": "http://iiif.io/api/image/2/context.json","@id":"http://iiif.test/id"}');
iiifInfo.setImageInfo(
'{"@context": "http://iiif.io/api/image/2/context.json","@id":"http://iiif.test/id"}'
);
expect(iiifInfo.getImageApiVersion()).to.be(Versions.VERSION2);
});
});
describe('getImageApiVersion', function() {
it('provides the correct Image API version', function() {
describe('getImageApiVersion', function () {
it('provides the correct Image API version', function () {
iiifInfo.setImageInfo({
'@id': 'http://iiif.test/id'
'@id': 'http://iiif.test/id',
});
expect(function() {
expect(function () {
iiifInfo.getImageApiVersion();
}).to.throwException();
iiifInfo.setImageInfo({
identifier: 'http://iiif.test/id',
profile: 'this is no valid profile'
profile: 'this is no valid profile',
});
expect(function() {
expect(function () {
iiifInfo.getImageApiVersion();
}).to.throwException();
iiifInfo.setImageInfo({
'@context': 'this is no valid context',
'@id': 'http://iiif.test/id'
'@id': 'http://iiif.test/id',
});
expect(function() {
expect(function () {
iiifInfo.getImageApiVersion();
}).to.throwException();
iiifInfo.setImageInfo({
identifier: 'http://iiif.test/id',
profile: 'http://library.stanford.edu/iiif/image-api/compliance.html#level0'
profile:
'http://library.stanford.edu/iiif/image-api/compliance.html#level0',
});
expect(iiifInfo.getImageApiVersion()).to.be(Versions.VERSION1);
iiifInfo.setImageInfo({
'@context': 'http://library.stanford.edu/iiif/image-api/1.1/context.json',
'@id': 'http://iiif.test/id'
'@context':
'http://library.stanford.edu/iiif/image-api/1.1/context.json',
'@id': 'http://iiif.test/id',
});
expect(iiifInfo.getImageApiVersion()).to.be(Versions.VERSION1);
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/1/context.json',
identifier: 'http://iiif.test/id'
identifier: 'http://iiif.test/id',
});
expect(iiifInfo.getImageApiVersion()).to.be(Versions.VERSION1);
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
'@id': 'http://iiif.test/id'
'@id': 'http://iiif.test/id',
});
expect(iiifInfo.getImageApiVersion()).to.be(Versions.VERSION2);
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
id: 'http://iiif.test/id'
id: 'http://iiif.test/id',
});
expect(iiifInfo.getImageApiVersion()).to.be(Versions.VERSION3);
});
});
describe('getComplianceLevelFromProfile', function() {
it('detects the correct compliance level', function() {
describe('getComplianceLevelFromProfile', function () {
it('detects the correct compliance level', function () {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
profile: 'level0'
profile: 'level0',
});
expect(iiifInfo.getComplianceLevelFromProfile()).to.be(undefined);
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
profile: 'http://iiif.io/api/image/level3.json'
profile: 'http://iiif.io/api/image/level3.json',
});
expect(iiifInfo.getComplianceLevelFromProfile()).to.be(undefined);
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
profile: 'level1'
profile: 'level1',
});
expect(iiifInfo.getComplianceLevelFromProfile()).to.be(undefined);
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
profile: 'http://iiif.io/api/image/2/level2.json'
profile: 'http://iiif.io/api/image/2/level2.json',
});
expect(iiifInfo.getComplianceLevelFromProfile()).to.be('level2');
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
profile: ['http://iiif.io/api/image/2/level1.json']
profile: ['http://iiif.io/api/image/2/level1.json'],
});
expect(iiifInfo.getComplianceLevelFromProfile()).to.be('level1');
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
profile: 'level4'
profile: 'level4',
});
expect(iiifInfo.getComplianceLevelFromProfile()).to.be(undefined);
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
profile: 'http://iiif.io/api/image/3/level3.json'
profile: 'http://iiif.io/api/image/3/level3.json',
});
expect(iiifInfo.getComplianceLevelFromProfile()).to.be(undefined);
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
profile: 'http://iiif.io/api/image/2/level1.json'
profile: 'http://iiif.io/api/image/2/level1.json',
});
expect(iiifInfo.getComplianceLevelFromProfile()).to.be(undefined);
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
profile: 'level2'
profile: 'level2',
});
expect(iiifInfo.getComplianceLevelFromProfile()).to.be('level2');
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
profile: 'http://iiif.io/api/image/3/level1.json'
profile: 'http://iiif.io/api/image/3/level1.json',
});
expect(iiifInfo.getComplianceLevelFromProfile()).to.be('level1');
});
});
describe('getComplianceLevelSupportedFeatures', function() {
it('provides the correct features for given versions and compliance levels', function() {
describe('getComplianceLevelSupportedFeatures', function () {
it('provides the correct features for given versions and compliance levels', function () {
iiifInfo.setImageInfo({
'@context': 'http://library.stanford.edu/iiif/image-api/1.1/context.json',
profile: 'http://library.stanford.edu/iiif/image-api/compliance.html#level0'
'@context':
'http://library.stanford.edu/iiif/image-api/1.1/context.json',
profile:
'http://library.stanford.edu/iiif/image-api/compliance.html#level0',
});
let level = iiifInfo.getComplianceLevelSupportedFeatures();
expect(level.supports).to.be.empty();
iiifInfo.setImageInfo({
'@context': 'http://library.stanford.edu/iiif/image-api/1.1/context.json',
profile: 'http://library.stanford.edu/iiif/image-api/compliance.html#level1'
'@context':
'http://library.stanford.edu/iiif/image-api/1.1/context.json',
profile:
'http://library.stanford.edu/iiif/image-api/compliance.html#level1',
});
level = iiifInfo.getComplianceLevelSupportedFeatures();
expect(level.supports).to.have.length(4);
@@ -173,8 +167,10 @@ describe('ol.format.IIIFInfo', function() {
expect(level.supports).to.contain('sizeByPct');
iiifInfo.setImageInfo({
'@context': 'http://library.stanford.edu/iiif/image-api/1.1/context.json',
profile: 'http://library.stanford.edu/iiif/image-api/compliance.html#level2'
'@context':
'http://library.stanford.edu/iiif/image-api/1.1/context.json',
profile:
'http://library.stanford.edu/iiif/image-api/compliance.html#level2',
});
level = iiifInfo.getComplianceLevelSupportedFeatures();
expect(level.supports).to.have.length(7);
@@ -188,14 +184,14 @@ describe('ol.format.IIIFInfo', function() {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
profile: 'http://iiif.io/api/image/2/level0.json'
profile: 'http://iiif.io/api/image/2/level0.json',
});
level = iiifInfo.getComplianceLevelSupportedFeatures();
expect(level.supports).to.be.empty();
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
profile: 'http://iiif.io/api/image/2/level1.json'
profile: 'http://iiif.io/api/image/2/level1.json',
});
level = iiifInfo.getComplianceLevelSupportedFeatures();
expect(level.supports).to.have.length(4);
@@ -206,7 +202,7 @@ describe('ol.format.IIIFInfo', function() {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
profile: 'http://iiif.io/api/image/2/level2.json'
profile: 'http://iiif.io/api/image/2/level2.json',
});
level = iiifInfo.getComplianceLevelSupportedFeatures();
expect(level.supports).to.have.length(8);
@@ -221,14 +217,14 @@ describe('ol.format.IIIFInfo', function() {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
profile: 'level0'
profile: 'level0',
});
level = iiifInfo.getComplianceLevelSupportedFeatures();
expect(level.supports).to.be.empty();
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
profile: 'level1'
profile: 'level1',
});
level = iiifInfo.getComplianceLevelSupportedFeatures();
expect(level.supports).to.have.length(5);
@@ -240,7 +236,7 @@ describe('ol.format.IIIFInfo', function() {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
profile: 'level2'
profile: 'level2',
});
level = iiifInfo.getComplianceLevelSupportedFeatures();
expect(level.supports).to.have.length(8);
@@ -252,26 +248,23 @@ describe('ol.format.IIIFInfo', function() {
expect(level.supports).to.contain('sizeByWh');
expect(level.supports).to.contain('sizeByConfinedWh');
expect(level.supports).to.contain('sizeByPct');
});
});
describe('getTileSourceOptions', function() {
it('produces options from minimal information responses', function() {
expect(function() {
describe('getTileSourceOptions', function () {
it('produces options from minimal information responses', function () {
expect(function () {
iiifInfo.setImageInfo({
width: 2000,
height: 1500
height: 1500,
});
iiifInfo.getTileSourceOptions();
}).to.throwException();
iiifInfo.setImageInfo({
identifier: 'id',
profile: 'http://library.stanford.edu/iiif/image-api/compliance.html#level0'
profile:
'http://library.stanford.edu/iiif/image-api/compliance.html#level0',
});
let options = iiifInfo.getTileSourceOptions();
@@ -282,7 +275,8 @@ describe('ol.format.IIIFInfo', function() {
identifier: 'identifier-version-1.0',
width: 2000,
height: 1500,
profile: 'http://library.stanford.edu/iiif/image-api/compliance.html#level0'
profile:
'http://library.stanford.edu/iiif/image-api/compliance.html#level0',
});
options = iiifInfo.getTileSourceOptions();
@@ -303,7 +297,7 @@ describe('ol.format.IIIFInfo', function() {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
'@id': 'http://iiif.test/version2/id'
'@id': 'http://iiif.test/version2/id',
});
options = iiifInfo.getTileSourceOptions();
@@ -311,21 +305,19 @@ describe('ol.format.IIIFInfo', function() {
expect(options).to.have.property('version', Versions.VERSION2);
expect(options).to.have.property('url', 'http://iiif.test/version2/id');
expect(options).to.have.property('format', 'jpg');
});
it('uses preferred options if applicable', function() {
it('uses preferred options if applicable', function () {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
'@id': 'http://iiif.test/version2/id',
width: 2000,
height: 1500,
profile: ['http://iiif.io/api/image/2/level2.json']
profile: ['http://iiif.io/api/image/2/level2.json'],
});
let options = iiifInfo.getTileSourceOptions({
quality: 'bitonal',
format: 'png'
format: 'png',
});
expect(options).to.have.property('quality', 'bitonal');
expect(options).to.have.property('format', 'png');
@@ -336,29 +328,27 @@ describe('ol.format.IIIFInfo', function() {
width: 2000,
height: 1500,
profile: 'level2',
extraQualities: ['gray', 'bitonal']
extraQualities: ['gray', 'bitonal'],
});
options = iiifInfo.getTileSourceOptions({
quality: 'bitonal',
format: 'png'
format: 'png',
});
expect(options).to.have.property('quality', 'bitonal');
expect(options).to.have.property('format', 'png');
});
it('ignores preferred options that are not supported', function() {
it('ignores preferred options that are not supported', function () {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
'@id': 'http://iiif.test/version2/id',
width: 2000,
height: 1500,
profile: ['http://iiif.io/api/image/2/level1.json']
profile: ['http://iiif.io/api/image/2/level1.json'],
});
let options = iiifInfo.getTileSourceOptions({
quality: 'bitonal',
format: 'png'
format: 'png',
});
expect(options).to.have.property('quality', 'default');
expect(options).to.have.property('format', 'jpg');
@@ -368,25 +358,26 @@ describe('ol.format.IIIFInfo', function() {
'@id': 'http://iiif.test/version3/id',
width: 2000,
height: 1500,
profile: 'level1'
profile: 'level1',
});
options = iiifInfo.getTileSourceOptions({
quality: 'bitonal',
format: 'png'
format: 'png',
});
expect(options).to.have.property('quality', 'default');
expect(options).to.have.property('format', 'jpg');
});
it('combines supported features indicated by compliance level and explicitly stated in image info', function() {
it('combines supported features indicated by compliance level and explicitly stated in image info', function () {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
'@id': 'http://iiif.test/id',
profile: ['http://iiif.io/api/image/2/level1.json', {
supports: ['regionByPct', 'sizeByWh']
}]
profile: [
'http://iiif.io/api/image/2/level1.json',
{
supports: ['regionByPct', 'sizeByWh'],
},
],
});
let options = iiifInfo.getTileSourceOptions();
@@ -402,7 +393,7 @@ describe('ol.format.IIIFInfo', function() {
'@context': 'http://iiif.io/api/image/3/context.json',
id: 'http://iiif.test/id',
profile: 'level1',
extraFeatures: ['regionByPct', 'sizeByPct']
extraFeatures: ['regionByPct', 'sizeByPct'],
});
options = iiifInfo.getTileSourceOptions();
@@ -414,26 +405,28 @@ describe('ol.format.IIIFInfo', function() {
expect(options.supports).to.contain('sizeByH');
expect(options.supports).to.contain('sizeByWh');
expect(options.supports).to.have.length(7);
});
it('uses the first available scale factors and tile sizes', function() {
it('uses the first available scale factors and tile sizes', function () {
iiifInfo.setImageInfo({
'@context': 'http://library.stanford.edu/iiif/image-api/1.1/context.json',
'@context':
'http://library.stanford.edu/iiif/image-api/1.1/context.json',
'@id': 'http://iiif.test/id',
profile: 'http://library.stanford.edu/iiif/image-api/compliance.html#level0'
profile:
'http://library.stanford.edu/iiif/image-api/compliance.html#level0',
});
let options = iiifInfo.getTileSourceOptions();
expect(options.resolutions).to.be(undefined);
expect(options.tileSize).to.be(undefined);
iiifInfo.setImageInfo({
'@context': 'http://library.stanford.edu/iiif/image-api/1.1/context.json',
'@context':
'http://library.stanford.edu/iiif/image-api/1.1/context.json',
'@id': 'http://iiif.test/id',
profile: 'http://library.stanford.edu/iiif/image-api/compliance.html#level0',
profile:
'http://library.stanford.edu/iiif/image-api/compliance.html#level0',
scale_factors: [1, 2, 4],
tile_width: 512
tile_width: 512,
});
options = iiifInfo.getTileSourceOptions();
expect(options.resolutions).to.have.length(3);
@@ -445,12 +438,14 @@ describe('ol.format.IIIFInfo', function() {
expect(options.tileSize[1]).to.be(512);
iiifInfo.setImageInfo({
'@context': 'http://library.stanford.edu/iiif/image-api/1.1/context.json',
'@context':
'http://library.stanford.edu/iiif/image-api/1.1/context.json',
'@id': 'http://iiif.test/id',
profile: 'http://library.stanford.edu/iiif/image-api/compliance.html#level0',
profile:
'http://library.stanford.edu/iiif/image-api/compliance.html#level0',
scale_factors: [1, 2, 4],
tile_width: 512,
tile_height: 1024
tile_height: 1024,
});
options = iiifInfo.getTileSourceOptions();
expect(options.resolutions).to.have.length(3);
@@ -464,7 +459,7 @@ describe('ol.format.IIIFInfo', function() {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
'@id': 'http://iiif.test/id',
profile: 'http://iiif.io/api/image/2/level0.json'
profile: 'http://iiif.io/api/image/2/level0.json',
});
options = iiifInfo.getTileSourceOptions();
expect(options.resolutions).to.be(undefined);
@@ -474,14 +469,16 @@ describe('ol.format.IIIFInfo', function() {
'@context': 'http://iiif.io/api/image/2/context.json',
'@id': 'http://iiif.test/id',
profile: 'http://iiif.io/api/image/2/level0.json',
tiles: [{
scaleFactors: [1, 2, 4],
width: 512
},
{
scaleFactors: [1, 2, 4, 8, 16],
width: 256
}]
tiles: [
{
scaleFactors: [1, 2, 4],
width: 512,
},
{
scaleFactors: [1, 2, 4, 8, 16],
width: 256,
},
],
});
options = iiifInfo.getTileSourceOptions();
expect(options.resolutions).to.have.length(3);
@@ -496,11 +493,13 @@ describe('ol.format.IIIFInfo', function() {
'@context': 'http://iiif.io/api/image/2/context.json',
'@id': 'http://iiif.test/id',
profile: 'http://iiif.io/api/image/2/level0.json',
tiles: [{
scaleFactors: [1, 2, 4],
width: 512,
height: 1024
}]
tiles: [
{
scaleFactors: [1, 2, 4],
width: 512,
height: 1024,
},
],
});
options = iiifInfo.getTileSourceOptions();
expect(options.resolutions).to.have.length(3);
@@ -515,11 +514,13 @@ describe('ol.format.IIIFInfo', function() {
'@context': 'http://iiif.io/api/image/3/context.json',
'@id': 'http://iiif.test/id',
profile: 'level0',
tiles: [{
scaleFactors: [1, 2, 4, 8],
width: 512,
height: 256
}]
tiles: [
{
scaleFactors: [1, 2, 4, 8],
width: 512,
height: 256,
},
],
});
options = iiifInfo.getTileSourceOptions();
expect(options.resolutions).to.have.length(4);
@@ -530,28 +531,27 @@ describe('ol.format.IIIFInfo', function() {
expect(options.tileSize).to.have.length(2);
expect(options.tileSize[0]).to.be(512);
expect(options.tileSize[1]).to.be(256);
});
});
it('provides each given size in sizes as OpenLayers Size', function() {
it('provides each given size in sizes as OpenLayers Size', function () {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/2/context.json',
'@id': 'http://iiif.test/id',
'sizes': [{
width: 2000,
height: 1000
},
{
width: 1000,
height: 500
},
{
width: 500,
height: 250
}]
'sizes': [
{
width: 2000,
height: 1000,
},
{
width: 1000,
height: 500,
},
{
width: 500,
height: 250,
},
],
});
let options = iiifInfo.getTileSourceOptions();
expect(options.sizes).to.have.length(3);
@@ -568,26 +568,26 @@ describe('ol.format.IIIFInfo', function() {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
'@id': 'http://iiif.test/id',
'sizes': [{
width: 1500,
height: 800
}]
'sizes': [
{
width: 1500,
height: 800,
},
],
});
options = iiifInfo.getTileSourceOptions();
expect(options.sizes).to.have.length(1);
expect(options.sizes[0]).to.have.length(2);
expect(options.sizes[0][0]).to.be(1500);
expect(options.sizes[0][1]).to.be(800);
});
it('respects the preferred image formats', function() {
it('respects the preferred image formats', function () {
iiifInfo.setImageInfo({
'@context': 'http://iiif.io/api/image/3/context.json',
'id': 'http://iiif.test/id',
'profile': 'level0',
'preferredFormats': ['png', 'gif']
'preferredFormats': ['png', 'gif'],
});
let options = iiifInfo.getTileSourceOptions();
expect(options.format).to.be('jpg');
@@ -596,7 +596,7 @@ describe('ol.format.IIIFInfo', function() {
'@context': 'http://iiif.io/api/image/3/context.json',
'id': 'http://iiif.test/id',
'profile': 'level1',
'preferredFormats': ['png', 'gif']
'preferredFormats': ['png', 'gif'],
});
options = iiifInfo.getTileSourceOptions();
expect(options.format).to.be('jpg');
@@ -606,7 +606,7 @@ describe('ol.format.IIIFInfo', function() {
'id': 'http://iiif.test/id',
'profile': 'level1',
'extraFormats': ['webp', 'gif'],
'preferredFormats': ['webp', 'png', 'gif']
'preferredFormats': ['webp', 'png', 'gif'],
});
options = iiifInfo.getTileSourceOptions();
expect(options.format).to.be('gif');
@@ -615,12 +615,9 @@ describe('ol.format.IIIFInfo', function() {
'@context': 'http://iiif.io/api/image/3/context.json',
'id': 'http://iiif.test/id',
'profile': 'level2',
'preferredFormats': ['png', 'gif']
'preferredFormats': ['png', 'gif'],
});
options = iiifInfo.getTileSourceOptions();
expect(options.format).to.be('png');
});
});