-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.d.ts
70 lines (56 loc) · 1.64 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
export interface SrcSetDefinition {
readonly url: string;
readonly width?: number;
readonly density?: number;
}
export interface Options {
/**
When strict mode is enabled, errors will be thrown on invalid input.
When disabled, a best effort will be made to handle invalid input and no errors will be thrown. The output may be invalid.
@default false
*/
readonly strict?: boolean;
}
/**
Parse the HTML `<img>` [srcset](http://mobile.smashingmagazine.com/2013/08/21/webkit-implements-srcset-and-why-its-a-good-thing/) attribute.
Accepts a “srcset” string and returns an array of objects with the possible properties: `url` (always), `width`, `density`, and `height`.
@param srcset - A “srcset” string.
@example
```
import {parseSrcset} from 'srcset';
console.log(parseSrcset('banner-HD.jpg 2x, banner-phone.jpg 100w'));
// [
// {
// url: 'banner-HD.jpg',
// density: 2
// },
// {
// url: 'banner-phone.jpg',
// width: 100
// }
// ]
```
*/
export function parseSrcset(srcset: string, options?: Options): SrcSetDefinition[];
/**
Stringify `SrcSetDefinition`s.
@param SrcSetDefinitions - Each object should have a `url` field and may have either `width` or `density`. When the `strict` option is `true`, only `width` or `density` is accepted.
@returns A “srcset” string.
@example
```
import {stringifySrcset} from 'srcset';
const stringified = stringifySrcset([
{
url: 'banner-HD.jpg',
density: 2
},
{
url: 'banner-phone.jpg',
width: 100
}
]);
console.log(stringified);
// banner-HD.jpg 2x, banner-phone.jpg 100w
```
*/
export function stringifySrcset(srcSetDefinitions: readonly SrcSetDefinition[], options?: Options): string;