JSPM

@putout/plugin-convert-for-in-to-for-of

2.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5733
  • Score
    100M100P100Q141730F
  • License MIT

🐊Putout plugin adds ability to convert for-in to for-of

Package Exports

  • @putout/plugin-convert-for-in-to-for-of
  • @putout/plugin-convert-for-in-to-for-of/lib/convert-for-in-to-for-of.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@putout/plugin-convert-for-in-to-for-of) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@putout/plugin-convert-for-in-to-for-of NPM version

The for...in statement iterates over all enumerable properties of an object that are keyed by strings.

The for...of statement creates a loop which invokes a custom iteration hook with statements to be executed for the value of each element of an array.

(c) MDN

🐊Putout plugin adds ability to convert for...in to for...of loop. Merged to @putout/plugin-for-of.

Install

npm i @putout/plugin-convert-for-in-to-for-of -D

Rule

{
    "rules": {
        "convert-for-in-to-for-of/positive": "on",
        "convert-for-in-to-for-of/negative": "on"
    }
}

❌ Example of incorrect code

for (const item in object) {
    if (object.hasOwnProperty(item)) {
        log(item);
    }
}

for (const item in object) {
    if (!object.hasOwnProperty(item))
        continue;
    
    log(item);
}

βœ… Example of correct code

for (const item of Object.keys(object)) {
    log(item);
}

License

MIT