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

fetch-page-assets

v1.1.8

Published

A versatile Node.js module for extracting assets (such as CSS files, JavaScript files, fonts, and images) from HTML content or URL.

Downloads

49

Readme

Fetch Page Assets

Overview

The extractAssets function extracts assets (such as images, fonts, stylesheets, and scripts) from a given URL or HTML string and saves them to a specified directory, while keeping the same folder structure. Unlike tools like wget, this function can handle more complex URLs, including those with query strings.

Installation

Ensure you have Node.js installed on your machine. Then, you can install the required dependencies using npm:

npm install fetch-page-assets

Usage

The extractAssets function takes two parameters:

input: Can be either a URL or an HTML string.

options: An optional object with arguments that allow you to further customize the behavior. See below for more details.

| Name | Description | Type | Default | | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ------- | ----------------- | | basePath | Defines the local directory where the program will save assets to. | String | Current Directory | | source | If an HTML string is provided instead of a URL as an input, define a source url where relative paths will resolve to. | String | none | | saveFile | Optionally, save the modified HTML to the root folder, given by the basePath option. | Boolean | true | | protocol | If a protocol is not present, this option will let you choose whether to use http or https. | String | https | | parseCss | This option is may help if you want to parse any urls from parsed css files. Useful if the source contains background images or fonts. | Boolean | true | | maxRetryAttempts | Defines how many attempts the program should retry in case of network errors. | Int | 3 | | retryDelay | Defines how long the program will halt in milliseconds in case of network errors. | Int | 1000 | | verbose | If sets to false, this option will silent the logs. | Boolean | true |

// Import the library.
import extractAssets from 'fetch-page-assets';

// Option 1: Pass an HTML string with any options as an object parameter.
const html = extractAssets('<img src="https://google.com/img/logo.png"/>', {});

console.log(html);
// Outputs '<img src="img/logo.png"/>'


// Option 2: Pass the source URL as the only argument.
extractAssets('https://example.com');

License

This project is licensed under the MIT License.

How to Contribute

Contributions are welcome! To contribute, follow these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Make your changes.
  4. Commit your changes (git commit -am 'Add new feature').
  5. Push to the branch (git push origin feature-branch).
  6. Open a Pull Request.

For any questions or suggestions, feel free to open an issue in the repository.