From 1a8f54f685335c9d55a33f27b3645cdbf561428d Mon Sep 17 00:00:00 2001 From: Omri Date: Mon, 25 Sep 2017 13:30:55 +0300 Subject: [PATCH] Expose instance - (made for Webpack external) #10 --- instance.js | 12 ++++++++++++ package.json | 2 +- readme.md | 29 ++++++++++++++++++++++++++++- singleton.js | 5 +++++ tests/instance.js | 8 ++++++++ 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 instance.js create mode 100644 tests/instance.js diff --git a/instance.js b/instance.js new file mode 100644 index 0000000..64362a5 --- /dev/null +++ b/instance.js @@ -0,0 +1,12 @@ +/** + * @module @fiverr/i18n/instance + * @since 1.5.0 + */ + +const I18n = require('./'); + +/** + * Shortcut to an empty I18n instance + * @type {I18n} + */ +module.exports = new I18n(); diff --git a/package.json b/package.json index e9aa8b9..b1c6808 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fiverr/i18n", - "version": "1.4.0", + "version": "1.5.0", "description": "Translation helper", "author": "Fiverr dev team", "license": "MIT", diff --git a/readme.md b/readme.md index 1f3010c..2086458 100644 --- a/readme.md +++ b/readme.md @@ -112,7 +112,34 @@ usersI18n.t('introduction', {username: 'Martin'}); // Hi, my name is Martin i18n.t('users.get.introduction', {username: 'Martin'}); // Hi, my name is Martin ``` -### Singleton +### Instance +Exposes an empty instance of i18n +```javascript +const i18n = require('@fiverr/i18n/instance'); + +i18n.add({...}); +``` + +Made especially for use as a webpack external +```javascript +externals: { + '@fiverr/i18n/instance': 'i18n' +} +``` + +> Name can alternate: +> ```javascript +> import phraser from '@fiverr/i18n/instance'; +> ``` +> +> ```javascript +> externals: { +> '@fiverr/i18n/instance': 'phraser' +> } +> ``` + + +### Singleton (i18n) Make sure you only have one instance of I18n in your global scope ```javascript const i18n = I18n.singleton; diff --git a/singleton.js b/singleton.js index 056a172..a26f3b7 100644 --- a/singleton.js +++ b/singleton.js @@ -1,3 +1,8 @@ +/** + * @module @fiverr/i18n/singleton + * @since 1.2.0 + */ + const I18n = require('./'); /** diff --git a/tests/instance.js b/tests/instance.js new file mode 100644 index 0000000..4271fd8 --- /dev/null +++ b/tests/instance.js @@ -0,0 +1,8 @@ +const {expect} = require('chai'); +const instance = require('../instance'); + +describe('Instance', () => { + it('exports an I18n instance', () => { + expect(instance.constructor.name).to.equal('I18n'); + }); +});