{"name":"srcset","version":"5.0.1","description":"Parse and stringify the HTML `<img>` srcset attribute","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/srcset.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","types":"./index.d.ts","sideEffects":false,"engines":{"node":"^12.20.0 || ^14.13.1 || >=16.0.0"},"scripts":{"//test":"xo && ava && tsd","test":"ava && tsd"},"keywords":["html","attribute","image","img","src","parse","stringify","srcset","responsive","picture","element"],"devDependencies":{"ava":"^3.15.0","tsd":"^0.19.0","xo":"^0.46.4"},"gitHead":"ee8997211913601aed606b80a22ce21b31c9e324","bugs":{"url":"https://github.com/sindresorhus/srcset/issues"},"homepage":"https://github.com/sindresorhus/srcset#readme","_id":"srcset@5.0.1","_nodeVersion":"20.11.0","_npmVersion":"9.2.0","dist":{"integrity":"sha512-/P1UYbGfJVlxZag7aABNRrulEXAwCSDo7fklafOQrantuPTDmYgijJMks2zusPCVzgW9+4P69mq7w6pYuZpgxw==","shasum":"e660a728f195419e4afa95121099bc9efb7a1e36","tarball":"http://registry-npm.ywwl.com/srcset/download/srcset-5.0.1.tgz","fileCount":5,"unpackedSize":10558,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCzksVORHIO0UFy9Cc01VWGISX6tNvox4Pvrm+vFoDotwIgYTTngrAs1O/PYzl1HXeS8b89BdY/k6yJJzgIEKpgVL4="}],"size":3954,"noattachment":false,"key":"/srcset/-/srcset-5.0.1.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/srcset_5.0.1_1706532378807_0.4137589416649372"},"_hasShrinkwrap":false,"readme":"# srcset\n\n> Parse and stringify the HTML `<img>` [srcset](https://www.smashingmagazine.com/2013/08/webkit-implements-srcset-and-why-its-a-good-thing/) attribute.\n\nCan be useful if you're creating a build-tool.\n\n## Install\n\n```sh\nnpm install srcset\n```\n\n## Usage\n\nHow an image with `srcset` might look like:\n\n```html\n<img\n\talt=\"The Breakfast Combo\"\n\tsrc=\"banner.jpg\"\n\tsrcset=\"banner-HD.jpg 2x, banner-phone.jpg 100w\"\n>\n```\n\nThen have some fun with it:\n\n```js\nimport {parseSrcset, stringifySrcset} from 'srcset';\n\nconst parsed = parseSrcset('banner-HD.jpg 2x, banner-phone.jpg 100w');\nconsole.log(parsed);\n/*\n[\n\t{\n\t\turl: 'banner-HD.jpg',\n\t\tdensity: 2\n\t},\n\t{\n\t\turl: 'banner-phone.jpg',\n\t\twidth: 100\n\t}\n]\n*/\n\nparsed.push({\n\turl: 'banner-super-HD.jpg',\n\tdensity: 3\n});\n\nconst stringified = stringifySrcset(parsed);\nconsole.log(stringified);\n/*\nbanner-HD.jpg 2x, banner-phone.jpg 100w, banner-super-HD.jpg 3x\n*/\n```\n\n## API\n\n### parseSrcset(string, options?)\n\nParse the HTML `<img>` [srcset](http://mobile.smashingmagazine.com/2013/08/21/webkit-implements-srcset-and-why-its-a-good-thing/) attribute.\n\nAccepts a “srcset” string and returns an array of objects with the possible properties: `url` (always), `width`, `height`, and `density`.\n\n#### string\n\nType: `string`\n\nA “srcset” string.\n\n#### options\n\nType: `object`\n\n##### strict\n\nType: `boolean`\\\nDefault: `false`\n\nWhen enabled, an invalid “srcset” string will cause an error to be thrown. When disabled, a best effort will be made to parse the string, potentially resulting in invalid or nonsensical output.\n\n### stringifySrcset(SrcSetDefinitions, options?)\n\nStringify `SrcSetDefinition`s. Accepts an array of `SrcSetDefinition` objects and returns a “srcset” string.\n\n#### srcsetDescriptors\n\nType: `array`\n\nAn array of `SrcSetDefinition` objects. Each object should have a `url` field and may have `width`, `height` or `density` fields. When the `strict` option is `true`, only `width` or `density` is accepted.\n\n#### options\n\nType: `object`\n\n##### strict\n\nType: `boolean`\\\nDefault: `false`\n\nEnable or disable validation of the `SrcSetDefinition`'s. When true, invalid input will cause an error to be thrown. When false, a best effort will be made to stringify invalid input, likely resulting in invalid srcset value.\n","publish_time":1706532378972,"_cnpm_publish_time":1706532378972,"dist-tags":{"latest":"5.0.3"}}