Socket
Socket
Sign inDemoInstall

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

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

🐊Putout plugin adds ability to convert 'const' to 'let'


Version published
Weekly downloads
3.4K
increased by8.15%
Maintainers
1
Install size
5.29 kB
Created
Weekly downloads
 

Readme

Source

@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 entries(tokens)) {
    if (!i)
        continue;
    
    fn(token);
}

License

MIT

Keywords

FAQs

Last updated on 14 Aug 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc