parse-srcset is a JavaScript parser for the HTML5 `srcset` attribute, designed to be spec-conformant with the WHATWG reference algorithm. It takes a `srcset` string as input and returns an array of objects, each representing a potential image source with properties like `url`, `width`, `height`, and `density`. The package is at version 1.0.2, with its last known update around 10 years ago, indicating it is no longer actively maintained. While it provides a foundational implementation for `srcset` parsing, developers seeking current specifications, ongoing support, or additional features like stringification should consider more recently updated alternatives. Its release cadence was sporadic, reflecting its early development and subsequent abandonment, distinguishing it from modern, regularly updated libraries in this domain. The library relies on an extensive test suite to ensure conformance to the W3C srcset checker, a strong point at the time of its development.
npm install parse-srcsetVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to parse a standard HTML `srcset` string using `require()` and then iterates through the resulting array of image source objects, logging their URLs and descriptors (density or width).
For new projects or if encountering parsing issues with modern srcset attributes, consider using actively maintained alternatives like `@prettier/parse-srcset` or `srcset`.
In Node.js ES Module environments, use `const parseSrcset = require('parse-srcset');` or rely on bundlers like Webpack/Rollup to handle CJS-ESM interoperability. For pure ESM, prefer the `@prettier/parse-srcset` fork or the `srcset` package which offer native ESM support.Migrate to `srcset` (e.g., `npm install srcset`) or `@prettier/parse-srcset` (e.g., `npm install @prettier/parse-srcset`) for TypeScript support, active development, and potentially better performance/spec compliance.
Thoroughly test parsing results with various `srcset` inputs, especially those involving modern descriptors or edge cases. Consider using a more actively maintained library for guaranteed spec compliance.
Change the import statement to `const parseSrcset = require('parse-srcset');` in Node.js environments. If using a bundler, ensure it is configured to correctly handle CJS-ESM interoperability. For new projects in ESM, use `@prettier/parse-srcset` or `srcset`.The `parse-srcset` package is CJS. Ensure your environment allows `require()` or use a bundler. For pure ESM projects, migrate to `@prettier/parse-srcset` or `srcset` which provide ESM compatibility.
Verify the `srcset` string against the WHATWG HTML specification for `srcset`. If the syntax is valid according to current specs, the parser itself is outdated. Upgrade to a modern `srcset` parsing library like `@prettier/parse-srcset` or `srcset` which are actively maintained and more likely to be spec-compliant.
No dependency data recorded yet.