@tsparticles/engine
Version:
Easily create highly customizable particle, confetti and fireworks animations and use them as animated backgrounds for your website. Ready to use components available also for React, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Riot.js, Inferno.
31 lines (30 loc) • 1.22 kB
JavaScript
import { messages } from "./ErrorMessages.js";
export { ErrorCodes } from "./ErrorCodes.js";
let registeredMessages;
const ensureRegisteredMessages = () => {
registeredMessages ??= new Map(Object.entries(messages));
return registeredMessages;
}, toStringValue = (value) => String(value), format = (template, args) => {
return template.replace(/\{(\d+)\}/g, (match, index) => {
const arg = args[Number(index)];
return arg === undefined ? match : toStringValue(arg);
});
};
export function addErrorMessages(extraMessages) {
if (typeof process !== "undefined" && process.env.NODE_ENV === "production") {
return;
}
const catalog = ensureRegisteredMessages();
for (const [code, message] of Object.entries(extraMessages)) {
if (message !== undefined) {
catalog.set(code, message);
}
}
}
export function getErrorMessage(code, ...args) {
if (typeof process !== "undefined" && process.env.NODE_ENV === "production") {
return `[tsParticles Error ${code}] https://particles.js.org/errors/#${code}`;
}
const template = ensureRegisteredMessages().get(code) ?? `Unknown error code ${code}`;
return format(template, args);
}