# @resugar/codemod-objects-destructuring

> Convert declarations & assignments to destructuring as appropriate.

Latest version **1.0.1** (published 2019-08-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @resugar/codemod-objects-destructuring
pnpm add @resugar/codemod-objects-destructuring
yarn add @resugar/codemod-objects-destructuring
bun add @resugar/codemod-objects-destructuring
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-08-04 |
| First published | 2019-07-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 692 |
| Author | Brian Donovan |
| Maintainers | eventualbuddha |

## Links

- npm: https://www.npmjs.com/package/@resugar/codemod-objects-destructuring
- Repository: https://github.com/resugar/resugar
- Issues: https://github.com/resugar/resugar/issues
- npm.io page: https://npm.io/package/@resugar/codemod-objects-destructuring

## Recent versions

- 1.0.1 (latest) — 2019-08-04
- 1.0.0 — 2019-07-26

## README

# resugar

Rewrite your JavaScript & TypeScript source code with sweet new features.

> TODO: Below is the README for esnext, the project this one came from. It will be replaced in time.

---

## Installation

```
$ yarn global add esnext
# or, with `npm`:
$ npm install -g esnext
```

## Usage

After installing, run `esnext -h` for comprehensive usage instructions.

## Features

### Functions

Translate some regular functions to arrow functions:

```js
list.map(function(item) {
  return item.name;
});

// ↑ becomes ↓

list.map(item => item.name);
```

### Declarations

Convert `var` declarations to `let` or `const` as appropriate:

```js
var arr = [];
for (var i = 0; i < 5; i++) {
  arr.push(i);
}

// ↑ becomes ↓

const arr = [];
for (let i = 0; i < 5; i++) {
  arr.push(i);
}
```

### Objects

Use shorthand syntax for various object constructs:

```js
let person = {
  first: first,
  last: last,

  fullName: function() {
    return `${first} ${last}`;
  }
};

// ↑ becomes ↓

let person = {
  first,
  last,

  fullName() {
    return `${first} ${last}`;
  }
};
```

### Strings

Convert string concatenation to string or template literals:

```js
let name = 'Brian' + ' ' + 'Donovan';
let greeting = 'Hello, ' + name;

// ↑ becomes ↓

let name = 'Brian Donovan';
let greeting = `Hello, ${name}`;
```

### Destructuring

Convert assignments and declarations to use object destructuring syntax:

```js
let a = obj.a,
  b = obj.b;
(a = obj2.a), (b = obj2.b);

// ↑ becomes ↓

let { a, b } = obj;
({ a, b } = obj2);
```

### Modules

Translate CommonJS modules into ES6 modules:

```js
var readFile = require('fs').readFile;
const MagicString = require('magic-string');
let { ok, strictEqual: eq } = require('assert');

exports.doSomething = function() {
  ok(1);
};

// ↑ becomes ↓

import { readFile } from 'fs';
import MagicString from 'magic-string';
import { ok, strictEqual as eq } from 'assert';

export function doSomething() {
  ok(1);
}
```

## Options

```js
{
  'declarations.block-scope': {
    /**
     * Set this to `true` to only turn `var` into `let`, never `const`.
     */
    disableConst: boolean
  }
}
```

---
_Source: https://npm.io/package/@resugar/codemod-objects-destructuring · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
