handlebars-i18n 1.10.0 → 1.10.2
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.
- package/.github/workflows/ci.yml +2 -5
- package/.github/workflows/coveralls.yml +3 -3
- package/.github/workflows/node.js.yml +10 -10
- package/CHANGELOG.md +1 -1
- package/dist/handlebars-i18n.js +1 -0
- package/dist/handlebars-i18n.min.js +1 -1
- package/package.json +14 -12
- package/readme.md +5 -5
- package/test/handlebars-i18n.test.js +7 -1
package/.github/workflows/ci.yml
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
name: Test and Coverage
|
|
1
|
+
name: CI Test and Coverage
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
push:
|
|
@@ -13,10 +13,10 @@ jobs:
|
|
|
13
13
|
|
|
14
14
|
- uses: actions/checkout@v3
|
|
15
15
|
|
|
16
|
-
- name: Use Node.js
|
|
16
|
+
- name: Use Node.js 22.x
|
|
17
17
|
uses: actions/setup-node@v3
|
|
18
18
|
with:
|
|
19
|
-
node-version:
|
|
19
|
+
node-version: 22.x
|
|
20
20
|
|
|
21
21
|
- name: npm install, make test-coverage
|
|
22
22
|
run: |
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
|
|
2
2
|
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
|
|
3
3
|
|
|
4
|
-
name:
|
|
4
|
+
name: CI Build
|
|
5
5
|
|
|
6
6
|
on:
|
|
7
7
|
push:
|
|
@@ -16,15 +16,15 @@ jobs:
|
|
|
16
16
|
|
|
17
17
|
strategy:
|
|
18
18
|
matrix:
|
|
19
|
-
node-version: [
|
|
19
|
+
node-version: [ 16.x, 18.x, 20.x ]
|
|
20
20
|
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
|
21
21
|
|
|
22
22
|
steps:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
- uses: actions/checkout@v3
|
|
24
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
25
|
+
uses: actions/setup-node@v3
|
|
26
|
+
with:
|
|
27
|
+
node-version: ${{ matrix.node-version }}
|
|
28
|
+
cache: 'npm'
|
|
29
|
+
- run: npm ci
|
|
30
|
+
- run: npm run build --if-present
|
package/CHANGELOG.md
CHANGED
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
|
|
48
48
|
### Bug Fixes
|
|
49
49
|
|
|
50
|
-
* it() in line 72 in handlebars-i18n.test.
|
|
50
|
+
* it() in line 72 in handlebars-i18n.test.mjs ([88049f9](https://github.com/fwalzel/handlebars-i18n/commit/88049f94c7dbf72ee58b713e0a3ab494a4cde28f))
|
|
51
51
|
* **release:** schedule release ([052f0e1](https://github.com/fwalzel/handlebars-i18n/commit/052f0e1e5cbae779060fe45c604fc97bf0b1c34f))
|
|
52
52
|
|
|
53
53
|
|
package/dist/handlebars-i18n.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){if("object"==typeof exports&&"object"==typeof module){const e=require("handlebars"),r=require("i18next"),n=require("intl"),a=require("relative-time-format");module.exports=t(e,r,n,a,"TEST"===process?.env?.NODE_ENV)}else if("function"==typeof define&&define.amd)define(["Handlebars","i18next","Intl"],t);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=t(e.Handlebars,e.i18next,e.Intl)}}(this,
|
|
1
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module){const e=require("handlebars"),r=require("i18next"),n=require("intl"),a=require("relative-time-format");module.exports=t(e,r,n,a,"TEST"===process?.env?.NODE_ENV)}else if("function"==typeof define&&define.amd)define(["Handlebars","i18next","Intl"],t);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=t(e.Handlebars,e.i18next,e.Intl)}}(this,function(e,t,r,n,a){"use strict";const o={DateTimeFormat:{standard:{},custom:{}},RelativeTimeFormat:{standard:{all:{unit:"hours"}},custom:{}},NumberFormat:{standard:{},custom:{}},PriceFormat:{standard:{all:{style:"currency",currency:"EUR"}},custom:{}}};let i=JSON.parse(JSON.stringify(o));const s={};function u(e,t){let r=[null].concat(t);return new(e.bind.apply(e,r))}function l(e,t,r){if("object"==typeof e&&"object"==typeof e.hash&&Object.keys(e.hash).length>0){let n=e.hash;if(void 0===n.format)return n;if(void 0!==r.custom[n.format]&&void 0!==r.custom[n.format][t])return r.custom[n.format][t]}return void 0!==r.standard[t]?r.standard[t]:void 0!==r.standard.all?r.standard.all:{}}function c(e,t,r,n){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","RelativeTimeFormat","NumberFormat","PriceFormat"].includes(t)?"object"!=typeof r?(console.error("@ handlebars-i18n.configure(): Invalid argument <"+r+"> Third argument must be an object containing the configuration parameters."),!1):(null==n||"string"==typeof n)&&""!==n&&" "!==n||(console.error("@ handlebars-i18n.configure(): Invalid argument <"+n+"> Fourth argument (optional) must be a string naming your custom format configuration."),!1):(console.error("@ handlebars-i18n.configure(): Invalid argument <"+t+'>. Second argument must be a string with the options key. Use either "DateTimeFormat", "RelativeTimeFormat", "NumberFormat", or "PriceFormat".'),!1)}function m(e,t,r,n){return null!=n?(void 0===i[t].custom[n]&&(i[t].custom[n]={}),i[t].custom[n][e]=r):i[t].standard[e]=r,!0}function g(e){return"number"==typeof e||"string"==typeof e&&""!==e}function f(e){let t;if("number"==typeof e)t=new Date(e);else if("string"==typeof e)if("["===e.charAt(0)&&"]"===e.slice(-1)){let r=(e=e.substring(1,e.length-1).replace(/ /g,"")).split(",");t=u.bind(null,Date)(r)}else t="now"===e.toLowerCase()||"today"===e.toLowerCase()?new Date:new Date(e);else t=new Date;return t}function d(e,t){if("function"==typeof r.RelativeTimeFormat)return new r.RelativeTimeFormat(e,t);if(void 0===s[e])try{s[e]=require(`relative-time-format/locale/${e}`)}catch(e){console.error(e)}return n.addLocale(s[e]),new n(e,t)}function b(e,t){return t=t||"hour",Math.trunc(e/{second:1e3,seconds:1e3,minute:6e4,minutes:6e4,hour:36e5,hours:36e5,day:864e5,days:864e5,week:6048e5,weeks:6048e5,month:2629746e3,months:2629746e3,quarter:78894e5,quarters:78894e5,year:315576e5,years:315576e5}[t])}return{configure:function(e,t,r,n){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 language 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(!c(e[0],e[1],e[2],e[3]))return!1;m(e[0],e[1],e[2],e[3])})}else{if(!c(e,t,r,n))return!1;m(e,t,r,n)}return!0},reset:function(){return i=JSON.parse(JSON.stringify(o)),!0},init:function(n,a){return"object"==typeof n&&null!==n?e=n:null!=n&&console.error("@ handlebars-i18n.init(): Invalid Argument [1] given for overrideHndlbrs. Argument must be the Handlebars object. Using generic Handlebars object instead."),"object"==typeof a&&null!==a?t=a:null!=a&&console.error("@ handlebars-i18n.init(): Invalid Argument [2] given for overrideI18n. Argument must be the i18next object. Using generic i18next object on module level instead."),e.registerHelper("__",function(r,n){const a=n.hash||{},o=void 0!==t?t.t(r,{...a,returnObjects:!0}):r;return"string"==typeof o?new e.SafeString(o):o}),e.registerHelper("keyExists",function(e){return t.exists(e)}),e.registerHelper("_locale",function(){return t.language}),e.registerHelper("localeIs",function(e){return t.language===e}),e.registerHelper("_date",function(e,n){const a=f(e),o=l(n,t.language,i.DateTimeFormat);return new r.DateTimeFormat(t.language,o).format(a)}),e.registerHelper("_dateAdd",function(e,n,a){if("number"!=typeof e&&"string"!=typeof e)throw new Error('@ handlebars-i18n: invalid first argument "dateInput" was given for _dateAdd.');if("number"!=typeof n)throw new Error('@ handlebars-i18n: invalid second argument "offset" was given for _dateAdd.');const o=f(e),s=l(a,t.language,i.DateTimeFormat);switch(s.unit=s.unit||"hour",s.unit){case"second":case"seconds":o.setSeconds(o.getSeconds()+n);break;case"minute":case"minutes":o.setMinutes(o.getMinutes()+n);break;case"hour":case"hours":o.setHours(o.getHours()+n);break;case"day":case"days":o.setDate(o.getDate()+n);break;case"week":case"weeks":o.setDate(o.getDate()+7*n);break;case"month":case"months":o.setMonth(o.getMonth()+n);break;case"quarter":case"quarters":o.setMonth(o.getMonth()+3*n);break;case"year":case"years":o.setFullYear(o.getFullYear()+n);break;default:throw new Error('@ handlebars-i18n: invalid argument "unit" was given for _dateAdd.Unit must be one of "second" | "minute" | "hour" | "day" | "week" | "month" | "quarter" | "year".')}return new r.DateTimeFormat(t.language,s).format(o)}),e.registerHelper("_dateRel",function(e,r){const n=parseInt(e),a=l(r,t.language,i.RelativeTimeFormat);return d(t.language,a).format(n,a.unit)}),e.registerHelper("_dateDiff",function(e,r,n){let a,o=l(n,t.language,i.RelativeTimeFormat);if(!g(e))return console.error("@ handlebars-i18n: invalid first argument dateInputA was given for _dateDiff."),null;r=r||"now",a=f(e)-f(r);const s=b(a,o.unit);return d(t.language,o).format(s,o.unit)}),e.registerHelper("_num",function(e,n){let a=l(n,t.language,i.NumberFormat);return new r.NumberFormat(t.language,a).format(e)}),e.registerHelper("_price",function(e,n){let a=l(n,t.language,i.PriceFormat);"string"!=typeof a.style&&"string"==typeof a.currency&&(a.style="currency");return new r.NumberFormat(t.language,a).format(e)}),e},...a&&{private:{applyToConstructor:u,configLookup:l,validateArgs:c,setArgs:m,isNumOrString:g,createDateObj:f,getRelDateFormatPolyfill:d,getDateDiff:b}}}});
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "handlebars-i18n",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.2",
|
|
4
4
|
"description": "handlebars-i18n adds internationalization to handlebars.js using i18next and Intl.",
|
|
5
5
|
"main": "dist/handlebars-i18n.js",
|
|
6
|
+
"types": "dist/handlebars-i18n.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"test": "NODE_ENV=TEST c8 mocha",
|
|
8
9
|
"test:coverage": "npm run test && NODE_ENV=TEST c8 report --reporter=text-lcov > coverage/lcov.info",
|
|
@@ -42,26 +43,27 @@
|
|
|
42
43
|
"intl": "^1.2.5"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
|
-
"@commitlint/cli": "
|
|
46
|
-
"@commitlint/config-conventional": "
|
|
46
|
+
"@commitlint/cli": "20.2.0",
|
|
47
|
+
"@commitlint/config-conventional": "20.2.0",
|
|
47
48
|
"@types/intl": "^1.2.2",
|
|
48
|
-
"@types/node": "^
|
|
49
|
+
"@types/node": "^25.0.3",
|
|
49
50
|
"c8": "^10.1.3",
|
|
50
|
-
"chai": "
|
|
51
|
-
"coveralls-next": "^
|
|
52
|
-
"
|
|
53
|
-
"gulp
|
|
51
|
+
"chai": "^6.2.2",
|
|
52
|
+
"coveralls-next": "^6.0.1",
|
|
53
|
+
"glob": "^13.0.0",
|
|
54
|
+
"gulp": "5.0.1",
|
|
55
|
+
"gulp-rename": "2.1.0",
|
|
54
56
|
"gulp-uglify": "3.0.2",
|
|
55
57
|
"gulp-uglify-es": "3.0.0",
|
|
56
58
|
"html-entities": "^2.6.0",
|
|
57
|
-
"mocha": "
|
|
59
|
+
"mocha": "11.7.5",
|
|
58
60
|
"mocha-lcov-reporter": "^1.3.0",
|
|
59
|
-
"nyc": "
|
|
60
|
-
"typescript": "^
|
|
61
|
+
"nyc": "17.1.0",
|
|
62
|
+
"typescript": "^5.9.3"
|
|
61
63
|
},
|
|
62
64
|
"dependencies": {
|
|
63
65
|
"handlebars": "^4.7.8",
|
|
64
|
-
"i18next": "^
|
|
66
|
+
"i18next": "^25.7.3",
|
|
65
67
|
"intl": "^1.2.5",
|
|
66
68
|
"relative-time-format": "^1.1.11"
|
|
67
69
|
},
|
package/readme.md
CHANGED
|
@@ -66,7 +66,7 @@ Usage in web browser (old school):
|
|
|
66
66
|
|
|
67
67
|
Via CDN:
|
|
68
68
|
```javascript
|
|
69
|
-
<script src="https://cdn.jsdelivr.net/npm/handlebars-i18n@1.10.
|
|
69
|
+
<script src="https://cdn.jsdelivr.net/npm/handlebars-i18n@1.10.1/dist/handlebars-i18n.min.js"></script>
|
|
70
70
|
```
|
|
71
71
|
|
|
72
72
|
## Quick Example
|
|
@@ -349,14 +349,14 @@ Adds a time offset in a given unit to a date, returns the modified date.
|
|
|
349
349
|
|
|
350
350
|
The first argument is a date (see function `_date` for valid date inputs). The second argument is a time amount given
|
|
351
351
|
as number. The option **unit** specifies the time amount. Possible units
|
|
352
|
-
are `
|
|
352
|
+
are `second` | `minute` | `hour` | `day` | `week` | `month` | `quarter` | `year` (default is `hour`).
|
|
353
353
|
Further options as for function `_date` can be applied.
|
|
354
354
|
|
|
355
355
|
---
|
|
356
356
|
|
|
357
357
|
### `_dateDiff`
|
|
358
358
|
|
|
359
|
-
Outputs the
|
|
359
|
+
Outputs the time difference between two given dates in the requested unit.
|
|
360
360
|
|
|
361
361
|
```hbs
|
|
362
362
|
{{_dateDiff "2000-12-17" "2001-12-17" unit="year"}}
|
|
@@ -365,7 +365,7 @@ Outputs the relative time difference between two given dates in the requested un
|
|
|
365
365
|
|
|
366
366
|
The second date argument is subtracted from the first. If the difference is a positive value, a future event statement
|
|
367
367
|
is made. A negative value refers to a past date. (If no second argument is given, the default date is the present moment).
|
|
368
|
-
Allowed date input formats are similar to `_date`, options equal `_dateRel`. Default unit is `
|
|
368
|
+
Allowed date input formats are similar to `_date`, options equal `_dateRel`. Default unit is `hour`.
|
|
369
369
|
|
|
370
370
|
---
|
|
371
371
|
|
|
@@ -386,7 +386,7 @@ Outputs a string with a relative date statement, formatted according to the lang
|
|
|
386
386
|
* output: en → **7 hours ago**
|
|
387
387
|
|
|
388
388
|
A positive number argument leads to a future event statement, a negative refers to a past date. Possible units
|
|
389
|
-
are `
|
|
389
|
+
are `second` | `minute` | `hour` | `day` | `week` | `month` | `quarter` | `year` (default is `hour`).
|
|
390
390
|
For a complete set of options (such as `numberingSystem` or `localeMatcher`)
|
|
391
391
|
see [Intl.RelativeTimeFormat Constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat).
|
|
392
392
|
Alternatively check this repo’s TS types in [handlebars-i18n.d.ts](./dist/handlebars-i18n.d.ts).
|
|
@@ -10,7 +10,13 @@ const expect = require('chai').expect;
|
|
|
10
10
|
|
|
11
11
|
const Handlebars = require('handlebars');
|
|
12
12
|
const i18next = require('i18next');
|
|
13
|
-
const HandlebarsI18n = require('../dist/handlebars-i18n');
|
|
13
|
+
const HandlebarsI18n = require('../dist/handlebars-i18n.js');
|
|
14
|
+
/*before(async () => {
|
|
15
|
+
const mod = await import('../dist/handlebars-i18n.js');
|
|
16
|
+
HandlebarsI18n = mod.default || mod; // ✅ Works in both CJS and ESM
|
|
17
|
+
});*/
|
|
18
|
+
|
|
19
|
+
console.log(HandlebarsI18n);
|
|
14
20
|
|
|
15
21
|
describe('handlebars-i18n Tests', function () {
|
|
16
22
|
|