Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function createDebugger(namespace: string | string[]): Debugger {
const globalNamespace = env('DEBUG_GLOBAL_NAMESPACE');
const namespaces = toArray(namespace);
if (globalNamespace) {
namespaces.unshift(globalNamespace);
}
const mainNamespace = namespaces.join(':');
debug(
'New debugger created: %s %s',
mainNamespace,
env('DEBUG_VERBOSE') ? '(verbose enabled)' : '',
);
const logger = coreDebug(mainNamespace) as Debugger;
// `debug` doesn't support this on an individual namespace basis,
export default function createTranslator(
namespace: string | string[],
resourcePath: PortablePath | PortablePath[],
{
autoDetect = true,
debug: debugOpt = false,
fallbackLocale = 'en',
locale,
lookupType,
resourceFormat = 'yaml',
}: TranslatorOptions = {},
): Translator {
const namespaces = toArray(namespace);
const resourcePaths = toArray(resourcePath).map(Path.create);
if (namespaces.length === 0) {
throw new RuntimeError('translate', 'TL_REQ_NAMESPACE');
} else if (resourcePaths.length === 0) {
throw new RuntimeError('translate', 'TL_REQ_RES_PATHS');
} else if (!autoDetect && !locale) {
throw new RuntimeError('translate', 'TL_REQ_MANUAL_LOCALE');
}
debug('New translator created: %s namespace(s)', namespaces.join(', '));
const translator = i18next.createInstance().use(new FileBackend());
if (autoDetect) {
translator.use(new LocaleDetector());
reportPackageVersions(patterns: string | string[], title: string = 'Packages'): this {
this.addSection(title);
glob
.sync(
toArray(patterns).map(pattern => path.join('node_modules', pattern)),
{
absolute: true,
deep: 1,
onlyDirectories: true,
onlyFiles: false,
},
)
.forEach(pkgPath => {
const pkg: { name: string; version: string } = requireModule(
path.join(pkgPath, 'package.json'),
);
this.add(pkg.name, pkg.version);
});
return this;
export default function createTranslator(
namespace: string | string[],
resourcePath: PortablePath | PortablePath[],
{
autoDetect = true,
debug: debugOpt = false,
fallbackLocale = 'en',
locale,
lookupType,
resourceFormat = 'yaml',
}: TranslatorOptions = {},
): Translator {
const namespaces = toArray(namespace);
const resourcePaths = toArray(resourcePath).map(Path.create);
if (namespaces.length === 0) {
throw new RuntimeError('translate', 'TL_REQ_NAMESPACE');
} else if (resourcePaths.length === 0) {
throw new RuntimeError('translate', 'TL_REQ_RES_PATHS');
} else if (!autoDetect && !locale) {
throw new RuntimeError('translate', 'TL_REQ_MANUAL_LOCALE');
}
debug('New translator created: %s namespace(s)', namespaces.join(', '));
const translator = i18next.createInstance().use(new FileBackend());
if (autoDetect) {
translator.use(new LocaleDetector());
}