Installations
npm install srcset
Developer
sindresorhus
Developer Guide
Module System
ESM
Min. Node Version
^12.20.0 || ^14.13.1 || >=16.0.0
Typescript Support
Yes
Node Version
20.11.0
NPM Version
9.2.0
Statistics
138 Stars
31 Commits
16 Forks
7 Watching
1 Branches
7 Contributors
Updated on 11 Nov 2024
Languages
JavaScript (95.75%)
TypeScript (4.25%)
Total Downloads
Cumulative downloads
Total Downloads
174,223,071
Last day
1.6%
156,215
Compared to previous day
Last week
9%
864,651
Compared to previous week
Last month
20.2%
3,528,414
Compared to previous month
Last year
62.2%
33,155,054
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
srcset
Parse and stringify the HTML
<img>
srcset attribute.
Can be useful if you're creating a build-tool.
Install
1npm install srcset
Usage
How an image with srcset
might look like:
1<img 2 alt="The Breakfast Combo" 3 src="banner.jpg" 4 srcset="banner-HD.jpg 2x, banner-phone.jpg 100w" 5>
Then have some fun with it:
1import {parseSrcset, stringifySrcset} from 'srcset'; 2 3const parsed = parseSrcset('banner-HD.jpg 2x, banner-phone.jpg 100w'); 4console.log(parsed); 5/* 6[ 7 { 8 url: 'banner-HD.jpg', 9 density: 2 10 }, 11 { 12 url: 'banner-phone.jpg', 13 width: 100 14 } 15] 16*/ 17 18parsed.push({ 19 url: 'banner-super-HD.jpg', 20 density: 3 21}); 22 23const stringified = stringifySrcset(parsed); 24console.log(stringified); 25/* 26banner-HD.jpg 2x, banner-phone.jpg 100w, banner-super-HD.jpg 3x 27*/
API
parseSrcset(string, options?)
Parse the HTML <img>
srcset attribute.
Accepts a “srcset” string and returns an array of objects with the possible properties: url
(always), width
, height
, and density
.
string
Type: string
A “srcset” string.
options
Type: object
strict
Type: boolean
Default: false
When 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.
stringifySrcset(SrcSetDefinitions, options?)
Stringify SrcSetDefinition
s. Accepts an array of SrcSetDefinition
objects and returns a “srcset” string.
srcsetDescriptors
Type: array
An 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.
options
Type: object
strict
Type: boolean
Default: false
Enable 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.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
- Info: security policy file detected: .github/security.md:1
- Info: Found linked content: .github/security.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: .github/security.md:1
- Info: Found text in security policy: .github/security.md:1
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
Found 8/30 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/srcset/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/srcset/main.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:22
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 8 are checked with a SAST tool
Score
4.2
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to srcset
parse-srcset
A spec-conformant JavaScript parser for the HTML5 srcset attribute
webpack-image-srcset-loader
Generate srcset string from image
@types/parse-srcset
TypeScript definitions for parse-srcset
@prettier/parse-srcset
A spec-conformant JavaScript parser for the HTML5 srcset attribute