https://github.com/prettier/parse-srcset
A spec-conformant JavaScript parser for the HTML5 srcset attribute
https://github.com/prettier/parse-srcset
Last synced: 4 months ago
JSON representation
A spec-conformant JavaScript parser for the HTML5 srcset attribute
- Host: GitHub
- URL: https://github.com/prettier/parse-srcset
- Owner: prettier
- License: mit
- Created: 2020-11-02T10:50:06.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-07-07T05:58:13.000Z (almost 2 years ago)
- Last Synced: 2024-10-29T15:15:10.765Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 913 KB
- Stars: 9
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# @prettier/parse-srcset
This repository is a fork of https://github.com/albell/parse-srcset for [Prettier](https://github.com/prettier/prettier).
---
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).
## Installation
```bash
yarn add @prettier/parse-srcset
```## Usage
```js
import parseSrcset from "@prettier/parse-srcset";parseSrcset('elva-fairy-320w.jpg, elva-fairy-480w.jpg 1.5x, elva-fairy-640w.jpg 2x');
/*
[
{ 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 }
}
]
*/
```