ramda: R.keys doesn't retrieve char indexes in string primitives

While I’m struggling to decide whether to let exceptions being thrown for null and undefined values in my own library (any insight is welcome), I noticed that you have a bug in R.keys here: https://github.com/ramda/ramda/blob/v0.21.0/src/keys.js#L47 (and later in line 50) due to the Object(obj) !== obj check.

The check is fine for string objects, not for primitives:

R.keys("foo") // => []
R.keys(new String("foo")) // => ["0", "1", "2"]

As you have already decided of not throwing exceptions, this can be easily solved with compose(Object.keys, Object) on line 47 and maybe in a quick’n’dirty way on line 50 by replacing the check with obj = Object(obj). That second bit is quick’n’dirty, but it should have less impact on performance than a more complicated check to allow an early exit from the function.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 26 (12 by maintainers)

Most upvoted comments

@CrossEye, don’t worry: we can resume later if you like.

You can also try an abstract of your thoughts as an exercise in epigrammatic style, while I think of something that will require hippopotomonstrosesquipedaliophobia combined with some Welsh word as an answer.

Ok, no, maybe later is for the best: good luck with your provider, been there way too many times.