-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.d.ts
45 lines (40 loc) · 1.38 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
export type Candidate = {
source: {
value: string;
startOffset: number;
};
width?: {
value: number;
};
height?: {
value: number;
};
density?: {
value: number;
};
};
/**
Parses the string value that appears in markup `<img srcset="here">`.
@description A javascript parser for the [HTML5 srcset](http://www.w3.org/TR/html-srcset/) attribute, based on the [WHATWG reference algorithm](https://html.spec.whatwg.org/multipage/embedded-content.html#parse-a-srcset-attribute). It has an extensive test suite based on the [W3C srcset conformance checker](http://w3c-test.org/html/semantics/embedded-content/the-img-element/srcset/parse-a-srcset-attribute.html)
@param {string} input - The string value to parse.
@returns {Candidate[]} An array of objects representing the image candidates.
@throws {Error} If the input string is empty or does not contain any image candidate strings.
@example
```ts
import parseSrcset from "@prettier/parse-srcset";
parseSrcset('elva-fairy-320w.jpg, elva-fairy-480w.jpg 1.5x, elva-fairy-640w.jpg 2x');
// output:
[
{ source: { value: 'elva-fairy-320w.jpg', startOffset: 0 } },
{
source: { value: 'elva-fairy-480w.jpg', startOffset: 21 },
density: { value: 1.5 }
},
{
source: { value: 'elva-fairy-640w.jpg', startOffset: 47 },
density: { value: 2 }
}
]
```
*/
export default function parseSrcset(input: string): Candidate[];