export function escapeRegExp(str: string): string {
  return (str || '')
    .toString()
    .replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
}

export function decodeBufferToString(buffer) {
  if (window.TextDecoder) {
    const decoder = new window.TextDecoder('utf8');
    return decoder.decode(buffer);
  }
  return String.fromCharCode(...new Uint8Array(buffer));
}

export function getTitleAsLink(title: string) {
  return title.replace(/ /g, '-').slice(0, 30);
}
