srcset-parse
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

srcset-parse

An extra small srcset attribute parser compliant with the latest spec. Unlike srcset package, supports:

  • URLs that contain commas;
  • Zero or one descriptors per image definitions (like 2x or 100w, but not both!).

Example usage:

import parse from "srcset-parse";
 
/**
 * [
 *   { url: "hifi-cat.jpeg",  density: 3 },
 *   { url: "lowfi-cat.jpeg", width: 128 },
 * ]
 */
parse("hifi-cat.jpeg 3x, lowfi-cat.jpeg 128w");

Using with TypeScript

The library is written in TypeScript, so you can import types if needed:

import parse, { ImageCandidate } from "srcset-parse";
 
const result: ImageCandidate[] = parse("icon@2x.png 2x, icon.png 1x");

Platform support

This library is written according to the ES2015 standard. Make sure your platform supports it, or your project is configured to transpile external modules.

Readme

Keywords

none

Package Sidebar

Install

npm i srcset-parse

Weekly Downloads

888

Version

1.1.0

License

MIT

Unpacked Size

4.63 kB

Total Files

6

Last publish

Collaborators

  • molefrog