npm / abbrev-js

Like ruby's Abbrev module
Other
164 stars 31 forks source link

[BUG] Issue with single item #96

Open MarketingPip opened 2 months ago

MarketingPip commented 2 months ago

Is there an existing issue for this?

Current Behavior

abbrev(["foo"])

throws error in :


// Uncaught TypeError: Cannot assign to read only property '0' of string 'foo'

function abbrev (...args) {
  let list = args.length === 1 || Array.isArray(args[0]) ? args[0] : args

  for (let i = 0, l = list.length; i < l; i++) {
    list[i] = typeof list[i] === 'string' ? list[i] : String(list[i]) /// Right here
  }
wraithgar commented 2 months ago

Abbrev expects strings, not an array. (...args) means you can pass it as many strings as you want in subsequent parameters, i.e.

abbrev('foo', 'bar', 'baz', ...)

MarketingPip commented 2 months ago

@wraithgar - then my issue still stands... try with a single string!

wraithgar commented 2 months ago

Yep you're right, didn't read close enough.

> require('.')('asdf')
Uncaught TypeError: list.sort is not a function
    at abbrev (/Users/wraithgar/Development/npm/abbrev-js/branches/main/lib/index.js:11:15)
> require('.')('asdf', 'asdr')
{ asdf: 'asdf', asdr: 'asdr' }
MarketingPip commented 2 months ago

@wraithgar - tbh I didn't even realize this was a npm based package but lol!

Wish I could commit but I know the rules! My fix about should work. Maybe add validation is string / or array of strings etc...?

wraithgar commented 2 months ago

Wish I could commit but I know the rules!

You can submit PRs from a fork, that's how all external contributions are made to npm. You'd just need to add a test for that case.