Skip to content

Commit 6ec4924

Browse files
committed
chore: export Y18N class
allows users to explicitly construct their Y18N instance with their own choice of shim.
1 parent 58a9a3c commit 6ec4924

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

index.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ const y18n = (opts) => {
55
return _y18n(opts, shim)
66
}
77

8+
export { Y18N } from './build/lib/index.js'
89
export default y18n

lib/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface PlatformShim {
3030
}
3131

3232
let shim: PlatformShim
33-
class Y18N {
33+
export class Y18N {
3434
directory: string;
3535
updateFiles: boolean;
3636
locale: string;
@@ -189,7 +189,7 @@ class Y18N {
189189
if (shim.fs.readFileSync) {
190190
localeLookup = JSON.parse(shim.fs.readFileSync(languageFile, 'utf-8'))
191191
}
192-
} catch (err) {
192+
} catch (err: any) {
193193
if (err instanceof SyntaxError) {
194194
err.message = 'syntax error in ' + languageFile
195195
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"prepare": "npm run compile"
4242
},
4343
"devDependencies": {
44-
"@types/node": "^14.6.4",
44+
"@types/node": "^16.11.7",
4545
"@wessberg/rollup-plugin-ts": "^1.3.1",
4646
"c8": "^7.3.0",
4747
"chai": "^4.0.1",

test/esm/y18n-test.mjs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
/* global describe, it */
22

33
import * as assert from 'assert'
4-
import y18n from '../../index.mjs'
4+
import y18n, { Y18N } from '../../index.mjs'
55

66
describe('y18n', function () {
77
it('__ smoke test', function () {
88
const __ = y18n({
99
locale: 'pirate',
1010
directory: './test/locales'
1111
}).__
12-
1312
assert.strictEqual(
1413
__`Hi, ${'Ben'} ${'Coe'}!`,
1514
'Yarr! Shiver me timbers, why \'tis Ben Coe!'
1615
)
1716
})
17+
18+
it('explicit construction', () => {
19+
const y18nOpts = {
20+
locale: 'pirate',
21+
directory: './test/locales'
22+
}
23+
const _y18n = new Y18N(y18nOpts)
24+
assert.strictEqual(
25+
_y18n.__`Hi, ${'Ben'} ${'Coe'}!`,
26+
'Yarr! Shiver me timbers, why \'tis Ben Coe!'
27+
)
28+
})
1829
})

0 commit comments

Comments
 (0)