All files / utils/i18n-importer provider.js

100% Statements 29/29
100% Branches 1/1
33.33% Functions 1/3
100% Lines 29/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 301x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 13x 13x 13x 13x 13x 13x 13x 1x 1x 1x 1x 1x 1x  
/** @import { importTranslations, importDefinitionMap } from './i18n-importer.js' */
 
/** @type {Implementation} */
const defaultImplementation = Object.freeze({
  importTranslations: () => ((console.error('importTranslations not implemented'), Promise.resolve({}))),
  importDefinitionMap: () => ((console.error('importLanguage not implemented'), Promise.resolve({}))),
})
 
export const implementation = Object.seal({
  ...defaultImplementation,
})
 
/**
 * @param {Implementation} newImpl - new implementation to use on the application
 */
export function provide (newImpl) {
  if (typeof newImpl?.importTranslations === 'function') {
    implementation.importTranslations = newImpl.importTranslations
  }
  if (typeof newImpl?.importDefinitionMap === 'function') {
    implementation.importDefinitionMap = newImpl.importDefinitionMap
  }
}
 
/**
 * @typedef {object} Implementation
 * @property {typeof importTranslations} importTranslations - {@link importTranslations} implementation function
 * @property {typeof importDefinitionMap} importDefinitionMap - {@link importTranslations} implementation function
 */