slack-message-parser

JavaScript library for parsing Slack message format (mrkdwn)

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
export const SELF = `'self'`;

export async function sha256(content: string): Promise<string> {
  const enc = new TextEncoder();
  const buf = await crypto.subtle.digest("SHA-256", enc.encode(content));
  const arr = Array.from(new Uint8Array(buf));

  const base64 = btoa(arr.map((b) => String.fromCharCode(b)).join(""));

  return `'sha256-${base64}'`;
}

export interface Policies {
  [name: string]: string[];
}

/**
 * Build CSP Header value.
 */
export function build(policies: Policies): string {
  return Object.entries(policies).map(([name, values]) =>
    `${name} ${values.join(" ")}`
  ).join(";");
}