code: function decode(msg) {
    const len = msg.length;
    if (len > 0) {
      const c = msg.charCodeAt(len - 1);
      if (c >= 1 && c <= 8) {
        const provided = msg.substr(len - c);
        const computed = String.fromCharCode(c).repeat(c);
        if (provided === computed) {
          return msg.substr(0, len - c);
        }
      }
    }
    throw new Error('Invalid padding');
  }
docs: Remove pkcs5 padding from a string.
  @param  {String}  msg  Text to remove padding from
  @returns {String}       Text with padding removed