Gathering detailed insights and metrics for @mapbox/appropriate-images-get-url
Gathering detailed insights and metrics for @mapbox/appropriate-images-get-url
Gathering detailed insights and metrics for @mapbox/appropriate-images-get-url
Gathering detailed insights and metrics for @mapbox/appropriate-images-get-url
Given an appropriate-images configuration, get the URL of the optimized image appropriate for a situation
npm install @mapbox/appropriate-images-get-url
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
4 Stars
35 Commits
3 Forks
110 Watchers
2 Branches
612 Contributors
Updated on Apr 12, 2024
Latest Version
1.2.0
Package Id
@mapbox/appropriate-images-get-url@1.2.0
Unpacked Size
16.49 kB
Size
5.70 kB
File Count
16
NPM Version
9.8.1
Node Version
18.18.2
Published on
Oct 31, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
5
Use in combination with appropriate-images.
After you've generated resized, optimized images with appropriate-images, you'll want to use them in the browser.
In order to do that, you'll need to determine which variant of the image to load — which size, and whether to load the .webp
version or not.
That's what this module is for.
This is how the image configuration used by appropriate-images can be reused in the browser to select the appropriate image to load at runtime.
If you're thinking about using this function in combination with React, check out appropriate-images-react.
npm install @mapbox/appropriate-images-get-url
getAppropriateImageUrl(options)
Uses the image id, image configuration, and width value to figure out the URL of the image variant that should be loaded. Returns a URL for the appropriate image variant that you created with appropriate-images.
The returned URL will account for
webp
.The image variant that is selected will be the narrowest variant that is at least as wide as the available width, or else, if the available width exceeds all sizes, the widest variant.
Type: string
.
Required.
Id of the image to be loaded. Image ids correspond to keys in your appropriate-images configuration.
Type: Object
.
Required.
Your appropriate-images configuration object.
Type number
.
Default: Infinity
.
Not technically required, but you should provide it. This is the width available to the image. This is key to figuring out which size variant to load.
Type number
.
Default: 1.3
.
The ratio at which you want to consider a screen "high resolution".
If the browser judges that the screen is high resolution, according to this ratio, the availableWidth
provided will be multiplied by this ratio when determining which size variant to load.
This means that in a 300px
-wide space but on a Retina screen, the image at least 600px
wide will be loaded.
Type string
.
If provided, this will be prepended to the URL.
1const getAppropriateImageUrl = require('@mapbox/appropriate-images-get-url'); 2 3const imageConfig = { 4 bear: { 5 basename: 'bear.png', 6 sizes: [{ width: 300 }, { width: 600 }] 7 }, 8 montaraz: { 9 basename: 'montaraz.jpg', 10 sizes: [ 11 { width: 600, height: 500 }, 12 { width: 1200, height: 800, crop: 'north' }, 13 { width: 200, height: 200, crop: 'southeast' }, 14 ] 15 } 16}; 17 18getAppropriateImageUrl({ imageConfig, imageId: 'bear', width: 280 }); 19// On a regular-resolution screen: bear-300.png or webp 20// On a high-resolution screen: bear-600.png or webp 21 22getAppropriateImageUrl({ imageConfig, imageId: 'bear', width: 550 }); 23// bear-600.png or webp 24 25getAppropriateImageUrl({ imageConfig, imageId: 'bear', width: 800 }); 26// bear-600.png or webp 27 28getAppropriateImageUrl({ 29 imageConfig, 30 imageId: 'montaraz', 31 width: 400, 32 imageDirectory: 'img/optimized/' 33}); 34// On a regular-resolution screen: img/optimized/montaraz-600x500.jpg or webp 35// On a high-resolution screen: img/optimized/montaraz-1200x800.jpg or webp
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
branch protection is not maximal on development and all release branches
Details
Reason
5 existing vulnerabilities detected
Details
Reason
Found 1/15 approved changesets -- score normalized to 0
Reason
project is archived
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
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 More