3.0.2 β’ Published 10 months ago
@putout/plugin-convert-object-entries-to-array-entries v3.0.2
@putout/plugin-convert-object-entries-to-array-entries 
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 newArray Iteratorobject that contains the key/value pairs for each index in the array.
π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 -DRule
{
"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