diff --git a/index.mjs b/index.mjs index 46c82133..1a3e9092 100644 --- a/index.mjs +++ b/index.mjs @@ -5,4 +5,5 @@ const y18n = (opts) => { return _y18n(opts, shim) } +export { Y18N } from './build/lib/index.js' export default y18n diff --git a/lib/index.ts b/lib/index.ts index 7254a34a..bc8c634d 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -30,7 +30,7 @@ export interface PlatformShim { } let shim: PlatformShim -class Y18N { +export class Y18N { directory: string; updateFiles: boolean; locale: string; @@ -189,7 +189,7 @@ class Y18N { if (shim.fs.readFileSync) { localeLookup = JSON.parse(shim.fs.readFileSync(languageFile, 'utf-8')) } - } catch (err) { + } catch (err: any) { if (err instanceof SyntaxError) { err.message = 'syntax error in ' + languageFile } diff --git a/test/esm/y18n-test.mjs b/test/esm/y18n-test.mjs index c8675ae7..fa572087 100644 --- a/test/esm/y18n-test.mjs +++ b/test/esm/y18n-test.mjs @@ -1,7 +1,7 @@ /* global describe, it */ import * as assert from 'assert' -import y18n from '../../index.mjs' +import y18n, { Y18N } from '../../index.mjs' describe('y18n', function () { it('__ smoke test', function () { @@ -9,10 +9,21 @@ describe('y18n', function () { locale: 'pirate', directory: './test/locales' }).__ - assert.strictEqual( __`Hi, ${'Ben'} ${'Coe'}!`, 'Yarr! Shiver me timbers, why \'tis Ben Coe!' ) }) + + it('exposes an explicit construction', () => { + const y18nOpts = { + locale: 'pirate', + directory: './test/locales' + } + const _y18n = new Y18N(y18nOpts) + assert.strictEqual( + _y18n.__`Hi, ${'Ben'} ${'Coe'}!`, + 'Yarr! Shiver me timbers, why \'tis Ben Coe!' + ) + }) })