From 470d6a1c0fd4333280fe6bd75264f6f88670ef11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Francisco=20Calvo?= Date: Wed, 7 Dec 2022 12:21:57 +0100 Subject: [PATCH 01/15] Upgrade GitHub actions from v2 to v3 --- .github/workflows/node.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml index 97e316e..aeb694c 100644 --- a/.github/workflows/node.yml +++ b/.github/workflows/node.yml @@ -15,9 +15,9 @@ jobs: node: ['18', '17', '16', '15', '14'] container: node:${{ matrix.node }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Restore dependencies cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/.npm key: ${{ runner.os }}-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }} From 67dcf36f6a690a79b80d43a04634efcb2695044e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Francisco=20Calvo?= Date: Wed, 7 Dec 2022 12:24:57 +0100 Subject: [PATCH 02/15] Add Node.js version 19 to GitHub testing action --- .github/workflows/node.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml index aeb694c..06f64f4 100644 --- a/.github/workflows/node.yml +++ b/.github/workflows/node.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: ['18', '17', '16', '15', '14'] + node: ['19', '18', '17', '16', '15', '14'] container: node:${{ matrix.node }} steps: - uses: actions/checkout@v3 From 041e3d15b43532d0bf1a4f16357f08371d3b5ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Francisco=20Calvo?= Date: Wed, 7 Dec 2022 16:29:08 +0100 Subject: [PATCH 03/15] Add Sequence class --- src/index.js | 4 +++- src/sequence.js | 19 +++++++++++++++++++ test/sequence.test.js | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/sequence.js create mode 100644 test/sequence.test.js diff --git a/src/index.js b/src/index.js index 60164c2..2946751 100644 --- a/src/index.js +++ b/src/index.js @@ -2,9 +2,11 @@ import Url from './url' import Source from './source' import Color from './color' import Position from './position' +import Sequence from './sequence' const url = Url.url const color = Color.color const position = Position.position +const sequence = Sequence.sequence -export default { url, Source, color, position } +export default { url, Source, color, position, sequence } diff --git a/src/sequence.js b/src/sequence.js new file mode 100644 index 0000000..6d2e665 --- /dev/null +++ b/src/sequence.js @@ -0,0 +1,19 @@ +export default class Sequence { + static #DEFAULT_SIZE = 16 + + static sequence(first, last, size = Sequence.#DEFAULT_SIZE) { + if (size <= 0) return [] + if (size === 1) return [first] + if (size === 2) return [first, last] + + const ratio = (last / first) ** (1 / (size - 1)) + + const sequence = [first] + for (let i = 1; i < size - 1; i++) { + sequence.push(sequence[i - 1] * ratio) + } + sequence.push(last) + + return sequence.map((value) => Math.round(value)) + } +} diff --git a/test/sequence.test.js b/test/sequence.test.js new file mode 100644 index 0000000..2715152 --- /dev/null +++ b/test/sequence.test.js @@ -0,0 +1,38 @@ +import Sequence from '../src/sequence' + +describe('Sequence', () => { + describe('sequence', () => { + it('returns an array with sequence default size', () => { + expect(Sequence.sequence(100, 8192)).toEqual([100, 134, 180, 241, 324, 434, 583, 781, 1048, 1406, 1886, 2530, 3394, 4553, 6107, 8192]) + expect(Sequence.sequence(8192, 100)).toEqual([8192, 6107, 4553, 3394, 2530, 1886, 1406, 1048, 781, 583, 434, 324, 241, 180, 134, 100]) + }) + + it('returns an empty array when the size of the sequence is a negative number', () => { + expect(Sequence.sequence(100, 8192, -1)).toEqual([]) + expect(Sequence.sequence(8192, 100, -1)).toEqual([]) + }) + + it('returns an empty array when the size of the sequence is zero', () => { + expect(Sequence.sequence(100, 8192, 0)).toEqual([]) + expect(Sequence.sequence(8192, 100, 0)).toEqual([]) + }) + + it('returns an array with expected ascending order sequence', () => { + expect(Sequence.sequence(100, 8192, 1)).toEqual([100]) + expect(Sequence.sequence(100, 8192, 2)).toEqual([100, 8192]) + expect(Sequence.sequence(100, 8192, 3)).toEqual([100, 905, 8192]) + expect(Sequence.sequence(100, 8192, 4)).toEqual([100, 434, 1886, 8192]) + expect(Sequence.sequence(100, 8192, 16)).toEqual([100, 134, 180, 241, 324, 434, 583, 781, 1048, 1406, 1886, 2530, 3394, 4553, 6107, 8192]) + expect(Sequence.sequence(100, 8192, 32)).toEqual([100, 115, 133, 153, 177, 204, 235, 270, 312, 359, 414, 477, 550, 634, 731, 843, 972, 1120, 1291, 1488, 1716, 1978, 2280, 2628, 3029, 3492, 4025, 4640, 5348, 6165, 7107, 8192]) + }) + + it('returns an array with expected descending order sequence', () => { + expect(Sequence.sequence(8192, 100, 1)).toEqual([8192]) + expect(Sequence.sequence(8192, 100, 2)).toEqual([8192, 100]) + expect(Sequence.sequence(8192, 100, 3)).toEqual([8192, 905, 100]) + expect(Sequence.sequence(8192, 100, 4)).toEqual([8192, 1886, 434, 100]) + expect(Sequence.sequence(8192, 100, 16)).toEqual([8192, 6107, 4553, 3394, 2530, 1886, 1406, 1048, 781, 583, 434, 324, 241, 180, 134, 100]) + expect(Sequence.sequence(8192, 100, 32)).toEqual([8192, 7107, 6165, 5348, 4640, 4025, 3492, 3029, 2628, 2280, 1978, 1716, 1488, 1291, 1120, 972, 843, 731, 634, 550, 477, 414, 359, 312, 270, 235, 204, 177, 153, 133, 115, 100]) + }) + }) +}) From 9f79f81f84431128fb85eeecaf249fe70fdfc8d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Francisco=20Calvo?= Date: Wed, 28 Dec 2022 14:12:24 +0100 Subject: [PATCH 04/15] Normalize url params with null value --- src/utils.js | 2 ++ test/url.test.js | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/utils.js b/src/utils.js index 11a2718..71ce87b 100644 --- a/src/utils.js +++ b/src/utils.js @@ -33,6 +33,8 @@ export default class Utils { switch(true) { case key === 'expires' && value instanceof Date: return { [key]: Math.floor(value / 1000) } + case value === null: + return { [key]: '' } default: return { [key]: value } } diff --git a/test/url.test.js b/test/url.test.js index dc40c9e..2c7b411 100644 --- a/test/url.test.js +++ b/test/url.test.js @@ -23,6 +23,12 @@ describe('Url', () => { expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&format=png') }) + it('returns url with null params', () => { + const url = Url.url('assets', 'example.jpeg', { width: 200, download: null }) + + expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&download=') + }) + it('returns url with params using string path', () => { const url = Url.url('assets', 'example.jpeg', { width: 200, height: 300, watermark: 'example.svg', format: 'png' }) @@ -225,6 +231,12 @@ describe('Url', () => { expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&format=png') }) + it('returns url with null params', () => { + const url = Url.url(new Source('assets'), 'example.jpeg', { width: 200, download: null }) + + expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&download=') + }) + it('returns url with params using string path', () => { const url = Url.url( new Source('assets'), @@ -573,6 +585,19 @@ describe('Url', () => { expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&format=png&signature=VJ159IlBl_AlN59QWvyJov5SlQXlrZNpXgDJLJgzP8g') }) + it('returns url with null params', () => { + const url = Url.url( + new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), + 'example.jpeg', + { + width: 200, + download: null + } + ) + + expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&download=&signature=ljL9HNRaxVrk7jfQaf6FPYFZn4RJzQPCW-aVNJoIQI8') + }) + it('returns url with params using string path', () => { const url = Url.url( new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), From 6d69c69a4b5106ed483cb1785ddf9bcf773f39d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Francisco=20Calvo?= Date: Fri, 30 Dec 2022 11:30:56 +0100 Subject: [PATCH 05/15] Rename internal constant --- src/sequence.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sequence.js b/src/sequence.js index 6d2e665..8d4d44d 100644 --- a/src/sequence.js +++ b/src/sequence.js @@ -8,12 +8,12 @@ export default class Sequence { const ratio = (last / first) ** (1 / (size - 1)) - const sequence = [first] + const seq = [first] for (let i = 1; i < size - 1; i++) { - sequence.push(sequence[i - 1] * ratio) + seq.push(seq[i - 1] * ratio) } - sequence.push(last) + seq.push(last) - return sequence.map((value) => Math.round(value)) + return seq.map((value) => Math.round(value)) } } From aea75368630c4e264225e0ff991fc13b8014070f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Francisco=20Calvo?= Date: Sat, 31 Dec 2022 16:22:31 +0100 Subject: [PATCH 06/15] Improve url tests --- README.md | 2 +- src/url.js | 10 +- test/url.test.js | 354 +++++++---------------------------------------- 3 files changed, 58 insertions(+), 308 deletions(-) diff --git a/README.md b/README.md index 12e5d4b..c8822e4 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Imglab.url('assets', 'example.jpeg', { width: 500, height: 600 }) You can use `Imglab.url` function to generate imglab compatible URLs for your application. -The easiest way to generate a URL is to specify the `sourceName`, `path` and required `parameters`: +The easiest way to generate a URL is to specify the name of the `source`, a `path` and required `parameters`: ```javascript Imglab.url('assets', 'image.jpeg', { width: 500, height: 600 }) diff --git a/src/url.js b/src/url.js index 5903961..685f613 100644 --- a/src/url.js +++ b/src/url.js @@ -3,13 +3,13 @@ import Signature from './signature' import Utils from './utils' export default class Url { - static url(sourceNameOrSource, path, params = {}) { - if (typeof sourceNameOrSource === 'string') { - return Url.#urlForSource(new Source(sourceNameOrSource), path, params) + static url(source, path, params = {}) { + if (typeof source === 'string') { + return Url.#urlForSource(new Source(source), path, params) } - if (sourceNameOrSource instanceof Source) { - return Url.#urlForSource(sourceNameOrSource, path, params) + if (source instanceof Source) { + return Url.#urlForSource(source, path, params) } throw new Error('Invalid source name or source') diff --git a/test/url.test.js b/test/url.test.js index 2c7b411..030ebd6 100644 --- a/test/url.test.js +++ b/test/url.test.js @@ -9,6 +9,9 @@ const position = Position.position const SECURE_KEY = 'ixUd9is/LDGBw6NPfLCGLjO/WraJlHdytC1+xiIFj22mXAWs/6R6ws4gxSXbDcUHMHv0G+oiTgyfMVsRS2b3' const SECURE_SALT = 'c9G9eYKCeWen7vkEyV1cnr4MZkfLI/yo6j72JItzKHjMGDNZKqPFzRtup//qiT51HKGJrAha6Gv2huSFLwJr' +const SOURCE = new Source('assets') +const SECURE_SOURCE = new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }) + describe('Url', () => { describe('url using source name', () => { it('returns url without params', () => { @@ -88,8 +91,6 @@ describe('Url', () => { }) it('returns url with params using url function with source', () => { - const source = new Source('assets') - const url = Url.url( 'assets', @@ -97,7 +98,7 @@ describe('Url', () => { { width: 200, height: 300, - watermark: Url.url(source, 'example.svg', { width: 100, format: 'png' }), + watermark: Url.url(SOURCE, 'example.svg', { width: 100, format: 'png' }), format: 'png' } ) @@ -220,26 +221,26 @@ describe('Url', () => { describe('url using source', () => { it('returns url without params', () => { - const url = Url.url(new Source('assets'), 'example.jpeg') + const url = Url.url(SOURCE, 'example.jpeg') expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg') }) it('returns url with params', () => { - const url = Url.url(new Source('assets'), 'example.jpeg', { width: 200, height: 300, format: 'png' }) + const url = Url.url(SOURCE, 'example.jpeg', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&format=png') }) it('returns url with null params', () => { - const url = Url.url(new Source('assets'), 'example.jpeg', { width: 200, download: null }) + const url = Url.url(SOURCE, 'example.jpeg', { width: 200, download: null }) expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&download=') }) it('returns url with params using string path', () => { const url = Url.url( - new Source('assets'), + SOURCE, 'example.jpeg', { width: 200, @@ -254,7 +255,7 @@ describe('Url', () => { it('returns url with params using string path with inline params', () => { const url = Url.url( - new Source('assets'), + SOURCE, 'example.jpeg', { width: 200, @@ -268,15 +269,13 @@ describe('Url', () => { }) it('returns url with params using url with source', () => { - const source = new Source('assets') - const url = Url.url( - source, + SOURCE, 'example.jpeg', { width: 200, height: 300, - watermark: Url.url(source, 'example.svg', { width: 100, format: 'png' }), + watermark: Url.url(SOURCE, 'example.svg', { width: 100, format: 'png' }), format: 'png' } ) @@ -286,7 +285,7 @@ describe('Url', () => { it('returns url with params using url with source name', () => { const url = Url.url( - new Source('assets'), + SOURCE, 'example.jpeg', { width: 200, @@ -300,25 +299,25 @@ describe('Url', () => { }) it('returns url with params using underscore attributes', () => { - const url = Url.url(new Source('assets'), 'example.jpeg', { trim: 'color', trim_color: 'orange' }) + const url = Url.url(SOURCE, 'example.jpeg', { trim: 'color', trim_color: 'orange' }) expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?trim=color&trim-color=orange') }) it('returns url with params using camel case attributes', () => { - const url = Url.url(new Source('assets'), 'example.jpeg', { trim: 'color', trimColor: 'orange' }) + const url = Url.url(SOURCE, 'example.jpeg', { trim: 'color', trimColor: 'orange' }) expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?trim=color&trim-color=orange') }) it('returns url with params using quoted attributes with hyphens', () => { - const url = Url.url(new Source('assets'), 'example.jpeg', { trim: 'color', 'trim-color': 'orange' }) + const url = Url.url(SOURCE, 'example.jpeg', { trim: 'color', 'trim-color': 'orange' }) expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?trim=color&trim-color=orange') }) it('returns url with expires param using a Date instance', () => { - const url = Url.url(new Source('assets'), 'example.jpeg', { width: 200, height: 300, expires: new Date(1464096368 * 1000) }) + const url = Url.url(SOURCE, 'example.jpeg', { width: 200, height: 300, expires: new Date(1464096368 * 1000) }) expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&expires=1464096368') }) @@ -394,168 +393,73 @@ describe('Url', () => { }) it('returns url with path starting with slash', () => { - const url = Url.url( - new Source('assets'), - '/example.jpeg', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SOURCE, '/example.jpeg', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&format=png') }) it('returns url with path starting with slash using reserved characters', () => { - const url = Url.url( - new Source('assets'), - '/example image%2C01%2C02.jpeg', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SOURCE, '/example image%2C01%2C02.jpeg', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/example%20image%252C01%252C02.jpeg?width=200&height=300&format=png') }) it('returns url with path starting and ending with slash', () => { - const url = Url.url( - new Source('assets'), - '/example.jpeg/', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SOURCE, '/example.jpeg/', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&format=png') }) it('returns url with path starting and ending with slash using reserved characters', () => { - const url = Url.url( - new Source('assets'), - '/example image%2C01%2C02.jpeg/', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SOURCE, '/example image%2C01%2C02.jpeg/', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/example%20image%252C01%252C02.jpeg?width=200&height=300&format=png') }) it('returns url with subfolder path starting with slash', () => { - const url = Url.url( - new Source('assets'), - '/subfolder/example.jpeg', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SOURCE, '/subfolder/example.jpeg', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/subfolder/example.jpeg?width=200&height=300&format=png') }) it('returns url with subfolder path starting with slash using reserved characters', () => { - const url = Url.url( - new Source('assets'), - '/subfolder images/example image%2C01%2C02.jpeg', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SOURCE, '/subfolder images/example image%2C01%2C02.jpeg', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/subfolder%20images/example%20image%252C01%252C02.jpeg?width=200&height=300&format=png') }) it('returns url with subfolder path starting and ending with slash', () => { - const url = Url.url( - new Source('assets'), - '/subfolder/example.jpeg/', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SOURCE, '/subfolder/example.jpeg/', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/subfolder/example.jpeg?width=200&height=300&format=png') }) it('returns url with subfolder path starting and ending with slash using reserved characters', () => { - const url = Url.url( - new Source('assets'), - '/subfolder images/example image%2C01%2C02.jpeg/', - { - width: 200, - height: 300, - format: 'png' - }) + const url = Url.url(SOURCE, '/subfolder images/example image%2C01%2C02.jpeg/', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/subfolder%20images/example%20image%252C01%252C02.jpeg?width=200&height=300&format=png') }) it('returns url with path using a http url', () => { - const url = Url.url( - new Source('assets'), - 'http://assets.com/subfolder/example.jpeg', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SOURCE, 'http://assets.com/subfolder/example.jpeg', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/http%3A%2F%2Fassets.com%2Fsubfolder%2Fexample.jpeg?width=200&height=300&format=png') }) it('returns url with path using a http url with reserved characters', () => { - const url = Url.url( - new Source('assets'), - 'http://assets.com/subfolder/example%2C01%2C02.jpeg', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SOURCE, 'http://assets.com/subfolder/example%2C01%2C02.jpeg', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/http%3A%2F%2Fassets.com%2Fsubfolder%2Fexample%252C01%252C02.jpeg?width=200&height=300&format=png') }) it('returns url with path using a https url', () => { - const url = Url.url( - new Source('assets'), - 'https://assets.com/subfolder/example.jpeg', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SOURCE, 'https://assets.com/subfolder/example.jpeg', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/https%3A%2F%2Fassets.com%2Fsubfolder%2Fexample.jpeg?width=200&height=300&format=png') }) it('returns url with path using a https url with reserved characters', () => { - const url = Url.url( - new Source('assets'), - 'https://assets.com/subfolder/example%2C01%2C02.jpeg', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SOURCE, 'https://assets.com/subfolder/example%2C01%2C02.jpeg', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/https%3A%2F%2Fassets.com%2Fsubfolder%2Fexample%252C01%252C02.jpeg?width=200&height=300&format=png') }) @@ -563,59 +467,32 @@ describe('Url', () => { describe('url using secure source', () => { it('returns url without params', () => { - const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), - 'example.jpeg' - ) + const url = Url.url(SECURE_SOURCE, 'example.jpeg') expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?signature=aRgmnJ-7b2A0QLxXpR3cqrHVYmCfpRCOglL-nsp7SdQ') }) it('returns url with params', () => { - const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), - 'example.jpeg', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SECURE_SOURCE, 'example.jpeg', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&format=png&signature=VJ159IlBl_AlN59QWvyJov5SlQXlrZNpXgDJLJgzP8g') }) it('returns url with null params', () => { - const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), - 'example.jpeg', - { - width: 200, - download: null - } - ) + const url = Url.url(SECURE_SOURCE, 'example.jpeg', { width: 200, download: null }) expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&download=&signature=ljL9HNRaxVrk7jfQaf6FPYFZn4RJzQPCW-aVNJoIQI8') }) it('returns url with params using string path', () => { - const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), - 'example.jpeg', - { - width: 200, - height: 300, - watermark: 'example.svg', - format: 'png' - } - ) + const url = Url.url(SECURE_SOURCE, 'example.jpeg', { width: 200, height: 300, watermark: 'example.svg', format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&watermark=example.svg&format=png&signature=xrwElVGVPyOrcTCNFnZiAa-tzkUp1ISrjnvEShSVsAg') }) it('returns url with params using string path with inline params', () => { const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), + SECURE_SOURCE, 'example.jpeg', { width: 200, @@ -629,15 +506,13 @@ describe('Url', () => { }) it('returns url with params using url with source', () => { - const source = new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }) - const url = Url.url( - source, + SECURE_SOURCE, 'example.jpeg', { width: 200, height: 300, - watermark: Url.url(source, 'example.svg', { width: 100, format: 'png' }), + watermark: Url.url(SECURE_SOURCE, 'example.svg', { width: 100, format: 'png' }), format: 'png' } ) @@ -647,7 +522,7 @@ describe('Url', () => { it('returns url with params using url with source name', () => { const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), + SECURE_SOURCE, 'example.jpeg', { width: 200, @@ -661,54 +536,25 @@ describe('Url', () => { }) it('returns url with params using underscore attributes', () => { - const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), - 'example.jpeg', - { - trim: 'color', - trim_color: 'orange' - } - ) + const url = Url.url(SECURE_SOURCE, 'example.jpeg', { trim: 'color', trim_color: 'orange' }) expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?trim=color&trim-color=orange&signature=cfYzBKvaWJhg_4ArtL5IafGYU6FEgRb_5ZADIgvviWw') }) it('returns url with params using camel case attributes', () => { - const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), - 'example.jpeg', - { - trim: 'color', - trimColor: 'orange' - } - ) + const url = Url.url(SECURE_SOURCE, 'example.jpeg', { trim: 'color', trimColor: 'orange' }) expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?trim=color&trim-color=orange&signature=cfYzBKvaWJhg_4ArtL5IafGYU6FEgRb_5ZADIgvviWw') }) it('returns url with params using quoted attributes with hyphens', () => { - const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), - 'example.jpeg', - { - trim: 'color', - 'trim-color': 'orange' - } - ) + const url = Url.url(SECURE_SOURCE, 'example.jpeg', { trim: 'color', 'trim-color': 'orange' }) expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?trim=color&trim-color=orange&signature=cfYzBKvaWJhg_4ArtL5IafGYU6FEgRb_5ZADIgvviWw') }) it('returns url with expires param using a Date instance', () => { - const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), - 'example.jpeg', - { - width: 200, - height: 300, - expires: new Date(1464096368 * 1000) - } - ) + const url = Url.url(SECURE_SOURCE, 'example.jpeg', { width: 200, height: 300, expires: new Date(1464096368 * 1000) }) expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&expires=1464096368&signature=DpkRMiecDlOaQAQM5IQ8Cd4ek8nGvfPxV6XmCN0GbAU') }) @@ -788,169 +634,73 @@ describe('Url', () => { }) it('returns url with path starting with slash', () => { - const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), - '/example.jpeg', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SECURE_SOURCE, '/example.jpeg', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&format=png&signature=VJ159IlBl_AlN59QWvyJov5SlQXlrZNpXgDJLJgzP8g') }) it('returns url with path starting with slash using reserved characters', () => { - const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), - '/example image%2C01%2C02.jpeg', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SECURE_SOURCE, '/example image%2C01%2C02.jpeg', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/example%20image%252C01%252C02.jpeg?width=200&height=300&format=png&signature=yZcUhTCB9VB3qzjyIJCCX_pfJ76Gb6kHe7KwusAPl-w') }) it('returns url with path starting and ending with slash', () => { - const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), - '/example.jpeg/', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SECURE_SOURCE, '/example.jpeg/', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&format=png&signature=VJ159IlBl_AlN59QWvyJov5SlQXlrZNpXgDJLJgzP8g') }) it('returns url with path starting and ending with slash using reserved characters', () => { - const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), - '/example image%2C01%2C02.jpeg/', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SECURE_SOURCE, '/example image%2C01%2C02.jpeg/', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/example%20image%252C01%252C02.jpeg?width=200&height=300&format=png&signature=yZcUhTCB9VB3qzjyIJCCX_pfJ76Gb6kHe7KwusAPl-w') }) it('returns url with subfolder path starting with slash', () => { - const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), - '/subfolder/example.jpeg', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SECURE_SOURCE, '/subfolder/example.jpeg', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/subfolder/example.jpeg?width=200&height=300&format=png&signature=3jydAIXhF8Nn_LXKhog2flf7FsACzISi_sXCKmASkOs') }) it('returns url with subfolder path starting with slash using reserved characters', () => { - const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), - '/subfolder images/example image%2C01%2C02.jpeg', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SECURE_SOURCE, '/subfolder images/example image%2C01%2C02.jpeg', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/subfolder%20images/example%20image%252C01%252C02.jpeg?width=200&height=300&format=png&signature=2oAmYelI7UEnvqSSPCfUA25TmS7na1FRVTaxfe5ADyY') }) it('returns url with subfolder path starting and ending with slash', () => { - const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), - '/subfolder/example.jpeg', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SECURE_SOURCE, '/subfolder/example.jpeg', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/subfolder/example.jpeg?width=200&height=300&format=png&signature=3jydAIXhF8Nn_LXKhog2flf7FsACzISi_sXCKmASkOs') }) it('returns url with subfolder path starting and ending with slash using reserved characters', () => { - const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), - '/subfolder images/example image%2C01%2C02.jpeg/', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SECURE_SOURCE, '/subfolder images/example image%2C01%2C02.jpeg/', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/subfolder%20images/example%20image%252C01%252C02.jpeg?width=200&height=300&format=png&signature=2oAmYelI7UEnvqSSPCfUA25TmS7na1FRVTaxfe5ADyY') }) it('returns url with path using a http url', () => { - const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), - 'http://assets.com/subfolder/example.jpeg', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SECURE_SOURCE, 'http://assets.com/subfolder/example.jpeg', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/http%3A%2F%2Fassets.com%2Fsubfolder%2Fexample.jpeg?width=200&height=300&format=png&signature=MuzfKbHDJY6lzeFQGRcsCS8DzxgL4nCpIowOMFLR1kA') }) it('returns url with path using a http url with reserved characters', () => { - const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), - 'http://assets.com/subfolder/example%2C01%2C02.jpeg', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SECURE_SOURCE, 'http://assets.com/subfolder/example%2C01%2C02.jpeg', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/http%3A%2F%2Fassets.com%2Fsubfolder%2Fexample%252C01%252C02.jpeg?width=200&height=300&format=png&signature=78e-ysfcy3d0e0rj70QJQ3wpuwI_hAl9ZYxIUVRw62I') }) it('returns url with path using a https url', () => { - const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), - 'https://assets.com/subfolder/example.jpeg', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SECURE_SOURCE, 'https://assets.com/subfolder/example.jpeg', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/https%3A%2F%2Fassets.com%2Fsubfolder%2Fexample.jpeg?width=200&height=300&format=png&signature=7Dp8Q01u_5YmpmH-j_y4P5vzOn_9EGvh77B3fi2Ke-s') }) it('returns url with path using a https url with reserved characters', () => { - const url = Url.url( - new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }), - 'https://assets.com/subfolder/example%2C01%2C02.jpeg', - { - width: 200, - height: 300, - format: 'png' - } - ) + const url = Url.url(SECURE_SOURCE, 'https://assets.com/subfolder/example%2C01%2C02.jpeg', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/https%3A%2F%2Fassets.com%2Fsubfolder%2Fexample%252C01%252C02.jpeg?width=200&height=300&format=png&signature=-zvh2hWXP8bHkoJVh8AdJFe9Kqdd1HpP1c2UmuQcYFQ') }) From 1edae14fadba40081ce2ec01bcbe07595ddb1d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Francisco=20Calvo?= Date: Wed, 11 Jan 2023 18:09:56 +0100 Subject: [PATCH 07/15] Add new srcset generation feature --- package-lock.json | 4 +- package.json | 2 +- src/index.js | 6 +- src/range.js | 33 + src/sequence.js | 4 +- src/srcset.js | 58 + src/srcset/utils.js | 77 + src/url.js | 2 +- src/{ => url}/utils.js | 2 +- test/range.test.js | 44 + test/srcset.test.js | 3294 ++++++++++++++++++++++++++++++++++ test/srcset/utils.test.js | 135 ++ test/url.test.js | 18 + test/{ => url}/utils.test.js | 4 +- 14 files changed, 3674 insertions(+), 9 deletions(-) create mode 100644 src/range.js create mode 100644 src/srcset.js create mode 100644 src/srcset/utils.js rename src/{ => url}/utils.js (96%) create mode 100644 test/range.test.js create mode 100644 test/srcset.test.js create mode 100644 test/srcset/utils.test.js rename test/{ => url}/utils.test.js (91%) diff --git a/package-lock.json b/package-lock.json index b091150..27506ec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@imglab/core", - "version": "0.2.1", + "version": "0.3.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@imglab/core", - "version": "0.2.1", + "version": "0.3.0", "license": "MIT", "devDependencies": { "@babel/core": "^7.16.0", diff --git a/package.json b/package.json index 9a8017a..ba599e9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@imglab/core", "source": "src/index.js", - "version": "0.2.1", + "version": "0.3.0", "description": "Official imglab Javascript library", "main": "dist/index.cjs.js", "module": "dist/index.esm.js", diff --git a/src/index.js b/src/index.js index 2946751..af46697 100644 --- a/src/index.js +++ b/src/index.js @@ -1,12 +1,16 @@ import Url from './url' +import Srcset from './srcset' import Source from './source' import Color from './color' import Position from './position' +import Range from './range' import Sequence from './sequence' const url = Url.url +const srcset = Srcset.srcset const color = Color.color const position = Position.position +const range = Range.range const sequence = Sequence.sequence -export default { url, Source, color, position, sequence } +export default { url, srcset, Source, color, position, range, sequence } diff --git a/src/range.js b/src/range.js new file mode 100644 index 0000000..be49c9c --- /dev/null +++ b/src/range.js @@ -0,0 +1,33 @@ +export default class Range { + #first + #last + #length + + static range(first, last) { + return new Range(first, last) + } + + constructor(first, last) { + this.#first = first + this.#last = last + this.#length = Math.abs(this.last - this.first) + 1 + } + + get first() { + return this.#first + } + + get last() { + return this.#last + } + + get length() { + return this.#length + } + + toArray() { + const inc = this.first < this.last ? 1 : -1 + + return Array.from({ length: this.length }, (_, i) => this.first + (i * inc)) + } +} diff --git a/src/sequence.js b/src/sequence.js index 8d4d44d..9ef0467 100644 --- a/src/sequence.js +++ b/src/sequence.js @@ -1,7 +1,7 @@ export default class Sequence { - static #DEFAULT_SIZE = 16 + static DEFAULT_SIZE = 16 - static sequence(first, last, size = Sequence.#DEFAULT_SIZE) { + static sequence(first, last, size = Sequence.DEFAULT_SIZE) { if (size <= 0) return [] if (size === 1) return [first] if (size === 2) return [first, last] diff --git a/src/srcset.js b/src/srcset.js new file mode 100644 index 0000000..5dc162b --- /dev/null +++ b/src/srcset.js @@ -0,0 +1,58 @@ +import Url from './url' +import Range from './range' +import Sequence from './sequence' +import Utils from './srcset/utils' + +export default class Srcset { + static #DEFAULT_DPRS = [1, 2, 3, 4, 5, 6] + static #DEFAULT_WIDTHS = Sequence.sequence(100, 8192) + + static srcset(source, path, params = {}) { + params = Utils.normalizeParams(params) + + switch(true) { + case Srcset.#isFluid(params.width): + if (Srcset.#isFluid(params.dpr)) { + throw new Error('dpr as Array or Range is not allowed when width is also an Array or Range') + } + + return Srcset.#srcset_width(source, path, params) + case !!(params.width || params.height): + if (Srcset.#isFluid(params.height)) { + throw new Error('height as Array or Range is only allowed when width is also an Array or Range') + } + + return Srcset.#srcset_dpr(source, path, {...params, ...{dpr: Srcset.#dprs(params)}}) + default: + if (Srcset.#isFluid(params.dpr)) { + throw new Error('dpr as Array or Range is not allowed without specifying width or height') + } + + return Srcset.#srcset_width(source, path, {...params, ...{width: Srcset.#DEFAULT_WIDTHS}}) + } + } + + static #dprs(params) { + if (Srcset.#isFluid(params.dpr)) { + return params.dpr + } else { + return Srcset.#DEFAULT_DPRS + } + } + + static #isFluid(value) { + return Array.isArray(value) || value instanceof Range + } + + static #srcset_dpr(source, path, params) { + return Utils.splitParamsDpr(params).map( + (splitParams) => `${Url.url(source, path, splitParams)} ${splitParams.dpr}x` + ).join(',\n') + } + + static #srcset_width(source, path, params) { + return Utils.splitParamsWidth(params).map( + (splitParams) => `${Url.url(source, path, splitParams)} ${splitParams.width}w` + ).join(',\n') + } +} diff --git a/src/srcset/utils.js b/src/srcset/utils.js new file mode 100644 index 0000000..71812a9 --- /dev/null +++ b/src/srcset/utils.js @@ -0,0 +1,77 @@ +import Range from '../range' +import Sequence from '../sequence' + +export default class Utils { + static #NORMALIZE_KEYS = ['dpr', 'width'] + + static #SPLIT_DPR_KEYS = ['dpr', 'quality'] + static #SPLIT_WIDTH_KEYS = ['width', 'height', 'quality'] + + static normalizeParams(params) { + return Object.entries(params).reduce((normalizedParams, [key, value]) => { + return Object.assign(normalizedParams, Utils.#normalizeParam(key, value)) + }, {}) + } + + static splitParamsDpr(params) { + return Utils.#splitValues(params, Utils.#SPLIT_DPR_KEYS, params.dpr.length).map( + ([dpr, quality]) => Utils.#mergeParams(params, {dpr: dpr, quality: quality}) + ) + } + + static splitParamsWidth(params) { + return Utils.#splitValues(params, Utils.#SPLIT_WIDTH_KEYS, Utils.#splitSize(params.width)).map( + ([width, height, quality]) => Utils.#mergeParams(params, {width: width, height: height, quality: quality}) + ) + } + + static #normalizeParam(key, value) { + switch(true) { + case Utils.#NORMALIZE_KEYS.includes(key) && Array.isArray(value) && value.length === 0: + return {} + default: + return { [key]: value } + } + } + + static #splitSize(value) { + switch(true) { + case value instanceof Range: + return Sequence.DEFAULT_SIZE + default: + return value.length + } + } + + static #splitValues(params, keys, size) { + return Utils.#zip(keys.map((key) => Utils.#splitValue(key, params[key], size))) + } + + static #splitValue(key, value, size) { + switch(true) { + case key === 'dpr' && value instanceof Range: + return value.toArray() + case value instanceof Range: + return Sequence.sequence(value.first, value.last, size) + case Array.isArray(value): + return value + default: + return Array(size).fill(value) + } + } + + static #zip(arrays) { + const length = Math.max(...arrays.map(array => array.length)) + + return Array.from({ length: length }, (_, i) => arrays.map(array => array[i])) + } + + static #mergeParams(params, mergeParams) { + return { + ...params, + ...Object.fromEntries( + Object.entries(mergeParams).filter(([key, _]) => key in params) + ) + } + } +} diff --git a/src/url.js b/src/url.js index 685f613..dc9a345 100644 --- a/src/url.js +++ b/src/url.js @@ -1,6 +1,6 @@ import Source from './source' import Signature from './signature' -import Utils from './utils' +import Utils from './url/utils' export default class Url { static url(source, path, params = {}) { diff --git a/src/utils.js b/src/url/utils.js similarity index 96% rename from src/utils.js rename to src/url/utils.js index 71ce87b..5b86ed6 100644 --- a/src/utils.js +++ b/src/url/utils.js @@ -33,7 +33,7 @@ export default class Utils { switch(true) { case key === 'expires' && value instanceof Date: return { [key]: Math.floor(value / 1000) } - case value === null: + case value === undefined || value === null: return { [key]: '' } default: return { [key]: value } diff --git a/test/range.test.js b/test/range.test.js new file mode 100644 index 0000000..9edfc25 --- /dev/null +++ b/test/range.test.js @@ -0,0 +1,44 @@ +import Range from '../src/range' + +describe('Range', () => { + describe('constructor', () => { + const range = new Range(2, 8) + + expect(range.first).toBe(2) + expect(range.last).toBe(8) + expect(range.length).toBe(7) + }) + + describe('first', () => { + expect(new Range(0, 1).first).toBe(0) + expect(new Range(1, 0).first).toBe(1) + expect(new Range(12, 2).first).toBe(12) + }) + + describe('last', () => { + expect(new Range(0, 1).last).toBe(1) + expect(new Range(1, 0).last).toBe(0) + expect(new Range(12, 2).last).toBe(2) + }) + + describe('length', () => { + expect(new Range(0, 1).length).toBe(2) + expect(new Range(1, 0).length).toBe(2) + expect(new Range(12, 2).length).toBe(11) + }) + + describe('toArray', () => { + it('returns array with numbers in range', () => { + expect(new Range(0, 0).toArray()).toEqual([0]) + expect(new Range(1, 1).toArray()).toEqual([1]) + expect(new Range(0, 1).toArray()).toEqual([0, 1]) + expect(new Range(1, 0).toArray()).toEqual([1, 0]) + expect(new Range(0, 2).toArray()).toEqual([0, 1, 2]) + expect(new Range(2, 0).toArray()).toEqual([2, 1, 0]) + expect(new Range(1, 6).toArray()).toEqual([1, 2, 3, 4, 5, 6]) + expect(new Range(6, 1).toArray()).toEqual([6, 5, 4, 3, 2, 1]) + expect(new Range(-2, 2).toArray()).toEqual([-2, -1, 0, 1, 2]) + expect(new Range(2, -2).toArray()).toEqual([2, 1, 0, -1, -2]) + }) + }) +}) diff --git a/test/srcset.test.js b/test/srcset.test.js new file mode 100644 index 0000000..d17d49d --- /dev/null +++ b/test/srcset.test.js @@ -0,0 +1,3294 @@ +import Srcset from '../src/srcset' +import Source from '../src/source' +import Range from '../src/range' +import Sequence from '../src/sequence' + +const range = Range.range +const sequence = Sequence.sequence + +const SECURE_KEY = 'ixUd9is/LDGBw6NPfLCGLjO/WraJlHdytC1+xiIFj22mXAWs/6R6ws4gxSXbDcUHMHv0G+oiTgyfMVsRS2b3' +const SECURE_SALT = 'c9G9eYKCeWen7vkEyV1cnr4MZkfLI/yo6j72JItzKHjMGDNZKqPFzRtup//qiT51HKGJrAha6Gv2huSFLwJr' + +const SOURCE = new Source('assets') +const SECURE_SOURCE = new Source('assets', { secureKey: SECURE_KEY, secureSalt: SECURE_SALT }) + +describe('Srcset', () => { + describe('srcset using source name', () => { + it('returns srcset without params', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg') + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=8192 8192w' + ) + }) + + it('returns srcset without size params', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { aspectRatio: '16:9', format: 'png' }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=8192 8192w' + ) + }) + + it('returns srcset with null width', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: null }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=8192 8192w' + ) + }) + + it('returns srcset with undefined width', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: undefined }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=8192 8192w' + ) + }) + + it('returns srcset with null height', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { height: null }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=8192 8192w' + ) + }) + + it('returns srcset with undefined height', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { height: undefined }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=8192 8192w' + ) + }) + + it('returns srcset without widht, without height and with fixed quality', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { quality: 75 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=8192 8192w' + ) + }) + + it('returns srcset without width, without height and with null quality', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { quality: null }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=8192 8192w' + ) + }) + + it('returns srcset without width, without height and with undefined quality', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { quality: undefined }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=8192 8192w' + ) + }) + + it('returns srcset without width, without height and with range of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=72&width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=69&width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=66&width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=63&width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=61&width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=58&width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=56&width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=54&width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=51&width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=49&width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=47&width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=45&width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=43&width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=42&width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=40&width=8192 8192w' + ) + }) + + it('returns srcset without width, without height and with empty array of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { quality: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=8192 8192w' + ) + }) + + it('returns srcset without width, without height and with array of qualities of size 1', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { quality: [75] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=8192 8192w' + ) + }) + + it('returns srcset without width, without height and with array of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=70&width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=65&width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=8192 8192w' + ) + }) + + it('returns srcset with fixed width', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and fixed dpr', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, dpr: 2 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and null dpr', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, dpr: null }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and undefined dpr', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, dpr: undefined }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and range of dprs', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, dpr: range(1, 4) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=4 4x' + ) + }) + + it('returns srcset with fixed width and empty array of dprs', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, dpr: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and array of dprs of size 1', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, dpr: [1] }) + + expect(srcset).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1 1x') + }) + + it('returns srcset with fixed width and array of dprs', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, dpr: [1, 2, 3] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3 3x' + ) + }) + + it('returns srcset with fixed width and fixed quality', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, quality: 75 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and null quality', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, quality: null }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and undefined quality', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, quality: undefined }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and range of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=66&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=58&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=51&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=45&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=40&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and empty array of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, quality: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and array of qualities of size 1', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, quality: [75] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and array of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=70&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=65&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width, range of dprs and range of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, dpr: range(1, 4), quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1&quality=75 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2&quality=61 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3&quality=49 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=4&quality=40 4x' + ) + }) + + it('returns srcset with fixed width, array of dprs and array of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, dpr: [1, 2, 3], quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1&quality=75 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2&quality=70 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3&quality=65 3x' + ) + }) + + it('returns srcset with fixed height', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { height: 200 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and fixed dpr', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { height: 200, dpr: 2 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and null dpr', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { height: 200, dpr: null }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and undefined dpr', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { height: 200, dpr: undefined }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and range of dprs', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { height: 200, dpr: range(1, 4) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=4 4x' + ) + }) + + it('returns srcset with fixed height and empty array of dprs', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { height: 200, dpr: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and array of dprs of size 1', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { height: 200, dpr: [1] }) + + expect(srcset).toBe('https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1 1x') + }) + + it('returns srcset with fixed height and array of dprs', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { height: 200, dpr: [1, 2, 3] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3 3x' + ) + }) + + it('returns srcset with fixed height and fixed quality', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { height: 200, quality: 75 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and null quality', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { height: 200, quality: null }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and undefined quality', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { height: 200, quality: undefined }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and range of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { height: 200, quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=66&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=58&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=51&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=45&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=40&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and empty array of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { height: 200, quality: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and array of qualities of size 1', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { height: 200, quality: [75] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and array of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { height: 200, quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=70&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=65&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height, range of dprs and range of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { height: 200, dpr: range(1, 4), quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1&quality=75 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2&quality=61 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3&quality=49 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=4&quality=40 4x' + ) + }) + + it('returns srcset with fixed height, array of dprs and array of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { height: 200, dpr: [1, 2, 3], quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1&quality=75 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2&quality=70 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3&quality=65 3x' + ) + }) + + it('returns srcset with fixed width and fixed height', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, height: 300 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width, fixed height and fixed dpr', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, height: 300, dpr: 2 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width, fixed height and range of dprs', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, height: 300, dpr: range(1, 4) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=4 4x' + ) + }) + + it('returns srcset with fixed width, fixed height and empty array of dprs', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, height: 300, dpr: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width, fixed height and array of dprs of size 1', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, height: 300, dpr: [1] }) + + expect(srcset).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1 1x') + }) + + it('returns srcset with fixed width, fixed height and array of dprs', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, height: 300, dpr: [1, 2, 3] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=3 3x' + ) + }) + + it('returns srcset with fixed width, fixed height and fixed quality', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, height: 300, quality: 75 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width, fixed height and range of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, height: 300, quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=66&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=58&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=51&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=45&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=40&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width, fixed height and empty array of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, height: 300, quality: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width, fixed height and array of qualities of size 1', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, height: 300, quality: [75] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width, fixed height and array of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, height: 300, quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=70&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=65&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width, fixed height, range of dprs and range of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, height: 300, dpr: range(1, 4), quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1&quality=75 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=2&quality=61 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=3&quality=49 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=4&quality=40 4x' + ) + }) + + it('returns srcset with fixed width, fixed height, array of dprs and array of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: 200, height: 300, dpr: [1, 2, 3], quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1&quality=75 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=2&quality=70 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=3&quality=65 3x' + ) + }) + + it('returns srcset with range of widths', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: range(100, 4096) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=128 128w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=164 164w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=210 210w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=269 269w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=345 345w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=442 442w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=566 566w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=724 724w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=928 928w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1188 1188w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1522 1522w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1949 1949w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=2497 2497w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=3198 3198w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4096 4096w' + ) + }) + + it('returns srcset with range of widths and range of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: range(100, 4096), quality: range(70, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100&quality=70 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=128&quality=67 128w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=164&quality=65 164w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=210&quality=63 210w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=269&quality=60 269w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=345&quality=58 345w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=442&quality=56 442w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=566&quality=54 566w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=724&quality=52 724w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=928&quality=50 928w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1188&quality=48 1188w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1522&quality=46 1522w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1949&quality=45 1949w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=2497&quality=43 2497w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=3198&quality=42 3198w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4096&quality=40 4096w' + ) + }) + + it('returns srcset with sequence of widths', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: sequence(100, 4096, 6) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=210 210w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=442 442w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=928 928w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1949 1949w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4096 4096w' + ) + }) + + it('returns srcset with sequence of widths and range of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: sequence(100, 4096, 6), quality: range(70, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100&quality=70 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=210&quality=63 210w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=442&quality=56 442w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=928&quality=50 928w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1949&quality=45 1949w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4096&quality=40 4096w' + ) + }) + + it('returns srcset with empty array of widths', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=8192 8192w' + ) + }) + + it('returns srcset with array of widths of size 1', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: [200] }) + + expect(srcset).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200 200w') + }) + + it('returns srcset with array of widths', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: [200, 300, 400] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400 400w' + ) + }) + + it('returns srcset with array of widths and range of heights', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: [200, 300, 400], height: range(300, 500) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&height=387 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&height=500 400w' + ) + }) + + it('returns srcset with array of widths and empty array of heights', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: [200, 300, 400], height: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height= 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&height= 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&height= 400w' + ) + }) + + it('returns srcset with array of widths and array of heights of size 1', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: [200, 300, 400], height: [300] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&height= 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&height= 400w' + ) + }) + + it('returns srcset with array of widths and array of heights', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: [200, 300, 400], height: [300, 400, 500] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&height=400 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&height=500 400w' + ) + }) + + it('returns srcset with array of widths and range of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: [200, 300, 400], quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&quality=55 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&quality=40 400w' + ) + }) + + it('returns srcset with array of widths and empty array of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: [200, 300, 400], quality: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality= 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&quality= 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&quality= 400w' + ) + }) + + it('returns srcset with array of widths and array of qualities of size 1', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: [200, 300, 400], quality: [75] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&quality= 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&quality= 400w' + ) + }) + + it('returns srcset with array of widths and array of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: [200, 300, 400], quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&quality=70 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&quality=65 400w' + ) + }) + + it('returns srcset with array of widths, range of heights and range of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: [200, 300, 400], height: range(300, 500), quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&height=387&quality=55 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&height=500&quality=40 400w' + ) + }) + + it('returns srcset with array of widths, array of heights and array of qualities', () => { + const srcset = Srcset.srcset('assets', 'example.jpeg', { width: [200, 300, 400], height: [300, 400, 500], quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&height=400&quality=70 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&height=500&quality=65 400w' + ) + }) + + it('throws a new error when width is fluid and dpr is also fluid', () => { + expect(() => { Srcset.srcset('assets', 'example.jpeg', { width: range(100, 300), dpr: range(1, 3) }) }).toThrow(Error) + expect(() => { Srcset.srcset('assets', 'example.jpeg', { width: range(100, 300), dpr: [1, 2, 3] }) }).toThrow(Error) + expect(() => { Srcset.srcset('assets', 'example.jpeg', { width: [100, 200, 300], dpr: range(1, 3) }) }).toThrow(Error) + expect(() => { Srcset.srcset('assets', 'example.jpeg', { width: [100, 200, 300], dpr: [1, 2, 3] }) }).toThrow(Error) + expect(() => { Srcset.srcset('assets', 'example.jpeg', { width: sequence(100, 300), dpr: range(1, 3) }) }).toThrow(Error) + expect(() => { Srcset.srcset('assets', 'example.jpeg', { width: sequence(100, 300), dpr: [1, 2, 3] }) }).toThrow(Error) + }) + + it('throws a new error when width is not fluid and height is fluid', () => { + expect(() => { Srcset.srcset('assets', 'example.jpeg', { height: range(100, 300) }) }).toThrow(Error) + expect(() => { Srcset.srcset('assets', 'example.jpeg', { height: [100, 200, 300] }) }).toThrow(Error) + expect(() => { Srcset.srcset('assets', 'example.jpeg', { width: 100, height: range(100, 300) }) }).toThrow(Error) + expect(() => { Srcset.srcset('assets', 'example.jpeg', { width: 100, height: [100, 200, 300] }) }).toThrow(Error) + }) + + it('throws a new error when width and height are not specified and dpr is fluid', () => { + expect(() => { Srcset.srcset('assets', 'example.jpeg', { dpr: range(1, 3) }) }).toThrow(Error) + expect(() => { Srcset.srcset('assets', 'example.jpeg', { dpr: [1, 2, 3] }) }).toThrow(Error) + }) + }) + + describe('srcset using source', () => { + it('returns srcset without params', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg') + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=8192 8192w' + ) + }) + + it('returns srcset without size params', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { aspectRatio: '16:9', format: 'png' }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=8192 8192w' + ) + }) + + it('returns srcset with null width', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: null }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=8192 8192w' + ) + }) + + it('returns srcset with undefined width', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: undefined }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=8192 8192w' + ) + }) + + it('returns srcset with null height', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { height: null }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=8192 8192w' + ) + }) + + it('returns srcset with undefined height', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { height: undefined }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=8192 8192w' + ) + }) + + it('returns srcset without widht, without height and with fixed quality', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { quality: 75 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=8192 8192w' + ) + }) + + it('returns srcset without width, without height and with null quality', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { quality: null }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=8192 8192w' + ) + }) + + it('returns srcset without width, without height and with undefined quality', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { quality: undefined }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=8192 8192w' + ) + }) + + it('returns srcset without width, without height and with range of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=72&width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=69&width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=66&width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=63&width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=61&width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=58&width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=56&width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=54&width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=51&width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=49&width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=47&width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=45&width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=43&width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=42&width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=40&width=8192 8192w' + ) + }) + + it('returns srcset without width, without height and with empty array of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { quality: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=8192 8192w' + ) + }) + + it('returns srcset without width, without height and with array of qualities of size 1', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { quality: [75] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=8192 8192w' + ) + }) + + it('returns srcset without width, without height and with array of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=70&width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=65&width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=8192 8192w' + ) + }) + + it('returns srcset with fixed width', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and fixed dpr', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, dpr: 2 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and null dpr', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, dpr: null }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and undefined dpr', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, dpr: undefined }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and range of dprs', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, dpr: range(1, 4) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=4 4x' + ) + }) + + it('returns srcset with fixed width and empty array of dprs', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, dpr: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and array of dprs of size 1', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, dpr: [1] }) + + expect(srcset).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1 1x') + }) + + it('returns srcset with fixed width and array of dprs', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, dpr: [1, 2, 3] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3 3x' + ) + }) + + it('returns srcset with fixed width and fixed quality', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, quality: 75 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and null quality', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, quality: null }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and undefined quality', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, quality: undefined }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and range of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=66&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=58&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=51&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=45&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=40&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and empty array of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, quality: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and array of qualities of size 1', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, quality: [75] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width and array of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=70&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=65&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width, range of dprs and range of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, dpr: range(1, 4), quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1&quality=75 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2&quality=61 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3&quality=49 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=4&quality=40 4x' + ) + }) + + it('returns srcset with fixed width, list of dprs and array of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, dpr: [1, 2, 3], quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1&quality=75 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2&quality=70 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3&quality=65 3x' + ) + }) + + it('returns srcset with fixed height', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { height: 200 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and fixed dpr', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { height: 200, dpr: 2 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and null dpr', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { height: 200, dpr: null }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and undefined dpr', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { height: 200, dpr: undefined }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and range of dprs', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { height: 200, dpr: range(1, 4) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=4 4x' + ) + }) + + it('returns srcset with fixed height and empty array of dprs', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { height: 200, dpr: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and array of dprs of size 1', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { height: 200, dpr: [1] }) + + expect(srcset).toBe('https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1 1x') + }) + + it('returns srcset with fixed height and array of dprs', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { height: 200, dpr: [1, 2, 3] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3 3x' + ) + }) + + it('returns srcset with fixed height and fixed quality', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { height: 200, quality: 75 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and null quality', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { height: 200, quality: null }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and undefined quality', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { height: 200, quality: undefined }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and range of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { height: 200, quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=66&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=58&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=51&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=45&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=40&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and empty array of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { height: 200, quality: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and array of qualities of size 1', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { height: 200, quality: [75] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height and array of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { height: 200, quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=70&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=65&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed height, range of dprs and range of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { height: 200, dpr: range(1, 4), quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1&quality=75 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2&quality=61 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3&quality=49 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=4&quality=40 4x' + ) + }) + + it('returns srcset with fixed height, array of dprs and array of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { height: 200, dpr: [1, 2, 3], quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1&quality=75 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2&quality=70 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3&quality=65 3x' + ) + }) + + it('returns srcset with fixed width and fixed height', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, height: 300 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width, fixed height and fixed dpr', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, height: 300, dpr: 2 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width, fixed height and range of dprs', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, height: 300, dpr: range(1, 4) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=4 4x' + ) + }) + + it('returns srcset with fixed width, fixed height and array list of dprs', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, height: 300, dpr: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width, fixed height and array of dprs of size 1', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, height: 300, dpr: [1] }) + + expect(srcset).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1 1x') + }) + + it('returns srcset with fixed width, fixed height and array of dprs', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, height: 300, dpr: [1, 2, 3] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=3 3x' + ) + }) + + it('returns srcset with fixed width, fixed height and fixed quality', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, height: 300, quality: 75 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width, fixed height and range of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, height: 300, quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=66&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=58&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=51&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=45&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=40&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width, fixed height and empty array of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, height: 300, quality: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width, fixed height and array of qualities of size 1', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, height: 300, quality: [75] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width, fixed height and array of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, height: 300, quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=1 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=70&dpr=2 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=65&dpr=3 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=4 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=5 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=6 6x' + ) + }) + + it('returns srcset with fixed width, fixed height, range of dprs and range of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, height: 300, dpr: range(1, 4), quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1&quality=75 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=2&quality=61 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=3&quality=49 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=4&quality=40 4x' + ) + }) + + it('returns srcset with fixed width, fixed height, array of dprs and arry of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: 200, height: 300, dpr: [1, 2, 3], quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1&quality=75 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=2&quality=70 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=3&quality=65 3x' + ) + }) + + it('returns srcset with range of widths', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: range(100, 4096) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=128 128w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=164 164w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=210 210w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=269 269w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=345 345w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=442 442w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=566 566w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=724 724w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=928 928w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1188 1188w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1522 1522w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1949 1949w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=2497 2497w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=3198 3198w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4096 4096w' + ) + }) + + it('returns srcset with range of widths and range of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: range(100, 4096), quality: range(70, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100&quality=70 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=128&quality=67 128w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=164&quality=65 164w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=210&quality=63 210w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=269&quality=60 269w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=345&quality=58 345w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=442&quality=56 442w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=566&quality=54 566w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=724&quality=52 724w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=928&quality=50 928w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1188&quality=48 1188w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1522&quality=46 1522w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1949&quality=45 1949w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=2497&quality=43 2497w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=3198&quality=42 3198w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4096&quality=40 4096w' + ) + }) + + it('returns srcset with sequence of widths', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: sequence(100, 4096, 6) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=210 210w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=442 442w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=928 928w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1949 1949w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4096 4096w' + ) + }) + + it('returns srcset with sequence of widths and range of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: sequence(100, 4096, 6), quality: range(70, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100&quality=70 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=210&quality=63 210w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=442&quality=56 442w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=928&quality=50 928w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1949&quality=45 1949w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4096&quality=40 4096w' + ) + }) + + it('returns srcset with empty array of widths', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=134 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=180 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=241 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=324 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=434 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=583 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=781 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1048 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1406 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1886 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=2530 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=3394 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4553 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=6107 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=8192 8192w' + ) + }) + + it('returns srcset with array of widths of size 1', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: [200] }) + + expect(srcset).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200 200w') + }) + + it('returns srcset with array of widths', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: [200, 300, 400] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400 400w' + ) + }) + + it('returns srcset with array of widths and range of heights', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: [200, 300, 400], height: range(300, 500) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&height=387 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&height=500 400w' + ) + }) + + it('returns srcset with array of widths and empty array of heights', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: [200, 300, 400], height: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height= 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&height= 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&height= 400w' + ) + }) + + it('returns srcset with array of widths and array of heights of size 1', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: [200, 300, 400], height: [300] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&height= 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&height= 400w' + ) + }) + + it('returns srcset with array of widths and array of heights', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: [200, 300, 400], height: [300, 400, 500] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&height=400 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&height=500 400w' + ) + }) + + it('returns srcset with array of widths and range of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: [200, 300, 400], quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&quality=55 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&quality=40 400w' + ) + }) + + it('returns srcset with array of widths and empty array of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: [200, 300, 400], quality: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality= 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&quality= 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&quality= 400w' + ) + }) + + it('returns srcset with array of widths and array of qualities of size 1', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: [200, 300, 400], quality: [75] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&quality= 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&quality= 400w' + ) + }) + + it('returns srcset with array of widths and array of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: [200, 300, 400], quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&quality=70 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&quality=65 400w' + ) + }) + + it('returns srcset with array of widths, range of heights and range of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: [200, 300, 400], height: range(300, 500), quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&height=387&quality=55 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&height=500&quality=40 400w' + ) + }) + + it('returns srcset with array of widths, array of heights and array of qualities', () => { + const srcset = Srcset.srcset(SOURCE, 'example.jpeg', { width: [200, 300, 400], height: [300, 400, 500], quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&height=400&quality=70 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&height=500&quality=65 400w' + ) + }) + + it('throws a new error when width is fluid and dpr is also fluid', () => { + expect(() => { Srcset.srcset(SOURCE, 'example.jpeg', { width: range(100, 300), dpr: range(1, 3) }) }).toThrow(Error) + expect(() => { Srcset.srcset(SOURCE, 'example.jpeg', { width: range(100, 300), dpr: [1, 2, 3] }) }).toThrow(Error) + expect(() => { Srcset.srcset(SOURCE, 'example.jpeg', { width: [100, 200, 300], dpr: range(1, 3) }) }).toThrow(Error) + expect(() => { Srcset.srcset(SOURCE, 'example.jpeg', { width: [100, 200, 300], dpr: [1, 2, 3] }) }).toThrow(Error) + expect(() => { Srcset.srcset(SOURCE, 'example.jpeg', { width: sequence(100, 300), dpr: range(1, 3) }) }).toThrow(Error) + expect(() => { Srcset.srcset(SOURCE, 'example.jpeg', { width: sequence(100, 300), dpr: [1, 2, 3] }) }).toThrow(Error) + }) + + it('throws a new error when width is not fluid and height is fluid', () => { + expect(() => { Srcset.srcset(SOURCE, 'example.jpeg', { height: range(100, 300) }) }).toThrow(Error) + expect(() => { Srcset.srcset(SOURCE, 'example.jpeg', { height: [100, 200, 300] }) }).toThrow(Error) + expect(() => { Srcset.srcset(SOURCE, 'example.jpeg', { width: 100, height: range(100, 300) }) }).toThrow(Error) + expect(() => { Srcset.srcset(SOURCE, 'example.jpeg', { width: 100, height: [100, 200, 300] }) }).toThrow(Error) + }) + + it('throws a new error when width and height are not specified and dpr is fluid', () => { + expect(() => { Srcset.srcset(SOURCE, 'example.jpeg', { dpr: range(1, 3) }) }).toThrow(Error) + expect(() => { Srcset.srcset(SOURCE, 'example.jpeg', { dpr: [1, 2, 3] }) }).toThrow(Error) + }) + }) + + describe('srcset using secure source', () => { + it('returns srcset without params', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg') + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100&signature=-G7slD-ae7GdT1lx8I0-7iUMnkMTU3NcTGB8GzaiaNg 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=134&signature=fHLmra9mxfjnp8E-7Cj7AZlJ43kRKLILUQ3Gawa0pxA 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=180&signature=omMuwPcMxKVGGnDk9sR2G6qD28uLIAldc-N9FvhwSH0 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=241&signature=09nboU72WGyryf9zyxMsNyBNu4PUrrGkuDlbM6shYas 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=324&signature=KOLqtvfSwSLUKnWY5-tvuaj-pOsBcN_WIHRTNLpJ7-Y 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=434&signature=48LOvc3n4CqstYfikmhT57XvKnydLRUa6qT-_IqZ0io 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=583&signature=IfEEELQp0__u7Ip-qzKQ2Plw70ybDOdrVeOz5jw9BOY 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=781&signature=p6sa4yVVce8AkuJagwLolgRD1nQUyzZsMw68KSQaVwM 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1048&signature=qz5KgcQRJHnCcubs9ldfGUGm1vzsvjBge17OWhykwp0 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1406&signature=Kh16qduc4dixmTKuhASbspncSVHlDTd4DnsbcmfB6Mw 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1886&signature=WN-YBqlX-bhiWxFydOVBsfkVIWjIuz09qvHkA2UZWvs 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=2530&signature=wH5aHb7P0S6xuJvBDoPgZPIo2-nosgViwt2ADVGhAvw 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=3394&signature=e_fi5Y-uruuUWips4wxJt5WkHKETn9P1MmHXVD9Cvxs 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4553&signature=AuXvD4c7FN279MOC63ogznGAqYmHqLCVDgQvl0I1IKM 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=6107&signature=nWDdC0v7d695Oo_bdhgc_AkxCkIyF7FSZgj7bAcOkNo 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=8192&signature=HNmtIa6jhuc8o3Yir2zZBjDvgiiAwGeMzM-x7ow1dSE 8192w' + ) + }) + + it('returns srcset without size params', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { aspectRatio: '16:9', format: 'png' }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=100&signature=NbJJwFNLXH2Lm04Vlq0bx4mQx8CAR4N_abDW4dGpPh8 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=134&signature=YReBU7g45tkZKQcSM0KCJHEBgy98F10a4ndYE5RAYZE 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=180&signature=cOHBLDWqFJYn3G5wSy7h10EbClkHU0pPk3vF6306hew 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=241&signature=RNLjPSNlme7d3UgJkuFScYmjquG1pWALFZcQmNcFaDs 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=324&signature=Oui_yhAccLk3qvOjb2BsPcItb4OQKRmdmEfEXO5RGf0 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=434&signature=yjSD343Tj-8iIUTCyhrTN0sgScsKOeZgRzwHRh0lbBk 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=583&signature=gPV3Gms4q38hj93EhxL1Ho0ZC-GkEDSuHbzs624eDyo 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=781&signature=69h4C_4odnjjo9DTDU8esuM9kDCPqSui8h1OFQH3GMs 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=1048&signature=5ULJml6M2hoExOZ20Ki1nt7dtqvvNSffb33iInBZocc 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=1406&signature=3aGhzUlEYZhMywzE5vfNphpJAtZWU0L-P3i6k26Fqvo 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=1886&signature=B2b4-1PIflt5BDQfcIm6G0OxLxQFNavbORPkukVuhPc 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=2530&signature=HjNxP9QSHyEP6iDZv1TgbGoNHRb57ncfPYdVWPawYgM 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=3394&signature=Rv1AyIY0-IGNb6G8cPOdRBmm6l3HB0cPYoL66qCcnhc 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=4553&signature=Ct7Kh3NAf8MZ_NsalXBymsdhrcF-BoKnwblXKNXQuGY 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=6107&signature=JazBYsfM0U0RJV0SdbbGBZznDRT6bHd8_Kc6uinl4Hs 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?aspect-ratio=16%3A9&format=png&width=8192&signature=-JvRN7tWRXGNDc1KABnZv5RmZ_FgTUsOUum3XXF1fxE 8192w' + ) + }) + + it('returns srcset with null width', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: null }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100&signature=-G7slD-ae7GdT1lx8I0-7iUMnkMTU3NcTGB8GzaiaNg 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=134&signature=fHLmra9mxfjnp8E-7Cj7AZlJ43kRKLILUQ3Gawa0pxA 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=180&signature=omMuwPcMxKVGGnDk9sR2G6qD28uLIAldc-N9FvhwSH0 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=241&signature=09nboU72WGyryf9zyxMsNyBNu4PUrrGkuDlbM6shYas 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=324&signature=KOLqtvfSwSLUKnWY5-tvuaj-pOsBcN_WIHRTNLpJ7-Y 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=434&signature=48LOvc3n4CqstYfikmhT57XvKnydLRUa6qT-_IqZ0io 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=583&signature=IfEEELQp0__u7Ip-qzKQ2Plw70ybDOdrVeOz5jw9BOY 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=781&signature=p6sa4yVVce8AkuJagwLolgRD1nQUyzZsMw68KSQaVwM 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1048&signature=qz5KgcQRJHnCcubs9ldfGUGm1vzsvjBge17OWhykwp0 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1406&signature=Kh16qduc4dixmTKuhASbspncSVHlDTd4DnsbcmfB6Mw 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1886&signature=WN-YBqlX-bhiWxFydOVBsfkVIWjIuz09qvHkA2UZWvs 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=2530&signature=wH5aHb7P0S6xuJvBDoPgZPIo2-nosgViwt2ADVGhAvw 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=3394&signature=e_fi5Y-uruuUWips4wxJt5WkHKETn9P1MmHXVD9Cvxs 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4553&signature=AuXvD4c7FN279MOC63ogznGAqYmHqLCVDgQvl0I1IKM 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=6107&signature=nWDdC0v7d695Oo_bdhgc_AkxCkIyF7FSZgj7bAcOkNo 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=8192&signature=HNmtIa6jhuc8o3Yir2zZBjDvgiiAwGeMzM-x7ow1dSE 8192w' + ) + }) + + it('returns srcset with undefined width', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: undefined }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100&signature=-G7slD-ae7GdT1lx8I0-7iUMnkMTU3NcTGB8GzaiaNg 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=134&signature=fHLmra9mxfjnp8E-7Cj7AZlJ43kRKLILUQ3Gawa0pxA 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=180&signature=omMuwPcMxKVGGnDk9sR2G6qD28uLIAldc-N9FvhwSH0 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=241&signature=09nboU72WGyryf9zyxMsNyBNu4PUrrGkuDlbM6shYas 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=324&signature=KOLqtvfSwSLUKnWY5-tvuaj-pOsBcN_WIHRTNLpJ7-Y 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=434&signature=48LOvc3n4CqstYfikmhT57XvKnydLRUa6qT-_IqZ0io 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=583&signature=IfEEELQp0__u7Ip-qzKQ2Plw70ybDOdrVeOz5jw9BOY 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=781&signature=p6sa4yVVce8AkuJagwLolgRD1nQUyzZsMw68KSQaVwM 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1048&signature=qz5KgcQRJHnCcubs9ldfGUGm1vzsvjBge17OWhykwp0 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1406&signature=Kh16qduc4dixmTKuhASbspncSVHlDTd4DnsbcmfB6Mw 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1886&signature=WN-YBqlX-bhiWxFydOVBsfkVIWjIuz09qvHkA2UZWvs 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=2530&signature=wH5aHb7P0S6xuJvBDoPgZPIo2-nosgViwt2ADVGhAvw 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=3394&signature=e_fi5Y-uruuUWips4wxJt5WkHKETn9P1MmHXVD9Cvxs 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4553&signature=AuXvD4c7FN279MOC63ogznGAqYmHqLCVDgQvl0I1IKM 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=6107&signature=nWDdC0v7d695Oo_bdhgc_AkxCkIyF7FSZgj7bAcOkNo 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=8192&signature=HNmtIa6jhuc8o3Yir2zZBjDvgiiAwGeMzM-x7ow1dSE 8192w' + ) + }) + + it('returns srcset with null height', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { height: null }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=100&signature=qgGwAacGLubPw_MV9gGsqSQxZwwwF6o3xrhsF7oZzeo 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=134&signature=A1X1Ufip8Y3a-Kx8RSbr3BKPK7sTokKuFQrY-Xa_24c 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=180&signature=yXqfS97rINsU0CSax5otWFNKMmvkrAPpRxobREUtdSs 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=241&signature=_Ugb6sjZCvH7O5Pz2JMFqacKrBOFz_3vsLxjTF9kclo 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=324&signature=sAIh1BhsFC1DyHWF0CFh0a-LAcy_loT2ElJspyC7vqY 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=434&signature=H02oPLw1sbftKYXoJc5AXH1cKWIXUzACNpiVxM-GUyY 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=583&signature=R8xJ-AkDk_zaTYM5ED7TgvQWTLwA5cZLs_jyuQGCiZk 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=781&signature=7PmZrtuoJOmMat6De-t8ymptJu9n9FQ7Gxn7pa2piW8 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=1048&signature=F8lJX64AcJfvss69fZbINKoPd7cbKHCRlYjX1z1_dsg 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=1406&signature=txn8esJ7vIqkgkZvwdKRSS53E3uf-7j1Yb8f0dIRlw4 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=1886&signature=wR2DposN7ibU8Dl9MzzjePe9AWVK1ox4xVV4CQ0OghY 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=2530&signature=zeDRRPL4BFfFg_rtCXTeFmsTT_C9kM0ntAghLVoazTs 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=3394&signature=CLIANKNBnTruPtrwmcbE8dqKgi5ft_ffTM2mH8kNvFo 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=4553&signature=Dn-shQtSttRLPh0j3fbUte7JkwWy4--nXbRJON0Dcqs 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=6107&signature=3F0v4wxNyoSunFplHbQps4EeLuQCLtVxDXfEi_GTYNE 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=8192&signature=ZhwS0bA6DmRns1bv1FuLw9r1Fg8Y46JixHRgvpiiwhw 8192w' + ) + }) + + it('returns srcset with undefined height', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { height: undefined }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=100&signature=qgGwAacGLubPw_MV9gGsqSQxZwwwF6o3xrhsF7oZzeo 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=134&signature=A1X1Ufip8Y3a-Kx8RSbr3BKPK7sTokKuFQrY-Xa_24c 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=180&signature=yXqfS97rINsU0CSax5otWFNKMmvkrAPpRxobREUtdSs 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=241&signature=_Ugb6sjZCvH7O5Pz2JMFqacKrBOFz_3vsLxjTF9kclo 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=324&signature=sAIh1BhsFC1DyHWF0CFh0a-LAcy_loT2ElJspyC7vqY 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=434&signature=H02oPLw1sbftKYXoJc5AXH1cKWIXUzACNpiVxM-GUyY 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=583&signature=R8xJ-AkDk_zaTYM5ED7TgvQWTLwA5cZLs_jyuQGCiZk 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=781&signature=7PmZrtuoJOmMat6De-t8ymptJu9n9FQ7Gxn7pa2piW8 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=1048&signature=F8lJX64AcJfvss69fZbINKoPd7cbKHCRlYjX1z1_dsg 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=1406&signature=txn8esJ7vIqkgkZvwdKRSS53E3uf-7j1Yb8f0dIRlw4 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=1886&signature=wR2DposN7ibU8Dl9MzzjePe9AWVK1ox4xVV4CQ0OghY 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=2530&signature=zeDRRPL4BFfFg_rtCXTeFmsTT_C9kM0ntAghLVoazTs 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=3394&signature=CLIANKNBnTruPtrwmcbE8dqKgi5ft_ffTM2mH8kNvFo 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=4553&signature=Dn-shQtSttRLPh0j3fbUte7JkwWy4--nXbRJON0Dcqs 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=6107&signature=3F0v4wxNyoSunFplHbQps4EeLuQCLtVxDXfEi_GTYNE 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=&width=8192&signature=ZhwS0bA6DmRns1bv1FuLw9r1Fg8Y46JixHRgvpiiwhw 8192w' + ) + }) + + it('returns srcset without widht, without height and with fixed quality', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { quality: 75 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=100&signature=MdlVEFrlbd_uNGEjZM1ALuGWIS-cZl1DGDhSDvDhato 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=134&signature=pSG9vgEsdniuyEUZ8r0Wfd_CNgFvbDmtUayIwPXTsPg 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=180&signature=291PUFY7rMNz2DxtTY5dcGxGYiwRnJD7ye7tgf-GZ8Y 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=241&signature=qn_UwdsTfRFtk-yq8arB5yo41372mzsdh26-AYAqMHQ 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=324&signature=8XELAadBAAFYQnae37ObGZA49oE8W9b5yF_pY3QVJQY 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=434&signature=U6NzmJJxrXm4KRyWZqQL6LwSVF4HygXHT_vYfvQI5xI 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=583&signature=XkXvyNCm4KUHS-fLzepPC1603et-ew3PH3CN_tQD6n8 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=781&signature=iPlNimegR3djYwTchz85-KFPY93d8aMTKcpzrzKNbKs 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=1048&signature=Ftqj-AGOCC0acyBIo18V8Epm6g82tiuHvq8I_djY0Ks 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=1406&signature=BsjFTuWi9ilETulFFJB-IEdxw-e_CWRBgnlDImz6-gc 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=1886&signature=E2TXXvpUm5eyljOQ7uG3i73ok1XBBLsm6AqW5zVTmN4 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=2530&signature=Dh7vfyl2hBMd1cD6YTJkHbmcA-0ZCi06HigvPaIlFSM 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=3394&signature=zHRSwjveBPRWo03Dn9dN7zjrewa7FpfF3Wb9aUi7bYM 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=4553&signature=yLwCeLEr1CHxb_zuPQSSbssejnsdGNqNLdTOj1D4ZsA 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=6107&signature=2GEzlHKTq98nTa5ObpB6-ARv8q8W-uHm19Vumzz-k2I 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=8192&signature=ShTkNRkOycgMAkCOKln6DPFCjM2673LNGaZPI2omGbo 8192w' + ) + }) + + it('returns srcset without width, without height and with null quality', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { quality: null }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=100&signature=vyUqI3Rk41lOSzhE0HAwl73gOfN6ERg6OOmq9Ysa1SU 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=134&signature=uy5848AZSPUeFGwSV27yLlGclqYU1oBpo1rsOow-pNo 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=180&signature=Ozgkx_JvAEICkszdoclwuWmZ5BEjyIDVZJNDl_O0aqg 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=241&signature=Jf9HPL2I0D9zNDGALITPlbMapmO1-aUsbiM5FqnczFc 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=324&signature=ff6JAgBW2sAPl1PfQGwkLPWUEkzfQts4mUe-bFLZ3Ec 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=434&signature=GldXfzEEI2N6SZk9IbeXLPxMlRcSRoEWO8e3Zpp8PH8 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=583&signature=5ebKNVmrlDGyQQVQcjbk0vAvmU_l1jtSpHkMxFxlbBw 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=781&signature=jJd3B8wzvTjwqIFHmB4ZXLHonbw-EQLCiE6TiHRT0tw 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1048&signature=DAxsrxK-VqaF-QaEoZru83yuhX2MV5oakelAn8-Jpb8 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1406&signature=UHqCY93GXmZh9WmR3ZypL-nv4mpcexghu2LXlUiLv10 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1886&signature=b6PhbtD5_uFpHj1VFCbP4_06ZhhZOBlYH-p0mGub8yI 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=2530&signature=3XIFh6uFYxgO7yNh_6EmQ7cZp9UMYsB0AdRzpaebvSM 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=3394&signature=gKVMiRqju-04c5xloACa4Wb1qYR2_zLtk00Cu5ZDIzI 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=4553&signature=jRUdh9g9bPeALalAepKCSBwr2bSU3mI5jS7HMaekhyc 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=6107&signature=nCkD13Of8MMZpopYN4RSEsZwhLNT3dsi3AFarXaPKTU 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=8192&signature=Ax9PBsp9q8KWyQiFyFaOnKdxWN6aY9RFWZpTE_sj9iQ 8192w' + ) + }) + + it('returns srcset without width, without height and with undefined quality', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { quality: undefined }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=100&signature=vyUqI3Rk41lOSzhE0HAwl73gOfN6ERg6OOmq9Ysa1SU 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=134&signature=uy5848AZSPUeFGwSV27yLlGclqYU1oBpo1rsOow-pNo 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=180&signature=Ozgkx_JvAEICkszdoclwuWmZ5BEjyIDVZJNDl_O0aqg 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=241&signature=Jf9HPL2I0D9zNDGALITPlbMapmO1-aUsbiM5FqnczFc 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=324&signature=ff6JAgBW2sAPl1PfQGwkLPWUEkzfQts4mUe-bFLZ3Ec 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=434&signature=GldXfzEEI2N6SZk9IbeXLPxMlRcSRoEWO8e3Zpp8PH8 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=583&signature=5ebKNVmrlDGyQQVQcjbk0vAvmU_l1jtSpHkMxFxlbBw 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=781&signature=jJd3B8wzvTjwqIFHmB4ZXLHonbw-EQLCiE6TiHRT0tw 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1048&signature=DAxsrxK-VqaF-QaEoZru83yuhX2MV5oakelAn8-Jpb8 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1406&signature=UHqCY93GXmZh9WmR3ZypL-nv4mpcexghu2LXlUiLv10 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1886&signature=b6PhbtD5_uFpHj1VFCbP4_06ZhhZOBlYH-p0mGub8yI 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=2530&signature=3XIFh6uFYxgO7yNh_6EmQ7cZp9UMYsB0AdRzpaebvSM 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=3394&signature=gKVMiRqju-04c5xloACa4Wb1qYR2_zLtk00Cu5ZDIzI 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=4553&signature=jRUdh9g9bPeALalAepKCSBwr2bSU3mI5jS7HMaekhyc 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=6107&signature=nCkD13Of8MMZpopYN4RSEsZwhLNT3dsi3AFarXaPKTU 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=8192&signature=Ax9PBsp9q8KWyQiFyFaOnKdxWN6aY9RFWZpTE_sj9iQ 8192w' + ) + }) + + it('returns srcset without width, without height and with range of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=100&signature=MdlVEFrlbd_uNGEjZM1ALuGWIS-cZl1DGDhSDvDhato 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=72&width=134&signature=Fh2C6Vf_0ivpN4fANWjW3yBUSseFL7kLEnQ9AqUh_94 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=69&width=180&signature=5UBJKCNaufIBc9SXsQTv_0vA9ADGPBvNAxInQZYfcVk 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=66&width=241&signature=t8trQBaYqW9xzz9bFEcW__1yfGLqEeacpZyfGauGvc0 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=63&width=324&signature=yhbdd6qiTmJmCX_PobKv_5zwMp1RDACCMvKkDhXRBVY 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=61&width=434&signature=yGYu0jjKy6r6aygEWC-ew85-6xTcVTtsvR1Cb1qF9OM 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=58&width=583&signature=N0ItLybI-R3NFwOtYQZMfbRzIVfiuEd5XFW39rZwxiA 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=56&width=781&signature=7UX9-2xa32IHajJgzeNC-q2ut9bWGHYFAAR-f5TclUc 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=54&width=1048&signature=LTqNlXbgql-IlWCjZ_NDE4upRfP2edc0hW5Lnm17AH8 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=51&width=1406&signature=xDju3Exs-kzpaU9gWcUdShhiygjxu2zsuSNnP7aOpLM 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=49&width=1886&signature=F49-uX9mQaAlieoq32QY-gv1JOwAzo_8DTRM54Blm7w 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=47&width=2530&signature=dl3xzdKQDwPTAMC2X35P4oWPvLhKj2CqHYtMsadeJxU 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=45&width=3394&signature=Qk7S4REwQNBocNQL4Lr-urMOVljtB8AAWmiXYSrYkV0 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=43&width=4553&signature=gzFsF5t-vOZbmzQcaDnFk058hzFFATqWI7eZ9FFCa20 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=42&width=6107&signature=h8T3dTy7tWObEYVzFHb_Nre8rfSTidhqCcUPNnO7-9E 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=40&width=8192&signature=nw1YyvOX5-5QGR_WAlj-f7Y0j69LS68wXKbv-JiNZXs 8192w' + ) + }) + + it('returns srcset without width, without height and with empty array of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { quality: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=100&signature=vyUqI3Rk41lOSzhE0HAwl73gOfN6ERg6OOmq9Ysa1SU 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=134&signature=uy5848AZSPUeFGwSV27yLlGclqYU1oBpo1rsOow-pNo 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=180&signature=Ozgkx_JvAEICkszdoclwuWmZ5BEjyIDVZJNDl_O0aqg 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=241&signature=Jf9HPL2I0D9zNDGALITPlbMapmO1-aUsbiM5FqnczFc 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=324&signature=ff6JAgBW2sAPl1PfQGwkLPWUEkzfQts4mUe-bFLZ3Ec 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=434&signature=GldXfzEEI2N6SZk9IbeXLPxMlRcSRoEWO8e3Zpp8PH8 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=583&signature=5ebKNVmrlDGyQQVQcjbk0vAvmU_l1jtSpHkMxFxlbBw 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=781&signature=jJd3B8wzvTjwqIFHmB4ZXLHonbw-EQLCiE6TiHRT0tw 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1048&signature=DAxsrxK-VqaF-QaEoZru83yuhX2MV5oakelAn8-Jpb8 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1406&signature=UHqCY93GXmZh9WmR3ZypL-nv4mpcexghu2LXlUiLv10 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1886&signature=b6PhbtD5_uFpHj1VFCbP4_06ZhhZOBlYH-p0mGub8yI 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=2530&signature=3XIFh6uFYxgO7yNh_6EmQ7cZp9UMYsB0AdRzpaebvSM 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=3394&signature=gKVMiRqju-04c5xloACa4Wb1qYR2_zLtk00Cu5ZDIzI 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=4553&signature=jRUdh9g9bPeALalAepKCSBwr2bSU3mI5jS7HMaekhyc 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=6107&signature=nCkD13Of8MMZpopYN4RSEsZwhLNT3dsi3AFarXaPKTU 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=8192&signature=Ax9PBsp9q8KWyQiFyFaOnKdxWN6aY9RFWZpTE_sj9iQ 8192w' + ) + }) + + it('returns srcset without width, without height and with array of qualities of size 1', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { quality: [75] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=100&signature=MdlVEFrlbd_uNGEjZM1ALuGWIS-cZl1DGDhSDvDhato 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=134&signature=uy5848AZSPUeFGwSV27yLlGclqYU1oBpo1rsOow-pNo 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=180&signature=Ozgkx_JvAEICkszdoclwuWmZ5BEjyIDVZJNDl_O0aqg 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=241&signature=Jf9HPL2I0D9zNDGALITPlbMapmO1-aUsbiM5FqnczFc 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=324&signature=ff6JAgBW2sAPl1PfQGwkLPWUEkzfQts4mUe-bFLZ3Ec 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=434&signature=GldXfzEEI2N6SZk9IbeXLPxMlRcSRoEWO8e3Zpp8PH8 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=583&signature=5ebKNVmrlDGyQQVQcjbk0vAvmU_l1jtSpHkMxFxlbBw 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=781&signature=jJd3B8wzvTjwqIFHmB4ZXLHonbw-EQLCiE6TiHRT0tw 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1048&signature=DAxsrxK-VqaF-QaEoZru83yuhX2MV5oakelAn8-Jpb8 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1406&signature=UHqCY93GXmZh9WmR3ZypL-nv4mpcexghu2LXlUiLv10 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1886&signature=b6PhbtD5_uFpHj1VFCbP4_06ZhhZOBlYH-p0mGub8yI 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=2530&signature=3XIFh6uFYxgO7yNh_6EmQ7cZp9UMYsB0AdRzpaebvSM 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=3394&signature=gKVMiRqju-04c5xloACa4Wb1qYR2_zLtk00Cu5ZDIzI 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=4553&signature=jRUdh9g9bPeALalAepKCSBwr2bSU3mI5jS7HMaekhyc 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=6107&signature=nCkD13Of8MMZpopYN4RSEsZwhLNT3dsi3AFarXaPKTU 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=8192&signature=Ax9PBsp9q8KWyQiFyFaOnKdxWN6aY9RFWZpTE_sj9iQ 8192w' + ) + }) + + it('returns srcset without width, without height and with array of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?quality=75&width=100&signature=MdlVEFrlbd_uNGEjZM1ALuGWIS-cZl1DGDhSDvDhato 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=70&width=134&signature=JJ1R-D0Y2uIxbuGndKiD9ybH7nCvqrH-AFCMEJ0wFFY 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=65&width=180&signature=gfTHds7_QB0Jw68RnDs1D3Hwq_MQ934IJsovJ9ewFOU 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=241&signature=Jf9HPL2I0D9zNDGALITPlbMapmO1-aUsbiM5FqnczFc 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=324&signature=ff6JAgBW2sAPl1PfQGwkLPWUEkzfQts4mUe-bFLZ3Ec 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=434&signature=GldXfzEEI2N6SZk9IbeXLPxMlRcSRoEWO8e3Zpp8PH8 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=583&signature=5ebKNVmrlDGyQQVQcjbk0vAvmU_l1jtSpHkMxFxlbBw 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=781&signature=jJd3B8wzvTjwqIFHmB4ZXLHonbw-EQLCiE6TiHRT0tw 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1048&signature=DAxsrxK-VqaF-QaEoZru83yuhX2MV5oakelAn8-Jpb8 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1406&signature=UHqCY93GXmZh9WmR3ZypL-nv4mpcexghu2LXlUiLv10 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=1886&signature=b6PhbtD5_uFpHj1VFCbP4_06ZhhZOBlYH-p0mGub8yI 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=2530&signature=3XIFh6uFYxgO7yNh_6EmQ7cZp9UMYsB0AdRzpaebvSM 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=3394&signature=gKVMiRqju-04c5xloACa4Wb1qYR2_zLtk00Cu5ZDIzI 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=4553&signature=jRUdh9g9bPeALalAepKCSBwr2bSU3mI5jS7HMaekhyc 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=6107&signature=nCkD13Of8MMZpopYN4RSEsZwhLNT3dsi3AFarXaPKTU 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?quality=&width=8192&signature=Ax9PBsp9q8KWyQiFyFaOnKdxWN6aY9RFWZpTE_sj9iQ 8192w' + ) + }) + + it('returns srcset with fixed width', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1&signature=Dt2QjQRTGriKiEL8b4bd1oR0s4kk_YR-t5ip9FG_8r4 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2&signature=ENOlJPVnPCsCl7xWghj4y-jeBPHvSaK9LG5r9gvf_14 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3&signature=Kx4REMpTxLA00Wt-NWM9dw8wML441Ok0C1nmATDVcho 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=4&signature=M3Jtp4O7QfsDJkCEiC48pRrscdCp8Pw_qz5l_HwfTdg 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=5&signature=65EB3f_-13GfS8Sfq_cQ1AHCkSmDYgaWkeFCF69vwEw 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=6&signature=1H6iBT7iifEFXYFdg016xjF0HnQljOki5z4acr2kRF0 6x' + ) + }) + + it('returns srcset with fixed width and fixed dpr', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, dpr: 2 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1&signature=Dt2QjQRTGriKiEL8b4bd1oR0s4kk_YR-t5ip9FG_8r4 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2&signature=ENOlJPVnPCsCl7xWghj4y-jeBPHvSaK9LG5r9gvf_14 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3&signature=Kx4REMpTxLA00Wt-NWM9dw8wML441Ok0C1nmATDVcho 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=4&signature=M3Jtp4O7QfsDJkCEiC48pRrscdCp8Pw_qz5l_HwfTdg 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=5&signature=65EB3f_-13GfS8Sfq_cQ1AHCkSmDYgaWkeFCF69vwEw 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=6&signature=1H6iBT7iifEFXYFdg016xjF0HnQljOki5z4acr2kRF0 6x' + ) + }) + + it('returns srcset with fixed width and null dpr', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, dpr: null }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1&signature=Dt2QjQRTGriKiEL8b4bd1oR0s4kk_YR-t5ip9FG_8r4 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2&signature=ENOlJPVnPCsCl7xWghj4y-jeBPHvSaK9LG5r9gvf_14 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3&signature=Kx4REMpTxLA00Wt-NWM9dw8wML441Ok0C1nmATDVcho 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=4&signature=M3Jtp4O7QfsDJkCEiC48pRrscdCp8Pw_qz5l_HwfTdg 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=5&signature=65EB3f_-13GfS8Sfq_cQ1AHCkSmDYgaWkeFCF69vwEw 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=6&signature=1H6iBT7iifEFXYFdg016xjF0HnQljOki5z4acr2kRF0 6x' + ) + }) + + it('returns srcset with fixed width and undefined dpr', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, dpr: undefined }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1&signature=Dt2QjQRTGriKiEL8b4bd1oR0s4kk_YR-t5ip9FG_8r4 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2&signature=ENOlJPVnPCsCl7xWghj4y-jeBPHvSaK9LG5r9gvf_14 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3&signature=Kx4REMpTxLA00Wt-NWM9dw8wML441Ok0C1nmATDVcho 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=4&signature=M3Jtp4O7QfsDJkCEiC48pRrscdCp8Pw_qz5l_HwfTdg 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=5&signature=65EB3f_-13GfS8Sfq_cQ1AHCkSmDYgaWkeFCF69vwEw 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=6&signature=1H6iBT7iifEFXYFdg016xjF0HnQljOki5z4acr2kRF0 6x' + ) + }) + + it('returns srcset with fixed width and range of dprs', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, dpr: range(1, 4) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1&signature=Dt2QjQRTGriKiEL8b4bd1oR0s4kk_YR-t5ip9FG_8r4 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2&signature=ENOlJPVnPCsCl7xWghj4y-jeBPHvSaK9LG5r9gvf_14 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3&signature=Kx4REMpTxLA00Wt-NWM9dw8wML441Ok0C1nmATDVcho 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=4&signature=M3Jtp4O7QfsDJkCEiC48pRrscdCp8Pw_qz5l_HwfTdg 4x' + ) + }) + + it('returns srcset with fixed width and empty array of dprs', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, dpr: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1&signature=Dt2QjQRTGriKiEL8b4bd1oR0s4kk_YR-t5ip9FG_8r4 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2&signature=ENOlJPVnPCsCl7xWghj4y-jeBPHvSaK9LG5r9gvf_14 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3&signature=Kx4REMpTxLA00Wt-NWM9dw8wML441Ok0C1nmATDVcho 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=4&signature=M3Jtp4O7QfsDJkCEiC48pRrscdCp8Pw_qz5l_HwfTdg 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=5&signature=65EB3f_-13GfS8Sfq_cQ1AHCkSmDYgaWkeFCF69vwEw 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=6&signature=1H6iBT7iifEFXYFdg016xjF0HnQljOki5z4acr2kRF0 6x' + ) + }) + + it('returns srcset with fixed width and array of dprs of size 1', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, dpr: [1] }) + + expect(srcset).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1&signature=Dt2QjQRTGriKiEL8b4bd1oR0s4kk_YR-t5ip9FG_8r4 1x') + }) + + it('returns srcset with fixed width and array of dprs', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, dpr: [1, 2, 3] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1&signature=Dt2QjQRTGriKiEL8b4bd1oR0s4kk_YR-t5ip9FG_8r4 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2&signature=ENOlJPVnPCsCl7xWghj4y-jeBPHvSaK9LG5r9gvf_14 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3&signature=Kx4REMpTxLA00Wt-NWM9dw8wML441Ok0C1nmATDVcho 3x' + ) + }) + + it('returns srcset with fixed width and fixed quality', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, quality: 75 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=1&signature=zf8CQyXlM8escASLnzgE-Ty32cv2LCoVMiC34IxGVZQ 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=2&signature=34do97OeAJKHeTdqcPLM0EVlzolbA0bWmBWCogQH3Hs 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=3&signature=M9uchI7N8SsJj1NWAjwkGFarhewbwn-PuJZuVvoAO9s 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=4&signature=i7zW4GGDKP4a5z65hGb2TlqdnvBQbeEr40JAn8PhEZg 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=5&signature=1hi15abMQlRMLXxERtnG2aecaHkXrBG8WUXbEEDjbyk 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=6&signature=TZg-SVdMxQbJW1jQuhU35-wQok0k3Y_pj3zBqIOz_J4 6x' + ) + }) + + it('returns srcset with fixed width and null quality', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, quality: null }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=1&signature=tgqva0giYvsn-FKsRYIO8d9Tm4iS85St8_ilDzFCoA4 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=2&signature=blj1DwMwrUc8ZhdT-7_uExNG5PSobt3955CpsZ01SGs 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=3&signature=j5lQ3w9EY6A-uHicfMakRnvy57XvE4bu6wBiHqStdDc 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=4&signature=IuxCY3JrnGVfuyvdXD7TeBXwqt_ySJalNm40VSMWGPQ 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=5&signature=IWR07lI3B8VmzHlrwwxgWGyt9yw01IXkd_W9zk68K3E 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=6&signature=KKG086kEMT2fu4c21ybf9ZNkddU1z07ZHPzdF0X4vNk 6x' + ) + }) + + it('returns srcset with fixed width and undefined quality', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, quality: undefined }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=1&signature=tgqva0giYvsn-FKsRYIO8d9Tm4iS85St8_ilDzFCoA4 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=2&signature=blj1DwMwrUc8ZhdT-7_uExNG5PSobt3955CpsZ01SGs 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=3&signature=j5lQ3w9EY6A-uHicfMakRnvy57XvE4bu6wBiHqStdDc 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=4&signature=IuxCY3JrnGVfuyvdXD7TeBXwqt_ySJalNm40VSMWGPQ 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=5&signature=IWR07lI3B8VmzHlrwwxgWGyt9yw01IXkd_W9zk68K3E 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=6&signature=KKG086kEMT2fu4c21ybf9ZNkddU1z07ZHPzdF0X4vNk 6x' + ) + }) + + it('returns srcset with fixed width and range of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=1&signature=zf8CQyXlM8escASLnzgE-Ty32cv2LCoVMiC34IxGVZQ 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=66&dpr=2&signature=YBES6qxx_Rs40YKoE4Mr9mWSZhXo3PXu1k9vR5pnNDU 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=58&dpr=3&signature=aprnNDUh9GiAKb7qnBuhj--3toBX-It11b0RySvrreE 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=51&dpr=4&signature=SLtY4Sat8xnYeZpVGBTvpmWe1nJdtj1pqtX0zhvbqSA 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=45&dpr=5&signature=wGAYFVmOIoHFKRH6X-FMLbtjUYdb7O4WGROFXTF8KDM 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=40&dpr=6&signature=ZJbG5VWJcYC1tV9fcNSl6h1T5GgAg7ANSftkt7nn8-E 6x' + ) + }) + + it('returns srcset with fixed width and empty array of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, quality: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=1&signature=tgqva0giYvsn-FKsRYIO8d9Tm4iS85St8_ilDzFCoA4 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=2&signature=blj1DwMwrUc8ZhdT-7_uExNG5PSobt3955CpsZ01SGs 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=3&signature=j5lQ3w9EY6A-uHicfMakRnvy57XvE4bu6wBiHqStdDc 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=4&signature=IuxCY3JrnGVfuyvdXD7TeBXwqt_ySJalNm40VSMWGPQ 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=5&signature=IWR07lI3B8VmzHlrwwxgWGyt9yw01IXkd_W9zk68K3E 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=6&signature=KKG086kEMT2fu4c21ybf9ZNkddU1z07ZHPzdF0X4vNk 6x' + ) + }) + + it('returns srcset with fixed width and array of qualities of size 1', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, quality: [75] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=1&signature=zf8CQyXlM8escASLnzgE-Ty32cv2LCoVMiC34IxGVZQ 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=2&signature=blj1DwMwrUc8ZhdT-7_uExNG5PSobt3955CpsZ01SGs 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=3&signature=j5lQ3w9EY6A-uHicfMakRnvy57XvE4bu6wBiHqStdDc 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=4&signature=IuxCY3JrnGVfuyvdXD7TeBXwqt_ySJalNm40VSMWGPQ 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=5&signature=IWR07lI3B8VmzHlrwwxgWGyt9yw01IXkd_W9zk68K3E 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=6&signature=KKG086kEMT2fu4c21ybf9ZNkddU1z07ZHPzdF0X4vNk 6x' + ) + }) + + it('returns srcset with fixed width and array of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&dpr=1&signature=zf8CQyXlM8escASLnzgE-Ty32cv2LCoVMiC34IxGVZQ 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=70&dpr=2&signature=UQWnjkkbdpin58NWsNI7fP9QnpVp3AOHQEEiTHFfAoQ 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=65&dpr=3&signature=fvJgZwx8p51mO_6ws36JssGTpJA2JZZf0213mePfHSw 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=4&signature=IuxCY3JrnGVfuyvdXD7TeBXwqt_ySJalNm40VSMWGPQ 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=5&signature=IWR07lI3B8VmzHlrwwxgWGyt9yw01IXkd_W9zk68K3E 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&dpr=6&signature=KKG086kEMT2fu4c21ybf9ZNkddU1z07ZHPzdF0X4vNk 6x' + ) + }) + + it('returns srcset with fixed width, range of dprs and range of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, dpr: range(1, 4), quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1&quality=75&signature=djrhMfgKiQcXYPpa2JorQHj4zz-hmg1-6l6wGnX6Ovc 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2&quality=61&signature=EQvDP8UcAkM6G8iaqO6FGhSZCcLRxwNVxcXq48BHQT4 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3&quality=49&signature=uITEVTQ_jpkyXNtIvg67XmmKJU1g0QnG88d5pUAhe7Y 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=4&quality=40&signature=LcL5119TTi9sBdHwKX-fCbtAYst7kqqx1M7daGLr2Rg 4x' + ) + }) + + it('returns srcset with fixed width, array of dprs and array of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, dpr: [1, 2, 3], quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=1&quality=75&signature=djrhMfgKiQcXYPpa2JorQHj4zz-hmg1-6l6wGnX6Ovc 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=2&quality=70&signature=JFakWQFwObD94TqD71hf8X7HB6XhpTAkOcRGvaulxxI 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&dpr=3&quality=65&signature=zm3rzIUUvJTdfOkiENdcY8_900vB-QRNYHtBaZqiWIo 3x' + ) + }) + + it('returns srcset with fixed height', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { height: 200 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1&signature=OPRYWD06ACeu6W8YXkZ87-swVGCl9hCk7bPLh_wn6Cw 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2&signature=4981fsA13f03qY95Xt9grU2ZyjVReTukEEGmEMaOyeU 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3&signature=NYcE4xjRvJ3m8FCTwVbC30VNjuKuCJzY-pBwqMXvdLc 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=4&signature=CosxSgq_XuY_XDYCDGZzMp0XHgQ45HWTTUNsfIWqAaI 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=5&signature=jNdvuKhq8n1ptnvALUZ7pttVj--8wctjeDEHKlPPxtY 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=6&signature=5b-Ojy9lICTxN3EoHsBWgOHhd_glloTtR7YHd6u43OM 6x' + ) + }) + + it('returns srcset with fixed height and fixed dpr', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { height: 200, dpr: 2 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1&signature=OPRYWD06ACeu6W8YXkZ87-swVGCl9hCk7bPLh_wn6Cw 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2&signature=4981fsA13f03qY95Xt9grU2ZyjVReTukEEGmEMaOyeU 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3&signature=NYcE4xjRvJ3m8FCTwVbC30VNjuKuCJzY-pBwqMXvdLc 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=4&signature=CosxSgq_XuY_XDYCDGZzMp0XHgQ45HWTTUNsfIWqAaI 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=5&signature=jNdvuKhq8n1ptnvALUZ7pttVj--8wctjeDEHKlPPxtY 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=6&signature=5b-Ojy9lICTxN3EoHsBWgOHhd_glloTtR7YHd6u43OM 6x' + ) + }) + + it('returns srcset with fixed height and null dpr', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { height: 200, dpr: null }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1&signature=OPRYWD06ACeu6W8YXkZ87-swVGCl9hCk7bPLh_wn6Cw 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2&signature=4981fsA13f03qY95Xt9grU2ZyjVReTukEEGmEMaOyeU 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3&signature=NYcE4xjRvJ3m8FCTwVbC30VNjuKuCJzY-pBwqMXvdLc 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=4&signature=CosxSgq_XuY_XDYCDGZzMp0XHgQ45HWTTUNsfIWqAaI 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=5&signature=jNdvuKhq8n1ptnvALUZ7pttVj--8wctjeDEHKlPPxtY 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=6&signature=5b-Ojy9lICTxN3EoHsBWgOHhd_glloTtR7YHd6u43OM 6x' + ) + }) + + it('returns srcset with fixed height and undefined dpr', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { height: 200, dpr: undefined }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1&signature=OPRYWD06ACeu6W8YXkZ87-swVGCl9hCk7bPLh_wn6Cw 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2&signature=4981fsA13f03qY95Xt9grU2ZyjVReTukEEGmEMaOyeU 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3&signature=NYcE4xjRvJ3m8FCTwVbC30VNjuKuCJzY-pBwqMXvdLc 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=4&signature=CosxSgq_XuY_XDYCDGZzMp0XHgQ45HWTTUNsfIWqAaI 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=5&signature=jNdvuKhq8n1ptnvALUZ7pttVj--8wctjeDEHKlPPxtY 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=6&signature=5b-Ojy9lICTxN3EoHsBWgOHhd_glloTtR7YHd6u43OM 6x' + ) + }) + + it('returns srcset with fixed height and range of dprs', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { height: 200, dpr: range(1, 4) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1&signature=OPRYWD06ACeu6W8YXkZ87-swVGCl9hCk7bPLh_wn6Cw 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2&signature=4981fsA13f03qY95Xt9grU2ZyjVReTukEEGmEMaOyeU 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3&signature=NYcE4xjRvJ3m8FCTwVbC30VNjuKuCJzY-pBwqMXvdLc 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=4&signature=CosxSgq_XuY_XDYCDGZzMp0XHgQ45HWTTUNsfIWqAaI 4x' + ) + }) + + it('returns srcset with fixed height and empty array of dprs', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { height: 200, dpr: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1&signature=OPRYWD06ACeu6W8YXkZ87-swVGCl9hCk7bPLh_wn6Cw 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2&signature=4981fsA13f03qY95Xt9grU2ZyjVReTukEEGmEMaOyeU 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3&signature=NYcE4xjRvJ3m8FCTwVbC30VNjuKuCJzY-pBwqMXvdLc 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=4&signature=CosxSgq_XuY_XDYCDGZzMp0XHgQ45HWTTUNsfIWqAaI 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=5&signature=jNdvuKhq8n1ptnvALUZ7pttVj--8wctjeDEHKlPPxtY 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=6&signature=5b-Ojy9lICTxN3EoHsBWgOHhd_glloTtR7YHd6u43OM 6x' + ) + }) + + it('returns srcset with fixed height and array of dprs of size 1', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { height: 200, dpr: [1] }) + + expect(srcset).toBe('https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1&signature=OPRYWD06ACeu6W8YXkZ87-swVGCl9hCk7bPLh_wn6Cw 1x') + }) + + it('returns srcset with fixed height and array of dprs', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { height: 200, dpr: [1, 2, 3] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1&signature=OPRYWD06ACeu6W8YXkZ87-swVGCl9hCk7bPLh_wn6Cw 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2&signature=4981fsA13f03qY95Xt9grU2ZyjVReTukEEGmEMaOyeU 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3&signature=NYcE4xjRvJ3m8FCTwVbC30VNjuKuCJzY-pBwqMXvdLc 3x' + ) + }) + + it('returns srcset with fixed height and fixed quality', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { height: 200, quality: 75 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=1&signature=gipsMEavWgTV3KTwyahYXj4f4KtIBXnfGl-Sf4K1AoU 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=2&signature=ILRBpAF4yyc3_lWihJwlvkid-6VZfHxNgZWhvh6Lhvs 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=3&signature=UXsqudgHsgSqDGAqC448V4vTRB_XL__FChpT19qhXNU 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=4&signature=Szk6Qc7wRuvv7hAQX3GrF-PGA7w7IFOFXnWG3lZRcd0 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=5&signature=W4QivDeu6jJOXWmIWihX24w3VPokgqUqQUSpCWMudVI 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=6&signature=NikOouFxX1NDIyqejGzzG8EpHKTeakKR3McjdQTNUxo 6x' + ) + }) + + it('returns srcset with fixed height and null quality', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { height: 200, quality: null }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=1&signature=QCoyLuiBDl0ytX1cTW167ByM5jWzJg3ZibYPtN2g44I 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=2&signature=KcIeRbexUWeBMCYVRfq8SC-lwl9JMSWFeQ7hgysQUqI 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=3&signature=YXH8ZTUFX4YXOMStgoae85f82QivRXy_HB25C3NabjY 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=4&signature=twl_a0CLY3-f3mPMAxeLDuIF9KGwTLoGQOE54FcJVC8 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=5&signature=xgo3Obp4ju4-icy-U7wf6BKdhXHUlJyfXUPtHgODPhs 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=6&signature=J4DCGr3c180ftlc1YQi4f5tHPC4j9hit5HIteJefXZM 6x' + ) + }) + + it('returns srcset with fixed height and undefined quality', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { height: 200, quality: undefined }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=1&signature=QCoyLuiBDl0ytX1cTW167ByM5jWzJg3ZibYPtN2g44I 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=2&signature=KcIeRbexUWeBMCYVRfq8SC-lwl9JMSWFeQ7hgysQUqI 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=3&signature=YXH8ZTUFX4YXOMStgoae85f82QivRXy_HB25C3NabjY 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=4&signature=twl_a0CLY3-f3mPMAxeLDuIF9KGwTLoGQOE54FcJVC8 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=5&signature=xgo3Obp4ju4-icy-U7wf6BKdhXHUlJyfXUPtHgODPhs 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=6&signature=J4DCGr3c180ftlc1YQi4f5tHPC4j9hit5HIteJefXZM 6x' + ) + }) + + it('returns srcset with fixed height and range of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { height: 200, quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=1&signature=gipsMEavWgTV3KTwyahYXj4f4KtIBXnfGl-Sf4K1AoU 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=66&dpr=2&signature=aMY4Y3IoWsnGAp9nraijGlfvngHN8xvfbGavO8KHhW0 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=58&dpr=3&signature=OlTH_pLosHDjkTQ3FqPY4ZwzXY0pF8IIeoGdd_4CXjM 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=51&dpr=4&signature=FOBkytNoJVhy2x4DxHlw94bUY9pyxC6D1okODEVbznc 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=45&dpr=5&signature=ZwpZsCH8Bbt9BpkV0KKOiBeETd3_gfFy4RVlz-3lIv4 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=40&dpr=6&signature=IjuHRWBbL3VBz5mahP-RxbFeTI_IzHoNnefOzUHZIdc 6x' + ) + }) + + it('returns srcset with fixed height and empty array of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { height: 200, quality: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=1&signature=QCoyLuiBDl0ytX1cTW167ByM5jWzJg3ZibYPtN2g44I 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=2&signature=KcIeRbexUWeBMCYVRfq8SC-lwl9JMSWFeQ7hgysQUqI 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=3&signature=YXH8ZTUFX4YXOMStgoae85f82QivRXy_HB25C3NabjY 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=4&signature=twl_a0CLY3-f3mPMAxeLDuIF9KGwTLoGQOE54FcJVC8 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=5&signature=xgo3Obp4ju4-icy-U7wf6BKdhXHUlJyfXUPtHgODPhs 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=6&signature=J4DCGr3c180ftlc1YQi4f5tHPC4j9hit5HIteJefXZM 6x' + ) + }) + + it('returns srcset with fixed height and array of qualities of size 1', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { height: 200, quality: [75] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=1&signature=gipsMEavWgTV3KTwyahYXj4f4KtIBXnfGl-Sf4K1AoU 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=2&signature=KcIeRbexUWeBMCYVRfq8SC-lwl9JMSWFeQ7hgysQUqI 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=3&signature=YXH8ZTUFX4YXOMStgoae85f82QivRXy_HB25C3NabjY 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=4&signature=twl_a0CLY3-f3mPMAxeLDuIF9KGwTLoGQOE54FcJVC8 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=5&signature=xgo3Obp4ju4-icy-U7wf6BKdhXHUlJyfXUPtHgODPhs 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=6&signature=J4DCGr3c180ftlc1YQi4f5tHPC4j9hit5HIteJefXZM 6x' + ) + }) + + it('returns srcset with fixed height and array of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { height: 200, quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=75&dpr=1&signature=gipsMEavWgTV3KTwyahYXj4f4KtIBXnfGl-Sf4K1AoU 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=70&dpr=2&signature=FacmhyVpHbzVJtjokktiI2hdXHgSYHgMdsiwIlSeIp0 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=65&dpr=3&signature=s64KtZO2Lkb11qMiynGMJo7Q145JbKIxN1GFr87WExg 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=4&signature=twl_a0CLY3-f3mPMAxeLDuIF9KGwTLoGQOE54FcJVC8 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=5&signature=xgo3Obp4ju4-icy-U7wf6BKdhXHUlJyfXUPtHgODPhs 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&quality=&dpr=6&signature=J4DCGr3c180ftlc1YQi4f5tHPC4j9hit5HIteJefXZM 6x' + ) + }) + + it('returns srcset with fixed height, range of dprs and range of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { height: 200, dpr: range(1, 4), quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1&quality=75&signature=25rT2PoNIjb3dNUktp6uKyiL5TaPtKzAvBikvflXeuU 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2&quality=61&signature=yIawysfrGLbT4SBOK-WUd_PGPhQMiUT32tKoLKtWTs0 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3&quality=49&signature=LBnzxpLpiuN0-Q19nRIiwY5kh6sn-KOnMQKGfROhpJo 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=4&quality=40&signature=Vh9_hy6G8r7QULCF7wGWjWc062SwqaQKQuvE0UYZQBk 4x' + ) + }) + + it('returns srcset with fixed height, array of dprs and array of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { height: 200, dpr: [1, 2, 3], quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=1&quality=75&signature=25rT2PoNIjb3dNUktp6uKyiL5TaPtKzAvBikvflXeuU 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=2&quality=70&signature=UloDZHD2ckqJSMcnXYHPHBIazvlBO13xXO81tUlOfFE 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?height=200&dpr=3&quality=65&signature=MJT1FBPv626BJwh2rdVRwliLRN1vPLrxibPcIkOaLg4 3x' + ) + }) + + it('returns srcset with fixed width and fixed height', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, height: 300 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1&signature=IJM9kyvoH30hC2Xr0-FG9CZxYvDSy9MsZJBbs6Wm2kg 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=2&signature=mSGPEv1SiYAFUO72DNUfMDdL4izJLHlwu1aiRGsonY4 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=3&signature=_M2FTPPtfAUaqOaRZXIOK-nHjJ3RbejVRz7jt5Bggw8 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=4&signature=jiT6foPkzDPgIfhnhh668OwFFKOb1etLBGKqdgQPzpk 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=5&signature=pDmFhsCoX1YIB2QUKSTZuy0qpfiL67yLNKaZW0L7HSs 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=6&signature=kvgSWBz889aNkuaNJV1BjMTj8fdAcy_kjJo0q-r9QgY 6x' + ) + }) + + it('returns srcset with fixed width, fixed height and fixed dpr', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, height: 300, dpr: 2 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1&signature=IJM9kyvoH30hC2Xr0-FG9CZxYvDSy9MsZJBbs6Wm2kg 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=2&signature=mSGPEv1SiYAFUO72DNUfMDdL4izJLHlwu1aiRGsonY4 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=3&signature=_M2FTPPtfAUaqOaRZXIOK-nHjJ3RbejVRz7jt5Bggw8 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=4&signature=jiT6foPkzDPgIfhnhh668OwFFKOb1etLBGKqdgQPzpk 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=5&signature=pDmFhsCoX1YIB2QUKSTZuy0qpfiL67yLNKaZW0L7HSs 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=6&signature=kvgSWBz889aNkuaNJV1BjMTj8fdAcy_kjJo0q-r9QgY 6x' + ) + }) + + it('returns srcset with fixed width, fixed height and range of dprs', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, height: 300, dpr: range(1, 4) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1&signature=IJM9kyvoH30hC2Xr0-FG9CZxYvDSy9MsZJBbs6Wm2kg 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=2&signature=mSGPEv1SiYAFUO72DNUfMDdL4izJLHlwu1aiRGsonY4 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=3&signature=_M2FTPPtfAUaqOaRZXIOK-nHjJ3RbejVRz7jt5Bggw8 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=4&signature=jiT6foPkzDPgIfhnhh668OwFFKOb1etLBGKqdgQPzpk 4x' + ) + }) + + it('returns srcset with fixed width, fixed height and empty array of dprs', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, height: 300, dpr: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1&signature=IJM9kyvoH30hC2Xr0-FG9CZxYvDSy9MsZJBbs6Wm2kg 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=2&signature=mSGPEv1SiYAFUO72DNUfMDdL4izJLHlwu1aiRGsonY4 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=3&signature=_M2FTPPtfAUaqOaRZXIOK-nHjJ3RbejVRz7jt5Bggw8 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=4&signature=jiT6foPkzDPgIfhnhh668OwFFKOb1etLBGKqdgQPzpk 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=5&signature=pDmFhsCoX1YIB2QUKSTZuy0qpfiL67yLNKaZW0L7HSs 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=6&signature=kvgSWBz889aNkuaNJV1BjMTj8fdAcy_kjJo0q-r9QgY 6x' + ) + }) + + it('returns srcset with fixed width, fixed height and array of dprs of size 1', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, height: 300, dpr: [1] }) + + expect(srcset).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1&signature=IJM9kyvoH30hC2Xr0-FG9CZxYvDSy9MsZJBbs6Wm2kg 1x') + }) + + it('returns srcset with fixed width, fixed height and array of dprs', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, height: 300, dpr: [1, 2, 3] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1&signature=IJM9kyvoH30hC2Xr0-FG9CZxYvDSy9MsZJBbs6Wm2kg 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=2&signature=mSGPEv1SiYAFUO72DNUfMDdL4izJLHlwu1aiRGsonY4 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=3&signature=_M2FTPPtfAUaqOaRZXIOK-nHjJ3RbejVRz7jt5Bggw8 3x' + ) + }) + + it('returns srcset with fixed width, fixed height and fixed quality', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, height: 300, quality: 75 }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=1&signature=PnadVjkFBE6kQMGUBuV-IVtHSoL8bmVEDXjvByjA4xg 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=2&signature=5J3U-Gf37ruvbgNOSK8xKHggHOjGEB4EvlcXr2KUeP0 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=3&signature=7Prpr-BMsQeW_a7DoFhqXxi_1pKIu3xQaN_RzeBLbqM 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=4&signature=ptth3HdLo4xxV76BumAgl7n9kJIML7PNupQ_Ko35GQU 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=5&signature=YatBW63wHTllgGrZK8MqhQ_Jl66kBCoAWAULeew39vk 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=6&signature=wIezHaEl9OYPh5PdOVMH3it_nE2n9lg7Nhe6BPhsrnY 6x' + ) + }) + + it('returns srcset with fixed width, fixed height and range of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, height: 300, quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=1&signature=PnadVjkFBE6kQMGUBuV-IVtHSoL8bmVEDXjvByjA4xg 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=66&dpr=2&signature=IWp9uUgUbhWZghziCC5N7Lct6Vp6ccRGVPvrRdm2WGE 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=58&dpr=3&signature=3WlYuqk7aJL7sWuMarFU1dYB9jiFVZRrMFsuzzJNPJ8 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=51&dpr=4&signature=lsQdhnA-9Zv6M0Wvy7zeu3QdC763e2In3Xq14RbQgwI 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=45&dpr=5&signature=ctuQrnocmmcQ597Tb4gxaNciH-pi5ZBfYzvNOSy6kNQ 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=40&dpr=6&signature=Zg0a1OhZeHCzhhzzzm_1MXqkOqMnREf_4DukDTZD8os 6x' + ) + }) + + it('returns srcset with fixed width, fixed height and empty array of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, height: 300, quality: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=1&signature=I33EBra07-ZnKfQnF3q_qWcrZgrVjmyLaKGtYnUPt1A 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=2&signature=TutthSvWJtm9jcWHiMVgmnpJSYd9-9qrRmrJSpXp61w 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=3&signature=qS0bMn8ZmZ_c_uzAqz24U_e4e76z_VSDGZUS2RwxY-s 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=4&signature=3tXfxmhvuVtfu5EVaama5ECwXCX3U9xG0DFJaCi6FbQ 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=5&signature=RWLeQdABIup6zLvmubBZ_MHnnw70SVLwAUhDDQkMFZ0 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=6&signature=5glXeaOZCVkKfFPYt6yjOFuKmKKPSmC9CRxkR8rYjFc 6x' + ) + }) + + it('returns srcset with fixed width, fixed height and array of qualities of size 1', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, height: 300, quality: [75] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=1&signature=PnadVjkFBE6kQMGUBuV-IVtHSoL8bmVEDXjvByjA4xg 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=2&signature=TutthSvWJtm9jcWHiMVgmnpJSYd9-9qrRmrJSpXp61w 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=3&signature=qS0bMn8ZmZ_c_uzAqz24U_e4e76z_VSDGZUS2RwxY-s 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=4&signature=3tXfxmhvuVtfu5EVaama5ECwXCX3U9xG0DFJaCi6FbQ 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=5&signature=RWLeQdABIup6zLvmubBZ_MHnnw70SVLwAUhDDQkMFZ0 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=6&signature=5glXeaOZCVkKfFPYt6yjOFuKmKKPSmC9CRxkR8rYjFc 6x' + ) + }) + + it('returns srcset with fixed width, fixed height and array of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, height: 300, quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&dpr=1&signature=PnadVjkFBE6kQMGUBuV-IVtHSoL8bmVEDXjvByjA4xg 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=70&dpr=2&signature=C-thQx7QmatepDvZuYtIPUmwGeMsDh347APm_qJpFFE 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=65&dpr=3&signature=z2J1hziiBKJ4NFyXNtQDpKqkFtoaTcUMxOGJcPSQ5Is 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=4&signature=3tXfxmhvuVtfu5EVaama5ECwXCX3U9xG0DFJaCi6FbQ 4x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=5&signature=RWLeQdABIup6zLvmubBZ_MHnnw70SVLwAUhDDQkMFZ0 5x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=&dpr=6&signature=5glXeaOZCVkKfFPYt6yjOFuKmKKPSmC9CRxkR8rYjFc 6x' + ) + }) + + it('returns srcset with fixed width, fixed height, range of dprs and range of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, height: 300, dpr: range(1, 4), quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1&quality=75&signature=t6k4Dapq2m5a-DpuUsQw47tl02aBX9XCNQJ8NChYpLE 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=2&quality=61&signature=kHXoQWMZigQ3ck3lq5PE2oPB_-CgJvu0Siw0qZUCPqQ 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=3&quality=49&signature=uMu3kinh0aZWyJympL5MkyNblm3z5cqc4o3p5nvu5kk 3x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=4&quality=40&signature=EwcIR2na2b6Io4jqL-yoA4UIVmIiv6YlxiDREMfHNQI 4x' + ) + }) + + it('returns srcset with fixed width, fixed height, array of dprs and array of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 200, height: 300, dpr: [1, 2, 3], quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=1&quality=75&signature=t6k4Dapq2m5a-DpuUsQw47tl02aBX9XCNQJ8NChYpLE 1x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=2&quality=70&signature=3cwCowdly2-A-bzVeygxuyspjL3FTvPYLleWxeyAeVI 2x,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&dpr=3&quality=65&signature=S2mYF1jlamW-ESRjeeasYvcPRNAvjetbatj0WPv2I0k 3x' + ) + }) + + it('returns srcset with range of widths', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: range(100, 4096) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100&signature=-G7slD-ae7GdT1lx8I0-7iUMnkMTU3NcTGB8GzaiaNg 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=128&signature=2cC_ykc-pqoIK_NQOTjarDcJIgZD5mPu_AnK2cvCW3c 128w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=164&signature=25acIxwSYj7b6Xt-hAq0QTsGLt9fYfZWvGdwFbktRlI 164w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=210&signature=FhItrI5gSCF4MhngaaXcbmKYJXnC1S_NQG8UNaI5Sp0 210w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=269&signature=N151yMSgG6nke2hcBKRekHLXzaEWMdH80vgqXGhDhYQ 269w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=345&signature=g-xGt_iGA-wC3P8iui5l0kv_OF6CF5U0PcUb9F1gQ4w 345w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=442&signature=CXrismkxq7CuoNFF_BFURwtZyWyFGO-mf8lDyLbj4SM 442w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=566&signature=_AHoRlDZVA-iuK85k4SkSycBWLi19ixUqZU4O_kvExk 566w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=724&signature=YX7T2AvjD8bdrqCumvILMX_QRoD2Z4fEKQm5alPuHqo 724w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=928&signature=A2ihMdOHDl2hGG6MdocDKTMg6WNIjleM6BtbNCcr44A 928w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1188&signature=XmUJuVHFLItcXFN8X6I7p4fvBQH_JCarPBz32vjrcu0 1188w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1522&signature=npRnE8jsSy1oAvxAA8TVsvqk1jG00tO_NJWFYyS-YXs 1522w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1949&signature=4hi_0-BD3AwuUUONQAmieWJEsTAOFxrX1TLXKeHCLqE 1949w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=2497&signature=7SxlJMpbxkA54ceWURFwnyIv8dynrW7Hx3OkauT8zcM 2497w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=3198&signature=Z-TSGIBt9U0OCLKKKbw2dMKefPj6LQeToy-9Sz6xzT8 3198w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4096&signature=TWdvbo0ucyOxAMxH8OI_T3WK7Ufbwwl40pWtPq7Ff78 4096w' + ) + }) + + it('returns srcset with range of widths and range of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: range(100, 4096), quality: range(70, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100&quality=70&signature=jWu-9brjqLkPD_CK4SX9_yckyaQ8d8vf7oWzszbuW-0 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=128&quality=67&signature=yfCWjWUJKlzBxOqF5dJI0Ej0jzhIQZ9ttus_n4OTkoM 128w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=164&quality=65&signature=LqSqBqxAKS1QJ2W73nj7Oub9P0DMTA9KiGxY76o_ROk 164w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=210&quality=63&signature=AR2sBFCQej47qzamZvmh2o7L_UFsiD0NT9iooOlqb2M 210w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=269&quality=60&signature=a7er0FLZIMVT-ZrGwCYnXAxoanHhH97kurkXaQDTjBU 269w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=345&quality=58&signature=tyC1UtP1dzYtBbfWXqVA8xFSXG3dbv4EJad_YAOcZiQ 345w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=442&quality=56&signature=usF3QE7FGA6v8Gg-Qu3ExHOWdg3NxsFgdjiYSHPH8KI 442w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=566&quality=54&signature=5dQ7teZBhv0ytZZaURZbfAoY7y6mtXZA-zy_jUxOJdw 566w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=724&quality=52&signature=bdWpkErDsqG9yFFHzVtVJMpRkgS3UZFIxRWsHY1zo1g 724w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=928&quality=50&signature=glEum5UD25WemwFC-zHHkfggPWme6cWTigF7zkdf930 928w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1188&quality=48&signature=ttlEa2gosU-ZgI3zvofvZaY5dHudpZ9j7POJB_Xy5TQ 1188w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1522&quality=46&signature=azycXOjL-l_KmHrVKUAbfwVFTns0xGFUGWxm2MrDHZ8 1522w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1949&quality=45&signature=lkh8M7JSklT26KTAaybQcZ3rz2Woc9OF4JjlI6eZk7M 1949w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=2497&quality=43&signature=-lU_Y-yW-PCTKOa63d_zEw9oUunOHpHi_1EVvU7QEhI 2497w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=3198&quality=42&signature=lYwxJOqDpjIrxFjZTTgJTcygSU5im7hvXKAZSAt2PPg 3198w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4096&quality=40&signature=2LpbFIpgUEeYFhyHaybrKWjub49WHuighWvesmRj4dk 4096w' + ) + }) + + it('returns srcset with sequence of widths', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: sequence(100, 4096, 6) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100&signature=-G7slD-ae7GdT1lx8I0-7iUMnkMTU3NcTGB8GzaiaNg 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=210&signature=FhItrI5gSCF4MhngaaXcbmKYJXnC1S_NQG8UNaI5Sp0 210w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=442&signature=CXrismkxq7CuoNFF_BFURwtZyWyFGO-mf8lDyLbj4SM 442w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=928&signature=A2ihMdOHDl2hGG6MdocDKTMg6WNIjleM6BtbNCcr44A 928w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1949&signature=4hi_0-BD3AwuUUONQAmieWJEsTAOFxrX1TLXKeHCLqE 1949w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4096&signature=TWdvbo0ucyOxAMxH8OI_T3WK7Ufbwwl40pWtPq7Ff78 4096w' + ) + }) + + it('returns srcset with sequence of widths and range of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: sequence(100, 4096, 6), quality: range(70, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100&quality=70&signature=jWu-9brjqLkPD_CK4SX9_yckyaQ8d8vf7oWzszbuW-0 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=210&quality=63&signature=AR2sBFCQej47qzamZvmh2o7L_UFsiD0NT9iooOlqb2M 210w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=442&quality=56&signature=usF3QE7FGA6v8Gg-Qu3ExHOWdg3NxsFgdjiYSHPH8KI 442w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=928&quality=50&signature=glEum5UD25WemwFC-zHHkfggPWme6cWTigF7zkdf930 928w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1949&quality=45&signature=lkh8M7JSklT26KTAaybQcZ3rz2Woc9OF4JjlI6eZk7M 1949w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4096&quality=40&signature=2LpbFIpgUEeYFhyHaybrKWjub49WHuighWvesmRj4dk 4096w' + ) + }) + + it('returns srcset with empty array of widths', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=100&signature=-G7slD-ae7GdT1lx8I0-7iUMnkMTU3NcTGB8GzaiaNg 100w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=134&signature=fHLmra9mxfjnp8E-7Cj7AZlJ43kRKLILUQ3Gawa0pxA 134w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=180&signature=omMuwPcMxKVGGnDk9sR2G6qD28uLIAldc-N9FvhwSH0 180w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=241&signature=09nboU72WGyryf9zyxMsNyBNu4PUrrGkuDlbM6shYas 241w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=324&signature=KOLqtvfSwSLUKnWY5-tvuaj-pOsBcN_WIHRTNLpJ7-Y 324w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=434&signature=48LOvc3n4CqstYfikmhT57XvKnydLRUa6qT-_IqZ0io 434w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=583&signature=IfEEELQp0__u7Ip-qzKQ2Plw70ybDOdrVeOz5jw9BOY 583w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=781&signature=p6sa4yVVce8AkuJagwLolgRD1nQUyzZsMw68KSQaVwM 781w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1048&signature=qz5KgcQRJHnCcubs9ldfGUGm1vzsvjBge17OWhykwp0 1048w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1406&signature=Kh16qduc4dixmTKuhASbspncSVHlDTd4DnsbcmfB6Mw 1406w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=1886&signature=WN-YBqlX-bhiWxFydOVBsfkVIWjIuz09qvHkA2UZWvs 1886w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=2530&signature=wH5aHb7P0S6xuJvBDoPgZPIo2-nosgViwt2ADVGhAvw 2530w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=3394&signature=e_fi5Y-uruuUWips4wxJt5WkHKETn9P1MmHXVD9Cvxs 3394w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=4553&signature=AuXvD4c7FN279MOC63ogznGAqYmHqLCVDgQvl0I1IKM 4553w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=6107&signature=nWDdC0v7d695Oo_bdhgc_AkxCkIyF7FSZgj7bAcOkNo 6107w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=8192&signature=HNmtIa6jhuc8o3Yir2zZBjDvgiiAwGeMzM-x7ow1dSE 8192w' + ) + }) + + it('returns srcset with array of widths of size 1', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: [200] }) + + expect(srcset).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&signature=oV-jpcwoz0-UdXsZCVCecPwJ3tb88vfb1lwM2nKfq60 200w') + }) + + it('returns srcset with array of widths', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: [200, 300, 400] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&signature=oV-jpcwoz0-UdXsZCVCecPwJ3tb88vfb1lwM2nKfq60 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&signature=BEQUozs795ZFLKcwTBrTrY3Ga0l8WeZE0cjVo_JjgwU 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&signature=eboiZiD6J2-wWKqi3aZLUiu2YQZTDeY1vxcfqmtsQhw 400w' + ) + }) + + it('returns srcset with array of widths and range of heights', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: [200, 300, 400], height: range(300, 500) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&signature=5LR9YGho_DVBmGZ_aR5NpG-051zJG23u-LNJe3-nEwU 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&height=387&signature=19698XtncA9IDVyo5d60-c3HPPRDOM3nxSYbGh8sCKY 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&height=500&signature=nB5xubhzQyvrGIU1e2JtoaS5KJC76qiHwTYwTtNHzE0 400w' + ) + }) + + it('returns srcset with array of widths and empty array of heights', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: [200, 300, 400], height: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=&signature=voipBs7wOgfiKHFeBqPi4zkBCwi_o4fNyy2eHur9Yr0 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&height=&signature=qtZUoqn9irWsq-35NKO1VAxqk4YaC961LroJOa8VgrA 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&height=&signature=LMYoRf_j_cYye718DX_kur72ZLpwlhzS1PB0ki7Bb18 400w' + ) + }) + + it('returns srcset with array of widths and array of heights of size 1', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: [200, 300, 400], height: [300] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&signature=5LR9YGho_DVBmGZ_aR5NpG-051zJG23u-LNJe3-nEwU 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&height=&signature=qtZUoqn9irWsq-35NKO1VAxqk4YaC961LroJOa8VgrA 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&height=&signature=LMYoRf_j_cYye718DX_kur72ZLpwlhzS1PB0ki7Bb18 400w' + ) + }) + + it('returns srcset with array of widths and array of heights', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: [200, 300, 400], height: [300, 400, 500] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&signature=5LR9YGho_DVBmGZ_aR5NpG-051zJG23u-LNJe3-nEwU 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&height=400&signature=6fgNZ57ztEH-0R6V_V8HpQnJDLs9FmmWujzZ-qz0Nl0 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&height=500&signature=nB5xubhzQyvrGIU1e2JtoaS5KJC76qiHwTYwTtNHzE0 400w' + ) + }) + + it('returns srcset with array of widths and range of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: [200, 300, 400], quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&signature=VxBn4eboQoUAC6C9kAoxTU88_pl8JsXIb9vna7IPEoU 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&quality=55&signature=HTal7YeJU25OqZhnEXpJmutEJL64XjZ50QIXBlcoS9w 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&quality=40&signature=YFxQwbC4YCEJ3tPLh5W1VsMjPa0NYNl9E-V-J2OmR2I 400w' + ) + }) + + it('returns srcset with array of widths and empty array of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: [200, 300, 400], quality: [] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=&signature=JsmWwDAytj5PL79rbgPMxsyZKpiShrlabxnZ6PYytW4 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&quality=&signature=o3FvvPVmG52OlZucA6qrG3ponTY3AksB8oaQU83XxLk 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&quality=&signature=v3Idf3iopkK41AjHZb1oBXcjmf0wgjcdrr3Bpw1bkJ0 400w' + ) + }) + + it('returns srcset with array of widths and array of qualities of size 1', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: [200, 300, 400], quality: [75] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&signature=VxBn4eboQoUAC6C9kAoxTU88_pl8JsXIb9vna7IPEoU 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&quality=&signature=o3FvvPVmG52OlZucA6qrG3ponTY3AksB8oaQU83XxLk 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&quality=&signature=v3Idf3iopkK41AjHZb1oBXcjmf0wgjcdrr3Bpw1bkJ0 400w' + ) + }) + + it('returns srcset with array of widths and array of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: [200, 300, 400], quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&quality=75&signature=VxBn4eboQoUAC6C9kAoxTU88_pl8JsXIb9vna7IPEoU 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&quality=70&signature=_Ec1jIoy0coaBnbqa3h5Uhsm3wWhJEJUszV_7swM-gA 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&quality=65&signature=n6ib7RsWbTSQvN5F5Rzy1wB9wexKx31IS-Omdg__RqY 400w' + ) + }) + + it('returns srcset with array of widths, range of heights and range of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: [200, 300, 400], height: range(300, 500), quality: range(75, 40) }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&signature=avflohh59fJI6eHUXL232Xb-wNXiraj5uxYPTFMCnNs 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&height=387&quality=55&signature=pvros3H2YqyZC8ae52VisbXo3OhsN4HVt90ElngutHs 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&height=500&quality=40&signature=_6g3LZxEZIcathWXeSaoIWISgz7kkUPmnP98RLp0qEM 400w' + ) + }) + + it('returns srcset with array of widths, array of heights and array of qualities', () => { + const srcset = Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: [200, 300, 400], height: [300, 400, 500], quality: [75, 70, 65] }) + + expect(srcset).toBe( + 'https://assets.imglab-cdn.net/example.jpeg?width=200&height=300&quality=75&signature=avflohh59fJI6eHUXL232Xb-wNXiraj5uxYPTFMCnNs 200w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=300&height=400&quality=70&signature=LOLbD83Cxw8nsn4jkHu33AOJEbhB3y3EWlDTUbf3g6A 300w,\n' + + 'https://assets.imglab-cdn.net/example.jpeg?width=400&height=500&quality=65&signature=KBMGUlSlyzUy4blPYnPh54Uu75v1lPyi4lSS_2hrkRE 400w' + ) + }) + + it('throws a new error when width is fluid and dpr is also fluid', () => { + expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: range(100, 300), dpr: range(1, 3) }) }).toThrow(Error) + expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: range(100, 300), dpr: [1, 2, 3] }) }).toThrow(Error) + expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: [100, 200, 300], dpr: range(1, 3) }) }).toThrow(Error) + expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: [100, 200, 300], dpr: [1, 2, 3] }) }).toThrow(Error) + expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: sequence(100, 300), dpr: range(1, 3) }) }).toThrow(Error) + expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: sequence(100, 300), dpr: [1, 2, 3] }) }).toThrow(Error) + }) + + it('throws a new error when width is not fluid and height is fluid', () => { + expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { height: range(100, 300) }) }).toThrow(Error) + expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { height: [100, 200, 300] }) }).toThrow(Error) + expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 100, height: range(100, 300) }) }).toThrow(Error) + expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: 100, height: [100, 200, 300] }) }).toThrow(Error) + }) + + it('throws a new error when width and height are not specified and dpr is fluid', () => { + expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { dpr: range(1, 3) }) }).toThrow(Error) + expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { dpr: [1, 2, 3] }) }).toThrow(Error) + }) + }) +}) diff --git a/test/srcset/utils.test.js b/test/srcset/utils.test.js new file mode 100644 index 0000000..4473f76 --- /dev/null +++ b/test/srcset/utils.test.js @@ -0,0 +1,135 @@ +import Utils from '../../src/srcset/utils' +import Range from '../../src/range' + +const range = Range.range + +describe ('Utils', () => { + describe('normalizeParams', () => { + it('returns normalized params', () => { + expect(Utils.normalizeParams({})).toEqual({}) + expect(Utils.normalizeParams({ dpr: [] })).toEqual({}) + expect(Utils.normalizeParams({ dpr: [], width: [] })).toEqual({}) + + expect(Utils.normalizeParams({ blur: 100, dpr: [], width: [], format: 'png' })).toEqual( + { blur: 100, format: 'png'} + ) + + expect(Utils.normalizeParams({ blur: 100, dpr: 1, width: 100, format: 'png'})).toEqual( + { blur: 100, dpr: 1, width: 100, format: 'png' } + ) + + expect(Utils.normalizeParams({ blur: 100, dpr: [1, 2, 3], width: [100, 200, 300], format: 'png' })).toEqual( + { blur: 100, dpr: [1, 2, 3], width: [100, 200, 300], format: 'png' } + ) + + expect(Utils.normalizeParams({ blur: 100, dpr: range(1, 3), width: range(100, 300), format: 'png' })).toEqual( + { blur: 100, dpr: range(1, 3), width: range(100, 300), format: 'png' } + ) + }) + }) + + describe('splitParamsDpr', () => { + it('returns split params by dpr', () => { + expect(Utils.splitParamsDpr({ width: 100, dpr: [1, 2], format: 'png' })).toEqual([ + { width: 100, dpr: 1, format: 'png' }, + { width: 100, dpr: 2, format: 'png' } + ]) + + expect(Utils.splitParamsDpr({ width: 100, dpr: [1, 2], quality: [75], format: 'png' })).toEqual([ + { width: 100, dpr: 1, quality: 75, format: 'png' }, + { width: 100, dpr: 2, quality: undefined, format: 'png' } + ]) + + expect(Utils.splitParamsDpr({ width: 100, dpr: [1, 2], quality: [75, 40], format: 'png' })).toEqual([ + { width: 100, dpr: 1, quality: 75, format: 'png' }, + { width: 100, dpr: 2, quality: 40, format: 'png' } + ]) + + expect(Utils.splitParamsDpr({ width: 100, dpr: range(1, 2), format: 'png' })).toEqual([ + { width: 100, dpr: 1, format: 'png' }, + { width: 100, dpr: 2, format: 'png' } + ]) + + expect(Utils.splitParamsDpr({ width: 100, dpr: range(1, 2), quality: [75], format: 'png' })).toEqual([ + { width: 100, dpr: 1, quality: 75, format: 'png' }, + { width: 100, dpr: 2, quality: undefined, format: 'png' } + ]) + + expect(Utils.splitParamsDpr({ width: 100, dpr: range(1, 2), quality: range(75, 40), format: 'png' })).toEqual([ + { width: 100, dpr: 1, quality: 75, format: 'png' }, + { width: 100, dpr: 2, quality: 40, format: 'png' } + ]) + }) + + describe('splitParamsWidth', () => { + it('returns split params by width', () => { + expect(Utils.splitParamsWidth({ width: [100, 200], format: 'png' })).toEqual([ + { width: 100, format: 'png' }, + { width: 200, format: 'png' } + ]) + + expect(Utils.splitParamsWidth({ width: [100, 200], height: [300], quality: [75], format: 'png' })).toEqual([ + { width: 100, height: 300, quality: 75, format: 'png' }, + { width: 200, height: undefined, quality: undefined, format: 'png' } + ]) + + expect(Utils.splitParamsWidth({ width: range(100, 200), format: 'png' })).toEqual([ + { width: 100, format: 'png' }, + { width: 105, format: 'png' }, + { width: 110, format: 'png' }, + { width: 115, format: 'png' }, + { width: 120, format: 'png' }, + { width: 126, format: 'png' }, + { width: 132, format: 'png' }, + { width: 138, format: 'png' }, + { width: 145, format: 'png' }, + { width: 152, format: 'png' }, + { width: 159, format: 'png' }, + { width: 166, format: 'png' }, + { width: 174, format: 'png' }, + { width: 182, format: 'png' }, + { width: 191, format: 'png' }, + { width: 200, format: 'png' } + ]) + + expect(Utils.splitParamsWidth({ width: range(100, 200), height: [300], quality: [75], format: 'png' })).toEqual([ + { width: 100, height: 300, quality: 75, format: 'png' }, + { width: 105, height: undefined, quality: undefined, format: 'png' }, + { width: 110, height: undefined, quality: undefined, format: 'png' }, + { width: 115, height: undefined, quality: undefined, format: 'png' }, + { width: 120, height: undefined, quality: undefined, format: 'png' }, + { width: 126, height: undefined, quality: undefined, format: 'png' }, + { width: 132, height: undefined, quality: undefined, format: 'png' }, + { width: 138, height: undefined, quality: undefined, format: 'png' }, + { width: 145, height: undefined, quality: undefined, format: 'png' }, + { width: 152, height: undefined, quality: undefined, format: 'png' }, + { width: 159, height: undefined, quality: undefined, format: 'png' }, + { width: 166, height: undefined, quality: undefined, format: 'png' }, + { width: 174, height: undefined, quality: undefined, format: 'png' }, + { width: 182, height: undefined, quality: undefined, format: 'png' }, + { width: 191, height: undefined, quality: undefined, format: 'png' }, + { width: 200, height: undefined, quality: undefined, format: 'png' } + ]) + + expect(Utils.splitParamsWidth({ width: range(100, 200), height: range(300, 500), quality: range(75, 40), format: 'png' })).toEqual([ + { width: 100, height: 300, quality: 75, format: 'png' }, + { width: 105, height: 310, quality: 72, format: 'png' }, + { width: 110, height: 321, quality: 69, format: 'png' }, + { width: 115, height: 332, quality: 66, format: 'png' }, + { width: 120, height: 344, quality: 63, format: 'png' }, + { width: 126, height: 356, quality: 61, format: 'png' }, + { width: 132, height: 368, quality: 58, format: 'png' }, + { width: 138, height: 381, quality: 56, format: 'png' }, + { width: 145, height: 394, quality: 54, format: 'png' }, + { width: 152, height: 408, quality: 51, format: 'png' }, + { width: 159, height: 422, quality: 49, format: 'png' }, + { width: 166, height: 436, quality: 47, format: 'png' }, + { width: 174, height: 451, quality: 45, format: 'png' }, + { width: 182, height: 467, quality: 43, format: 'png' }, + { width: 191, height: 483, quality: 42, format: 'png' }, + { width: 200, height: 500, quality: 40, format: 'png' } + ]) + }) + }) + }) +}) diff --git a/test/url.test.js b/test/url.test.js index 030ebd6..daa7fda 100644 --- a/test/url.test.js +++ b/test/url.test.js @@ -32,6 +32,12 @@ describe('Url', () => { expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&download=') }) + it('returns url with undefined params', () => { + const url = Url.url('assets', 'example.jpeg', { width: 200, download: undefined }) + + expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&download=') + }) + it('returns url with params using string path', () => { const url = Url.url('assets', 'example.jpeg', { width: 200, height: 300, watermark: 'example.svg', format: 'png' }) @@ -238,6 +244,12 @@ describe('Url', () => { expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&download=') }) + it('returns url with undefined params', () => { + const url = Url.url(SOURCE, 'example.jpeg', { width: 200, download: undefined }) + + expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&download=') + }) + it('returns url with params using string path', () => { const url = Url.url( SOURCE, @@ -484,6 +496,12 @@ describe('Url', () => { expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&download=&signature=ljL9HNRaxVrk7jfQaf6FPYFZn4RJzQPCW-aVNJoIQI8') }) + it('returns url with undefined params', () => { + const url = Url.url(SECURE_SOURCE, 'example.jpeg', { width: 200, download: undefined }) + + expect(url).toBe('https://assets.imglab-cdn.net/example.jpeg?width=200&download=&signature=ljL9HNRaxVrk7jfQaf6FPYFZn4RJzQPCW-aVNJoIQI8') + }) + it('returns url with params using string path', () => { const url = Url.url(SECURE_SOURCE, 'example.jpeg', { width: 200, height: 300, watermark: 'example.svg', format: 'png' }) diff --git a/test/utils.test.js b/test/url/utils.test.js similarity index 91% rename from test/utils.test.js rename to test/url/utils.test.js index 78737af..2a2aaea 100644 --- a/test/utils.test.js +++ b/test/url/utils.test.js @@ -1,4 +1,4 @@ -import Utils from '../src/utils' +import Utils from '../../src/url/utils' describe('Utils', () => { describe('normalizePath', () => { @@ -25,6 +25,8 @@ describe('Utils', () => { it('returns normalized params', () => { expect(Utils.normalizeParams({})).toEqual({}) expect(Utils.normalizeParams({ width: 200, height: 300})).toEqual({ width: 200, height: 300}) + expect(Utils.normalizeParams({ width: 200, height: 300, download: null })).toEqual({ width: 200, height: 300, download: '' }) + expect(Utils.normalizeParams({ width: 200, height: 300, download: undefined })).toEqual({ width: 200, height: 300, download: '' }) expect(Utils.normalizeParams({ trim: 'color', 'trim-color': 'orange' })).toEqual({ trim: 'color', 'trim-color': 'orange' }) expect(Utils.normalizeParams({ trim: 'color', trim_color: 'orange' })).toEqual({ trim: 'color', 'trim-color': 'orange' }) expect(Utils.normalizeParams({ trim: 'color', trimColor: 'orange' })).toEqual({ trim: 'color', 'trim-color': 'orange' }) From 4acbc9d7d634c142dca8ed541d411410844d9269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Francisco=20Calvo?= Date: Wed, 11 Jan 2023 18:13:28 +0100 Subject: [PATCH 08/15] Upgrade caniuse-lite --- package-lock.json | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 27506ec..2bf2f3f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2899,14 +2899,20 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001283", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001283.tgz", - "integrity": "sha512-9RoKo841j1GQFSJz/nCXOj0sD7tHBtlowjYlrqIUS812x9/emfBLBt6IyMz1zIaYc/eRL8Cs6HPUVi2Hzq4sIg==", - "dev": true, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/browserslist" - } + "version": "1.0.30001442", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001442.tgz", + "integrity": "sha512-239m03Pqy0hwxYPYR5JwOIxRJfLTWtle9FV8zosfV5pHg+/51uD4nxcUlM8+mWWGfwKtt8lJNHnD3cWw9VZ6ow==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/caniuse-lite" + } + ] }, "node_modules/chalk": { "version": "2.4.2", @@ -9181,9 +9187,9 @@ "dev": true }, "caniuse-lite": { - "version": "1.0.30001283", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001283.tgz", - "integrity": "sha512-9RoKo841j1GQFSJz/nCXOj0sD7tHBtlowjYlrqIUS812x9/emfBLBt6IyMz1zIaYc/eRL8Cs6HPUVi2Hzq4sIg==", + "version": "1.0.30001442", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001442.tgz", + "integrity": "sha512-239m03Pqy0hwxYPYR5JwOIxRJfLTWtle9FV8zosfV5pHg+/51uD4nxcUlM8+mWWGfwKtt8lJNHnD3cWw9VZ6ow==", "dev": true }, "chalk": { From c675a7310cc11e75a242847166f1f65bdb59b5a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Francisco=20Calvo?= Date: Thu, 12 Jan 2023 12:10:13 +0100 Subject: [PATCH 09/15] Linting code with ESLint --- src/color.js | 6 +++--- src/position.js | 8 ++++---- src/range.js | 12 ++++++------ src/sequence.js | 2 +- src/signature.js | 2 +- src/source.js | 22 +++++++++++----------- src/srcset.js | 16 ++++++++-------- src/srcset/utils.js | 30 +++++++++++++++--------------- src/url.js | 18 +++++++++--------- src/url/utils.js | 12 ++++++------ test/source.test.js | 4 ++-- test/srcset.test.js | 12 ++++++------ test/srcset/utils.test.js | 6 +++--- test/url.test.js | 4 ++-- test/url/utils.test.js | 4 ++-- 15 files changed, 79 insertions(+), 79 deletions(-) diff --git a/src/color.js b/src/color.js index feb6b06..d2d3656 100644 --- a/src/color.js +++ b/src/color.js @@ -150,7 +150,7 @@ export default class Color { 'yellowgreen' ] - static color() { + static color () { if (arguments.length === 1 && Color.#COLORS.includes(arguments[0])) { return arguments[0] } @@ -166,11 +166,11 @@ export default class Color { throw new Error('Invalid color') } - static #areValidComponents() { + static #areValidComponents () { return [...arguments].every((component) => { return Color.#isValidComponent(component) }) } - static #isValidComponent(component) { + static #isValidComponent (component) { return Number.isInteger(component) && component >= 0 && component <= 255 } } diff --git a/src/position.js b/src/position.js index 0433c57..d01572a 100644 --- a/src/position.js +++ b/src/position.js @@ -2,7 +2,7 @@ export default class Position { static #HORIZONTAL = ['left', 'center', 'right'] static #VERTICAL = ['top', 'middle', 'bottom'] - static position() { + static position () { if (arguments.length === 1 && Position.#isValidPosition(arguments[0])) { return arguments[0] } @@ -14,7 +14,7 @@ export default class Position { throw new Error('Invalid position') } - static #isValidPosition() { + static #isValidPosition () { if (arguments.length === 1 && Position.#isValidDirection(arguments[0])) { return true } @@ -26,11 +26,11 @@ export default class Position { return false } - static #isValidDirection(direction) { + static #isValidDirection (direction) { return Position.#HORIZONTAL.includes(direction) || Position.#VERTICAL.includes(direction) } - static #areValidDirections(directionA, directionB) { + static #areValidDirections (directionA, directionB) { return (Position.#HORIZONTAL.includes(directionA) && Position.#VERTICAL.includes(directionB)) || (Position.#HORIZONTAL.includes(directionB) && Position.#VERTICAL.includes(directionA)) } diff --git a/src/range.js b/src/range.js index be49c9c..8d6f618 100644 --- a/src/range.js +++ b/src/range.js @@ -3,29 +3,29 @@ export default class Range { #last #length - static range(first, last) { + static range (first, last) { return new Range(first, last) } - constructor(first, last) { + constructor (first, last) { this.#first = first this.#last = last this.#length = Math.abs(this.last - this.first) + 1 } - get first() { + get first () { return this.#first } - get last() { + get last () { return this.#last } - get length() { + get length () { return this.#length } - toArray() { + toArray () { const inc = this.first < this.last ? 1 : -1 return Array.from({ length: this.length }, (_, i) => this.first + (i * inc)) diff --git a/src/sequence.js b/src/sequence.js index 9ef0467..d363d87 100644 --- a/src/sequence.js +++ b/src/sequence.js @@ -1,7 +1,7 @@ export default class Sequence { static DEFAULT_SIZE = 16 - static sequence(first, last, size = Sequence.DEFAULT_SIZE) { + static sequence (first, last, size = Sequence.DEFAULT_SIZE) { if (size <= 0) return [] if (size === 1) return [first] if (size === 2) return [first, last] diff --git a/src/signature.js b/src/signature.js index 87430bc..e0d0dea 100644 --- a/src/signature.js +++ b/src/signature.js @@ -1,7 +1,7 @@ import crypto from 'crypto' export default class Signature { - static generate(source, path, encodedParams = null) { + static generate (source, path, encodedParams = null) { const decodedSecureKey = Buffer.from(source.secureKey, 'base64') const decodedSecureSalt = Buffer.from(source.secureSalt, 'base64') const hmac = crypto.createHmac('sha256', decodedSecureKey) diff --git a/src/source.js b/src/source.js index eba8e85..b7a9087 100644 --- a/src/source.js +++ b/src/source.js @@ -11,7 +11,7 @@ export default class Source { #secureSalt #subdomains - constructor(name, opts = {}) { + constructor (name, opts = {}) { opts = { ...Source.#DEFAULT_OPTS, ...opts } this.#host = opts.host @@ -23,43 +23,43 @@ export default class Source { this.#subdomains = opts.subdomains } - get host() { + get host () { return (this.#subdomains ? `${this.#name}.${this.#host}` : this.#host) } - get https() { + get https () { return this.#https } - get name() { + get name () { return this.#name } - get port() { + get port () { return this.#port } - get secureKey() { + get secureKey () { return this.#secureKey } - get secureSalt() { + get secureSalt () { return this.#secureSalt } - get subdomains() { + get subdomains () { return this.#subdomains } - scheme() { + scheme () { return (this.#https ? 'https' : 'http') } - path(path) { + path (path) { return (this.#subdomains ? path : _path.join(this.#name, path)) } - isSecure() { + isSecure () { return !!(this.#secureKey && this.#secureSalt) } } diff --git a/src/srcset.js b/src/srcset.js index 5dc162b..0f46eb8 100644 --- a/src/srcset.js +++ b/src/srcset.js @@ -7,10 +7,10 @@ export default class Srcset { static #DEFAULT_DPRS = [1, 2, 3, 4, 5, 6] static #DEFAULT_WIDTHS = Sequence.sequence(100, 8192) - static srcset(source, path, params = {}) { + static srcset (source, path, params = {}) { params = Utils.normalizeParams(params) - switch(true) { + switch (true) { case Srcset.#isFluid(params.width): if (Srcset.#isFluid(params.dpr)) { throw new Error('dpr as Array or Range is not allowed when width is also an Array or Range') @@ -22,17 +22,17 @@ export default class Srcset { throw new Error('height as Array or Range is only allowed when width is also an Array or Range') } - return Srcset.#srcset_dpr(source, path, {...params, ...{dpr: Srcset.#dprs(params)}}) + return Srcset.#srcset_dpr(source, path, { ...params, ...{ dpr: Srcset.#dprs(params) } }) default: if (Srcset.#isFluid(params.dpr)) { throw new Error('dpr as Array or Range is not allowed without specifying width or height') } - return Srcset.#srcset_width(source, path, {...params, ...{width: Srcset.#DEFAULT_WIDTHS}}) + return Srcset.#srcset_width(source, path, { ...params, ...{ width: Srcset.#DEFAULT_WIDTHS } }) } } - static #dprs(params) { + static #dprs (params) { if (Srcset.#isFluid(params.dpr)) { return params.dpr } else { @@ -40,17 +40,17 @@ export default class Srcset { } } - static #isFluid(value) { + static #isFluid (value) { return Array.isArray(value) || value instanceof Range } - static #srcset_dpr(source, path, params) { + static #srcset_dpr (source, path, params) { return Utils.splitParamsDpr(params).map( (splitParams) => `${Url.url(source, path, splitParams)} ${splitParams.dpr}x` ).join(',\n') } - static #srcset_width(source, path, params) { + static #srcset_width (source, path, params) { return Utils.splitParamsWidth(params).map( (splitParams) => `${Url.url(source, path, splitParams)} ${splitParams.width}w` ).join(',\n') diff --git a/src/srcset/utils.js b/src/srcset/utils.js index 71812a9..2cd9457 100644 --- a/src/srcset/utils.js +++ b/src/srcset/utils.js @@ -7,26 +7,26 @@ export default class Utils { static #SPLIT_DPR_KEYS = ['dpr', 'quality'] static #SPLIT_WIDTH_KEYS = ['width', 'height', 'quality'] - static normalizeParams(params) { + static normalizeParams (params) { return Object.entries(params).reduce((normalizedParams, [key, value]) => { return Object.assign(normalizedParams, Utils.#normalizeParam(key, value)) }, {}) } - static splitParamsDpr(params) { + static splitParamsDpr (params) { return Utils.#splitValues(params, Utils.#SPLIT_DPR_KEYS, params.dpr.length).map( - ([dpr, quality]) => Utils.#mergeParams(params, {dpr: dpr, quality: quality}) + ([dpr, quality]) => Utils.#mergeParams(params, { dpr, quality }) ) } - static splitParamsWidth(params) { + static splitParamsWidth (params) { return Utils.#splitValues(params, Utils.#SPLIT_WIDTH_KEYS, Utils.#splitSize(params.width)).map( - ([width, height, quality]) => Utils.#mergeParams(params, {width: width, height: height, quality: quality}) + ([width, height, quality]) => Utils.#mergeParams(params, { width, height, quality }) ) } - static #normalizeParam(key, value) { - switch(true) { + static #normalizeParam (key, value) { + switch (true) { case Utils.#NORMALIZE_KEYS.includes(key) && Array.isArray(value) && value.length === 0: return {} default: @@ -34,8 +34,8 @@ export default class Utils { } } - static #splitSize(value) { - switch(true) { + static #splitSize (value) { + switch (true) { case value instanceof Range: return Sequence.DEFAULT_SIZE default: @@ -43,12 +43,12 @@ export default class Utils { } } - static #splitValues(params, keys, size) { + static #splitValues (params, keys, size) { return Utils.#zip(keys.map((key) => Utils.#splitValue(key, params[key], size))) } - static #splitValue(key, value, size) { - switch(true) { + static #splitValue (key, value, size) { + switch (true) { case key === 'dpr' && value instanceof Range: return value.toArray() case value instanceof Range: @@ -60,13 +60,13 @@ export default class Utils { } } - static #zip(arrays) { + static #zip (arrays) { const length = Math.max(...arrays.map(array => array.length)) - return Array.from({ length: length }, (_, i) => arrays.map(array => array[i])) + return Array.from({ length }, (_, i) => arrays.map(array => array[i])) } - static #mergeParams(params, mergeParams) { + static #mergeParams (params, mergeParams) { return { ...params, ...Object.fromEntries( diff --git a/src/url.js b/src/url.js index dc9a345..000786e 100644 --- a/src/url.js +++ b/src/url.js @@ -3,7 +3,7 @@ import Signature from './signature' import Utils from './url/utils' export default class Url { - static url(source, path, params = {}) { + static url (source, path, params = {}) { if (typeof source === 'string') { return Url.#urlForSource(new Source(source), path, params) } @@ -15,11 +15,11 @@ export default class Url { throw new Error('Invalid source name or source') } - static #urlForSource(source, path, params) { - var normalizedPath = Utils.normalizePath(path) - var normalizedParams = Utils.normalizeParams(params) + static #urlForSource (source, path, params) { + const normalizedPath = Utils.normalizePath(path) + const normalizedParams = Utils.normalizeParams(params) - var url = new URL('https://imglab-cdn.net') + const url = new URL('https://imglab-cdn.net') url.protocol = source.scheme() url.hostname = source.host @@ -30,7 +30,7 @@ export default class Url { return url.toString() } - static #encodePath(path) { + static #encodePath (path) { if (Utils.isWebURL(path)) { return encodeURIComponent(path) } else { @@ -40,13 +40,13 @@ export default class Url { } } - static #encodeParams(source, path, params) { + static #encodeParams (source, path, params) { if (Object.keys(params).length === 0) { return Url.#encodeEmptyParams(source, path) } if (source.isSecure()) { - params['signature'] = Signature.generate(source, path, new URLSearchParams(params).toString()) + params.signature = Signature.generate(source, path, new URLSearchParams(params).toString()) return new URLSearchParams(params) } else { @@ -54,7 +54,7 @@ export default class Url { } } - static #encodeEmptyParams(source, path) { + static #encodeEmptyParams (source, path) { if (source.isSecure()) { return new URLSearchParams({ signature: Signature.generate(source, path) }) } else { diff --git a/src/url/utils.js b/src/url/utils.js index 5b86ed6..7555849 100644 --- a/src/url/utils.js +++ b/src/url/utils.js @@ -5,17 +5,17 @@ export default class Utils { static #WEB_URL_PROTOCOLS = ['https:', 'http:'] - static normalizePath(path) { + static normalizePath (path) { return path.replace(Utils.#NORMALIZE_PATH_PREFIX_REGEXP, '').replace(Utils.#NORMALIZE_PATH_SUFFIX_REGEXP, '') } - static normalizeParams(params) { + static normalizeParams (params) { return Object.entries(params).reduce((normalizedParams, [key, value]) => { return Object.assign(normalizedParams, Utils.#normalizeParam(Utils.#normalizeKey(key), value)) }, {}) } - static isWebURL(url) { + static isWebURL (url) { try { const parsedURL = new URL(url) @@ -25,12 +25,12 @@ export default class Utils { } } - static #normalizeKey(key) { + static #normalizeKey (key) { return key.replace(Utils.#NORMALIZE_KEY_REGEXP, '$1-$2').replace('_', '-').toLowerCase() } - static #normalizeParam(key, value) { - switch(true) { + static #normalizeParam (key, value) { + switch (true) { case key === 'expires' && value instanceof Date: return { [key]: Math.floor(value / 1000) } case value === undefined || value === null: diff --git a/test/source.test.js b/test/source.test.js index 24d750f..7829bca 100644 --- a/test/source.test.js +++ b/test/source.test.js @@ -60,13 +60,13 @@ describe('Source', () => { describe('scheme', () => { expect(new Source('assets').scheme()).toBe('https') expect(new Source('assets', { https: true }).scheme()).toBe('https') - expect(new Source('assets', { https: false}).scheme()).toBe('http') + expect(new Source('assets', { https: false }).scheme()).toBe('http') }) describe('host', () => { expect(new Source('assets').host).toBe('assets.imglab-cdn.net') expect(new Source('assets', { subdomains: false }).host).toBe('imglab-cdn.net') - expect(new Source('assets', { subdomains: false, host: 'imglab.net'}).host).toBe('imglab.net') + expect(new Source('assets', { subdomains: false, host: 'imglab.net' }).host).toBe('imglab.net') expect(new Source('assets', { subdomains: true }).host).toBe('assets.imglab-cdn.net') expect(new Source('assets', { subdomains: true, host: 'imglab.net' }).host).toBe('assets.imglab.net') }) diff --git a/test/srcset.test.js b/test/srcset.test.js index d17d49d..06f1752 100644 --- a/test/srcset.test.js +++ b/test/srcset.test.js @@ -3271,12 +3271,12 @@ describe('Srcset', () => { }) it('throws a new error when width is fluid and dpr is also fluid', () => { - expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: range(100, 300), dpr: range(1, 3) }) }).toThrow(Error) - expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: range(100, 300), dpr: [1, 2, 3] }) }).toThrow(Error) - expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: [100, 200, 300], dpr: range(1, 3) }) }).toThrow(Error) - expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: [100, 200, 300], dpr: [1, 2, 3] }) }).toThrow(Error) - expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: sequence(100, 300), dpr: range(1, 3) }) }).toThrow(Error) - expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: sequence(100, 300), dpr: [1, 2, 3] }) }).toThrow(Error) + expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: range(100, 300), dpr: range(1, 3) }) }).toThrow(Error) + expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: range(100, 300), dpr: [1, 2, 3] }) }).toThrow(Error) + expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: [100, 200, 300], dpr: range(1, 3) }) }).toThrow(Error) + expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: [100, 200, 300], dpr: [1, 2, 3] }) }).toThrow(Error) + expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: sequence(100, 300), dpr: range(1, 3) }) }).toThrow(Error) + expect(() => { Srcset.srcset(SECURE_SOURCE, 'example.jpeg', { width: sequence(100, 300), dpr: [1, 2, 3] }) }).toThrow(Error) }) it('throws a new error when width is not fluid and height is fluid', () => { diff --git a/test/srcset/utils.test.js b/test/srcset/utils.test.js index 4473f76..04510eb 100644 --- a/test/srcset/utils.test.js +++ b/test/srcset/utils.test.js @@ -3,7 +3,7 @@ import Range from '../../src/range' const range = Range.range -describe ('Utils', () => { +describe('Utils', () => { describe('normalizeParams', () => { it('returns normalized params', () => { expect(Utils.normalizeParams({})).toEqual({}) @@ -11,10 +11,10 @@ describe ('Utils', () => { expect(Utils.normalizeParams({ dpr: [], width: [] })).toEqual({}) expect(Utils.normalizeParams({ blur: 100, dpr: [], width: [], format: 'png' })).toEqual( - { blur: 100, format: 'png'} + { blur: 100, format: 'png' } ) - expect(Utils.normalizeParams({ blur: 100, dpr: 1, width: 100, format: 'png'})).toEqual( + expect(Utils.normalizeParams({ blur: 100, dpr: 1, width: 100, format: 'png' })).toEqual( { blur: 100, dpr: 1, width: 100, format: 'png' } ) diff --git a/test/url.test.js b/test/url.test.js index daa7fda..ee2e896 100644 --- a/test/url.test.js +++ b/test/url.test.js @@ -189,7 +189,7 @@ describe('Url', () => { }) it('returns url with subfolder path starting and ending with slash', () => { - const url = Url.url('assets', '/subfolder/example.jpeg/', { width: 200, height: 300, format: 'png'}) + const url = Url.url('assets', '/subfolder/example.jpeg/', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/subfolder/example.jpeg?width=200&height=300&format=png') }) @@ -212,7 +212,7 @@ describe('Url', () => { expect(url).toBe('https://assets.imglab-cdn.net/http%3A%2F%2Fassets.com%2Fsubfolder%2Fexample%252C01%252C02.jpeg?width=200&height=300&format=png') }) - it('returns url with path using a https url', () => { + it('returns url with path using a https url', () => { const url = Url.url('assets', 'https://assets.com/subfolder/example.jpeg', { width: 200, height: 300, format: 'png' }) expect(url).toBe('https://assets.imglab-cdn.net/https%3A%2F%2Fassets.com%2Fsubfolder%2Fexample.jpeg?width=200&height=300&format=png') diff --git a/test/url/utils.test.js b/test/url/utils.test.js index 2a2aaea..65328c1 100644 --- a/test/url/utils.test.js +++ b/test/url/utils.test.js @@ -24,7 +24,7 @@ describe('Utils', () => { describe('normalizeParams', () => { it('returns normalized params', () => { expect(Utils.normalizeParams({})).toEqual({}) - expect(Utils.normalizeParams({ width: 200, height: 300})).toEqual({ width: 200, height: 300}) + expect(Utils.normalizeParams({ width: 200, height: 300 })).toEqual({ width: 200, height: 300 }) expect(Utils.normalizeParams({ width: 200, height: 300, download: null })).toEqual({ width: 200, height: 300, download: '' }) expect(Utils.normalizeParams({ width: 200, height: 300, download: undefined })).toEqual({ width: 200, height: 300, download: '' }) expect(Utils.normalizeParams({ trim: 'color', 'trim-color': 'orange' })).toEqual({ trim: 'color', 'trim-color': 'orange' }) @@ -32,7 +32,7 @@ describe('Utils', () => { expect(Utils.normalizeParams({ trim: 'color', trimColor: 'orange' })).toEqual({ trim: 'color', 'trim-color': 'orange' }) expect(Utils.normalizeParams({ width: 200, expires: 1464096368 })).toEqual({ width: 200, expires: 1464096368 }) expect(Utils.normalizeParams({ width: 200, expires: '1464096368' })).toEqual({ width: 200, expires: '1464096368' }) - expect(Utils.normalizeParams({ width: 200, expires: new Date(1464096368 * 1000)})).toEqual({ width: 200, expires: 1464096368 }) + expect(Utils.normalizeParams({ width: 200, expires: new Date(1464096368 * 1000) })).toEqual({ width: 200, expires: 1464096368 }) }) }) From 4e3734b1c061cb472be1d428849dcacd2dc54a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Francisco=20Calvo?= Date: Thu, 12 Jan 2023 12:13:06 +0100 Subject: [PATCH 10/15] Fix dependency vulnerabilities --- package-lock.json | 194 +++++++++++++++++++++++++++++++--------------- 1 file changed, 130 insertions(+), 64 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2bf2f3f..0bcfaae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2260,6 +2260,64 @@ "node": ">=8" } }, + "node_modules/@jridgewell/gen-mapping": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.2.tgz", + "integrity": "sha512-mh65xKQAzI6iBcFzwv28KVWSmCkdRBWoOh+bYQGW3+6OZvbbN3TqMGo5hqYxQniRcH9F2VZIoJCm4pa3BPDK/A==", + "dev": true, + "dependencies": { + "@jridgewell/set-array": "^1.0.1", + "@jridgewell/sourcemap-codec": "^1.4.10", + "@jridgewell/trace-mapping": "^0.3.9" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", + "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==", + "dev": true, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/set-array": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.2.tgz", + "integrity": "sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==", + "dev": true, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/source-map": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.2.tgz", + "integrity": "sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw==", + "dev": true, + "dependencies": { + "@jridgewell/gen-mapping": "^0.3.0", + "@jridgewell/trace-mapping": "^0.3.9" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.4.14", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz", + "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==", + "dev": true + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.17", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.17.tgz", + "integrity": "sha512-MCNzAp77qzKca9+W/+I0+sEpaUnZoeasnghNeVc41VZCEKaCH73Vq3BZZ/SzWIgrqE4H4ceI+p+b6C0mHf9T4g==", + "dev": true, + "dependencies": { + "@jridgewell/resolve-uri": "3.1.0", + "@jridgewell/sourcemap-codec": "1.4.14" + } + }, "node_modules/@rollup/plugin-babel": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/@rollup/plugin-babel/-/plugin-babel-5.3.0.tgz", @@ -5625,13 +5683,10 @@ } }, "node_modules/json5": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.0.tgz", - "integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==", + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", "dev": true, - "dependencies": { - "minimist": "^1.2.5" - }, "bin": { "json5": "lib/cli.js" }, @@ -5789,9 +5844,9 @@ } }, "node_modules/minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "dev": true, "dependencies": { "brace-expansion": "^1.1.7" @@ -5800,12 +5855,6 @@ "node": "*" } }, - "node_modules/minimist": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", - "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", - "dev": true - }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -6619,13 +6668,14 @@ } }, "node_modules/terser": { - "version": "5.10.0", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.10.0.tgz", - "integrity": "sha512-AMmF99DMfEDiRJfxfY5jj5wNH/bYO09cniSqhfoyxc8sFoYIgkJy86G04UoZU5VjlpnplVu0K6Tx6E9b5+DlHA==", + "version": "5.16.1", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.16.1.tgz", + "integrity": "sha512-xvQfyfA1ayT0qdK47zskQgRZeWLoOQ8JQ6mIgRGVNwZKdQMU+5FkCBjmv4QjcrTzyZquRw2FVtlJSRUmMKQslw==", "dev": true, "dependencies": { + "@jridgewell/source-map": "^0.3.2", + "acorn": "^8.5.0", "commander": "^2.20.0", - "source-map": "~0.7.2", "source-map-support": "~0.5.20" }, "bin": { @@ -6633,23 +6683,6 @@ }, "engines": { "node": ">=10" - }, - "peerDependencies": { - "acorn": "^8.5.0" - }, - "peerDependenciesMeta": { - "acorn": { - "optional": true - } - } - }, - "node_modules/terser/node_modules/source-map": { - "version": "0.7.3", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.3.tgz", - "integrity": "sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==", - "dev": true, - "engines": { - "node": ">= 8" } }, "node_modules/test-exclude": { @@ -8673,6 +8706,55 @@ } } }, + "@jridgewell/gen-mapping": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.2.tgz", + "integrity": "sha512-mh65xKQAzI6iBcFzwv28KVWSmCkdRBWoOh+bYQGW3+6OZvbbN3TqMGo5hqYxQniRcH9F2VZIoJCm4pa3BPDK/A==", + "dev": true, + "requires": { + "@jridgewell/set-array": "^1.0.1", + "@jridgewell/sourcemap-codec": "^1.4.10", + "@jridgewell/trace-mapping": "^0.3.9" + } + }, + "@jridgewell/resolve-uri": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", + "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==", + "dev": true + }, + "@jridgewell/set-array": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.2.tgz", + "integrity": "sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==", + "dev": true + }, + "@jridgewell/source-map": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.2.tgz", + "integrity": "sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw==", + "dev": true, + "requires": { + "@jridgewell/gen-mapping": "^0.3.0", + "@jridgewell/trace-mapping": "^0.3.9" + } + }, + "@jridgewell/sourcemap-codec": { + "version": "1.4.14", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz", + "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==", + "dev": true + }, + "@jridgewell/trace-mapping": { + "version": "0.3.17", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.17.tgz", + "integrity": "sha512-MCNzAp77qzKca9+W/+I0+sEpaUnZoeasnghNeVc41VZCEKaCH73Vq3BZZ/SzWIgrqE4H4ceI+p+b6C0mHf9T4g==", + "dev": true, + "requires": { + "@jridgewell/resolve-uri": "3.1.0", + "@jridgewell/sourcemap-codec": "1.4.14" + } + }, "@rollup/plugin-babel": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/@rollup/plugin-babel/-/plugin-babel-5.3.0.tgz", @@ -11233,13 +11315,10 @@ "dev": true }, "json5": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.0.tgz", - "integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==", - "dev": true, - "requires": { - "minimist": "^1.2.5" - } + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "dev": true }, "kleur": { "version": "3.0.3", @@ -11358,20 +11437,14 @@ "dev": true }, "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "dev": true, "requires": { "brace-expansion": "^1.1.7" } }, - "minimist": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", - "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", - "dev": true - }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -12008,22 +12081,15 @@ } }, "terser": { - "version": "5.10.0", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.10.0.tgz", - "integrity": "sha512-AMmF99DMfEDiRJfxfY5jj5wNH/bYO09cniSqhfoyxc8sFoYIgkJy86G04UoZU5VjlpnplVu0K6Tx6E9b5+DlHA==", + "version": "5.16.1", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.16.1.tgz", + "integrity": "sha512-xvQfyfA1ayT0qdK47zskQgRZeWLoOQ8JQ6mIgRGVNwZKdQMU+5FkCBjmv4QjcrTzyZquRw2FVtlJSRUmMKQslw==", "dev": true, "requires": { + "@jridgewell/source-map": "^0.3.2", + "acorn": "^8.5.0", "commander": "^2.20.0", - "source-map": "~0.7.2", "source-map-support": "~0.5.20" - }, - "dependencies": { - "source-map": { - "version": "0.7.3", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.3.tgz", - "integrity": "sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==", - "dev": true - } } }, "test-exclude": { From 25e8c2794ca4e56150ef4a86094672245267e02b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Francisco=20Calvo?= Date: Thu, 12 Jan 2023 12:36:53 +0100 Subject: [PATCH 11/15] Small fix encoding url params --- src/url.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/url.js b/src/url.js index 000786e..741c337 100644 --- a/src/url.js +++ b/src/url.js @@ -47,11 +47,9 @@ export default class Url { if (source.isSecure()) { params.signature = Signature.generate(source, path, new URLSearchParams(params).toString()) - - return new URLSearchParams(params) - } else { - return new URLSearchParams(params) } + + return new URLSearchParams(params) } static #encodeEmptyParams (source, path) { From dc4c7436ac8ae090bc91d4696906aa2e00a1637b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Francisco=20Calvo?= Date: Thu, 12 Jan 2023 18:13:26 +0100 Subject: [PATCH 12/15] Add srcset section to README.md --- README.md | 304 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 302 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c8822e4..3557bc8 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ Imglab.url('assets', 'image.jpeg', { width: 500, height: 600, mode: 'contain', b You can additionally use `Imglab.color` helper function to specify these color values: ```javascript -// If you prefer to avoid Imglab scope you can load color helper function in a constant +// If you prefer to avoid Imglab scope you can load color helper function into a constant const color = Imglab.color // Using color helper for a RGB color @@ -181,7 +181,7 @@ Imglab.url('assets', 'image.jpeg', { width: 500, height: 500, mode: 'crop', crop You can additionally use `Imglab.position` helper function to specify these position values: ```javascript -// If you prefer to avoid Imglab scope you can load position helper function in a constant +// If you prefer to avoid Imglab scope you can load position helper function into a constant const position = Imglab.position // Using position helper for a horizontal and vertical position @@ -331,6 +331,306 @@ Imglab.url(source, 'logo.png', { width: 300, height: 300, format: 'png' }) 'http://my-company.com:8080/images/logo.png?width=300&height=300&format=png' ``` +## Generating srcsets + +You can use `Imglab.srcset` function to generate custom string values for `srcset` attributes, to be used for Web responsive images inside a `` tag. + +This function works similarly to `Imglab.url`, expecting the same parameters and values, except for some specific query parameters that have a special meaning and can receive `Imglab.Range` or `Array` values. + +> To learn more about responsive images and the `srcset` attribute, you can take a look to the [MDN article about responsive images](https://developer.mozilla.org/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images). + +### Fixed size + +When enough information is provided about the image output size (using `width` or `height` parameters), `Imglab.srcset` function will generate a collection of URLs with a default sequence of device pixel ratios. + +For the following example we are specying a fixed value of `500` pixels for `width` parameter: + +```javascript +Imglab.srcset('assets', 'image.jpeg', { width: 500 }) +``` + +``` +https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=1 1x, +https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=2 2x, +https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=3 3x, +https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=4 4x, +https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=5 5x, +https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=6 6x +``` + +A very common practice consists in reducing the quality of images with high pixel density, decreasing the final file size. To achieve this you can optionally specify a `Imglab.Range` object for `quality` parameter, gradually reducing the quality and file size while increasing the image size. + +In this example we are specifying a fixed `width` value of `500` pixels and a `quality` range between `80` and `40`: + +```javascript +// If you prefer to avoid Imglab scope you can load range helper function into a constant +const range = Imglab.range + +Imglab.srcset('assets', 'image.jpeg', { width: 500, quality: range(80, 40) }) +``` + +``` +https://assets.imglab-cdn.net/image.jpeg?width=500&quality=80&dpr=1 1x, +https://assets.imglab-cdn.net/image.jpeg?width=500&quality=70&dpr=2 2x, +https://assets.imglab-cdn.net/image.jpeg?width=500&quality=61&dpr=3 3x, +https://assets.imglab-cdn.net/image.jpeg?width=500&quality=53&dpr=4 4x, +https://assets.imglab-cdn.net/image.jpeg?width=500&quality=46&dpr=5 5x, +https://assets.imglab-cdn.net/image.jpeg?width=500&quality=40&dpr=6 6x +``` + +A custom `range` value can be set for `dpr` parameter too, overriding the default sequence of generated dprs: + +```javascript +Imglab.srcset('assets', 'image.jpeg', { width: 500, dpr: range(1, 4) }) +``` + +``` +https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=1 1x, +https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=2 2x, +https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=3 3x, +https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=4 4x +``` + +Using `range` values for `dpr` and `quality` parameters in the same `srcset` call is also possible: + +```javascript +Imglab.srcset('assets', 'image.jpeg', { width: 500, dpr: range(1, 4), quality: range(80, 40) }) +``` + +``` +https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=1&quality=80 1x, +https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=2&quality=63 2x, +https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=3&quality=50 3x, +https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=4&quality=40 4x +``` + +If necessary you can also use Arrays with explicit values for `dpr` and `quality`: + +```javascript +Imglab.srcset('assets', 'image.jpeg', { width: 500, dpr: [1, 2, 3], quality: [80, 75, 60] }) +``` + +``` +https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=1&quality=80 1x, +https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=2&quality=75 2x, +https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=3&quality=60 3x +``` + +Or even use a specific `quality` value for all the URLs in the same srcset: + +```javascript +Imglab.srcset('assets', 'image.jpeg', { width: 500, dpr: [1, 2, 3], quality: 70 }) +``` + +``` +https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=1&quality=70 1x, +https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=2&quality=70 2x, +https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=3&quality=70 3x +``` + +### Fluid width + +When a specific sequence of width values are required you can use `Imglab.range`, `Imglab.sequence`, or `Array` values for `width` parameter. + +When a `range` value is used, a `Imglab.sequence` with a default size of 16 URLs will be generated inside the specified interval: + +```javascript +Imglab.srcset('assets', 'image.jpeg', { width: range(100, 2000) }) +``` + +``` +https://assets.imglab-cdn.net/image.jpeg?width=100 100w, +https://assets.imglab-cdn.net/image.jpeg?width=122 122w, +https://assets.imglab-cdn.net/image.jpeg?width=149 149w, +https://assets.imglab-cdn.net/image.jpeg?width=182 182w, +https://assets.imglab-cdn.net/image.jpeg?width=222 222w, +https://assets.imglab-cdn.net/image.jpeg?width=271 271w, +https://assets.imglab-cdn.net/image.jpeg?width=331 331w, +https://assets.imglab-cdn.net/image.jpeg?width=405 405w, +https://assets.imglab-cdn.net/image.jpeg?width=494 494w, +https://assets.imglab-cdn.net/image.jpeg?width=603 603w, +https://assets.imglab-cdn.net/image.jpeg?width=737 737w, +https://assets.imglab-cdn.net/image.jpeg?width=900 900w, +https://assets.imglab-cdn.net/image.jpeg?width=1099 1099w, +https://assets.imglab-cdn.net/image.jpeg?width=1341 1341w, +https://assets.imglab-cdn.net/image.jpeg?width=1638 1638w, +https://assets.imglab-cdn.net/image.jpeg?width=2000 2000w +``` + +If required you can specify a `range` value for `quality` parameter too: + +```javascript +Imglab.srcset('assets', 'image.jpeg', { width: range(100, 2000), quality: range(80, 40) }) +``` + +``` +https://assets.imglab-cdn.net/image.jpeg?width=100&quality=80 100w, +https://assets.imglab-cdn.net/image.jpeg?width=122&quality=76 122w, +https://assets.imglab-cdn.net/image.jpeg?width=149&quality=73 149w, +https://assets.imglab-cdn.net/image.jpeg?width=182&quality=70 182w, +https://assets.imglab-cdn.net/image.jpeg?width=222&quality=66 222w, +https://assets.imglab-cdn.net/image.jpeg?width=271&quality=63 271w, +https://assets.imglab-cdn.net/image.jpeg?width=331&quality=61 331w, +https://assets.imglab-cdn.net/image.jpeg?width=405&quality=58 405w, +https://assets.imglab-cdn.net/image.jpeg?width=494&quality=55 494w, +https://assets.imglab-cdn.net/image.jpeg?width=603&quality=53 603w, +https://assets.imglab-cdn.net/image.jpeg?width=737&quality=50 737w, +https://assets.imglab-cdn.net/image.jpeg?width=900&quality=48 900w, +https://assets.imglab-cdn.net/image.jpeg?width=1099&quality=46 1099w, +https://assets.imglab-cdn.net/image.jpeg?width=1341&quality=44 1341w, +https://assets.imglab-cdn.net/image.jpeg?width=1638&quality=42 1638w, +https://assets.imglab-cdn.net/image.jpeg?width=2000&quality=40 2000w +``` + +If you want to generate a sequence of numbers for `width` parameter with a specific number of URLs you can use `Imglab.sequence` function helper: + +```javascript +// If you prefer to avoid Imglab scope you can load sequence helper function into a constant +const sequence = Imglab.sequence + +// Generating a srcset string with a sequence of 5 URLs between 100 and 2000 pixels for width parameter +Imglab.srcset('assets', 'image.jpeg', { width: sequence(100, 2000, 5) }) +``` + +``` +https://assets.imglab-cdn.net/image.jpeg?width=100 100w, +https://assets.imglab-cdn.net/image.jpeg?width=211 211w, +https://assets.imglab-cdn.net/image.jpeg?width=447 447w, +https://assets.imglab-cdn.net/image.jpeg?width=946 946w, +https://assets.imglab-cdn.net/image.jpeg?width=2000 2000w +``` + +Using an Array with specific values will generate URLs only for those widths: + +```javascript +Imglab.srcset('assets', 'image.jpeg', { width: [100, 300, 500] }) +``` + +``` +https://assets.imglab-cdn.net/image.jpeg?width=100 100w, +https://assets.imglab-cdn.net/image.jpeg?width=300 300w, +https://assets.imglab-cdn.net/image.jpeg?width=500 500w +``` + +It is also possible to specify an Array of values for `height` and `quality` parameters: + +```javascript +Imglab.srcset('assets', 'image.jpeg', { width: [100, 300, 500], height: [200, 400, 600], quality: [75, 70, 65] }) +``` + +``` +https://assets.imglab-cdn.net/image.jpeg?width=100&height=200&quality=75 100w, +https://assets.imglab-cdn.net/image.jpeg?width=300&height=400&quality=70 300w, +https://assets.imglab-cdn.net/image.jpeg?width=500&height=600&quality=65 500w +``` + +### No size + +When `srcset` function doesn't have information about the image output size (`width` or `height` parameters are not set) it will generate a default `Imglab.sequence` of 16 URLs specifying a `width` value with an interval between `100` and `8192` pixels: + +```javascript +Imglab.srcset('assets', 'image.jpeg') +``` + +``` +https://assets.imglab-cdn.net/image.jpeg?width=100 100w, +https://assets.imglab-cdn.net/image.jpeg?width=134 134w, +https://assets.imglab-cdn.net/image.jpeg?width=180 180w, +https://assets.imglab-cdn.net/image.jpeg?width=241 241w, +https://assets.imglab-cdn.net/image.jpeg?width=324 324w, +https://assets.imglab-cdn.net/image.jpeg?width=434 434w, +https://assets.imglab-cdn.net/image.jpeg?width=583 583w, +https://assets.imglab-cdn.net/image.jpeg?width=781 781w, +https://assets.imglab-cdn.net/image.jpeg?width=1048 1048w, +https://assets.imglab-cdn.net/image.jpeg?width=1406 1406w, +https://assets.imglab-cdn.net/image.jpeg?width=1886 1886w, +https://assets.imglab-cdn.net/image.jpeg?width=2530 2530w, +https://assets.imglab-cdn.net/image.jpeg?width=3394 3394w, +https://assets.imglab-cdn.net/image.jpeg?width=4553 4553w, +https://assets.imglab-cdn.net/image.jpeg?width=6107 6107w, +https://assets.imglab-cdn.net/image.jpeg?width=8192 8192w +``` + +It is always possible to change this default behavior using `Imglab.sequence` function helper. In the following example we are specifying a sequence of 10 different URLs between `320` and `4096` pixels: + +```javascript +const sequence = Imglab.sequence + +Imglab.srcset('assets', 'image.jpeg', { width: sequence(320, 4096, 10) }) +``` + +``` +https://assets.imglab-cdn.net/image.jpeg?width=320 320w, +https://assets.imglab-cdn.net/image.jpeg?width=425 425w, +https://assets.imglab-cdn.net/image.jpeg?width=564 564w, +https://assets.imglab-cdn.net/image.jpeg?width=749 749w, +https://assets.imglab-cdn.net/image.jpeg?width=994 994w, +https://assets.imglab-cdn.net/image.jpeg?width=1319 1319w, +https://assets.imglab-cdn.net/image.jpeg?width=1751 1751w, +https://assets.imglab-cdn.net/image.jpeg?width=2324 2324w, +https://assets.imglab-cdn.net/image.jpeg?width=3086 3086w, +https://assets.imglab-cdn.net/image.jpeg?width=4096 4096w +``` + +### Image aspect ratio and srcset + +A usual scenario is to generate multiple URLs while maintaining the same aspect ratio for all of them. If a specific image aspect ratio is required while using `srcset` function you can set a value to `aspect-ratio` parameter along with `mode` parameter using `crop`, `contain`, `face`, or `force` resize modes. + +For the following example we are using a specific value of `300` pixels for `width`, and an aspect ratio of `1:1` (square), cropping the image with `crop` resize mode and setting output format to `webp`: + +```javascript +Imglab.srcset('assets', 'image.jpeg', { width: 300, aspectRatio: '1:1', mode: 'crop', format: 'webp' }) +``` + +``` +https://assets.imglab-cdn.net/image.jpeg?width=300&aspect-ratio=1%3A1&mode=crop&format=webp&dpr=1 1x, +https://assets.imglab-cdn.net/image.jpeg?width=300&aspect-ratio=1%3A1&mode=crop&format=webp&dpr=2 2x, +https://assets.imglab-cdn.net/image.jpeg?width=300&aspect-ratio=1%3A1&mode=crop&format=webp&dpr=3 3x, +https://assets.imglab-cdn.net/image.jpeg?width=300&aspect-ratio=1%3A1&mode=crop&format=webp&dpr=4 4x, +https://assets.imglab-cdn.net/image.jpeg?width=300&aspect-ratio=1%3A1&mode=crop&format=webp&dpr=5 5x, +https://assets.imglab-cdn.net/image.jpeg?width=300&aspect-ratio=1%3A1&mode=crop&format=webp&dpr=6 6x +``` + +You can instead use `height` value. In this example we are specifying a fixed value of `300` pixels for `height` parameter, a `aspect-ratio` of `16:9` (widescreen) with `crop` resize mode, and `webp` output format: + +```javascript +Imglab.srcset('assets', 'image.jpeg', { height: 300, aspectRatio: '16:9', mode: 'crop', format: 'webp' }) +``` + +``` +https://assets.imglab-cdn.net/image.jpeg?height=300&aspect-ratio=16%3A9&mode=crop&format=webp&dpr=1 1x, +https://assets.imglab-cdn.net/image.jpeg?height=300&aspect-ratio=16%3A9&mode=crop&format=webp&dpr=2 2x, +https://assets.imglab-cdn.net/image.jpeg?height=300&aspect-ratio=16%3A9&mode=crop&format=webp&dpr=3 3x, +https://assets.imglab-cdn.net/image.jpeg?height=300&aspect-ratio=16%3A9&mode=crop&format=webp&dpr=4 4x, +https://assets.imglab-cdn.net/image.jpeg?height=300&aspect-ratio=16%3A9&mode=crop&format=webp&dpr=5 5x, +https://assets.imglab-cdn.net/image.jpeg?height=300&aspect-ratio=16%3A9&mode=crop&format=webp&dpr=6 6x +``` + +You can also use fluid values for `width` parameter while maintaining the same aspect ratio for all generated URLs. In this example, we are using a `range` value between `100` and `4096` for `width` parameter, a value of `1:1` for `aspect-ratio`, `crop` resize mode and `webp` output format: + +```javascript +Imglab.srcset('assets', 'image.jpeg', { width: range(100, 4096), aspectRatio: '1:1', mode: 'crop', format: 'webp' }) +``` + +``` +https://assets.imglab-cdn.net/image.jpeg?width=100&aspect-ratio=1%3A1&mode=crop&format=webp 100w, +https://assets.imglab-cdn.net/image.jpeg?width=128&aspect-ratio=1%3A1&mode=crop&format=webp 128w, +https://assets.imglab-cdn.net/image.jpeg?width=164&aspect-ratio=1%3A1&mode=crop&format=webp 164w, +https://assets.imglab-cdn.net/image.jpeg?width=210&aspect-ratio=1%3A1&mode=crop&format=webp 210w, +https://assets.imglab-cdn.net/image.jpeg?width=269&aspect-ratio=1%3A1&mode=crop&format=webp 269w, +https://assets.imglab-cdn.net/image.jpeg?width=345&aspect-ratio=1%3A1&mode=crop&format=webp 345w, +https://assets.imglab-cdn.net/image.jpeg?width=442&aspect-ratio=1%3A1&mode=crop&format=webp 442w, +https://assets.imglab-cdn.net/image.jpeg?width=566&aspect-ratio=1%3A1&mode=crop&format=webp 566w, +https://assets.imglab-cdn.net/image.jpeg?width=724&aspect-ratio=1%3A1&mode=crop&format=webp 724w, +https://assets.imglab-cdn.net/image.jpeg?width=928&aspect-ratio=1%3A1&mode=crop&format=webp 928w, +https://assets.imglab-cdn.net/image.jpeg?width=1188&aspect-ratio=1%3A1&mode=crop&format=webp 1188w, +https://assets.imglab-cdn.net/image.jpeg?width=1522&aspect-ratio=1%3A1&mode=crop&format=webp 1522w, +https://assets.imglab-cdn.net/image.jpeg?width=1949&aspect-ratio=1%3A1&mode=crop&format=webp 1949w, +https://assets.imglab-cdn.net/image.jpeg?width=2497&aspect-ratio=1%3A1&mode=crop&format=webp 2497w, +https://assets.imglab-cdn.net/image.jpeg?width=3198&aspect-ratio=1%3A1&mode=crop&format=webp 3198w, +https://assets.imglab-cdn.net/image.jpeg?width=4096&aspect-ratio=1%3A1&mode=crop&format=webp 4096w +``` + ## License imglab source code is released under [MIT License](LICENSE). From ef2180f36e2bc2618f22cb197dd0458faa47c925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Francisco=20Calvo?= Date: Thu, 12 Jan 2023 18:14:17 +0100 Subject: [PATCH 13/15] Add Range class to default exports --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index af46697..a72801d 100644 --- a/src/index.js +++ b/src/index.js @@ -13,4 +13,4 @@ const position = Position.position const range = Range.range const sequence = Sequence.sequence -export default { url, srcset, Source, color, position, range, sequence } +export default { url, srcset, Source, color, position, Range, range, sequence } From 4cb2aee03474a022bc9e89a169aa4ed052036331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Francisco=20Calvo?= Date: Fri, 13 Jan 2023 16:26:01 +0100 Subject: [PATCH 14/15] Add html format to srcset examples --- README.md | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 3557bc8..f024d4c 100644 --- a/README.md +++ b/README.md @@ -333,7 +333,7 @@ Imglab.url(source, 'logo.png', { width: 300, height: 300, format: 'png' }) ## Generating srcsets -You can use `Imglab.srcset` function to generate custom string values for `srcset` attributes, to be used for Web responsive images inside a `` tag. +You can use `Imglab.srcset` function to generate custom string values for `srcset` attributes, to be used for Web responsive images inside an `` HTML element or picture ``. This function works similarly to `Imglab.url`, expecting the same parameters and values, except for some specific query parameters that have a special meaning and can receive `Imglab.Range` or `Array` values. @@ -349,7 +349,9 @@ For the following example we are specying a fixed value of `500` pixels for `wid Imglab.srcset('assets', 'image.jpeg', { width: 500 }) ``` -``` +Generating the following output: + +```html https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=1 1x, https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=2 2x, https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=3 3x, @@ -369,7 +371,7 @@ const range = Imglab.range Imglab.srcset('assets', 'image.jpeg', { width: 500, quality: range(80, 40) }) ``` -``` +```html https://assets.imglab-cdn.net/image.jpeg?width=500&quality=80&dpr=1 1x, https://assets.imglab-cdn.net/image.jpeg?width=500&quality=70&dpr=2 2x, https://assets.imglab-cdn.net/image.jpeg?width=500&quality=61&dpr=3 3x, @@ -384,7 +386,7 @@ A custom `range` value can be set for `dpr` parameter too, overriding the defaul Imglab.srcset('assets', 'image.jpeg', { width: 500, dpr: range(1, 4) }) ``` -``` +```html https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=1 1x, https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=2 2x, https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=3 3x, @@ -397,7 +399,7 @@ Using `range` values for `dpr` and `quality` parameters in the same `srcset` cal Imglab.srcset('assets', 'image.jpeg', { width: 500, dpr: range(1, 4), quality: range(80, 40) }) ``` -``` +```html https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=1&quality=80 1x, https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=2&quality=63 2x, https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=3&quality=50 3x, @@ -410,7 +412,7 @@ If necessary you can also use Arrays with explicit values for `dpr` and `quality Imglab.srcset('assets', 'image.jpeg', { width: 500, dpr: [1, 2, 3], quality: [80, 75, 60] }) ``` -``` +```html https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=1&quality=80 1x, https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=2&quality=75 2x, https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=3&quality=60 3x @@ -422,7 +424,7 @@ Or even use a specific `quality` value for all the URLs in the same srcset: Imglab.srcset('assets', 'image.jpeg', { width: 500, dpr: [1, 2, 3], quality: 70 }) ``` -``` +```html https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=1&quality=70 1x, https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=2&quality=70 2x, https://assets.imglab-cdn.net/image.jpeg?width=500&dpr=3&quality=70 3x @@ -438,7 +440,7 @@ When a `range` value is used, a `Imglab.sequence` with a default size of 16 URLs Imglab.srcset('assets', 'image.jpeg', { width: range(100, 2000) }) ``` -``` +```html https://assets.imglab-cdn.net/image.jpeg?width=100 100w, https://assets.imglab-cdn.net/image.jpeg?width=122 122w, https://assets.imglab-cdn.net/image.jpeg?width=149 149w, @@ -463,7 +465,7 @@ If required you can specify a `range` value for `quality` parameter too: Imglab.srcset('assets', 'image.jpeg', { width: range(100, 2000), quality: range(80, 40) }) ``` -``` +```html https://assets.imglab-cdn.net/image.jpeg?width=100&quality=80 100w, https://assets.imglab-cdn.net/image.jpeg?width=122&quality=76 122w, https://assets.imglab-cdn.net/image.jpeg?width=149&quality=73 149w, @@ -492,7 +494,7 @@ const sequence = Imglab.sequence Imglab.srcset('assets', 'image.jpeg', { width: sequence(100, 2000, 5) }) ``` -``` +```html https://assets.imglab-cdn.net/image.jpeg?width=100 100w, https://assets.imglab-cdn.net/image.jpeg?width=211 211w, https://assets.imglab-cdn.net/image.jpeg?width=447 447w, @@ -506,7 +508,7 @@ Using an Array with specific values will generate URLs only for those widths: Imglab.srcset('assets', 'image.jpeg', { width: [100, 300, 500] }) ``` -``` +```html https://assets.imglab-cdn.net/image.jpeg?width=100 100w, https://assets.imglab-cdn.net/image.jpeg?width=300 300w, https://assets.imglab-cdn.net/image.jpeg?width=500 500w @@ -518,7 +520,7 @@ It is also possible to specify an Array of values for `height` and `quality` par Imglab.srcset('assets', 'image.jpeg', { width: [100, 300, 500], height: [200, 400, 600], quality: [75, 70, 65] }) ``` -``` +```html https://assets.imglab-cdn.net/image.jpeg?width=100&height=200&quality=75 100w, https://assets.imglab-cdn.net/image.jpeg?width=300&height=400&quality=70 300w, https://assets.imglab-cdn.net/image.jpeg?width=500&height=600&quality=65 500w @@ -532,7 +534,7 @@ When `srcset` function doesn't have information about the image output size (`wi Imglab.srcset('assets', 'image.jpeg') ``` -``` +```html https://assets.imglab-cdn.net/image.jpeg?width=100 100w, https://assets.imglab-cdn.net/image.jpeg?width=134 134w, https://assets.imglab-cdn.net/image.jpeg?width=180 180w, @@ -559,7 +561,7 @@ const sequence = Imglab.sequence Imglab.srcset('assets', 'image.jpeg', { width: sequence(320, 4096, 10) }) ``` -``` +```html https://assets.imglab-cdn.net/image.jpeg?width=320 320w, https://assets.imglab-cdn.net/image.jpeg?width=425 425w, https://assets.imglab-cdn.net/image.jpeg?width=564 564w, @@ -582,7 +584,7 @@ For the following example we are using a specific value of `300` pixels for `wid Imglab.srcset('assets', 'image.jpeg', { width: 300, aspectRatio: '1:1', mode: 'crop', format: 'webp' }) ``` -``` +```html https://assets.imglab-cdn.net/image.jpeg?width=300&aspect-ratio=1%3A1&mode=crop&format=webp&dpr=1 1x, https://assets.imglab-cdn.net/image.jpeg?width=300&aspect-ratio=1%3A1&mode=crop&format=webp&dpr=2 2x, https://assets.imglab-cdn.net/image.jpeg?width=300&aspect-ratio=1%3A1&mode=crop&format=webp&dpr=3 3x, @@ -597,7 +599,7 @@ You can instead use `height` value. In this example we are specifying a fixed va Imglab.srcset('assets', 'image.jpeg', { height: 300, aspectRatio: '16:9', mode: 'crop', format: 'webp' }) ``` -``` +```html https://assets.imglab-cdn.net/image.jpeg?height=300&aspect-ratio=16%3A9&mode=crop&format=webp&dpr=1 1x, https://assets.imglab-cdn.net/image.jpeg?height=300&aspect-ratio=16%3A9&mode=crop&format=webp&dpr=2 2x, https://assets.imglab-cdn.net/image.jpeg?height=300&aspect-ratio=16%3A9&mode=crop&format=webp&dpr=3 3x, @@ -612,7 +614,7 @@ You can also use fluid values for `width` parameter while maintaining the same a Imglab.srcset('assets', 'image.jpeg', { width: range(100, 4096), aspectRatio: '1:1', mode: 'crop', format: 'webp' }) ``` -``` +```html https://assets.imglab-cdn.net/image.jpeg?width=100&aspect-ratio=1%3A1&mode=crop&format=webp 100w, https://assets.imglab-cdn.net/image.jpeg?width=128&aspect-ratio=1%3A1&mode=crop&format=webp 128w, https://assets.imglab-cdn.net/image.jpeg?width=164&aspect-ratio=1%3A1&mode=crop&format=webp 164w, From 2323824df5b7cbee1b58e7c4f6802daba48c007b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Francisco=20Calvo?= Date: Fri, 13 Jan 2023 16:27:38 +0100 Subject: [PATCH 15/15] Upgrade browser header examples to version 0.3.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f024d4c..e395ed8 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,9 @@ If you prefer to use a `script` tag in your code to load `@imglab/core` try to u ```html - + - + ``` After adding the library you can use it normally: