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

babel-plugin-imagehelper

v1.1.1

Published

Load image information (width, height, aspectRatio, path) into an assocative array for use in your app.

Downloads

13

Readme

babel-plugin-imagehelper

Load image information (width, height, aspectRatio and path) into variable so that all the information is accessible to your app.

Installation

$ npm install babel-plugin-imagehelper

Usage

Add the plugin to .babelrc. Specify the path to the image directory with path in options.

["babel-plugin-imagehelper", {
  path: path.join(__dirname, '/img'),
  httpPath: '/static',
  limit: 10000,
  hashLength: 8
  props: ['src', 'absPath', 'ext', 'width', 'widthPx', 'height', 'heightPx', 'aspectRatio', 'hash', 'data']
}]

In the source code any variable with the string value __babelPluginImageHelper__ will be replace with an associative array with information about the images in the directory your specified for the plugin in .babelrc.

Options

  • path: (required) Path to directory with images
  • httpPath: HTTP path to the image for the src attribute in HTML img tag
  • limit: Byte limit to inline files as Data URL (inspired by webpack url-loader). Set to 0 to disable.
  • hashLength: md5sum length for cache busting
  • props: Selects which properties that will be included for each image. If omitted, all the properties will be included.

Example

Say you have 4 image files in the ./static/i directory:

  • img1.jpg
  • img2.png
  • img3.svg
  • subdir/img.jpg

And a file in your source code named images.js:

// images.js
// Transformed by babel-plugin-imagehelper
export const images = '__babelPluginImageHelper__'

Using the plugin images.js becomes:

// images.js
export default {
  'img.jpg': {
    path: "/Users/erikfossvold/Development/npm_pkgs/babel-plugin-imagehelper/img/img.jpg",
    ext: ".jpg",
    src: "/static/img.jpg",
    width: 1200,
    widthPx: "1200px",
    height: 630,
    heightPx: "630px",
    aspectRatio: 0.525,
    hash: "8556baa0"
  },
  'img.png': {
    path: "/Users/erikfossvold/Development/npm_pkgs/babel-plugin-imagehelper/img/img.png",
    ext: ".png",
    src: "/static/img.png",
    width: 455,
    widthPx: "455px",
    height: 454,
    heightPx: "454px",
    aspectRatio: 0.9978021978021978,
    hash: "80050422"
  },
  'img.svg': {
    path: "/Users/erikfossvold/Development/npm_pkgs/babel-plugin-imagehelper/img/img.svg",
    ext: ".svg",
    src: "/static/img.svg",
    width: 580,
    widthPx: "580px",
    height: 580,
    heightPx: "580px",
    aspectRatio: 1,
    hash: "f1472623",
    data: "PHN2ZyB2aWV3Qm94PSIwIDAgNTgwIDU4MCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+PGRlZnM+PHJlY3QgaWQ9ImEiIGhlaWdodD0iNTgwIiByeD0iMjkwIiB3aWR0aD0iNTgwIi8+PG1hc2sgaWQ9ImIiIGZpbGw9IiNmZmYiPjx1c2UgZmlsbD0iI2ZmZiIgZmlsbC1ydWxlPSJldmVub2RkIiB4bGluazpocmVmPSIjYSIvPjwvbWFzaz48L2RlZnM+PGcgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIj48dXNlIGZpbGw9IiM0ZTZmODIiIHhsaW5rOmhyZWY9IiNh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hc2s9InVybCgjYikiPjx0c3BhbiB4PSIxNjAiIHk9IjM0OSI+NDA0PC90c3Bhbj48L3RleHQ+PHRleHQgZmlsbD0iIzRlNmY4MiIgZm9udC1mYW1pbHk9Ik9wZW5TYW5zLVNlbWlib2xkLCBPcGVuIFNhbnMiIGZvbnQtc2l6ZT0iMTgiIGZvbnQtd2VpZ2h0PSI1MDAiIG1hc2s9InVybCgjYikiPjx0c3BhbiB4PSIxNjAiIHk9IjIyNyI+UkVQT1JUPC90c3Bhbj48L3RleHQ+PC9nPjwvc3ZnPg=="
  },
  'subdir/img.jpg': {
    path: "/Users/erikfossvold/Development/npm_pkgs/babel-plugin-imagehelper/img/subdir/img.jpg",
    ext: ".jpg",
    src: "/static/subdir/img.jpg",
    width: 1200,
    widthPx: "1200px",
    height: 630,
    heightPx: "630px",
    aspectRatio: 0.525,
    hash: "8556baa0"
  }
};