@technically/img-src-placeholder
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

img-src-placeholder

Micro library to generate data-uri placeholder images of a given size.

Features

  • Blazing fast
  • Zero dependencies
  • Ultra-small: less than 1KB (minified)
  • Works in browser
  • Works in server-side node
  • Typescript type definitions

Usage

Plain JS:

import { placeholder } from '@technically/img-src-placeholder';

document.querySelectorAll('img').forEach(function (img) {
  img.src = placeholder(100, 100); // placeholder returns a data-uri string ready-to-use as a `src` attribute. 
});

React:

import { placeholder } from '@technically/img-src-placeholder';

interface Props {
    width: number;
    height: number;
}

export function ImagePlaceholder({ width, height }: Props) {
  return <img src={placeholder(width, height)} />;
}

Credits

Created with ❤️ by Ivan Voskoboinyk 🇺🇦

Package Sidebar

Install

npm i @technically/img-src-placeholder

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

7.51 kB

Total Files

7

Last publish

Collaborators

  • e1npm