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

@ayang4114/load_assets

v0.1.1

Published

Generates a JavaScript file that loads all files via 'require' in a given directory. This is stored as an exported object.

Downloads

5

Readme

load_assets

A command that generates a JavaScript file which contains an object that maps to loaded assets from a directory, including static images files, using require(...). This was built to support writing many imports/require statements for bundlers that load static assets/resources like webpack.

Install

npm install -g @ayang4114/load_assets

Usage

On the command line, execute the following command

load_assets <directory_of_assets>

Flags

Any arguments passed without a flag is treated as an argument for the --input flag, i.e. it treated as the input directory.

|Flag|Description|Default |-------------|---|---| |--input | The path to the directory to be converted into an asset file. | None |--output | The output path name of the converted asset file | assets.js or assets.ts |--targetLang| The target language of the output asset file: either 'ts' or 'js' | 'js' |--indents | The number of indents in output file. | 2 |--excludeExt| A space-separated sequence of all filetype extensions to ignore. | None |--includeExt| A space-separated sequence of all filetype extensions to include. | None

Supported Type Extensions

By default, all files with the extensions jpg, jpeg, png, and gif are included when traversing through the assets directory. These files can be ignored by adding the unwanted extensions as arguments in --excludeExt.

Example

Consider the following tree:

assets
├── moon.png
├── sun.png
├── nested_assets_1
│   ├── moon.jpg
│   └── sun.jpg
└── nested_assets_2
    ├── moon.jpg
    ├── nested_assets
    │   ├── moon.jpg
    │   └── sun.jpg
    └── sun.jpg

Then, load_assets assets will produce the following output in assets.js:

module.asset = {
  jpg: {
    "nested_assets_1": {
      "moon": require("./assets/nested_assets_1/moon.jpg"),
      "sun": require("./assets/nested_assets_1/sun.jpg"),
    },
    "nested_assets_2": {
      "moon": require("./assets/nested_assets_2/moon.jpg"),
      "nested_assets": {
        "moon": require("./assets/nested_assets_2/nested_assets/moon.jpg"),
        "sun": require("./assets/nested_assets_2/nested_assets/sun.jpg"),
      },
      "sun": require("./assets/nested_assets_2/sun.jpg"),
    },
  },
  png: {
    "moon": require("./assets/moon.png"),
    "sun": require("./assets/sun.png"),
  }
};

Contributing

Feel free to add issues or suggestions in the repository.

You can also make PRs:

  1. Fork the repository.
  2. Create a feature branch in the forked repository.
  3. Push changes to the feature branch.
  4. Submit a PR request.

License

ISC License