/* global SCSRenderAPI */ // @ts-check /** @file This file is shared by render and compilation */ /** * BaseUtils contains methods that work regardless of the environment they are executed in (client-side render and * Node.js compilation) */ export class BaseUtils { /** @param {any} [SCSCompileAPI] SCSCompileAPI, provided only in compilation */ constructor(SCSCompileAPI) { this.isCompilation = !!SCSCompileAPI; this.SCSCompileAPI = SCSCompileAPI; } /** * @param {string} propertyName * @returns {string | undefined} */ getCustomSiteProperty(propertyName) { if (this.isCompilation) { return this.SCSCompileAPI.getCustomSiteProperty(propertyName); } return SCSRenderAPI.getCustomSiteProperty(propertyName); } /** * Returns `true` if the `IR_BUY_NOW_LOCALES` is set up ("en-gb,de-de") and current locale is included * * @param {string | undefined} localeAlias * @returns {boolean} */ isIRWhereToBuyAvailableForCurrentLocale(localeAlias) { const irWhereToBuyLocales = this.getCustomSiteProperty('IR_BUY_NOW_LOCALES') ?.replace(/ /g, '') .toLowerCase() .split(','); if (!irWhereToBuyLocales) { return false; } if (!localeAlias) { return irWhereToBuyLocales.includes('en'); } return irWhereToBuyLocales.includes(localeAlias.toLowerCase()); } }