Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: export Y18N class #136

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ const y18n = (opts) => {
return _y18n(opts, shim)
}

export { Y18N } from './build/lib/index.js'
export default y18n
4 changes: 2 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface PlatformShim {
}

let shim: PlatformShim
class Y18N {
export class Y18N {
directory: string;
updateFiles: boolean;
locale: string;
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 13 additions & 2 deletions test/esm/y18n-test.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
/* 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 () {
const __ = y18n({
locale: 'pirate',
directory: './test/locales'
}).__

assert.strictEqual(
__`Hi, ${'Ben'} ${'Coe'}!`,
'Yarr! Shiver me timbers, why \'tis Ben Coe!'
)
})

it('explicit construction', () => {
bcoe marked this conversation as resolved.
Show resolved Hide resolved
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!'
)
})
})