UNPKG

@agnostack/next-shopify

Version:

Please contact agnoStack via info@agnostack.com for any questions

21 lines 1.31 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.replaceHeaders = void 0; const mustache_1 = __importDefault(require("mustache")); const shared_1 = require("../../shared"); const templateReplace = (template, replacements, partials, tokens) => { // NOTE: fixes issues where by default standard characters are HTML encoded (https://stackoverflow.com/questions/22910428/mustache-globally-disable-html-escaping) mustache_1.default.escape = (value) => (value); return mustache_1.default.render((0, shared_1.ensureString)(template), (0, shared_1.ensureObject)(replacements), partials, tokens); }; const replaceHeaders = ({ headers, replacements } = {}) => { if ((0, shared_1.objectEmpty)(replacements)) { return headers; } return Object.entries(headers).reduce((_replacedHeaders, [header, headerValue]) => (Object.assign(Object.assign({}, _replacedHeaders), { [header]: (headerValue === null || headerValue === void 0 ? void 0 : headerValue.includes('{{')) ? templateReplace(headerValue, replacements) : headerValue })), {}); }; exports.replaceHeaders = replaceHeaders; //# sourceMappingURL=headers.js.map