rannn505 / child-shell

Node.js bindings 🔗 for shell
http://rannn505.github.io/child-shell/
MIT License
301 stars 71 forks source link

Switch option (passing null) does not work #104

Closed robmcfeely closed 2 years ago

robmcfeely commented 4 years ago

Your utils.js has a method called convertToPSParam which I believe is supposed to handle the passing of null to result in the return of null, allowing you, in turn, to specify null parameters values to indicate switches. However, it does not work. This code demonstrates this.

const getType = obj => Object.prototype.toString.call(obj).slice(8, -1);

const convertToPSParam = val => {
    let x = getType(val);
    console.log(x)
  switch (x) {
    case 'String':
      return 1
    case 'Number':
        return 2
    case 'Array':
        return 3
    case 'Object':
        return 4
    case 'Boolean':
        return 5
    case 'Date':
        return 6
    case 'Undefined' || 'Null':
        return 7
    default:
        return 8
};
}

console.log(convertToPSParam(null))

I think it should be

const getType = obj => Object.prototype.toString.call(obj).slice(8, -1);

const convertToPSParam = val => {
    let x = getType(val);
    console.log(x)
  switch (x) {
    case 'String':
      return 1
    case 'Number':
        return 2
    case 'Array':
        return 3
    case 'Object':
        return 4
    case 'Boolean':
        return 5
    case 'Date':
        return 6
    case 'Undefined':
   case 'Null': 
                return 7
    default:
        return 8
};
}

console.log(convertToPSParam(null))

JennyL1 commented 3 years ago

Any updates on this bug?