Gathering detailed insights and metrics for @mapbox/appropriate-images-react
Gathering detailed insights and metrics for @mapbox/appropriate-images-react
Gathering detailed insights and metrics for @mapbox/appropriate-images-react
Gathering detailed insights and metrics for @mapbox/appropriate-images-react
Given an appropriate-images configuration, render the appropriate size variant of an image
npm install @mapbox/appropriate-images-react
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
13 Stars
45 Commits
4 Forks
105 Watchers
1 Branches
613 Contributors
Updated on Apr 12, 2024
Latest Version
2.3.0
Package Id
@mapbox/appropriate-images-react@2.3.0
Unpacked Size
15.02 kB
Size
5.32 kB
File Count
5
NPM Version
9.6.6
Node Version
18.15.0
Published on
Nov 02, 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
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.
If you like React, you'll want to use them with React.
You'll need to determine which variant of the image to load — that is, which size, and whether to load the .webp
version or not.
This module does that.
Here are the steps it takes.
(If you aren't using React but want to use your appropriate-images in the browser, check out appropriate-images-get-url).
scopeAppropriateImage(imageConfig, [options])
A named import for ES2015 modules, or a property on the CommonJS module.
1import { scopeAppropriateImage } from '@mapbox/appropriate-images-react'; 2// OR 3const scopeAppropriateImage = require('@mapbox/appropriate-images-react').scopeAppropriateImage;
Returns an AppropriateImage component scoped according to your appropriate-images configuration and options.
Type Object
.
Required.
Your appropriate-images configuration. Use the same configuration at run time, in the browser, as you do at build time, when generating the resized, optimized images.
Type: (originalUrl: string) => string
.
Default: x => x
.
If you want to transform the URL in some way, use this function.
One use-case is to take advantage of Webpack's augmented require()
to get the URL that Webpack creates — if, for example, you're adding a hash to the end of files loaded with Webpack's file-loader.
For example:
1import { scopeAppropriateImage } from '@mapbox/appropriate-images-react';
2const AppropriateImage = scopeAppropriateImage(myImageConfig, {
3 transformUrl: url => require(`/my/image/directory/${url}`)
4});
Type: number
.
Default: 1.3
.
See the same option for appropriate-images-get-url.
This is the component that is returned by scopeAppropriateImage
.
It can render your image in two ways:
<img>
.
Usually you'll do this.<div>
.
This can be handy in situations when you want to take advantage of powerful CSS background properties like background-size
and background-position
.All props you pass other than those documented below are applied directly to the rendered element (e.g. alt
, id
, data-*
, aria-*
).
Type string
.
Required.
The id of the image to render. Must correspond with a key in the appropriate-images configuration.
Type boolean
.
Default: false
.
By default, an <img>
element is rendered.
If this option is true
, you instead get a <div>
, absolutely positioned to fill its container, whose background-image
will be the appropriate image.
Type string
.
Default: 'center center'
.
Only meaningful if background={true}
.
Any background-position
value will do.
Type string
.
Default: 'cover'
.
Only meaningful if background={true}
.
Any background-size
value will do.
1const React = require('react'); 2const { scopeAppropriateImage } = require('@mapbox/appropriate-images-react'); 3const imageConfig = require('./path/to/my/image-config.js'); 4 5const AppropriateImage = scopeAppropriateImage(imageConfig); 6 7class MyPage extends React.PureComponent { 8 render() { 9 return ( 10 <div> 11 <p>An appropriate image will be loaded below:</p> 12 <AppropriateImage imageId="bear" style={{ maxWidth: '100%' }}/> 13 </div> 14 ); 15 } 16}
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
6 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