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

@insulo/media-optimizer

v0.1.6

Published

Optimize your media assets before publishing - save storage, speed up performance, make your customers happier!

Downloads

6

Readme

Insulo: Media Optimizer

Optimize your media assets before publishing - save storage, speed up performance, make your customers happier!

Including a file watcher for local development, only re-optimizes changed files, currently doesn't delete files when source files are deleted.

Handler

For different file type support install and register needed handler.

  • dynamic: generic copy of files

    npm i --save @insulo/media-optimizer-handler-dynamic

    const handlerConfig = {
        dynamic: {
            files: ['**/*.{pdf,gif}']
        }
    };
  • gif: optimize animated and non-animated gif with gifsicle future, not implemented

  • handbrake: optimize video files with Handbrake

    npm i --save @insulo/media-optimizer-handler-handbrake

    const handlerConfig = {
        handbrake: {
            // uses handbrake, must be installed as peer dep. on linux
            optimize: true,
            // framerate, 15 for most web
            rate: 15,
            // high no. = low quality
            quality: 24.0,
            // mp4, avi and more https://handbrake.fr
            files: ['**/*.mp4']
        }
    };
  • image-transform: rotate, resize, transform different image types with sharp future, not implemented

    npm i --save @insulo/media-optimizer-handler-image-transform

    const handlerConfig = {
        task1: {handler:()=>{}},
        task2: {handler:()=>{}}
    };
  • jpg: optimize jpg images with mozjpeg

    npm i --save @insulo/media-optimizer-handler-jpg

    const handlerConfig = {
        jpg: {
            quality: 80,
            progressive: true,
            files: ['**/*.{jpg,jpeg}']
        }
    };
  • png: optimize png images with pngquant

    npm i --save @insulo/media-optimizer-handler-png

    const handlerConfig = {
        png: {
            quality: 80,
            files: ['**/*.png']
        }
    };
  • svg: optimize svg files with svgo

    npm i --save @insulo/media-optimizer-handler-dynamic

    const handlerConfig = {
        svg: {
            removeViewBox: false,
            files: ['**/*.svg']
        }
    };

Example

const {MediaOptimizer} = require('@insulo/media-optimizer');

// add default handler functions, must be activated through a config for loading during runtime
MediaOptimizer.constructor.handler_default = {
    png: () => require('@insulo/media-optimizer-handler-png'),
    jpg: () => require('@insulo/media-optimizer-handler-jpg'),
    svg: () => require('@insulo/media-optimizer-handler-svg'),
    handbrake: () => require('@insulo/media-optimizer-handler-handbrake'),
    dynamic: () => require('@insulo/media-optimizer-handler-dynamic'),
    customType: () => require('your-package/customType'),
};

const handlerConfig = {
    png: { /* include config */ },
    jpg: {
        /* include config */ 
        // overwrite default handler
        handler: require('your-package/customJpg')
    },
    svg: { /* include config */ },
    handbrake: { /* include config */ },
    dynamic: { /* include config */ },
    customType: { /* include config */ },
};

let watch = true;

const src = __dirname + '/src';
const build = __dirname + '/build';

let optimizer = new MediaOptimizer(watch);

// activate handlers with handlerConfig
for(let type in handlerConfig) {
    if(option.hasOwnProperty(type)) {
        optimizer.addHandler(type, option[type]);
    }
}

// trigger execution
optimizer.run(src, build).then(res => {
    
});

Example Custom Handler

this.option contains the used handlerConfig

/**
 * @type {HandlerBase}
 */
const HandlerBase = require('@insulo/media-optimizer/lib/HandlerBase');

class HandlerCustom extends HandlerBase {
    run() {
        // inline handle dependency load for using `option` provided by handler for setup
        const executionHandler = new SomePlugin(this.option);
       
        // run the actual thing wrapped in logger, registers it on watcher and everything needed
        return super.run_internal((on_finish => {
            // your actual async thing
            executionHandler.doingStuff((err, data) => {
                if(err) {
                    throw err;
                }
                // important to call with existing errors
                on_finish(err);
            });
        }));
    }
}

// Existing variables, from HandlerBase filled on construct
/**
 * Root of `src` folder, will be used to get the pure name from an full src path
 * @type string
 */
HandlerCustom.root
/**
 * Full path to one file
 * @type string
 */
HandlerCustom.src
/**
 * Path to build directory
 * @type string
 */
HandlerCustom.build
/**
 * Options pushed in for the specific handler type
 * @type {Object}
 */
HandlerCustom.option
/**
 * Relative path to an file, added to `build` is absolute path to `dist` and added to `root` is absolute path to `src`
 * @type {string}
 */
HandlerCustom.name
/**
 * Absolute path to the distribution target
 * @type string
 */
HandlerCustom.dist

/**
 *
 * @type {HandlerCustom}
 */
module.exports = HandlerCustom;

Licence

This project is free software distributed under the terms of two licences, the CeCILL-C and the GNU Lesser General Public License. You can use, modify and/ or redistribute the software under the terms of CeCILL-C (v1) for Europe or GNU LGPL (v3) for the rest of the world.

This file and the LICENCE.* files need to be distributed and not changed when distributing. For more informations on the licences which are applied read: LICENCE.md

Copyright

2018 | bemit UG (haftungsbeschränkt) - [email protected]
Author: Michael Becker - [email protected]