From 6ec4924eac229cd460e9ac05f040239db2ce48f4 Mon Sep 17 00:00:00 2001 From: Darrel O'Pry Date: Wed, 2 Jun 2021 13:43:50 -0400 Subject: [PATCH 1/2] chore: export Y18N class allows users to explicitly construct their Y18N instance with their own choice of shim. --- index.mjs | 1 + lib/index.ts | 4 ++-- package.json | 2 +- test/esm/y18n-test.mjs | 15 +++++++++++++-- 4 files changed, 17 insertions(+), 5 deletions(-) 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 37f2322b..de2d7ad0 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/package.json b/package.json index 4e5c1ca6..389db54e 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "prepare": "npm run compile" }, "devDependencies": { - "@types/node": "^14.6.4", + "@types/node": "^16.11.7", "@wessberg/rollup-plugin-ts": "^1.3.1", "c8": "^7.3.0", "chai": "^4.0.1", diff --git a/test/esm/y18n-test.mjs b/test/esm/y18n-test.mjs index c8675ae7..7c4b04ac 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('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!' + ) + }) }) From 2306d1d52a0197b094fe32dfdb1b465fd2802d8a Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Wed, 17 Nov 2021 23:25:10 +0000 Subject: [PATCH 2/2] Update test/esm/y18n-test.mjs --- test/esm/y18n-test.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/esm/y18n-test.mjs b/test/esm/y18n-test.mjs index 7c4b04ac..fa572087 100644 --- a/test/esm/y18n-test.mjs +++ b/test/esm/y18n-test.mjs @@ -15,7 +15,7 @@ describe('y18n', function () { ) }) - it('explicit construction', () => { + it('exposes an explicit construction', () => { const y18nOpts = { locale: 'pirate', directory: './test/locales'