~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/pds.js

An atproto PDS in JavaScript, for Cloudflare Workers and Node

0
0
main
25 lines · 729 B Raw History
// @pdsjs/core/html - Shared helpers for the server-rendered pages

/**
 * Escape HTML special characters.
 * @param {string} s
 * @returns {string}
 */
export function escapeHtml(s) {
  return s
    .replace(/&/g, '&')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/"/g, '&quot;');
}

/**
 * base64url helpers for inline passkey scripts. WebAuthn speaks ArrayBuffers;
 * every field crossing the wire here is base64url text.
 */
export const B64_SCRIPT = `
const b64 = (buf) => btoa(String.fromCharCode(...new Uint8Array(buf)))
  .replace(/\\+/g,'-').replace(/\\//g,'_').replace(/=+$/,'');
const unb64 = (s) => Uint8Array.from(
  atob(s.replace(/-/g,'+').replace(/_/g,'/')), (c) => c.charCodeAt(0));
`;