Skip to content

Commit

Permalink
Update examples to not combine desity and width
Browse files Browse the repository at this point in the history
Hey, thanks for making this library!

sindresorhus#6 updated the codebase to not allow density and width when parsing. (Although, amusingly, it does still allow it when stringifying - kind of the opposite of the robustness principle.)

This updates the readme to match so that the examples are correct and parse-able.

On a related note, would you be interested in another PR to make stringifying more strict? Also, what about a not-strict mode that does it's best and doesn't throw errors? (It would be handy for my use-case. For the moment I'm just wrapping this in a try/catch and using the original value if it throws.)
  • Loading branch information
nfriedly authored May 5, 2021
1 parent 2c153e4 commit e8979d9
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ How an image with `srcset` might look like:
```html
<img alt="The Breakfast Combo"
src="banner.jpg"
srcset="banner-HD.jpg 2x, banner-phone.jpg 100w, banner-phone-HD.jpg 100w 2x">
srcset="banner-HD.jpg 2x, banner-phone.jpg 100w">
```

Then have some fun with it:
Expand All @@ -41,15 +41,14 @@ console.log(parsed);
*/

parsed.push({
url: 'banner-phone-HD.jpg',
width: 100,
density: 2
url: 'banner-super-HD.jpg',
density: 3
});

const stringified = srcset.stringify(parsed);
console.log(stringified);
/*
banner-HD.jpg 2x, banner-phone.jpg 100w, banner-phone-HD.jpg 100w 2x
banner-HD.jpg 2x, banner-phone.jpg 100w, banner-super-HD.jpg 3x
*/
```

Expand Down

0 comments on commit e8979d9

Please sign in to comment.