`def.substr(0, def.length - 2)` I think is a little more clear as: `def.slice(0, -2)`

Also please use `util.format` for assembling strings like that