Skip to content

Using an array as an object key #9

Closed
@nhz-io

Description

Consider this block:

minimist/index.js

Lines 52 to 66 in 62fde7d

Object.keys(opts.alias || {}).forEach(function (key) {
aliases[key] = [].concat(opts.alias[key]);
aliases[key].forEach(function (x) {
aliases[x] = [key].concat(aliases[key].filter(function (y) {
return x !== y;
}));
});
});
[].concat(opts.string).filter(Boolean).forEach(function (key) {
flags.strings[key] = true;
if (aliases[key]) {
flags.strings[aliases[key]] = true;
}
});

Here it builds an array of aliased args:

minimist/index.js

Lines 55 to 57 in 62fde7d

aliases[x] = [key].concat(aliases[key].filter(function (y) {
return x !== y;
}));

And here it uses this array as a key for strings:

flags.strings[aliases[key]] = true;

Which will just result in:

{
  strings: {
    "[object Object]": true
  }
}

It should either build flat aliases or iterate over the nested array

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedpull requests welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions