locize-cli 7.14.0 → 7.14.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/CHANGELOG.md CHANGED
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  Project versioning adheres to [Semantic Versioning](http://semver.org/).
6
6
  Change log format is based on [Keep a Changelog](http://keepachangelog.com/).
7
7
 
8
+ ## [7.14.2](https://github.com/locize/locize-cli/compare/v7.14.1...v7.14.2) - 2023-05-09
9
+
10
+ - optimize unflatten algorithm
11
+
12
+ ## [7.14.1](https://github.com/locize/locize-cli/compare/v7.14.0...v7.14.1) - 2023-03-28
13
+
14
+ - update fluent_conv to fix [#84](https://github.com/locize/locize-cli/pull/84)
15
+
8
16
  ## [7.14.0](https://github.com/locize/locize-cli/compare/v7.13.2...v7.14.0) - 2023-03-11
9
17
 
10
18
  - support for .env file [#83](https://github.com/locize/locize-cli/pull/83)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "locize-cli",
3
- "version": "7.14.0",
3
+ "version": "7.14.2",
4
4
  "description": "locize cli to import locales",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -17,16 +17,16 @@
17
17
  "diff": "5.1.0",
18
18
  "dotenv": "16.0.3",
19
19
  "flat": "5.0.2",
20
- "fluent_conv": "3.1.0",
20
+ "fluent_conv": "3.2.0",
21
21
  "gettext-converter": "1.2.3",
22
22
  "https-proxy-agent": "5.0.1",
23
23
  "ini": "3.0.1",
24
24
  "js-yaml": "4.1.0",
25
25
  "laravelphp": "2.0.3",
26
26
  "lodash.clonedeep": "4.5.0",
27
- "mkdirp": "2.1.5",
27
+ "mkdirp": "2.1.6",
28
28
  "node-fetch": "2.6.8",
29
- "resx": "2.0.3",
29
+ "resx": "2.0.4",
30
30
  "rimraf": "3.0.2",
31
31
  "strings-file": "0.0.5",
32
32
  "tmexchange": "2.0.4",
@@ -34,7 +34,7 @@
34
34
  "xlsx": "0.18.5"
35
35
  },
36
36
  "devDependencies": {
37
- "eslint": "8.36.0",
37
+ "eslint": "8.40.0",
38
38
  "gh-release": "7.0.2",
39
39
  "pkg": "5.8.1"
40
40
  },
package/unflatten.js CHANGED
@@ -1,5 +1,6 @@
1
1
  module.exports = (data) => {
2
2
  const result = {};
3
+ const shouldConvertArray = {};
3
4
  for (var i in data) {
4
5
  const keys = i.split('.');
5
6
  keys.reduce((r, e, j) => {
@@ -13,8 +14,59 @@ module.exports = (data) => {
13
14
  return mem;
14
15
  }, {});
15
16
  }
17
+ if (Array.isArray(r[e]) && r[e].length > 50) {
18
+ const base = i.substring(0, i.indexOf(e) + e.length);
19
+ if (Object.values(r[e]).length < (r[e].length / 2)) {
20
+ shouldConvertArray[base] = true;
21
+ } else if (shouldConvertArray[base]) {
22
+ delete shouldConvertArray[base];
23
+ }
24
+ }
25
+ if (typeof r === 'string') {
26
+ if (e === '' && keys.length > 2) {
27
+ const lastPart = keys[keys.length - 2] + '.';
28
+ const firstParts = keys.slice(0, keys.length - 2);
29
+ let obj;
30
+ try {
31
+ obj = firstParts.reduce((acc, p) => acc[p], result);
32
+ } catch (err) {
33
+ if (firstParts.indexOf('') < 0) throw err;
34
+
35
+ let navRes = result;
36
+ for (let ind = 0; ind < firstParts.length; ind++) {
37
+ const p = firstParts[ind];
38
+ if (typeof navRes[p] === 'object') {
39
+ navRes = navRes[p];
40
+ } else {
41
+ const rest = firstParts.slice(ind).map((c) => (c === '' ? '.' : c)).join('.');
42
+ navRes[rest] = data[i];
43
+ break;
44
+ }
45
+ }
46
+ }
47
+ if (obj && typeof obj !== 'string' && obj[lastPart] === undefined) {
48
+ obj[lastPart] = data[i];
49
+ }
50
+ }
51
+ return r;
52
+ }
16
53
  return r[e] || (r[e] = (!isNumber || hasLeadingZero || tooHighNumberToBeAnArrayIndex) ? (keys.length - 1 === j ? data[i] : {}) : []);
17
54
  }, result);
18
55
  }
56
+ const arrsToConvert = Object.keys(shouldConvertArray);
57
+ arrsToConvert.forEach((arrToConvert) => {
58
+ const parts = arrToConvert.split('.');
59
+ let pr = result;
60
+ parts.forEach((part, ind) => {
61
+ if (ind === parts.length - 1) {
62
+ pr[part] = pr[part].reduce((mem, item, ind) => {
63
+ mem[ind] = item;
64
+ return mem;
65
+ }, {});
66
+ } else {
67
+ pr = pr[part];
68
+ }
69
+ });
70
+ });
19
71
  return result;
20
72
  };