import { MapOf } from "@implab/core-amd/interfaces"; import { NlsBundle } from "./NlsBundle"; import { isPromise } from "@implab/core-amd/safe"; export function bundle(nls: T, locales?: MapOf) { const nlsBundle = new NlsBundle(nls, locales); const fn = (locale?: string) => { const result = nlsBundle.getLocale(locale); if (isPromise(result)) throw new Error(`The bundle '${locale}' isn't loaded`); else return result; }; fn.define = (pack: Partial) => pack; fn.default = nlsBundle.default; fn.load = async (id: string, require: Require, cb: { (): void; error: (arg0: any) => void; }) => { try { await nlsBundle.getLocale(id); cb(); } catch (e) { cb.error(e); } }; return fn; }