npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

img-srcx

v1.0.0

Published

Tiny JSX helper function for high-DPI (Retina Display) images.

Downloads

2

Readme

Tiny JSX helper function for high-DPI (Retina Display) images.

394 bytes minified and gzipped for ESM (830 bytes for ES5).

Installation

npm install --save img-srcx
# or
yarn install img-srcx
# or
pnpm install img-srcx

If you’re using this in older runtimes, such as node 8, Internet Explorer, or Android before 4.4.4, you’ll need to use a URL polyfill. You may find Can I use URL? useful.

Example

import { srcx, type Scale } from "img-srcx";

function MyImageComponent({ src, forceScale }: { src: string; forceScale?: Scale; }) {
	return <img {...srcx(src, { forceScale })} />;
}

function Root() {
	return (
		<div>
			<MyImageComponent src="https://repo.chariz.com/CydiaIcon.png" />
			<MyImageComponent src="https://www.google.com/google.jpg" forceScale={1} />
			<MyImageComponent src="https://github.githubassets.com/favicons/favicon.svg" />
		</div>
	);
}

ReactDOM.render(
	<Root />,
	document.getElementById("root")
);

Yields the following rendered HTML:

<div>
	<img
		src="https://repo.chariz.com/CydiaIcon.png"
		srcSet="https://repo.chariz.com/[email protected] 2x,https://repo.chariz.com/[email protected] 3x">

	<img
		src="https://www.google.com/google.jpg">

	<img
		src="https://github.githubassets.com/favicons/favicon.svg">
</div>

Usage

srcx(src: string, options?: { scales?: Scale[], forceScale?: Scale }): { src: string; srcSet?: string }

Returns JSX properties for use on an <img> element. The src and srcSet attributes set as appropriate for the given parameters.

  • src: The URL of the image to be displayed. Will be passed through exactly as the src attribute, unless forceScale is set.
  • options: Optional object with the following properties:
    • scales: An array of image scales to use. Defaults to [1, 2, 3]. The lowest scale will be used as the src attribute, and the remainder will be used as the srcSet attribute, unless forceScale is set.
    • forceScale: The minimum scale to use. If set, the src attribute will be set to the URL matching the given scale, and the srcSet attribute will be set to the remaining scales above the given scale.

Paths ending in .svg will be returned as-is, without srcSet.

Scale

A type for indicating scale factors. This is defined to 1 | 2 | 3, matching the common scale factors for high-DPI images.

Credits

Developed by Chariz:

License

Licensed under the Apache License, version 2.0. Refer to LICENSE.md.