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

@putout/plugin-minify

v8.2.0

Published

๐ŸŠPutout plugin contains minifiers

Downloads

356

Readme

@putout/plugin-minify NPM version

๐ŸŠPutout plugin adds support of minifiers used in @putout/minify and minify.

Install

npm i @putout/plugin-putout -D

Rules

{
    "rules": {
        "minify/apply-ternary": "on",
        "minify/apply-template-literal": "on",
        "minify/convert-var-to-const": "on",
        "minify/convert-if-to-logical": "on",
        "minify/convert-strict-equal-to-equal": "on",
        "minify/convert-array-from-to-spread": "on",
        "minify/extract-body": "on",
        "minify/expand-bindings": "on",
        "minify/mangle-names": ["on", {
            "mangleClassNames": true
        }],
        "minify/merge-variables": "on",
        "minify/merge-loops": "on",
        "minify/remove-var-undefined": "on",
        "minify/remove-return-undefined": "on",
        "minify/simplify-floor": "on",
        "minify/shorten-names": "on",
        "minify/inline": "on",
        "minify/types": "on"
    }
}

apply-ternary

Check out in ๐ŸŠPutout Editor.

โŒ Example of incorrect code

if (a)
    b();
else
    c();

โœ… Example of correct code

a ? b() : c();

apply-template-literal

Not only short, but also fast:

// 34.795ms
for (let i = 0; i < 1_000_000; i++)
    String(i);

// 28.302ms
for (let i = 0; i < 1_000_000; i++)
    i.toString();

// 24.818ms
for (let i = 0; i < 1_000_000; i++)
    `${i}`;

โŒ Example of incorrect code

x.toString();
String(x);

โœ… Example of correct code

String(x);

convert-if-to-logical

Check out in ๐ŸŠPutout Editor.

โŒ Example of incorrect code

if (a)
    console.log('hello');

if (b) {
    console.log('hello');
    console.log('world');
}

if (a) {
    console.log(1);
    console.log(2);
} else {
    console.log(3);
    console.log(4);
}

โœ… Example of correct code

a && console.log('hello');

b && (console.log('hello'), console.log('world'));

a ? (console.log(1), console.log(2)) : (console.log(3), console.log(4));

convert-const-to-var

โŒ Example of incorrect code

const a = 5;

โœ… Example of correct code

var a = 5;

convert-strict-equal-to-equal

Check out in ๐ŸŠPutout Editor.

โŒ Example of incorrect code

a === b;

โœ… Example of correct code

a === b;

convert-array-from-to-spread

โŒ Example of incorrect code

Array
    .from(a)
    .map((x, i) => `${i}: ${x}`);

โœ… Example of correct code

[...a].map((x, i) => `${i}: ${x}`);

extract-body

Check out in ๐ŸŠPutout Editor.

โŒ Example of incorrect code

if (x)
    return;

const hello = () => {
    return 'world';
};

โœ… Example of correct code

if (x)
    return;

const hello = () => 'world';

expand-bindings

Check out in ๐ŸŠPutout Editor.

โŒ Example of incorrect code

const y = 'abc';
const x = y;
const fn = require(x);

const a = 5;
const b = a;
const c = b;

fn(c);

โœ… Example of correct code

require('abc')(5);

remove-var-undefined

Checkout in ๐ŸŠPutout Editor.

โŒ Example of incorrect code

var a = undefined;

โœ… Example of correct code

var a;

remove-return-undefined

โŒ Example of incorrect code

const fn = () => {
    if (a)
        return undefined;
    
    return undefined;
};

โœ… Example of correct code

const fn = () => {
    if (a)
        return;
};

mangle-names

Check out in ๐ŸŠPutout Editor.

โŒ Example of incorrect code

function generate() {
    const hello = 'hi';
    return hello;
}

โœ… Example of correct code

function generate() {
    const a = 'hi';
    return a;
}

When you want to preserve class names use

{
    "rules": {
        "minify/mangle-names": ["on", {
            "mangleClassNames": false
        }]
    }
}

In this case you will see:

โŒ Example of incorrect code

class Hello {
    world() {
        const hello = 'hello';
        return hello;
    }
}

โœ… Example of correct code

class Hello {
    world() {
        const a = 'hello';
        return a;
    }
}

merge-variables

Check out in ๐ŸŠPutout Editor.

โŒ Example of incorrect code

var a, b;

โœ… Example of correct code

var a;
var b;

merge-loops

Check out in ๐ŸŠPutout Editor.

โŒ Example of incorrect code

for (const aa of a)
    d.push(aa);

for (const bb of b)
    d.push(bb);

โœ… Example of correct code

for (const aa of [...a, ...b])
    d.push(aa);

simplify-floor

Not only shorter, but faster:

// 5.027ms
for (let i = 0; i < 1_000_000; i++)
    Math.floor(i + 0.5);

// 3.493ms
for (let i = 0; i < 1_000_000; i++)
    ~~(i + 0.5);

โŒ Example of incorrect code

Math.floor(x);

โœ… Example of correct code

~~x;

shorten-names

Feats good to @putout/plugin-declare. Check out in ๐ŸŠPutout Editor.

โŒ Example of incorrect code

const a = (b) => {
    Object.keys(b);
};

const b = (keys) => {
    Object.keys(keys);
};

Object.freeze(a);
Object.defineProperty(b);

โœ… Example of correct code

const a = (b) => {
    keys(b);
};

const b = (keys) => {
    Object.keys(keys);
};

freeze(a);
defineProperty(b);

types

Check out in ๐ŸŠPutout Editor.

โŒ Example of incorrect code

const a = undefined;
const b = true;
const c = false;

โœ… Example of correct code

const a = void 0;
const b = !0;
const c = !1;

inline

Check out in ๐ŸŠPutout Editor.

โŒ Example of incorrect code

let x = 1;
--x;

if (!x)
    console.log('hello');

โœ… Example of correct code

let x = 1;

if (!--x)
    console.log('hello');

License

MIT