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 ๐Ÿ™

ยฉ 2025 โ€“ย Pkg Stats / Ryan Hefner

@putout/plugin-destructuring

v1.3.0

Published

๐ŸŠPutout plugin adds ability to transform destructuring

Readme

@putout/plugin-destructuring NPM version

The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.

(c) MDN

๐ŸŠPutout plugin adds ability to use destructuring on variable declarations.

Install

npm i @putout/plugin-destructuring

Rules

Config

{
    "rules": {
        "destructuring/apply-object": "on",
        "destructuring/apply-array": "on",
        "destructuring/convert-object-to-array": "on",
        "destructuring/extract-properties": "on",
        "destructuring/remove-useless-object": "on",
        "destructuring/remove-useless-arguments": "on",
        "destructuring/remove-useless-variables": "on",
        "destructuring/split-nested": "on",
        "destructuring/split-call": "on",
        "destructuring/merge-properties": "on"
    }
}

apply-array

โŒ Example of incorrect code

const first = array[0];

โœ… Example of correct code

const [first] = array;

apply-object

โŒ Example of incorrect code

const name = user.name;

hello = world.hello;

โœ… Example of correct code

const {name} = user;

({hello} = world);

remove-useless-object

Check out in ๐ŸŠPutout Editor.

โŒ Example of incorrect code

const {maxElementsInOneLine} = {
    options,
};

โœ… Example of correct code

const {maxElementsInOneLine} = options;

convert-object-to-array

Check out in ๐ŸŠPutout Editor.

โŒ Example of incorrect code

const {0: a, 1: b} = c;

โœ… Example of correct code

const [a, b] = c;

split-nested

  • Don't use nested destructuring on data that comes from any external data sources (such as REST APIs, GraphQL endpoints or files).
  • Don't use nested destructuring on function arguments that have long or complicated signatures.

(c) Destructuring in JavaScript: the not so good parts

๐ŸŠPutout plugin adds ability to split nested destructuring.

โŒ Example of incorrect code

const {
    a: {
        b,
    },
    a: {
        b: x,
    },
} = c;

function f({a}) {
    const {b} = a;
    console.log(b);
}

โœ… Example of correct code

const {a} = c;
const {b, b: x} = a;

function f({a}) {
    const {b} = a;
    console.log(b);
}

split-call

โŒ Example of incorrect code

console.log('hello')({uid} = path.scope);
console.log('hello')[uid] = path.scope;

โœ… Example of correct code

console.log('hello');
({uid} = path.scope);

console.log('hello');
[uid] = path.scope;

merge-properties

Checkout in ๐ŸŠPutout Editor.

โŒ Example of incorrect code

const {one} = require('numbers');
const {two} = require('numbers');

({from} = data);
({to} = data);
({names} = data);

โœ… Example of correct code

const {one, two} = require('numbers');

({
    from,
    to,
    names,
} = data);

remove-useless-arguments

โŒ Example of incorrect code

onIfStatement({
    push,
    generate,
    abc,
    helloworld,
});

function onIfStatement({push}) {}

โœ… Example of correct code

onIfStatement({
    push,
});

function onIfStatement({push}) {}

remove-useless-variables

โŒ Example of incorrect code

function hi(c) {
    const {a, b} = c;
}

โœ… Example of correct code

function hi({a, b}) {}

extract-properties

Equal Deep

โŒ Example of incorrect code

const {replaceWith} = a.operate;
const {isIdentifier} = a.types;

โœ… Example of correct code

const {operator, types} = a;

const {replaceWith} = operator;
const {isIdentifier} = types;

Not Equal Deep

โŒ Example of incorrect code

const {replaceWith} = a;
const {isIdentifier} = a.types;

โœ… Example of correct code

const {replaceWith, types} = a;
const {isIdentifier} = types;

License

MIT