@pcdevil/eleventy-plugin-intl-utils 1.0.1 → 1.1.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.
- package/.prettierrc.json +11 -0
- package/README.md +17 -0
- package/package.json +12 -9
- package/src/eleventy.js +18 -0
- package/src/filters/country_name.js +1 -1
- package/src/filters/language_name.js +1 -1
- package/src/filters/short_datetime_format.js +1 -1
- package/src/shortcodes/year_interval.js +1 -1
- package/src/shortcodes/year_open_interval.js +16 -0
- package/.eleventy.js +0 -16
package/.prettierrc.json
ADDED
package/README.md
CHANGED
|
@@ -116,5 +116,22 @@ This behaviour helps when an open-ended / ongoing interval needs be displayed:
|
|
|
116
116
|
|
|
117
117
|
This renders "2011 – 2021" (with en dash in the middle) when the `intlUtilConfig.locale` is `en` and the current year is 2021.
|
|
118
118
|
|
|
119
|
+
### `year_open_interval`
|
|
120
|
+
Transforms a date string into an _open_ year range where the end date is absent. Useful when a ongoing interval is presented.
|
|
121
|
+
|
|
122
|
+
- **Used Internationalization API**: `Intl.DateTimeFormat.prototype.formatRange()` with _numeric_ year ([MDN article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange))
|
|
123
|
+
|
|
124
|
+
#### LiquidJS Example
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
{% assign startDate = "2011-05-16 11:00 +0200" %}
|
|
128
|
+
{% year_interval startDate %}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
This renders "2011 – " (with en dash in the middle) when the `intlUtilConfig.locale` is `en`.
|
|
132
|
+
|
|
133
|
+
#### Difference from `year_interval`
|
|
134
|
+
While the [`year_interval`](#year_interval) shortcode always created a _closed_ year range (by applying the current year as default), the `year_open_interval` only displays the start date.
|
|
135
|
+
|
|
119
136
|
## License
|
|
120
137
|
Available under the [MIT license](LICENSE.md).
|
package/package.json
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pcdevil/eleventy-plugin-intl-utils",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"description": "A set of internationalization utils for Eleventy.",
|
|
9
9
|
"engines": {
|
|
10
|
-
"node": ">=
|
|
10
|
+
"node": ">= 18.0.0"
|
|
11
11
|
},
|
|
12
|
-
"main": "
|
|
12
|
+
"main": "./src/eleventy.js",
|
|
13
13
|
"scripts": {
|
|
14
|
-
"
|
|
14
|
+
"format": "prettier --check src/",
|
|
15
|
+
"format:fix": "npm run format -- --write",
|
|
16
|
+
"lint": "npx eslint --ignore-path .gitignore .",
|
|
17
|
+
"lint:fix": "npm run lint -- --fix",
|
|
18
|
+
"release:major": "npm version major",
|
|
19
|
+
"release:minor": "npm version minor",
|
|
20
|
+
"release:patch": "npm version patch"
|
|
15
21
|
},
|
|
16
22
|
"repository": {
|
|
17
23
|
"type": "git",
|
|
@@ -36,10 +42,7 @@
|
|
|
36
42
|
},
|
|
37
43
|
"homepage": "https://github.com/pcdevil/eleventy-plugin-intl-utils#readme",
|
|
38
44
|
"devDependencies": {
|
|
39
|
-
"eslint": "^
|
|
40
|
-
"
|
|
41
|
-
"eslint-plugin-import": "^2.25.3",
|
|
42
|
-
"eslint-plugin-node": "^11.1.0",
|
|
43
|
-
"eslint-plugin-promise": "^5.2.0"
|
|
45
|
+
"eslint": "^8.36.0",
|
|
46
|
+
"prettier": "^2.8.6"
|
|
44
47
|
}
|
|
45
48
|
}
|
package/src/eleventy.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const countryNameFactory = require('./filters/country_name');
|
|
4
|
+
const languageNameFactory = require('./filters/language_name');
|
|
5
|
+
const shortDateTimeFormatFactory = require('./filters/short_datetime_format');
|
|
6
|
+
const yearIntervalFactory = require('./shortcodes/year_interval');
|
|
7
|
+
const yearOpenIntervalFactory = require('./shortcodes/year_open_interval');
|
|
8
|
+
|
|
9
|
+
module.exports = (eleventyConfig, pluginConfig = {}) => {
|
|
10
|
+
const { locale } = pluginConfig;
|
|
11
|
+
|
|
12
|
+
eleventyConfig.addFilter('country_name', countryNameFactory(locale));
|
|
13
|
+
eleventyConfig.addFilter('language_name', languageNameFactory(locale));
|
|
14
|
+
eleventyConfig.addFilter('short_datetime_format', shortDateTimeFormatFactory(locale));
|
|
15
|
+
|
|
16
|
+
eleventyConfig.addShortcode('year_interval', yearIntervalFactory(locale));
|
|
17
|
+
eleventyConfig.addShortcode('year_open_interval', yearOpenIntervalFactory(locale));
|
|
18
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function yearOpenIntervalFactory(locale) {
|
|
4
|
+
const dateTimeFormat = new Intl.DateTimeFormat(locale, {
|
|
5
|
+
year: 'numeric',
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
return (startDate) =>
|
|
9
|
+
dateTimeFormat
|
|
10
|
+
.formatRangeToParts(new Date(startDate), new Date())
|
|
11
|
+
.filter(({ source }) => source !== 'endRange')
|
|
12
|
+
.map(({ value }) => value)
|
|
13
|
+
.join('');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = yearOpenIntervalFactory;
|
package/.eleventy.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const countryNameFactory = require('./src/filters/country_name');
|
|
4
|
-
const languageNameFactory = require('./src/filters/language_name');
|
|
5
|
-
const shortDateTimeFormatFactory = require('./src/filters/short_datetime_format');
|
|
6
|
-
const yearIntervalFactory = require('./src/shortcodes/year_interval');
|
|
7
|
-
|
|
8
|
-
module.exports = (eleventyConfig, pluginConfig = {}) => {
|
|
9
|
-
const { locale } = pluginConfig;
|
|
10
|
-
|
|
11
|
-
eleventyConfig.addFilter('country_name', countryNameFactory(locale));
|
|
12
|
-
eleventyConfig.addFilter('language_name', languageNameFactory(locale));
|
|
13
|
-
eleventyConfig.addFilter('short_datetime_format', shortDateTimeFormatFactory(locale));
|
|
14
|
-
|
|
15
|
-
eleventyConfig.addShortcode('year_interval', yearIntervalFactory(locale));
|
|
16
|
-
};
|