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

find-es-resources

v4.0.0

Published

Find resource files within JavaScript files

Downloads

7

Readme

find-es-resources

This project is meant to help assist you find resource files within parsed JavaScript. It currently has very limited support for syntactic structures where the resource files can be found. See the list below.

It also allows some optional basic scanning of HTML for scripts, images, and stylesheets, and for CSS URLs.

A main use case is to supply it to workbox-build so as to be able to build a service-worker which caches the files that your application fetches, etc.

Presently supported AST for detection

Because we wish to avoid grabbing strings which are not file resources, we need to whitelist the JavaScript structures where we can expect to find files (and we can't follow variables everywhere--literals are expected to be found at a predictable location).

The intent is to expand this gradually as we find a need ourselves. PRs are welcome (with tests) for supporting other types of structures.

You should just need to add a method to src/queries.js.

  • fetch (e.g., for polyglot usage, ala node-fetch) - Literals within an array directly supplied to a map call which returns the result of a fetch call:
await Promise.all([
  './test1.json',
  './test2.json'
].map((path) => {
  return fetch(path);
}));

Install

npm i find-es-resources

API

import {findESResources} from 'find-es-resources';

const arrayOfFileStrings = await findESResources({
  // File as a string path
  input: filePath,
  // See the `es-file-traverse` package:
  //  https://github.com/brettz9/es-file-traverse
  // Can be an empty object
  esFileTraverseOptions,

  // Point to a CJS file exporting an object with string selectors as keys
  //   to functions which accept a node and return the string resources.
  queryOptions: {
    queryModule: moduleString
  }
});

// Module pointed to by `moduleString`:
const queries = {
  'an > AST > Selector' (node) {
    return getResourceStringsOutOfNode(node);
  },
  'another AST Selector' (node) {
    return getResourceStringsAlso(node);
  }
};
export default queries;

CLI Usage

doc-includes/cli.svg

See also

Changelog

The changelog can be found on CHANGES.md.

Authors and license

Brett Zamir and contributors.

MIT License, see the included LICENSE-MIT.tx file.