@lingual/i18n-check 0.8.1 → 0.8.3

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.
@@ -9,21 +9,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.hasDiff = exports.compareTranslationFiles = exports.findInvalid18nTranslations = void 0;
10
10
  const i18NextParser_1 = require("./i18NextParser");
11
11
  const findInvalid18nTranslations = (source, targets) => {
12
- let differences = {};
12
+ const differences = {};
13
13
  if (Object.keys(targets).length === 0) {
14
14
  return differences;
15
15
  }
16
16
  for (const [lang, file] of Object.entries(targets)) {
17
17
  const result = (0, exports.compareTranslationFiles)(source, file);
18
18
  if (result.length > 0) {
19
- differences = Object.assign(differences, { [lang]: result });
19
+ differences[lang] = result;
20
20
  }
21
21
  }
22
22
  return differences;
23
23
  };
24
24
  exports.findInvalid18nTranslations = findInvalid18nTranslations;
25
25
  const compareTranslationFiles = (a, b) => {
26
- let diffs = [];
26
+ const diffs = [];
27
27
  for (const key in a) {
28
28
  if (b[key] === undefined) {
29
29
  continue;
@@ -47,20 +47,20 @@ const lookUp = {
47
47
  tag: 5,
48
48
  };
49
49
  const sortParsedKeys = (a, b) => {
50
- if (a.type === b.type && a.type !== "tag" && b.type !== "tag") {
50
+ if (a.type === b.type && a.type !== 'tag' && b.type !== 'tag') {
51
51
  return a.content < b.content ? -1 : 1;
52
52
  }
53
- if (a.type === "tag" && b.type === "tag") {
53
+ if (a.type === 'tag' && b.type === 'tag') {
54
54
  return a.raw < b.raw ? -1 : 1;
55
55
  }
56
56
  return lookUp[a.type] - lookUp[b.type];
57
57
  };
58
58
  const hasDiff = (a, b) => {
59
59
  const compA = a
60
- .filter((element) => element.type !== "text")
60
+ .filter((element) => element.type !== 'text')
61
61
  .sort(sortParsedKeys);
62
62
  const compB = b
63
- .filter((element) => element.type !== "text")
63
+ .filter((element) => element.type !== 'text')
64
64
  .sort(sortParsedKeys);
65
65
  if (compA.length !== compB.length) {
66
66
  return true;
@@ -70,28 +70,28 @@ const hasDiff = (a, b) => {
70
70
  if (formatElementA.type !== formatElementB.type) {
71
71
  return true;
72
72
  }
73
- if (formatElementA.type === "tag" && formatElementB.type === "tag") {
73
+ if (formatElementA.type === 'tag' && formatElementB.type === 'tag') {
74
74
  return (formatElementA.raw !== formatElementB.raw ||
75
75
  formatElementA.voidElement !== formatElementB.voidElement);
76
76
  }
77
- if ((formatElementA.type === "interpolation" &&
78
- formatElementB.type === "interpolation") ||
79
- (formatElementA.type === "interpolation_unescaped" &&
80
- formatElementB.type === "interpolation_unescaped") ||
81
- (formatElementA.type === "nesting" &&
82
- formatElementB.type === "nesting") ||
83
- (formatElementA.type === "plural" && formatElementB.type === "plural")) {
77
+ if ((formatElementA.type === 'interpolation' &&
78
+ formatElementB.type === 'interpolation') ||
79
+ (formatElementA.type === 'interpolation_unescaped' &&
80
+ formatElementB.type === 'interpolation_unescaped') ||
81
+ (formatElementA.type === 'nesting' &&
82
+ formatElementB.type === 'nesting') ||
83
+ (formatElementA.type === 'plural' && formatElementB.type === 'plural')) {
84
84
  const optionsA = formatElementA.variable
85
- .split(",")
85
+ .split(',')
86
86
  .map((value) => value.trim())
87
87
  .sort()
88
- .join("-")
88
+ .join('-')
89
89
  .trim();
90
90
  const optionsB = formatElementB.variable
91
- .split(",")
91
+ .split(',')
92
92
  .map((value) => value.trim())
93
93
  .sort()
94
- .join("-")
94
+ .join('-')
95
95
  .trim();
96
96
  if (optionsA !== optionsB) {
97
97
  return true;
@@ -110,10 +110,10 @@ const hasDiff = (a, b) => {
110
110
  exports.hasDiff = hasDiff;
111
111
  const getErrorMessage = (a, b) => {
112
112
  const compA = a
113
- .filter((element) => element.type !== "text")
113
+ .filter((element) => element.type !== 'text')
114
114
  .sort(sortParsedKeys);
115
115
  const compB = b
116
- .filter((element) => element.type !== "text")
116
+ .filter((element) => element.type !== 'text')
117
117
  .sort(sortParsedKeys);
118
118
  const errors = compA.reduce((acc, formatElementA, index) => {
119
119
  const formatElementB = compB[index];
@@ -125,7 +125,7 @@ const getErrorMessage = (a, b) => {
125
125
  acc.push(`Expected element of type "${formatElementA.type}" but received "${formatElementB.type}"`);
126
126
  return acc;
127
127
  }
128
- if (formatElementA.type === "tag" && formatElementB.type === "tag") {
128
+ if (formatElementA.type === 'tag' && formatElementB.type === 'tag') {
129
129
  if (formatElementA.raw !== formatElementB.raw) {
130
130
  acc.push(`Expected tag "${formatElementA.raw}" but received "${formatElementB.raw}"`);
131
131
  }
@@ -140,13 +140,13 @@ const getErrorMessage = (a, b) => {
140
140
  return acc;
141
141
  }
142
142
  }
143
- if ((formatElementA.type === "interpolation" &&
144
- formatElementB.type === "interpolation") ||
145
- (formatElementA.type === "interpolation_unescaped" &&
146
- formatElementB.type === "interpolation_unescaped") ||
147
- (formatElementA.type === "nesting" &&
148
- formatElementB.type === "nesting") ||
149
- (formatElementA.type === "plural" && formatElementB.type === "plural")) {
143
+ if ((formatElementA.type === 'interpolation' &&
144
+ formatElementB.type === 'interpolation') ||
145
+ (formatElementA.type === 'interpolation_unescaped' &&
146
+ formatElementB.type === 'interpolation_unescaped') ||
147
+ (formatElementA.type === 'nesting' &&
148
+ formatElementB.type === 'nesting') ||
149
+ (formatElementA.type === 'plural' && formatElementB.type === 'plural')) {
150
150
  if (formatElementA.prefix !== formatElementA.prefix) {
151
151
  acc.push(`Error in ${formatElementA.type}: Expected prefix "${formatElementA.prefix}" but received "${formatElementB.prefix}"`);
152
152
  return acc;
@@ -156,14 +156,14 @@ const getErrorMessage = (a, b) => {
156
156
  return acc;
157
157
  }
158
158
  const optionsA = formatElementA.variable
159
- .split(",")
159
+ .split(',')
160
160
  .map((value) => value.trim())
161
161
  .sort();
162
162
  const optionsB = formatElementB.variable
163
- .split(",")
163
+ .split(',')
164
164
  .map((value) => value.trim())
165
165
  .sort();
166
- let elementErrors = [];
166
+ const elementErrors = [];
167
167
  optionsA.forEach((key, index) => {
168
168
  if (key !== optionsB[index]) {
169
169
  elementErrors.push(`Expected ${key} but received ${optionsB[index]}`);
@@ -172,7 +172,7 @@ const getErrorMessage = (a, b) => {
172
172
  if (elementErrors.length > 0) {
173
173
  acc.push(`Error in ${formatElementA.type}: ${elementErrors
174
174
  .flatMap((elementError) => elementError)
175
- .join(", ")}`);
175
+ .join(', ')}`);
176
176
  }
177
177
  return acc;
178
178
  }
@@ -185,8 +185,8 @@ const getErrorMessage = (a, b) => {
185
185
  acc.push(`Unexpected ${formatElementB.type} element`);
186
186
  return acc;
187
187
  }, [])
188
- .join(", ");
189
- return [...errors, unexpectedElements].join(", ");
188
+ .join(', ');
189
+ return [...errors, unexpectedElements].join(', ');
190
190
  }
191
- return errors.join(", ");
191
+ return errors.join(', ');
192
192
  };
@@ -2,204 +2,204 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const findInvalidi18nTranslations_1 = require("./findInvalidi18nTranslations");
4
4
  const flattenTranslations_1 = require("./flattenTranslations");
5
- const sourceFile = require("../../translations/i18NextMessageExamples/en-us.json");
6
- const targetFile = require("../../translations/i18NextMessageExamples/de-de.json");
7
- describe("findInvalid18nTranslations:compareTranslationFiles", () => {
8
- it("should return empty array if files are identical", () => {
5
+ const sourceFile = require('../../translations/i18NextMessageExamples/en-us.json');
6
+ const targetFile = require('../../translations/i18NextMessageExamples/de-de.json');
7
+ describe('findInvalid18nTranslations:compareTranslationFiles', () => {
8
+ it('should return empty array if files are identical', () => {
9
9
  expect((0, findInvalidi18nTranslations_1.compareTranslationFiles)((0, flattenTranslations_1.flattenTranslations)(sourceFile), (0, flattenTranslations_1.flattenTranslations)(sourceFile))).toEqual([]);
10
10
  });
11
- it("should return the invalid keys in the target file", () => {
11
+ it('should return the invalid keys in the target file', () => {
12
12
  expect((0, findInvalidi18nTranslations_1.compareTranslationFiles)((0, flattenTranslations_1.flattenTranslations)({
13
13
  ...sourceFile,
14
- "ten.eleven.twelve": "ten eleven twelve",
14
+ 'ten.eleven.twelve': 'ten eleven twelve',
15
15
  }), (0, flattenTranslations_1.flattenTranslations)(targetFile))).toEqual([
16
16
  {
17
- key: "key_with_broken_de",
18
- msg: "Error in interpolation: Expected value but received val",
17
+ key: 'key_with_broken_de',
18
+ msg: 'Error in interpolation: Expected value but received val',
19
19
  },
20
20
  {
21
- key: "intlNumber_broken_de",
22
- msg: "Missing element interpolation",
21
+ key: 'intlNumber_broken_de',
22
+ msg: 'Missing element interpolation',
23
23
  },
24
24
  ]);
25
25
  });
26
- it("should return an empty array if the strings contain paranthesis that have different content", () => {
26
+ it('should return an empty array if the strings contain paranthesis that have different content', () => {
27
27
  expect((0, findInvalidi18nTranslations_1.compareTranslationFiles)((0, flattenTranslations_1.flattenTranslations)({
28
- keyText: "Key(s)",
29
- }), (0, flattenTranslations_1.flattenTranslations)({ keyText: "Taste(n)" }))).toEqual([]);
28
+ keyText: 'Key(s)',
29
+ }), (0, flattenTranslations_1.flattenTranslations)({ keyText: 'Taste(n)' }))).toEqual([]);
30
30
  });
31
- it("should return empty array if placeholders are identical but in different positions", () => {
31
+ it('should return empty array if placeholders are identical but in different positions', () => {
32
32
  expect((0, findInvalidi18nTranslations_1.compareTranslationFiles)({
33
- basic: "added {{this}} and {{that}} should work.",
33
+ basic: 'added {{this}} and {{that}} should work.',
34
34
  }, {
35
- basic: "It is {{this}} with different position {{that}}",
35
+ basic: 'It is {{this}} with different position {{that}}',
36
36
  })).toEqual([]);
37
37
  });
38
- it("should return the invalid key if tags are not identical", () => {
38
+ it('should return the invalid key if tags are not identical', () => {
39
39
  expect((0, findInvalidi18nTranslations_1.compareTranslationFiles)({
40
- tag: "This is some <b>bold text</b> and some <i>italic</i> text.",
40
+ tag: 'This is some <b>bold text</b> and some <i>italic</i> text.',
41
41
  }, {
42
- tag: "There is some <b>bold text</b> and some other <span>italic</span> text.",
42
+ tag: 'There is some <b>bold text</b> and some other <span>italic</span> text.',
43
43
  })).toEqual([
44
44
  {
45
- key: "tag",
45
+ key: 'tag',
46
46
  msg: 'Expected tag "</i>" but received "</span>", Expected tag "<i>" but received "<span>"',
47
47
  },
48
48
  ]);
49
49
  });
50
- it("should return empty array if tags are identical", () => {
50
+ it('should return empty array if tags are identical', () => {
51
51
  expect((0, findInvalidi18nTranslations_1.compareTranslationFiles)({
52
- tag: "This is some <b>bold text</b> and some <i>italic</i> text.",
52
+ tag: 'This is some <b>bold text</b> and some <i>italic</i> text.',
53
53
  }, {
54
- tag: "There is some <b>bold text</b> and some other <i>italic</i> text.",
54
+ tag: 'There is some <b>bold text</b> and some other <i>italic</i> text.',
55
55
  })).toEqual([]);
56
56
  });
57
57
  });
58
- describe("findInvalidTranslations", () => {
59
- it("should return an empty object if all files have no invalid keys", () => {
58
+ describe('findInvalidTranslations', () => {
59
+ it('should return an empty object if all files have no invalid keys', () => {
60
60
  expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)(sourceFile, { de: sourceFile })).toEqual({});
61
61
  });
62
- it("should return an object containing the keys for the missing language", () => {
63
- expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)({ ...sourceFile, "ten.eleven.twelve": "ten eleven twelve" }, { de: targetFile })).toEqual({
62
+ it('should return an object containing the keys for the missing language', () => {
63
+ expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)({ ...sourceFile, 'ten.eleven.twelve': 'ten eleven twelve' }, { de: targetFile })).toEqual({
64
64
  de: [
65
65
  {
66
- key: "key_with_broken_de",
67
- msg: "Error in interpolation: Expected value but received val",
66
+ key: 'key_with_broken_de',
67
+ msg: 'Error in interpolation: Expected value but received val',
68
68
  },
69
69
  {
70
- key: "intlNumber_broken_de",
71
- msg: "Missing element interpolation",
70
+ key: 'intlNumber_broken_de',
71
+ msg: 'Missing element interpolation',
72
72
  },
73
73
  ],
74
74
  });
75
75
  });
76
- it("should return an object containing the keys for every language with missing key", () => {
77
- expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)({ ...sourceFile, "ten.eleven.twelve": "ten eleven twelve" }, {
76
+ it('should return an object containing the keys for every language with missing key', () => {
77
+ expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)({ ...sourceFile, 'ten.eleven.twelve': 'ten eleven twelve' }, {
78
78
  de: targetFile,
79
79
  fr: {
80
- key_with_broken_de: "Some format {{value, formatname}} and some other format {{value, formatname}}",
80
+ key_with_broken_de: 'Some format {{value, formatname}} and some other format {{value, formatname}}',
81
81
  },
82
82
  })).toEqual({
83
83
  de: [
84
84
  {
85
- key: "key_with_broken_de",
86
- msg: "Error in interpolation: Expected value but received val",
85
+ key: 'key_with_broken_de',
86
+ msg: 'Error in interpolation: Expected value but received val',
87
87
  },
88
88
  {
89
- key: "intlNumber_broken_de",
90
- msg: "Missing element interpolation",
89
+ key: 'intlNumber_broken_de',
90
+ msg: 'Missing element interpolation',
91
91
  },
92
92
  ],
93
93
  fr: [
94
94
  {
95
- key: "key_with_broken_de",
96
- msg: "Unexpected interpolation element",
95
+ key: 'key_with_broken_de',
96
+ msg: 'Unexpected interpolation element',
97
97
  },
98
98
  ],
99
99
  });
100
100
  });
101
- it("should find invalid interval", () => {
101
+ it('should find invalid interval', () => {
102
102
  expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)({
103
- key1_interval: "(1)[one item];(2-7)[a few items];(7-inf)[a lot of items];",
103
+ key1_interval: '(1)[one item];(2-7)[a few items];(7-inf)[a lot of items];',
104
104
  }, {
105
105
  de: {
106
- key1_interval: "(1-2)[one or two items];(3-7)[a few items];(7-inf)[a lot of items];",
106
+ key1_interval: '(1-2)[one or two items];(3-7)[a few items];(7-inf)[a lot of items];',
107
107
  },
108
108
  })).toEqual({
109
109
  de: [
110
110
  {
111
- key: "key1_interval",
112
- msg: "Error in plural: Expected 1 but received 1-2, Error in plural: Expected 2-7 but received 3-7",
111
+ key: 'key1_interval',
112
+ msg: 'Error in plural: Expected 1 but received 1-2, Error in plural: Expected 2-7 but received 3-7',
113
113
  },
114
114
  ],
115
115
  });
116
116
  });
117
- it("should find invalid nested interpolation", () => {
117
+ it('should find invalid nested interpolation', () => {
118
118
  expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)({
119
- "tree.one": "added {{something}}",
119
+ 'tree.one': 'added {{something}}',
120
120
  }, {
121
121
  de: {
122
- "tree.one": "added {{somethings}}",
122
+ 'tree.one': 'added {{somethings}}',
123
123
  },
124
124
  })).toEqual({
125
125
  de: [
126
126
  {
127
- key: "tree.one",
128
- msg: "Error in interpolation: Expected something but received somethings",
127
+ key: 'tree.one',
128
+ msg: 'Error in interpolation: Expected something but received somethings',
129
129
  },
130
130
  ],
131
131
  });
132
132
  });
133
- it("should find invalid relative time formatting", () => {
133
+ it('should find invalid relative time formatting', () => {
134
134
  expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)({
135
- intlRelativeTimeWithOptionsExplicit: "Lorem {{val, relativetime(range: quarter; style: narrow;)}}",
135
+ intlRelativeTimeWithOptionsExplicit: 'Lorem {{val, relativetime(range: quarter; style: narrow;)}}',
136
136
  }, {
137
137
  de: {
138
- intlRelativeTimeWithOptionsExplicit: "Lorem {{val, relativetime(range: quarter; style: long;)}}",
138
+ intlRelativeTimeWithOptionsExplicit: 'Lorem {{val, relativetime(range: quarter; style: long;)}}',
139
139
  },
140
140
  })).toEqual({
141
141
  de: [
142
142
  {
143
- key: "intlRelativeTimeWithOptionsExplicit",
144
- msg: "Error in interpolation: Expected relativetime(range: quarter; style: narrow;) but received relativetime(range: quarter; style: long;)",
143
+ key: 'intlRelativeTimeWithOptionsExplicit',
144
+ msg: 'Error in interpolation: Expected relativetime(range: quarter; style: narrow;) but received relativetime(range: quarter; style: long;)',
145
145
  },
146
146
  ],
147
147
  });
148
148
  });
149
- it("should find invalid key with options", () => {
149
+ it('should find invalid key with options', () => {
150
150
  expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)({
151
- keyWithOptions: "Some format {{value, formatname(option1Name: option1Value; option2Name: option2Value)}}",
151
+ keyWithOptions: 'Some format {{value, formatname(option1Name: option1Value; option2Name: option2Value)}}',
152
152
  }, {
153
153
  de: {
154
- keyWithOptions: "Some format {{value, formatname(option3Name: option3Value; option4Name: option4Value)}}",
154
+ keyWithOptions: 'Some format {{value, formatname(option3Name: option3Value; option4Name: option4Value)}}',
155
155
  },
156
156
  })).toEqual({
157
157
  de: [
158
158
  {
159
- key: "keyWithOptions",
160
- msg: "Error in interpolation: Expected formatname(option1Name: option1Value; option2Name: option2Value) but received formatname(option3Name: option3Value; option4Name: option4Value)",
159
+ key: 'keyWithOptions',
160
+ msg: 'Error in interpolation: Expected formatname(option1Name: option1Value; option2Name: option2Value) but received formatname(option3Name: option3Value; option4Name: option4Value)',
161
161
  },
162
162
  ],
163
163
  });
164
164
  });
165
- it("should find invalid nesting", () => {
165
+ it('should find invalid nesting', () => {
166
166
  expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)({
167
- nesting1: "1 $t(nesting2)",
167
+ nesting1: '1 $t(nesting2)',
168
168
  }, {
169
169
  de: {
170
- nesting1: "1 $t(nesting3)",
170
+ nesting1: '1 $t(nesting3)',
171
171
  },
172
172
  })).toEqual({
173
173
  de: [
174
174
  {
175
- key: "nesting1",
176
- msg: "Error in nesting: Expected nesting2 but received nesting3",
175
+ key: 'nesting1',
176
+ msg: 'Error in nesting: Expected nesting2 but received nesting3',
177
177
  },
178
178
  ],
179
179
  });
180
180
  });
181
- it("should find invalid tags", () => {
181
+ it('should find invalid tags', () => {
182
182
  expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)({
183
- tag: "This is some <b>bold text</b> and some <i>italic</i> text.",
183
+ tag: 'This is some <b>bold text</b> and some <i>italic</i> text.',
184
184
  }, {
185
185
  de: {
186
- tag: "There is some <b>bold text</b> and some other <span>text inside a span</span>!",
186
+ tag: 'There is some <b>bold text</b> and some other <span>text inside a span</span>!',
187
187
  },
188
188
  })).toEqual({
189
189
  de: [
190
190
  {
191
- key: "tag",
191
+ key: 'tag',
192
192
  msg: 'Expected tag "</i>" but received "</span>", Expected tag "<i>" but received "<span>"',
193
193
  },
194
194
  ],
195
195
  });
196
196
  });
197
- it("should recognize special characters", () => {
197
+ it('should recognize special characters', () => {
198
198
  expect((0, findInvalidi18nTranslations_1.findInvalid18nTranslations)({
199
- key: "Test < {{a}} and > {{max_a}}",
199
+ key: 'Test < {{a}} and > {{max_a}}',
200
200
  }, {
201
201
  de: {
202
- key: "Test < {{a}} und > {{max_a}}",
202
+ key: 'Test < {{a}} und > {{max_a}}',
203
203
  },
204
204
  })).toEqual({});
205
205
  });
@@ -1,3 +1,3 @@
1
- import { Translation } from "../types";
2
- export declare const findMissingKeys: (source: Translation, targets: Record<string, Translation>) => {};
1
+ import { Translation } from '../types';
2
+ export declare const findMissingKeys: (source: Translation, targets: Record<string, Translation>) => Record<string, string[]>;
3
3
  export declare const compareTranslationFiles: (a: Translation, b: Translation) => string[];
@@ -2,18 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.compareTranslationFiles = exports.findMissingKeys = void 0;
4
4
  const findMissingKeys = (source, targets) => {
5
- let differences = {};
5
+ const differences = {};
6
6
  for (const [lang, file] of Object.entries(targets)) {
7
7
  const result = (0, exports.compareTranslationFiles)(source, file);
8
8
  if (result.length > 0) {
9
- differences = Object.assign(differences, { [lang]: result });
9
+ differences[lang] = result;
10
10
  }
11
11
  }
12
12
  return differences;
13
13
  };
14
14
  exports.findMissingKeys = findMissingKeys;
15
15
  const compareTranslationFiles = (a, b) => {
16
- let diffs = [];
16
+ const diffs = [];
17
17
  for (const key in a) {
18
18
  const counterKey = b[key];
19
19
  if (!counterKey) {
@@ -2,40 +2,40 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const findMissingKeys_1 = require("./findMissingKeys");
4
4
  const sourceFile = {
5
- "one.two.three": "one two three",
6
- "four.five.six": "four five six",
7
- "seven.eight.nine": "seven eight nine",
5
+ 'one.two.three': 'one two three',
6
+ 'four.five.six': 'four five six',
7
+ 'seven.eight.nine': 'seven eight nine',
8
8
  };
9
9
  const secondaryFile = {
10
- "one.two.three": "one two three",
11
- "four.five.six": "four five six",
12
- "seven.eight.nine": "seven eight nine",
10
+ 'one.two.three': 'one two three',
11
+ 'four.five.six': 'four five six',
12
+ 'seven.eight.nine': 'seven eight nine',
13
13
  };
14
- describe("findMissingKeys:compareTranslationFiles", () => {
15
- it("should return empty array if files are identical", () => {
14
+ describe('findMissingKeys:compareTranslationFiles', () => {
15
+ it('should return empty array if files are identical', () => {
16
16
  expect((0, findMissingKeys_1.compareTranslationFiles)(sourceFile, secondaryFile)).toEqual([]);
17
17
  });
18
- it("should return the missing keys in the secondary file", () => {
19
- expect((0, findMissingKeys_1.compareTranslationFiles)({ ...sourceFile, "ten.eleven.twelve": "ten eleven twelve" }, secondaryFile)).toEqual(["ten.eleven.twelve"]);
18
+ it('should return the missing keys in the secondary file', () => {
19
+ expect((0, findMissingKeys_1.compareTranslationFiles)({ ...sourceFile, 'ten.eleven.twelve': 'ten eleven twelve' }, secondaryFile)).toEqual(['ten.eleven.twelve']);
20
20
  });
21
21
  });
22
- describe("findMissingKeys", () => {
23
- it("should return an empty object if all files have no missing keys", () => {
22
+ describe('findMissingKeys', () => {
23
+ it('should return an empty object if all files have no missing keys', () => {
24
24
  expect((0, findMissingKeys_1.findMissingKeys)(sourceFile, { de: secondaryFile })).toEqual({});
25
25
  });
26
- it("should return an object containing the keys for the missing language", () => {
27
- expect((0, findMissingKeys_1.findMissingKeys)({ ...sourceFile, "ten.eleven.twelve": "ten eleven twelve" }, { de: secondaryFile })).toEqual({ de: ["ten.eleven.twelve"] });
26
+ it('should return an object containing the keys for the missing language', () => {
27
+ expect((0, findMissingKeys_1.findMissingKeys)({ ...sourceFile, 'ten.eleven.twelve': 'ten eleven twelve' }, { de: secondaryFile })).toEqual({ de: ['ten.eleven.twelve'] });
28
28
  });
29
- it("should return an object containing the keys for every language with missing key", () => {
30
- expect((0, findMissingKeys_1.findMissingKeys)({ ...sourceFile, "ten.eleven.twelve": "ten eleven twelve" }, {
29
+ it('should return an object containing the keys for every language with missing key', () => {
30
+ expect((0, findMissingKeys_1.findMissingKeys)({ ...sourceFile, 'ten.eleven.twelve': 'ten eleven twelve' }, {
31
31
  de: secondaryFile,
32
32
  fr: {
33
- "four.five.six": "four five six",
34
- "seven.eight.nine": "seven eight nine",
33
+ 'four.five.six': 'four five six',
34
+ 'seven.eight.nine': 'seven eight nine',
35
35
  },
36
36
  })).toEqual({
37
- de: ["ten.eleven.twelve"],
38
- fr: ["one.two.three", "ten.eleven.twelve"],
37
+ de: ['ten.eleven.twelve'],
38
+ fr: ['one.two.three', 'ten.eleven.twelve'],
39
39
  });
40
40
  });
41
41
  });
@@ -1,3 +1,3 @@
1
- import { Translation } from "../types";
1
+ import { Translation } from '../types';
2
2
  export declare const flattenTranslations: (translations: Translation) => Translation;
3
3
  export declare const flattenEntry: (entry: Translation, keys?: string[]) => Translation;
@@ -12,13 +12,13 @@ exports.flattenTranslations = flattenTranslations;
12
12
  * Top level search for any objects
13
13
  */
14
14
  const hasNestedDefinitions = (translations) => {
15
- return Object.values(translations).find((translation) => typeof translation === "object");
15
+ return Object.values(translations).find((translation) => typeof translation === 'object');
16
16
  };
17
17
  const isTranslationObject = (entry) => {
18
- return typeof entry === "object";
18
+ return typeof entry === 'object';
19
19
  };
20
20
  const flattenEntry = (entry, keys = []) => {
21
- let result = {};
21
+ const result = {};
22
22
  if (!entry) {
23
23
  return result;
24
24
  }
@@ -26,7 +26,7 @@ const flattenEntry = (entry, keys = []) => {
26
26
  for (const [k, v] of entries) {
27
27
  Object.assign(result, isTranslationObject(v)
28
28
  ? (0, exports.flattenEntry)(v, [...keys, String(k)])
29
- : { [[...keys, String(k)].join(".")]: v });
29
+ : { [[...keys, String(k)].join('.')]: v });
30
30
  }
31
31
  return result;
32
32
  };
@@ -1,28 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const flattenTranslations_1 = require("./flattenTranslations");
4
- const flatStructure = require("../../translations/en-us.json");
5
- const nestedStructure = require("../../translations/flattenExamples/en-us.json");
4
+ const flatStructure = require('../../translations/en-us.json');
5
+ const nestedStructure = require('../../translations/flattenExamples/en-us.json');
6
6
  const expectedFlatStructure = {
7
- "test.drive.one": "testing one",
8
- "test.drive.two": "testing two",
9
- "other.nested.three": "testing three",
10
- "other.nested.deep.more.final": "nested translation",
7
+ 'test.drive.one': 'testing one',
8
+ 'test.drive.two': 'testing two',
9
+ 'other.nested.three': 'testing three',
10
+ 'other.nested.deep.more.final': 'nested translation',
11
11
  };
12
- describe("flattenTranslations", () => {
13
- it("should do nothing if the file structure is flat", () => {
12
+ describe('flattenTranslations', () => {
13
+ it('should do nothing if the file structure is flat', () => {
14
14
  expect((0, flattenTranslations_1.flattenTranslations)(flatStructure)).toEqual(flatStructure);
15
15
  });
16
- describe("flattenEntry", () => {
17
- it("should flatten a nested object", () => {
16
+ describe('flattenEntry', () => {
17
+ it('should flatten a nested object', () => {
18
18
  expect((0, flattenTranslations_1.flattenEntry)({
19
19
  a: {
20
- b: { c: "one" },
20
+ b: { c: 'one' },
21
21
  },
22
- })).toEqual({ "a.b.c": "one" });
22
+ })).toEqual({ 'a.b.c': 'one' });
23
23
  });
24
24
  });
25
- it("should do nothing if the file structure is flat", () => {
25
+ it('should do nothing if the file structure is flat', () => {
26
26
  expect((0, flattenTranslations_1.flattenTranslations)(nestedStructure)).toEqual(expectedFlatStructure);
27
27
  });
28
28
  });