UNPKG

@trifrost/core

Version:

Blazingly fast, runtime-agnostic server framework for modern edge and node environments

28 lines (27 loc) 769 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NONCEMARKER = void 0; exports.nonce = nonce; exports.NONCE_WIN_SCRIPT = NONCE_WIN_SCRIPT; const use_1 = require("./use"); exports.NONCEMARKER = 'tfnonce'; function nonce() { return (0, use_1.getActiveCtx)()?.nonce || null; } /** * Nonce Window script setter for full-page ssr behavior * * @param {string} val - Nonce value */ function NONCE_WIN_SCRIPT(val) { if (typeof val !== 'string' || !val.length) return ''; return [ '<script nonce="' + val + '">', 'Object.defineProperty(window,"$' + exports.NONCEMARKER + '",{', 'value:"' + val + '",', 'configurable:!1,', 'writable:!1', '})</script>', ].join(''); }