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

@asset-pipe/node-client

v1.0.0-alpha.2

Published

Node.js client for Asset Pipe

Downloads

4

Readme

Asset Pipe Node Client

The Asset Pipe Node.js client facilitates switching between local and production assets in Node.js apps based on values provided by an assets.json metafile.

Install

npm install @asset-pipe/node-client

Basic usage

include the client in your node apps

const Client = require('@asset-pipe/node-client');

in production mode the client will build an object pointing to production assets

The client will read your local assets.json file and build a object based on the values found therein.

const client = new Client();

// client.js will be an object of the form:
/* 
[
    { type: 'module', value: 'http://<asset server>/finn/js/my-app/1.0.0/main/index.js' },
    { type: 'iife', value: 'http://<asset server>/finn/js/my-app/1.0.0/ie11/index.js' },
]
*/

// client.css will be an object of the form:
/*
[
    { type: 'text/css', value: 'http://<asset server>/finn/css/my-app/1.0.0/index.css' }
]
*/

In both cases, each object in the array also has a toHTML() method that can be used to render out the appropriate HTML tag for the object.

const client = new Client();

client.js[0].toHTML();
// <script type="module" src="http://<asset server>/finn/js/my-app/1.0.0/main/index.js"><script>

client.js[1].toHTML();
// <script src="http://<asset server>/finn/js/my-app/1.0.0/ie11/index.js"><script>

client.css[0].toHTML();
// <link rel="stylesheet" type="text/css" href="http://<asset server>/finn/js/my-app/1.0.0/main/index.css">

in development mode the client will build an object pointing to development assets provided

const client = new Client({ js: '/assets/scripts.js', css: '/assets/styles.css' development: true });

// client.js will be an array of the form [{ type: 'module', value: '/assets/script.js' }]
// client.css will be an array of the form [{ type: 'text/css', value: '/assets/styles.css' }]

It's up to you to make sure that these assets are available to the app. In an express app you might use express-static to serve the assets with your app

Example: Express app using express-static

app.use('/assets', express.static('assets'));

const client = new Client({
    js: '/assets/scripts.js',
    css: '/assets/styles.css'
    development: true
});

Or you might use webpack or some other bundling system that can also serve the assets in development mode for you (remembering to set appropriate CORS headers)

Example: Setup when using Webpack dev server

const client = new Client({
    js: 'http://localhost:8080/scripts.bundle.js',
    development: true,
});

Or you might just use an HTTP server to serve your files on a port such as 4000. (remembering to set appropriate CORS headers)

Example: Setup when using a standalone web server

const client = new Client({
    js: 'http://localhost:4000/assets/scripts.js',
    css: 'http://localhost:4000/assets/styles.css'
    development: true
});

API

Client

new Client(opts);

Creates a new instance of the client. Created instance have the accessor properties .js and .css as described below.

opts

| name | description | type | default | required | | ----------- | -------------------------------------------------------------------------------------------------------------------------------------- | --------------- | --------------- | -------- | | development | switches the client between development and non development modes | boolean | false | false | | path | modifies the default path to the assets.json meta file | string | ./assets.json | false | | js | URL or path to location of JavaScript assets to be used in development mode. An object can also be passed for additional configuration | string|object | | false | | css | URL or path to location of CSS assets to be used in development mode. An object can also be passed for additional configuration | string|object | | false |

Example

const client = new Client({
    path: './some/other/assets.json',
    development: true,
    js: '/assets/scripts.js',
    css: '/assets/styles.css',
});

Example

const client = new Client({
    development: true,
    js: { value: '/assets/scripts.js', type: 'module', async: true },
    css: { value: '/assets/styles.css', type: 'text/css' },
});

client.js

Returns an array of JavaScript asset objects for the given mode (development or non development) based on values in assets.json As asset object can be serialized using JSON.stringify or converted into an HTML script tag using the method .toHTML()

Examples

client.js; // [{ type: 'module', value: 'http://<asset server>/finn/js/my-app/1.0.0/index.js' }]
client.js[0].toHTML(); // <script type="module" src="http://<asset server>/finn/js/my-app/1.0.0/index.js">

client.css

Returns an array of CSS asset objects for the given mode (development or non development) based on values in assets.json As asset object can be serialized using JSON.stringify or converted into an HTML link tag using the method .toHTML()

Example

client.css; // [{ type: 'default', value: 'http://<asset server>/finn/css/my-app/1.0.0/index.css' }]
client.css[0].toHTML(); // <link type="text/stylesheet" rel="stylesheet" href="http://<asset server>/finn/css/my-app/1.0.0/index.css">

client.scripts

Returns JavaScript script tag markup for the given mode (development or non development) based on values in assets.json

Examples

client.scripts;
// <script src="http://localhost:4001/my-org/pkg/my-app-name/1.0.0/main/index.js" type="module"></script>
// <script src="http://localhost:4001/my-org/pkg/my-app-name/1.0.0/ie11/index.js"></script>`

client.styles

Returns CSS link tag markup for the given mode (development or non development) based on values in assets.json

Examples

client.styles;
// <link href="http://localhost:4001/my-org/pkg/my-app-name/1.0.0/main/index.css" type="text/css" rel="stylesheet">