handlebars-i18n 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": ["@commitlint/config-conventional"]
3
+ }
@@ -0,0 +1,36 @@
1
+ name: CI
2
+
3
+ on: [create, pull_request, push]
4
+
5
+ env:
6
+ IMAGE_ID: ${{ github.repository }}
7
+
8
+ jobs:
9
+ build:
10
+ name: Build
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Git checkout
14
+ uses: actions/checkout@v2.3.4
15
+ - name: Build
16
+ run: |
17
+ npm i
18
+ npm run test
19
+ semantic-release:
20
+ if: github.event_name != 'pull_request'
21
+ name: Semantic Release
22
+ runs-on: ubuntu-latest
23
+ needs: build
24
+ steps:
25
+ - uses: actions/checkout@v2.3.4
26
+ with:
27
+ token: ${{ secrets.GITHUB_TOKEN }}
28
+ - name: Semantic Release
29
+ uses: cycjimmy/semantic-release-action@v2.5.3
30
+ with:
31
+ extra_plugins: |
32
+ @semantic-release/changelog
33
+ @semantic-release/git
34
+ env:
35
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -0,0 +1,49 @@
1
+ name: Scheduled Release
2
+
3
+ on:
4
+ schedule:
5
+ - cron: '0 0 * * 1' # Every Monday at 00:00 AM UTC on the default branch
6
+
7
+ jobs:
8
+ analyze-tags:
9
+ runs-on: ubuntu-latest
10
+ outputs:
11
+ previous-tag: ${{ steps.previoustag.outputs.tag }}
12
+ timestamp-diff: ${{ steps.diff.outputs.timestamp-diff }}
13
+ steps:
14
+ - uses: actions/checkout@v2.3.4
15
+ with:
16
+ fetch-depth: 0
17
+ - name: Get previous tag
18
+ id: previoustag
19
+ uses: "WyriHaximus/github-action-get-previous-tag@1.0.0"
20
+ - name: Get seconds from previous tag to now
21
+ id: diff
22
+ shell: bash
23
+ env:
24
+ TIMESTAMP_TAG: ${{ steps.previoustag.outputs.timestamp }}
25
+ run: |
26
+ echo "::set-output name=timestamp-diff::$(expr $(printf '%(%s)T') - $TIMESTAMP_TAG)"
27
+
28
+ schedule-release:
29
+ runs-on: ubuntu-latest
30
+ needs: analyze-tags
31
+ if: needs.analyze-tags.outputs.timestamp-diff > 604800 # 604800 equal one week.
32
+ steps:
33
+ - uses: actions/checkout@v2.3.4
34
+ with:
35
+ token: ${{ secrets.GITHUB_TOKEN }}
36
+ - name: Get next minor version
37
+ id: semvers
38
+ uses: "WyriHaximus/github-action-next-semvers@v1"
39
+ with:
40
+ version: ${{ needs.analyze-tags.outputs.previous-tag }}
41
+ - name: manifest Version
42
+ uses: deef0000dragon1/json-edit-action/@v1
43
+ env:
44
+ KEY: scheduleVersion
45
+ VALUE: ${{ steps.semvers.outputs.patch }}
46
+ FILE: package.json
47
+ - uses: stefanzweifel/git-auto-commit-action@v4.10.0
48
+ with:
49
+ commit_message: 'fix(release): schedule release'
package/.idea/.name ADDED
@@ -0,0 +1 @@
1
+ handlebars-i18n
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$" />
5
+ <orderEntry type="inheritedJdk" />
6
+ <orderEntry type="sourceFolder" forTests="false" />
7
+ </component>
8
+ </module>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="JavaScriptLibraryMappings">
4
+ <includedPredefinedLibrary name="ECMAScript 6" />
5
+ </component>
6
+ </project>
package/.idea/misc.xml ADDED
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectLevelVcsManager" settingsEditedManually="false">
4
+ <OptionsSetting value="true" id="Add" />
5
+ <OptionsSetting value="true" id="Remove" />
6
+ <OptionsSetting value="true" id="Checkout" />
7
+ <OptionsSetting value="true" id="Update" />
8
+ <OptionsSetting value="true" id="Status" />
9
+ <OptionsSetting value="true" id="Edit" />
10
+ <ConfirmationsSetting value="0" id="Add" />
11
+ <ConfirmationsSetting value="0" id="Remove" />
12
+ </component>
13
+ <component name="ProjectRootManager" version="2" />
14
+ </project>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/handlebars-i18n.iml" filepath="$PROJECT_DIR$/.idea/handlebars-i18n.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
package/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectTasksOptions" suppressed-tasks="Traceur compiler;Babel" />
4
+ </project>
@@ -0,0 +1,11 @@
1
+ {
2
+ "plugins": [
3
+ "@semantic-release/commit-analyzer",
4
+ "@semantic-release/release-notes-generator",
5
+ "@semantic-release/changelog",
6
+ "@semantic-release/npm",
7
+ "@semantic-release/github",
8
+ "@semantic-release/git"
9
+ ],
10
+ "tagFormat": "${version}"
11
+ }
package/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: node_js
2
+
3
+ node_js:
4
+ - stable
5
+
6
+ install:
7
+ - npm install
8
+
9
+ script:
10
+ - npm test
11
+
12
+ after_success: 'npm run coveralls'
13
+
14
+ after_failure:
15
+ - cat /Users/travis/.npm/_logs/*.log
package/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ # [1.3.0](https://github.com/fwalzel/handlebars-i18n/compare/1.2.1...1.3.0) (2021-09-17)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * it() in line 72 in handlebars-i18n.test.js ([88049f9](https://github.com/fwalzel/handlebars-i18n/commit/88049f94c7dbf72ee58b713e0a3ab494a4cde28f))
7
+ * **release:** schedule release ([052f0e1](https://github.com/fwalzel/handlebars-i18n/commit/052f0e1e5cbae779060fe45c604fc97bf0b1c34f))
8
+
9
+
10
+ ### Features
11
+
12
+ * compressed .min file ([ce8e28c](https://github.com/fwalzel/handlebars-i18n/commit/ce8e28cddbec9ee8e0e3188fbe24ff404eb8a63f))
13
+
14
+ ## [1.2.1](https://github.com/fwalzel/handlebars-i18n/compare/1.2.0...1.2.1) (2021-05-28)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * **release:** schedule release ([9e3aa53](https://github.com/fwalzel/handlebars-i18n/commit/9e3aa534a83466c242525c76a802d2b6d9d14623))
20
+
21
+ # [1.2.0](https://github.com/fwalzel/handlebars-i18n/compare/1.1.5...1.2.0) (2021-04-29)
22
+
23
+
24
+ ### Features
25
+
26
+ * **semantic-release:** implement automatic releases ([fb88190](https://github.com/fwalzel/handlebars-i18n/commit/fb88190724aac1ea426caec533bed1dabc59d247))
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Florian Walzel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,423 @@
1
+ /********************************************************************
2
+ * handlebars-i18n.js
3
+ *
4
+ * @author: Florian Walzel
5
+ * @date: 2021-10
6
+ *
7
+ * handlebars-i18n adds features for localization/
8
+ * internationalization to handlebars.js
9
+ *
10
+ * Copyright (c) 2020 Florian Walzel
11
+ *
12
+ * Permission is hereby granted, free of charge, to any person
13
+ * obtaininga copy of this software and associated documentation
14
+ * files (the "Software"), to deal in the Software without restriction,
15
+ * including without limitation the rights to use, copy, modify, merge,
16
+ * publish, distribute, sublicense, and/or sell copies of the Software,
17
+ * and to permit persons to whom the Software is furnished to do so,
18
+ * subject to the following conditions:
19
+ *
20
+ * The above copyright notice and this permission notice shall be
21
+ * included in all copies or substantial portions of the Software.
22
+ *
23
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30
+ * THE SOFTWARE.
31
+ *
32
+ *********************************************************************/
33
+
34
+ (function (root, factory) {
35
+
36
+ if (typeof exports === 'object' && typeof module === 'object') {
37
+ const Handlebars = require('handlebars'),
38
+ i18next = require('i18next'),
39
+ Intl = require('intl');
40
+ module.exports = factory(Handlebars, i18next, Intl);
41
+ }
42
+ else if (typeof define === 'function' && define.amd)
43
+ define(['Handlebars', 'i18next', 'Intl'], factory);
44
+ else if (typeof root.Handlebars === 'object'
45
+ && typeof root.i18next === 'object'
46
+ && typeof root.Intl === 'object')
47
+ root['HandlebarsI18n'] = factory(root.Handlebars, root.i18next, root.Intl);
48
+ else {
49
+ console.error('@ handlebars-i18n: One or more dependencies are missing. Check for Handlebars, i18next and Intl.');
50
+ return false;
51
+ }
52
+
53
+ })(this, function (handlebars, i18next, Intl) {
54
+
55
+ 'use strict';
56
+
57
+ var defaultConf = {
58
+ DateTimeFormat: {
59
+ standard: {},
60
+ custom: {}
61
+ },
62
+ NumberFormat: {
63
+ standard: {},
64
+ custom: {}
65
+ },
66
+ PriceFormat: {
67
+ standard: {
68
+ all: {style: 'currency', currency: 'EUR'}
69
+ },
70
+ custom: {}
71
+ }
72
+ };
73
+
74
+ // make a copy of default object
75
+ var optionsConf = JSON.parse(JSON.stringify(defaultConf));
76
+
77
+
78
+ /*************************************
79
+ * PRIVATE FUNCTIONS (HELPERS)
80
+ *************************************/
81
+
82
+ /**
83
+ *
84
+ * @param constructor
85
+ * @param argArray
86
+ * @returns {*|function(this:*)}
87
+ * @private
88
+ */
89
+ function __applyToConstructor(constructor, argArray) {
90
+ var args = [null].concat(argArray);
91
+ var factoryFunction = constructor.bind.apply(constructor, args);
92
+ return new factoryFunction();
93
+ }
94
+
95
+ /**
96
+ *
97
+ * @param hndlbrsOpts
98
+ * @param OCFormat
99
+ * @returns {*}
100
+ * @private
101
+ */
102
+ function __configLookup(hndlbrsOpts, lang, OCFormat) {
103
+
104
+ // check if an options object with .hash exists, and holds some content
105
+ if (typeof hndlbrsOpts === 'object'
106
+ && typeof hndlbrsOpts.hash === 'object'
107
+ && Object.keys(hndlbrsOpts.hash).length > 0) {
108
+
109
+ var oh = hndlbrsOpts.hash;
110
+
111
+ // check against a custom format, if nonexistent
112
+ // return the options hash (= template configuration)
113
+ if (typeof oh.format === 'undefined') {
114
+ return oh;
115
+ }
116
+ // when custom format is given, check if the configuration was set
117
+ else if (typeof OCFormat.custom[oh.format] !== 'undefined'
118
+ && typeof OCFormat.custom[oh.format][lang] !== 'undefined') {
119
+ return OCFormat.custom[oh.format][lang];
120
+ }
121
+ }
122
+
123
+ // when no options for custom formats given, first check whether
124
+ // the specific language has a generic definition
125
+ if (typeof OCFormat.standard[lang] !== 'undefined')
126
+ return OCFormat.standard[lang];
127
+
128
+ // … then check if a universal format definition for all languages exist
129
+ if (typeof OCFormat.standard.all !== 'undefined')
130
+ return OCFormat.standard.all;
131
+
132
+ // no configuration delivered, fallback is Intl standard definition
133
+ else
134
+ return {};
135
+ }
136
+
137
+ /**
138
+ *
139
+ * @param lngShortcode
140
+ * @param typeOfFormat
141
+ * @param options
142
+ * @returns {boolean}
143
+ * @private
144
+ */
145
+ function __validateArgs(lngShortcode, typeOfFormat, options, customFormat) {
146
+
147
+ if (typeof lngShortcode !== 'string') {
148
+ console.error('@ handlebars-i18n.configure(): Invalid argument <' + lngShortcode + '> ' +
149
+ 'First argument must be a string with language code such as "en".');
150
+ return false;
151
+ }
152
+
153
+ if (typeOfFormat !== 'DateTimeFormat'
154
+ && typeOfFormat !== 'NumberFormat'
155
+ && typeOfFormat !== 'PriceFormat') {
156
+ console.error('@ handlebars-i18n.configure(): Invalid argument <' + typeOfFormat + '>. ' +
157
+ 'Second argument must be a string with the options key. ' +
158
+ 'Use either "DateTimeFormat", "NumberFormat" or "PriceFormat".');
159
+ return false;
160
+ }
161
+
162
+ if (typeof options !== 'object') {
163
+ console.error('@ handlebars-i18n.configure(): Invalid argument <' + options + '> ' +
164
+ 'Third argument must be an object containing the configuration parameters.');
165
+ return false;
166
+ }
167
+
168
+ if ((customFormat !== null && typeof customFormat !== 'undefined' && typeof customFormat !== 'string')
169
+ || customFormat == '' || customFormat == ' ') {
170
+ console.error('@ handlebars-i18n.configure(): Invalid argument <' + customFormat + '> ' +
171
+ 'Fourth argument (optional) must be a string naming your custom format configuration.');
172
+ return false;
173
+ }
174
+
175
+ return true;
176
+ }
177
+
178
+ /**
179
+ *
180
+ * @param lang
181
+ * @param typeOfFormat
182
+ * @param options
183
+ * @param customFormat
184
+ * @returns {boolean}
185
+ * @private
186
+ */
187
+ function __setArgs(lang, typeOfFormat, options, customFormat) {
188
+
189
+ if (typeof customFormat !== 'undefined' && customFormat !== null) {
190
+ // create object node with name of the configuration if not already existing
191
+ if (typeof optionsConf[typeOfFormat].custom[customFormat] === 'undefined')
192
+ optionsConf[typeOfFormat].custom[customFormat] = {};
193
+
194
+ optionsConf[typeOfFormat].custom[customFormat][lang] = options;
195
+ }
196
+ else
197
+ optionsConf[typeOfFormat].standard[lang] = options;
198
+
199
+ return true;
200
+ }
201
+
202
+
203
+ /*************************************
204
+ * PUBLIC INTERFACE
205
+ *************************************/
206
+
207
+ return {
208
+ /**
209
+ * configure the options for INTL number, currency, and date formatting
210
+ *
211
+ * @param langOrArr : string – the language key like 'fr' or 'all' for all languages
212
+ * | array – an array with multiple options
213
+ * @param typeOfFormat : string - DateTimeFormat | NumberFormat | PriceFormat
214
+ * @param options : object - the options object
215
+ */
216
+ configure: function (langOrArr, typeOfFormat, options, customFormatname = null) {
217
+
218
+ if (typeof langOrArr !== 'string' && !Array.isArray(langOrArr)) {
219
+ console.error('@ handlebars-i18n.configure(): Invalid argument <' + langOrArr + '> ' +
220
+ 'First argument must be a string with language code such as "en" or an array with parameters.');
221
+ return false;
222
+ }
223
+
224
+ if (Array.isArray(langOrArr)) {
225
+ if (langOrArr.length < 1) {
226
+ console.log('@ handlebars-i18n.configure(): ' +
227
+ 'You passed an empty array, no parameters taken.');
228
+ return false;
229
+ }
230
+ langOrArr.forEach(elem => {
231
+ if (__validateArgs(elem[0], elem[1], elem[2], elem[3]))
232
+ __setArgs(elem[0], elem[1], elem[2], elem[3]);
233
+ else
234
+ return false;
235
+ });
236
+ }
237
+ else {
238
+ if (__validateArgs(langOrArr, typeOfFormat, options, customFormatname))
239
+ __setArgs(langOrArr, typeOfFormat, options, customFormatname);
240
+ else
241
+ return false;
242
+ }
243
+
244
+ return true;
245
+ },
246
+
247
+ /**
248
+ * resets the configuration to default state like it is before configure() is called
249
+ */
250
+ reset: function () {
251
+ optionsConf = JSON.parse(JSON.stringify(defaultConf));
252
+ return true;
253
+ },
254
+
255
+ /**
256
+ * init all handlebars helpers
257
+ *
258
+ * @param overrideHndlbrs | optional: pass an individual instance of handlebars objec to the init() function
259
+ * to override the generic handlebars instance required in LINE 38
260
+ *
261
+ * @returns {*}
262
+ */
263
+ init: function (overrideHndlbrs) {
264
+
265
+ if (typeof overrideHndlbrs === 'object')
266
+ handlebars = overrideHndlbrs;
267
+ else if (typeof overrideHndlbrs !== 'undefined' && overrideHndlbrs !== null)
268
+ console.error('@ handlebars-i18n.init(): Invalid Argument given for overrideHndlbrs. ' +
269
+ 'Argument must be the Handlebars Object. Using previously required handlebars object instead.');
270
+
271
+ handlebars.registerHelper('__',
272
+ /**
273
+ * retrieves the translation phrase from a key given as string
274
+ * use like: {{__ "key_name"}}
275
+ * or with attributes: {{__ "key_with_count" count=7}}
276
+ *
277
+ * @param str
278
+ * @param attributes
279
+ * @returns {*}
280
+ */
281
+ function (str, attributes) {
282
+ return new handlebars.SafeString((typeof(i18next) !== 'undefined' ? i18next.t(str, attributes.hash) : str));
283
+ }
284
+ );
285
+ handlebars.registerHelper('_locale',
286
+ /**
287
+ * echos the current language
288
+ * use like: {{_locale}}
289
+ *
290
+ * @returns {language|any|string|*|e}
291
+ */
292
+ function () {
293
+ return i18next.language;
294
+ }
295
+ );
296
+ handlebars.registerHelper('localeIs',
297
+ /**
298
+ * checks against the current language
299
+ * use like: {{#if (localeIs "en")}} Hello EN {{/if}}
300
+ *
301
+ * @returns {language|any|string|*|e}
302
+ */
303
+ function (language) {
304
+ return i18next.language === language;
305
+ }
306
+ );
307
+ handlebars.registerHelper('_date',
308
+ /**
309
+ * formats a given date by the give internationalization options
310
+ *
311
+ * allows multiple input forms:
312
+ * {{_date}}
313
+ * -> returns the current date
314
+ *
315
+ * {{_date "now" hour="numeric" minute="numeric" second="numeric"}}
316
+ * -> returns the current date with specific options
317
+ *
318
+ * {{_date 1583922952743}}
319
+ * -> returns the date given in milliseconds since begin of unix epoch
320
+ *
321
+ * {{_date "2020-03-11T03:24:00"}} or {{_date "March 11, 2020 03:24:00"}}
322
+ * -> returns the date given according to date string
323
+ *
324
+ * {{_date "[2020, 2, 11]"}}
325
+ * -> returns the date given according to parameters: year, month, day, hours, minutes, seconds, milliseconds
326
+ *
327
+ * @link https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
328
+ * @link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
329
+ *
330
+ * @param dateInput : string | number
331
+ * @param options
332
+ */
333
+ function (dateInput, options) {
334
+
335
+ var date;
336
+
337
+ if (typeof dateInput === 'number') {
338
+ // input as milliseconds since unix epoch, like: 1583922952743
339
+ date = new Date(dateInput);
340
+ }
341
+ else if (typeof dateInput === 'string') {
342
+
343
+ if (dateInput.charAt(0) == '[' && dateInput.slice(-1) == ']') {
344
+ // input as array represented as string such as "[2020, 11]"
345
+ dateInput = dateInput.substring(1, dateInput.length - 1).replace(/ /g, '');
346
+ var dateArr = dateInput.split(',');
347
+ var dateFactory = __applyToConstructor.bind(null, Date);
348
+ date = dateFactory(dateArr);
349
+ }
350
+ else if (dateInput.toLowerCase() == 'now' || dateInput.toLowerCase() == 'today') {
351
+ // input as word "now" or "today"
352
+ date = new Date();
353
+ }
354
+ else {
355
+ // input as date string such as "1995-12-17T03:24:00"
356
+ date = new Date(dateInput);
357
+ }
358
+ }
359
+ else {
360
+ // fallback: today's date
361
+ date = new Date();
362
+ }
363
+
364
+ var opts = __configLookup(options, i18next.language, optionsConf.DateTimeFormat);
365
+
366
+ const dateFormat = new Intl.DateTimeFormat(i18next.language, opts);
367
+ return dateFormat.format(date);
368
+ }
369
+ );
370
+ handlebars.registerHelper('_num',
371
+ /**
372
+ * formats a given number by internationalization options
373
+ *
374
+ * use with preset: {{_num 3000}}
375
+ * or with individual option parameters: {{_num 3000 minimumFractionDigits=2}}
376
+ *
377
+ * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat
378
+ *
379
+ * @param number : number
380
+ * @param options
381
+ * @returns {*}
382
+ */
383
+ function (number, options) {
384
+
385
+ var opts = __configLookup(options, i18next.language, optionsConf.NumberFormat);
386
+
387
+ const priceFormat = new Intl.NumberFormat(i18next.language, opts);
388
+ return priceFormat.format(number);
389
+ }
390
+ );
391
+ handlebars.registerHelper('_price',
392
+ /**
393
+ * formats a number as currency
394
+ *
395
+ * use with preset: {{_price 4999.99}}
396
+ * or with individual option parameters: {{_price 4999.99 currency="EUR" minimumFractionDigits=2}}
397
+ *
398
+ * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat
399
+ *
400
+ * @param price : number
401
+ * @param options
402
+ * @returns {*}
403
+ */
404
+ function (price, options) {
405
+
406
+ var opts = __configLookup(options, i18next.language, optionsConf.PriceFormat);
407
+
408
+ // for convenience automatically add the object parameter style:'currency' if not given
409
+ if (typeof opts['style'] !== 'string' && typeof opts['currency'] === 'string')
410
+ opts['style'] = 'currency';
411
+
412
+ const priceFormat = new Intl.NumberFormat(i18next.language, opts);
413
+ return priceFormat.format(price);
414
+ }
415
+ );
416
+
417
+ return handlebars;
418
+ }
419
+ }
420
+ });
421
+
422
+
423
+
@@ -0,0 +1 @@
1
+ !function(e,r){if("object"==typeof exports&&"object"==typeof module){const e=require("handlebars"),n=require("i18next"),t=require("intl");module.exports=r(e,n,t)}else if("function"==typeof define&&define.amd)define(["Handlebars","i18next","Intl"],r);else{if("object"!=typeof e.Handlebars||"object"!=typeof e.i18next||"object"!=typeof e.Intl)return console.error("@ handlebars-i18n: One or more dependencies are missing. Check for Handlebars, i18next and Intl."),!1;e.HandlebarsI18n=r(e.Handlebars,e.i18next,e.Intl)}}(this,(function(e,r,n){"use strict";var t={DateTimeFormat:{standard:{},custom:{}},NumberFormat:{standard:{},custom:{}},PriceFormat:{standard:{all:{style:"currency",currency:"EUR"}},custom:{}}},a=JSON.parse(JSON.stringify(t));function o(e,r){var n=[null].concat(r);return new(e.bind.apply(e,n))}function i(e,r,n){if("object"==typeof e&&"object"==typeof e.hash&&Object.keys(e.hash).length>0){var t=e.hash;if(void 0===t.format)return t;if(void 0!==n.custom[t.format]&&void 0!==n.custom[t.format][r])return n.custom[t.format][r]}return void 0!==n.standard[r]?n.standard[r]:void 0!==n.standard.all?n.standard.all:{}}function s(e,r,n,t){return"string"!=typeof e?(console.error("@ handlebars-i18n.configure(): Invalid argument <"+e+'> First argument must be a string with language code such as "en".'),!1):"DateTimeFormat"!==r&&"NumberFormat"!==r&&"PriceFormat"!==r?(console.error("@ handlebars-i18n.configure(): Invalid argument <"+r+'>. Second argument must be a string with the options key. Use either "DateTimeFormat", "NumberFormat" or "PriceFormat".'),!1):"object"!=typeof n?(console.error("@ handlebars-i18n.configure(): Invalid argument <"+n+"> Third argument must be an object containing the configuration parameters."),!1):(null==t||"string"==typeof t)&&""!=t&&" "!=t||(console.error("@ handlebars-i18n.configure(): Invalid argument <"+t+"> Fourth argument (optional) must be a string naming your custom format configuration."),!1)}function u(e,r,n,t){return null!=t?(void 0===a[r].custom[t]&&(a[r].custom[t]={}),a[r].custom[t][e]=n):a[r].standard[e]=n,!0}return{configure:function(e,r,n,t=null){if("string"!=typeof e&&!Array.isArray(e))return console.error("@ handlebars-i18n.configure(): Invalid argument <"+e+'> First argument must be a string with language code such as "en" or an array with parameters.'),!1;if(Array.isArray(e)){if(e.length<1)return console.log("@ handlebars-i18n.configure(): You passed an empty array, no parameters taken."),!1;e.forEach(e=>{if(!s(e[0],e[1],e[2],e[3]))return!1;u(e[0],e[1],e[2],e[3])})}else{if(!s(e,r,n,t))return!1;u(e,r,n,t)}return!0},reset:function(){return a=JSON.parse(JSON.stringify(t)),!0},init:function(t){return"object"==typeof t?e=t:null!=t&&console.error("@ handlebars-i18n.init(): Invalid Argument given for overrideHndlbrs. Argument must be the Handlebars Object. Using previously required handlebars object instead."),e.registerHelper("__",(function(n,t){return new e.SafeString(void 0!==r?r.t(n,t.hash):n)})),e.registerHelper("_locale",(function(){return r.language})),e.registerHelper("localeIs",(function(e){return r.language===e})),e.registerHelper("_date",(function(e,t){var s;if("number"==typeof e)s=new Date(e);else if("string"==typeof e)if("["==e.charAt(0)&&"]"==e.slice(-1)){var u=(e=e.substring(1,e.length-1).replace(/ /g,"")).split(",");s=o.bind(null,Date)(u)}else s="now"==e.toLowerCase()||"today"==e.toLowerCase()?new Date:new Date(e);else s=new Date;var l=i(t,r.language,a.DateTimeFormat);return new n.DateTimeFormat(r.language,l).format(s)})),e.registerHelper("_num",(function(e,t){var o=i(t,r.language,a.NumberFormat);return new n.NumberFormat(r.language,o).format(e)})),e.registerHelper("_price",(function(e,t){var o=i(t,r.language,a.PriceFormat);"string"!=typeof o.style&&"string"==typeof o.currency&&(o.style="currency");return new n.NumberFormat(r.language,o).format(e)})),e}}}));