i18nizeelement 0.3.0 → 0.5.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/README.md +10 -2
- package/dist/i18nizeelement-jamilih-plugin.d.ts +4 -0
- package/dist/i18nizeelement-jamilih-plugin.d.ts.map +1 -0
- package/dist/i18nizeelement-jamilih-plugin.es6.js +168 -149
- package/dist/i18nizeelement-jamilih-plugin.es6.js.map +1 -1
- package/dist/i18nizeelement-jamilih-plugin.umd.js +296 -277
- package/dist/i18nizeelement-jamilih-plugin.umd.js.map +1 -1
- package/dist/i18nizeelement.es6.js +152 -141
- package/dist/i18nizeelement.es6.js.map +1 -1
- package/dist/i18nizeelement.umd.js +257 -246
- package/dist/i18nizeelement.umd.js.map +1 -1
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/package.json +64 -49
- package/src/i18nizeelement-jamilih-plugin.js +14 -3
- package/src/index.js +30 -7
- package/CHANGES.md +0 -28
package/package.json
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "i18nizeelement",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"author": "Brett Zamir",
|
|
5
5
|
"contributors": [],
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "Internationalize an element with `lang`, `dir`, and `style.writingMode` as indicated by the supplied language and settings",
|
|
8
|
+
"type": "module",
|
|
8
9
|
"main": "dist/i18nizeelement.umd.js",
|
|
9
|
-
"
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/i18nizeelement.es6.js",
|
|
14
|
+
"require": "./dist/i18nizeelement.umd.js"
|
|
15
|
+
},
|
|
16
|
+
"./jamilih-plugin.js": {
|
|
17
|
+
"types": "./dist/i18nizeelement-jamilih-plugin.d.ts",
|
|
18
|
+
"import": "./dist/i18nizeelement-jamilih-plugin.es6.js",
|
|
19
|
+
"require": "./dist/i18nizeelement-jamilih-plugin.umd.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
10
22
|
"repository": {
|
|
11
23
|
"type": "git",
|
|
12
24
|
"url": "https://github.com/brettz9/i18nizeElement"
|
|
@@ -18,56 +30,59 @@
|
|
|
18
30
|
"html",
|
|
19
31
|
"rtl"
|
|
20
32
|
],
|
|
21
|
-
"scripts": {
|
|
22
|
-
"eslint": "eslint --ext=js,md,html .",
|
|
23
|
-
"rollup": "rollup -c rollup.config.umd.js && rollup -c rollup.config.es6.js",
|
|
24
|
-
"start": "npm run test:watch",
|
|
25
|
-
"mocha": "_mocha --require esm --require test/bootstrap/node.js test/*.js --exit",
|
|
26
|
-
"test:watch": "nodemon --watch src --watch test --exec 'npm test'",
|
|
27
|
-
"nyc": "echo 'Deleting esm cache for coverage' && rm -Rf node_modules/.cache/esm && nyc npm run mocha",
|
|
28
|
-
"test": "npm run mocha",
|
|
29
|
-
"test-cov": "npm run rollup && npm run nyc",
|
|
30
|
-
"browser-test": "npm run rollup && open-cli http://127.0.0.1:8080/test/ && static -p 8080",
|
|
31
|
-
"prepare": "npm run rollup && npm test"
|
|
32
|
-
},
|
|
33
33
|
"engines": {
|
|
34
|
-
"node": ">=
|
|
34
|
+
"node": ">=16.0.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@babel/core": "^7.
|
|
38
|
-
"@
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"eslint
|
|
47
|
-
"eslint-
|
|
48
|
-
"eslint-
|
|
49
|
-
"eslint-plugin-
|
|
50
|
-
"eslint-plugin-
|
|
51
|
-
"eslint-plugin-
|
|
52
|
-
"eslint-plugin-
|
|
53
|
-
"eslint-plugin-
|
|
54
|
-
"eslint-plugin-
|
|
55
|
-
"eslint-plugin-
|
|
37
|
+
"@babel/core": "^7.21.8",
|
|
38
|
+
"@brettz9/eslint-plugin": "^1.0.4",
|
|
39
|
+
"@rollup/plugin-babel": "^6.0.3",
|
|
40
|
+
"@rollup/plugin-node-resolve": "^15.0.2",
|
|
41
|
+
"@types/chai": "^4.3.5",
|
|
42
|
+
"@types/jsdom": "^21.1.1",
|
|
43
|
+
"@types/mocha": "^10.0.1",
|
|
44
|
+
"c8": "^7.13.0",
|
|
45
|
+
"chai": "^4.3.7",
|
|
46
|
+
"eslint": "^8.40.0",
|
|
47
|
+
"eslint-config-ash-nazg": "^34.12.0",
|
|
48
|
+
"eslint-config-standard": "^17.0.0",
|
|
49
|
+
"eslint-plugin-array-func": "^3.1.8",
|
|
50
|
+
"eslint-plugin-compat": "^4.1.4",
|
|
51
|
+
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
52
|
+
"eslint-plugin-html": "^7.1.0",
|
|
53
|
+
"eslint-plugin-import": "^2.27.5",
|
|
54
|
+
"eslint-plugin-jsdoc": "^44.2.1",
|
|
55
|
+
"eslint-plugin-markdown": "^3.0.0",
|
|
56
|
+
"eslint-plugin-no-unsanitized": "^4.0.2",
|
|
57
|
+
"eslint-plugin-no-use-extend-native": "^0.5.0",
|
|
58
|
+
"eslint-plugin-node": "^11.1.0",
|
|
59
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
60
|
+
"eslint-plugin-sonarjs": "^0.19.0",
|
|
61
|
+
"eslint-plugin-standard": "^4.1.0",
|
|
62
|
+
"eslint-plugin-unicorn": "^47.0.0",
|
|
56
63
|
"esm": "^3.2.25",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
64
|
+
"intl-locale-textinfo-polyfill": "^1.0.1",
|
|
65
|
+
"jamilih": "^0.57.1",
|
|
66
|
+
"jsdom": "^22.0.0",
|
|
67
|
+
"mocha": "^10.2.0",
|
|
60
68
|
"node-static": "0.7.11",
|
|
61
|
-
"nodemon": "^
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"rollup-plugin-commonjs": "^10.1.0",
|
|
67
|
-
"rollup-plugin-node-resolve": "^5.2.0",
|
|
68
|
-
"rtl-detect": "^1.0.2",
|
|
69
|
-
"source-map-support": "^0.5.16",
|
|
70
|
-
"typescript": "^3.7.2"
|
|
69
|
+
"nodemon": "^2.0.22",
|
|
70
|
+
"open-cli": "^7.2.0",
|
|
71
|
+
"rollup": "^3.21.6",
|
|
72
|
+
"source-map-support": "^0.5.21",
|
|
73
|
+
"typescript": "^5.0.4"
|
|
71
74
|
},
|
|
72
|
-
"
|
|
73
|
-
|
|
75
|
+
"scripts": {
|
|
76
|
+
"lint": "npm run eslint",
|
|
77
|
+
"eslint": "eslint --ext=js,md,html .",
|
|
78
|
+
"tsc": "tsc",
|
|
79
|
+
"build": "npm run rollup && tsc -p tsconfig-prod.json",
|
|
80
|
+
"rollup": "rollup -c rollup.config.umd.js && rollup -c rollup.config.es6.js",
|
|
81
|
+
"start": "npm run test:watch",
|
|
82
|
+
"mocha": "_mocha --require chai/register-expect.js --require test/bootstrap/node.js test/*.js --exit",
|
|
83
|
+
"test:watch": "nodemon --watch src --watch test --exec 'npm test'",
|
|
84
|
+
"c8": "echo 'Deleting esm cache for coverage' && rm -Rf node_modules/.cache && c8 npm run mocha",
|
|
85
|
+
"test": "npm run eslint && npm run build && npm run c8",
|
|
86
|
+
"browser-test": "npm run build && open-cli http://127.0.0.1:8080/test/ && static -p 8080"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import i18nizeElement from './index.js';
|
|
2
2
|
|
|
3
|
+
/** @type {import('jamilih').JamilihPlugin} */
|
|
3
4
|
const plugin = {
|
|
4
5
|
name: '$_language',
|
|
5
|
-
async set ({element, attribute: {value
|
|
6
|
+
async set ({element, attribute: {value}}) {
|
|
7
|
+
let options = /** @type {import('jamilih').PluginValue} */ (
|
|
8
|
+
value
|
|
9
|
+
);
|
|
6
10
|
if (typeof options === 'string') {
|
|
7
11
|
options = {language: options};
|
|
8
12
|
} else if (Array.isArray(options)) {
|
|
@@ -16,8 +20,15 @@ const plugin = {
|
|
|
16
20
|
// the child element into the ancestors
|
|
17
21
|
// it is being built with
|
|
18
22
|
await Promise.resolve();
|
|
19
|
-
i18nizeElement(element, {
|
|
20
|
-
...
|
|
23
|
+
i18nizeElement(/** @type {HTMLElement} */ (element), {
|
|
24
|
+
...(
|
|
25
|
+
/**
|
|
26
|
+
* @type {{
|
|
27
|
+
* [key: string]: any;
|
|
28
|
+
* }}
|
|
29
|
+
*/
|
|
30
|
+
(options)
|
|
31
|
+
)
|
|
21
32
|
});
|
|
22
33
|
}
|
|
23
34
|
};
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import 'intl-locale-textinfo-polyfill/lib/polyfill.js';
|
|
2
|
+
|
|
3
3
|
// e.g., `i18nizeElement(document.title, {language: 'ar-AR'});`
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {HTMLElement} element
|
|
7
|
+
* @param {{
|
|
8
|
+
* language?: string,
|
|
9
|
+
* avoidLangIfSet?: boolean,
|
|
10
|
+
* avoidDirIfSet?: boolean,
|
|
11
|
+
* avoidLTRByDefault?: boolean
|
|
12
|
+
* }} cfg
|
|
13
|
+
*/
|
|
4
14
|
const i18nizeElement = (element, {
|
|
5
15
|
language,
|
|
6
16
|
// These avoid setting if found to be already set with the same value
|
|
@@ -22,7 +32,9 @@ const i18nizeElement = (element, {
|
|
|
22
32
|
// 3. The closest ancestor with `lang` has a different language from
|
|
23
33
|
// the supplied
|
|
24
34
|
if (avoidLangIfSet) {
|
|
25
|
-
presetLangElement =
|
|
35
|
+
presetLangElement = /** @type {HTMLElement} */ (
|
|
36
|
+
element.closest('[lang]')
|
|
37
|
+
);
|
|
26
38
|
}
|
|
27
39
|
if (!presetLangElement || presetLangElement.lang !== language) {
|
|
28
40
|
element.lang = language;
|
|
@@ -37,14 +49,25 @@ const i18nizeElement = (element, {
|
|
|
37
49
|
// direction or the user isn't avoiding (the default) LTR)
|
|
38
50
|
// 3. The closest ancestor with `dir` has a different `dir` from the
|
|
39
51
|
// direction of the supplied language
|
|
40
|
-
const dir =
|
|
52
|
+
const {direction: dir} =
|
|
53
|
+
/**
|
|
54
|
+
* @type {Intl.Locale & {
|
|
55
|
+
* textInfo: {direction: "ltr"|"rtl"|"ttb"}
|
|
56
|
+
* }}
|
|
57
|
+
*/ (
|
|
58
|
+
new Intl.Locale(language)
|
|
59
|
+
).textInfo;
|
|
60
|
+
|
|
61
|
+
/** @type {HTMLElement|undefined} */
|
|
41
62
|
let presetDirElement;
|
|
42
63
|
if (avoidDirIfSet ||
|
|
43
64
|
// If avoiding the default LTR except when different (even if not
|
|
44
65
|
// avoiding an (RTL) already-set dir), we need to know if different
|
|
45
66
|
(avoidLTRByDefault && dir === 'ltr')
|
|
46
67
|
) {
|
|
47
|
-
presetDirElement =
|
|
68
|
+
presetDirElement = /** @type {HTMLElement} */ (
|
|
69
|
+
element.closest('[dir]')
|
|
70
|
+
);
|
|
48
71
|
}
|
|
49
72
|
if (
|
|
50
73
|
// If the closest ancestor with `dir` is different, we need to
|
|
@@ -63,8 +86,8 @@ const i18nizeElement = (element, {
|
|
|
63
86
|
) {
|
|
64
87
|
element.dir = dir;
|
|
65
88
|
|
|
66
|
-
/*
|
|
67
|
-
if (dir === 'ttb') {
|
|
89
|
+
/* c8 ignore next 3 */
|
|
90
|
+
if (dir === 'ttb') {
|
|
68
91
|
element.style.writingMode = 'vertical-lr';
|
|
69
92
|
}
|
|
70
93
|
}
|
package/CHANGES.md
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# CHANGES for i18nizeelement
|
|
2
|
-
|
|
3
|
-
## 0.3.0
|
|
4
|
-
|
|
5
|
-
- Breaking change: Insist on Node >= 6
|
|
6
|
-
- Linting (ESLint): Apply ash-nazg; use a recommended extension ("js")
|
|
7
|
-
- Testing: Move `tests` to `test`
|
|
8
|
-
- Testing: Switch to `esm`
|
|
9
|
-
- Testing: Add `nyc` for coverage and bring to 100%
|
|
10
|
-
- Build: Switch to Babel; update Rollup API usage
|
|
11
|
-
- Maintenance: Add `.editorconfig`
|
|
12
|
-
- Docs: Add badges
|
|
13
|
-
- npm: Update devDeps; avoid `build` script; `opn-cli`->`open-cli`
|
|
14
|
-
- npm: Remove `rollup-watch` and `rollup-plugin-multi-entry`
|
|
15
|
-
|
|
16
|
-
## 0.2.1
|
|
17
|
-
|
|
18
|
-
- Exclude items from `.npmignore`
|
|
19
|
-
|
|
20
|
-
## 0.2.0
|
|
21
|
-
|
|
22
|
-
- Build: Add i18nizeElement Jamilih plugin builds, ensuring buble runs
|
|
23
|
-
before other Rollup plugins
|
|
24
|
-
- Refactoring: Rename plugin file
|
|
25
|
-
|
|
26
|
-
## 0.1.0
|
|
27
|
-
|
|
28
|
-
- Initial release
|