ether-code 0.7.0 → 0.7.1
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/cli/ether.js +1 -1
- package/generators/js-generator.js +33 -7
- package/package.json +1 -1
package/cli/ether.js
CHANGED
|
@@ -32,11 +32,15 @@ class JSGenerator {
|
|
|
32
32
|
return
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
const normalize = (str) => {
|
|
36
|
+
return str.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '')
|
|
37
|
+
}
|
|
38
|
+
|
|
35
39
|
const addToMap = (map, section, prefix = '') => {
|
|
36
40
|
if (!section) return
|
|
37
41
|
for (const [key, translations] of Object.entries(section)) {
|
|
38
42
|
if (translations && translations.fr && translations.en) {
|
|
39
|
-
const frKey = translations.fr
|
|
43
|
+
const frKey = normalize(translations.fr)
|
|
40
44
|
const enValue = translations.en
|
|
41
45
|
if (prefix) {
|
|
42
46
|
if (!this.contextualMap[frKey]) {
|
|
@@ -266,7 +270,9 @@ class JSGenerator {
|
|
|
266
270
|
}
|
|
267
271
|
|
|
268
272
|
buildDefaultMaps() {
|
|
269
|
-
|
|
273
|
+
const norm = (str) => str.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '')
|
|
274
|
+
|
|
275
|
+
const rawKeywords = {
|
|
270
276
|
'variable': 'let',
|
|
271
277
|
'constante': 'const',
|
|
272
278
|
'variable globale': 'var',
|
|
@@ -377,7 +383,7 @@ class JSGenerator {
|
|
|
377
383
|
'gabarit étiqueté': 'tagged template'
|
|
378
384
|
}
|
|
379
385
|
|
|
380
|
-
|
|
386
|
+
const rawOperators = {
|
|
381
387
|
'plus': '+',
|
|
382
388
|
'moins': '-',
|
|
383
389
|
'fois': '*',
|
|
@@ -414,7 +420,7 @@ class JSGenerator {
|
|
|
414
420
|
'décomposition': '...'
|
|
415
421
|
}
|
|
416
422
|
|
|
417
|
-
|
|
423
|
+
const rawMethods = {
|
|
418
424
|
'afficher': 'console.log',
|
|
419
425
|
'journal': 'console.log',
|
|
420
426
|
'erreur': 'console.error',
|
|
@@ -776,7 +782,23 @@ class JSGenerator {
|
|
|
776
782
|
'décoder URI': 'decodeURI',
|
|
777
783
|
'décoder composant URI': 'decodeURIComponent',
|
|
778
784
|
'encoder URI': 'encodeURI',
|
|
779
|
-
'encoder composant URI': 'encodeURIComponent'
|
|
785
|
+
'encoder composant URI': 'encodeURIComponent',
|
|
786
|
+
'selecteur': 'querySelector',
|
|
787
|
+
'selecteurs': 'querySelectorAll'
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
this.keywordMap = {}
|
|
791
|
+
this.operatorMap = {}
|
|
792
|
+
this.methodMap = {}
|
|
793
|
+
|
|
794
|
+
for (const [key, value] of Object.entries(rawKeywords)) {
|
|
795
|
+
this.keywordMap[norm(key)] = value
|
|
796
|
+
}
|
|
797
|
+
for (const [key, value] of Object.entries(rawOperators)) {
|
|
798
|
+
this.operatorMap[norm(key)] = value
|
|
799
|
+
}
|
|
800
|
+
for (const [key, value] of Object.entries(rawMethods)) {
|
|
801
|
+
this.methodMap[norm(key)] = value
|
|
780
802
|
}
|
|
781
803
|
|
|
782
804
|
this.buildConflictResolution()
|
|
@@ -795,7 +817,7 @@ class JSGenerator {
|
|
|
795
817
|
}
|
|
796
818
|
|
|
797
819
|
translateWithContext(word, explicitContext = null) {
|
|
798
|
-
const lower =
|
|
820
|
+
const lower = this.normalize(word)
|
|
799
821
|
const ctx = explicitContext || this.getCurrentContext()
|
|
800
822
|
|
|
801
823
|
if (this.conflicts[lower] && ctx) {
|
|
@@ -814,8 +836,12 @@ class JSGenerator {
|
|
|
814
836
|
word
|
|
815
837
|
}
|
|
816
838
|
|
|
839
|
+
normalize(str) {
|
|
840
|
+
return str.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '')
|
|
841
|
+
}
|
|
842
|
+
|
|
817
843
|
translate(word, isMethod = false) {
|
|
818
|
-
const lower =
|
|
844
|
+
const lower = this.normalize(word)
|
|
819
845
|
|
|
820
846
|
if (this.keywordMap[lower]) {
|
|
821
847
|
return this.keywordMap[lower]
|