@putout/plugin-convert-object-entries-to-array-entries
🐊Putout plugin adds ability to convert 'const' to 'let'
Last updated 2 months ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @putout/plugin-convert-object-entries-to-array-entries 
SYNC missed versions from official npm registry.

@putout/plugin-convert-object-entries-to-array-entries NPM version

The Object.entries() static method returns an array of a given object's own enumerable string-keyed property key-value pairs.

(c) Object.entries()

The entries() method returns a new Array Iterator object that contains the key/value pairs for each index in the array.

(c) Array.prototype.entries()

????Putout plugin adds ability to convert Object.entries() to Array.prototype.entries() to avoid bugs related to using index in unary (!index) or binary (index > length) expressions, the thing is Object.entries() returns list of Array<String, any> tuples, and Array.prototype.entries() returns list of Array<Number, any> tuples it can lead to bugs when you expected that index is number.

Check out in ????Putout Editor.

Install

npm i @putout/plugin-convert-object-entries-to-array-entries -D

Rule

{
    "rules": {
        "convert-object-entries-to-array-entries": "on"
    }
}

❌ Example of incorrect code

const {entries} = Object;

for (const [i, token] of entries(tokens)) {
    if (!i)
        continue;
    
    fn(token);
}

✅ Example of correct code

for (const [i, token] of tokens.entries()) {
    if (!i)
        continue;
    
    fn(token);
}

License

MIT

Current Tags

  • 4.0.0                                ...           latest (2 months ago)

7 Versions

  • 4.0.0                                ...           2 months ago
  • 3.0.2                                ...           a year ago
  • 3.0.1                                ...           3 years ago
  • 3.0.0                                ...           3 years ago
  • 2.0.0                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 1
Dependencies (0)
None
Dev Dependencies (7)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |