superscriptjs / superscript

A dialogue engine for creating chat bots
http://superscriptjs.com
MIT License
1.65k stars 209 forks source link

Booleans are received as strings? #384

Open pateketrueke opened 6 years ago

pateketrueke commented 6 years ago

Hi, I'm super excited about this project, fun and interesting!

Of course I was playing around to make it work, so I tried to understand this:

https://github.com/superscriptjs/superscript/blob/37f2be9c149112db924f817faa3726ed2c648c27/src/plugins/user.js#L40

I wrote my own hasProp plugin which receives booleans perfectly, so it could be used as {^hasProp("name", false)} without issues:

function hasProp(prop, val, cb) {
  const memory = this.user.memory;
  const userId = this.user.id;

  memory.db.get({ subject: prop, predicate: userId }, (err, res) => {
    const value = res[0] && res[0].object;

    if (typeof value !== 'undefined' && value !== null) {
      cb(null, val === true);
    } else {
      cb(null, val === false);
    }
  });
}

I don't feel this consistent, unless you encourage us to use plugins as {^hasProp("name", "false")} which is bit weird imho.

The question is, why you used a string comparison instead?