@natlibfi/sfs-4900 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/.eslintignore ADDED
@@ -0,0 +1,3 @@
1
+ bin/
2
+ build/
3
+ lib/
@@ -0,0 +1,2 @@
1
+ # With this line @NatLibFi/melinda-js-lead owns review rights to any files in repository
2
+ * @NatLibFi/melinda-js-lead
@@ -0,0 +1,45 @@
1
+ # NatLibFi/Melinda maintenance strategy
2
+ # https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/configuration-options-for-dependency-updates
3
+
4
+ version: 2
5
+ updates:
6
+ # Maintain dependencies for GitHub Actions
7
+ - package-ecosystem: "github-actions"
8
+ directory: "/"
9
+ schedule:
10
+ interval: "daily"
11
+ time: "06:30"
12
+ timezone: "Europe/Helsinki"
13
+ target-branch: "test"
14
+
15
+ # Minor updates to npm production dependencies daily
16
+ - package-ecosystem: "npm"
17
+ directory: "/"
18
+ schedule:
19
+ interval: "daily"
20
+ time: "06:45"
21
+ timezone: "Europe/Helsinki"
22
+ versioning-strategy: lockfile-only
23
+ target-branch: "test"
24
+ pull-request-branch-name:
25
+ separator: "-"
26
+ groups:
27
+ production-dependencies:
28
+ dependency-type: "production"
29
+ development-dependencies:
30
+ dependency-type: "development"
31
+
32
+ # Major updates to npm dependencies weekly @tuesday
33
+ # Not possible yet https://github.com/dependabot/dependabot-core/issues/1778
34
+ # - package-ecosystem: "npm"
35
+ # directory: "/"
36
+ # schedule:
37
+ # interval: "weekly"
38
+ # day: "tuesday"
39
+ # time: "07:00"
40
+ # timezone: "Europe/Helsinki"
41
+ # versioning-strategy: increase-if-necessary
42
+ # labels:
43
+ # - "npm major dependencies"
44
+ # reviewers:
45
+ # - "natlibfi/melinda-js-lead"
@@ -0,0 +1,79 @@
1
+ # Melinda node tests
2
+
3
+ name: Melinda-node-tests
4
+
5
+ on: push
6
+
7
+ jobs:
8
+ build-node-versions:
9
+ name: Node version matrix
10
+ runs-on: ubuntu-latest
11
+ env:
12
+ TZ: Europe/Helsinki
13
+
14
+ strategy:
15
+ matrix:
16
+ node-version: [18.x, 20.x]
17
+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
18
+
19
+ steps:
20
+ - name: Checkout the code
21
+ uses: actions/checkout@v4
22
+ - name: Use Node.js ${{ matrix.node-version }}
23
+ uses: actions/setup-node@v4
24
+ with:
25
+ node-version: ${{ matrix.node-version }}
26
+ cache: 'npm'
27
+ env:
28
+ NPM_CONFIG_IGNORE_SCRIPTS: true
29
+ MONGOMS_DOWNLOAD_URL: https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-7.0.12.tgz
30
+ MONGOMS_VERSION: 7.0.12
31
+ - run: npm i -g npm@latest
32
+ - run: npm audit --package-lock-only --production --audit-level=high
33
+ - run: npm i
34
+ - run: npm test
35
+ - run: npm run build --if-present
36
+
37
+ njsscan:
38
+ name: Njsscan-check
39
+ runs-on: ubuntu-latest
40
+ container: node:18
41
+
42
+ steps:
43
+ - name: Checkout the code
44
+ uses: actions/checkout@v4
45
+ - name: nodejsscan scan
46
+ id: njsscan
47
+ uses: ajinabraham/njsscan-action@master
48
+ with:
49
+ args: '.'
50
+
51
+ license-scan:
52
+ name: License compliance check
53
+ runs-on: ubuntu-latest
54
+ container: node:18
55
+
56
+ steps:
57
+ - uses: actions/checkout@v4
58
+ - uses: mikaelvesavuori/license-compliance-action@v1
59
+ with:
60
+ exclude_pattern: /^@natlibfi/
61
+
62
+ publish:
63
+ name: Npm publishing
64
+ runs-on: ubuntu-latest
65
+ container: node:18
66
+ needs: [build-node-versions, njsscan]
67
+ if: contains(github.ref, 'refs/tags/')
68
+
69
+ steps:
70
+ - uses: actions/checkout@v4
71
+ # Setup .npmrc file to publish to npm
72
+ - uses: actions/setup-node@v4
73
+ with:
74
+ node-version: '18.x'
75
+ registry-url: 'https://registry.npmjs.org'
76
+ - run: npm ci
77
+ - run: npm publish
78
+ env:
79
+ NODE_AUTH_TOKEN: ${{ secrets.MELINDA_RECORD_IMPORT_COMMONS_JS_NPM_TOKEN }}
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Transliteration from Russian and Ukranian texts to Finnish as defined in SFS-4900 standard
2
+
3
+ ## Installation
4
+
5
+ ```
6
+ npm install sfs4900
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ ```
12
+ var converter = require('sfs4900');
13
+
14
+ var conversion = converter.convertToLatin('Чайковский, Гоголь'); // defaults to russian
15
+
16
+ // Second argument can be used to specify language code: 'rus' or 'ukr':
17
+ var ukrainianConversion = converter.convertToLatin('Гоголь', 'ukr');
18
+
19
+
20
+
21
+ console.log(conversion);
22
+ /* prints:
23
+ {
24
+ 'from': 'Чайковский, Гоголь',
25
+ 'result': 'Tšaikovski, Gogol',
26
+ 'warnings': []
27
+ }
28
+ */
29
+
30
+
31
+ console.log(ukrainianConversion);
32
+ /* prints:
33
+ {
34
+ 'from': 'Гоголь',
35
+ 'result': 'Hohol',
36
+ 'warnings': []
37
+ }
38
+ */
39
+ ```
40
+
41
+ Warnings include notes on characters that were not converted.
42
+
43
+ ## See also
44
+
45
+ https://fi.wikipedia.org/wiki/Ven%C3%A4j%C3%A4n_translitterointi
@@ -0,0 +1,243 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.convertToLatin = convertToLatin;
7
+ // Based on https://fi.wikipedia.org/wiki/Ven%C3%A4j%C3%A4n_translitterointi and https://fi.wikipedia.org/wiki/Ukrainan_translitterointi
8
+
9
+ const consonants = ['б', 'в', 'г', 'ґ', 'д', 'ж', 'з', 'к', 'л', 'м', 'н', 'п', 'р', 'с', 'т', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'Б', 'В', 'Г', 'Ґ', 'Д', 'Ж', 'З', 'К', 'Л', 'М', 'Н', 'П', 'Р', 'С', 'Т', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ'];
10
+ const characters = ['А', 'а', 'Б', 'б', 'В', 'в', 'Г', 'г', 'Ґ', 'ґ', 'Д', 'д', 'Е', 'е', 'E', 'e', 'Ё', 'ё', 'Ё', 'ё', 'Є', 'є', 'Ж', 'ж', 'З', 'з', 'И', 'и', 'И', 'и', 'І', 'і', 'Ї', 'ї', 'Й', 'й', 'Й', 'й', 'Й', 'й', 'К', 'к', 'Л', 'л', 'М', 'м', 'Н', 'н', 'О', 'о', 'П', 'п', 'Р', 'р', 'С', 'с', 'Т', 'т', 'У', 'у', 'Ф', 'ф', 'Х', 'х', 'Ц', 'ц', 'Ч', 'ч', 'Ш', 'ш', 'Щ', 'щ', 'Ъ', 'ъ', 'Ы', 'ы', 'Ь', 'ь', 'Э', 'э', 'Ю', 'ю', 'Я', 'я', '’'];
11
+ const map = {
12
+ 'А': 'A',
13
+ // Both
14
+ 'а': 'a',
15
+ 'Б': 'B',
16
+ // Both
17
+ 'б': 'b',
18
+ 'В': 'V',
19
+ // Both
20
+ 'в': 'v',
21
+ 'Г': 'G',
22
+ // rus, ukr h, Ґ ґ g, see code
23
+ 'г': 'g',
24
+ 'Ґ': 'G',
25
+ // UKR-only
26
+ 'ґ': 'g',
27
+ 'Д': 'D',
28
+ // both
29
+ 'д': 'd',
30
+ // 'Е': 'E', // UKR is simpler
31
+ // 'е': 'e',
32
+ // 'E': 'Je',
33
+ // 'e': 'je',
34
+ // 'Ё': 'O', // RUS only
35
+ // 'ё': 'o',
36
+ // 'Ё': 'Jo',
37
+ // 'ё': 'jo',
38
+ 'Є': 'Je',
39
+ // UKR only
40
+ 'є': 'je',
41
+ 'Ж': 'Ž',
42
+ // Both
43
+ 'ж': 'ž',
44
+ 'З': 'Z',
45
+ // Both
46
+ 'з': 'z',
47
+ 'И': 'I',
48
+ // RUS: 'i'/'ji'. UKR: 'y'. Default to 'i'
49
+ 'и': 'i',
50
+ //'И': 'Ji',
51
+ //'и': 'ji',*/
52
+ 'І': 'I',
53
+ // UKR only
54
+ 'і': 'i',
55
+ 'Ї': 'Ji',
56
+ // UKR only
57
+ 'ї': 'ji',
58
+ 'Й': 'I',
59
+ // RUS and UKR both map to 'i'/'j'/'', but the rules differ slightly. Map to I/i by default
60
+ 'й': 'i',
61
+ //'Й': 'J',
62
+ //'й': 'j',
63
+ //'Й': '',
64
+ //'й': '',
65
+ 'К': 'K',
66
+ // both
67
+ 'к': 'k',
68
+ 'Л': 'L',
69
+ // both
70
+ 'л': 'l',
71
+ 'М': 'M',
72
+ // both
73
+ 'м': 'm',
74
+ 'Н': 'N',
75
+ // both
76
+ 'н': 'n',
77
+ 'О': 'O',
78
+ // both
79
+ 'о': 'o',
80
+ 'П': 'P',
81
+ // both
82
+ 'п': 'p',
83
+ 'Р': 'R',
84
+ // both
85
+ 'р': 'r',
86
+ 'С': 'S',
87
+ // both
88
+ 'с': 's',
89
+ 'Т': 'T',
90
+ // both
91
+ 'т': 't',
92
+ 'У': 'U',
93
+ // both
94
+ 'у': 'u',
95
+ 'Ф': 'F',
96
+ // both
97
+ 'ф': 'f',
98
+ 'Х': 'H',
99
+ // UKR: h’
100
+ 'х': 'h',
101
+ 'Ц': 'Ts',
102
+ // both
103
+ 'ц': 'ts',
104
+ 'Ч': 'Tš',
105
+ // both
106
+ 'ч': 'tš',
107
+ 'Ш': 'Š',
108
+ // both
109
+ 'ш': 'š',
110
+ 'Щ': 'Štš',
111
+ // both
112
+ 'щ': 'štš',
113
+ 'Ъ': '',
114
+ // both (UKR: no longer used)
115
+ 'ъ': '',
116
+ 'Ы': 'Y',
117
+ // RUS onlt
118
+ 'ы': 'y',
119
+ 'Ь': '',
120
+ // both
121
+ 'ь': '',
122
+ 'Э': 'E',
123
+ // RUS only
124
+ 'э': 'e',
125
+ 'Ю': 'Ju',
126
+ // Both
127
+ 'ю': 'ju',
128
+ 'Я': 'Ja',
129
+ // Both
130
+ 'я': 'ja',
131
+ '’': '' // UKR only
132
+ };
133
+ function createConverter(word, lang = 'rus') {
134
+ // lang: 'rus' and 'ukr' supported
135
+ const warnings = [];
136
+ console.log(`LANG: ${lang}`); // eslint-disable-line no-console
137
+
138
+ function eOrJe(char, previousCharacter) {
139
+ if (lang === 'ukr') {
140
+ return char === 'Е' ? 'E' : 'e';
141
+ }
142
+ if (isConsonant(previousCharacter)) {
143
+ if (['Ъ', 'Ь', 'ъ', 'ь'].includes(previousCharacter)) {
144
+ return char === 'Е' ? 'Je' : 'je';
145
+ }
146
+ return char === 'Е' ? 'E' : 'e';
147
+ }
148
+
149
+ //if (isFirstCharacter || ['Ъ','Ь','ъ','ь'].includes(previousCharacter) || !isConsonant(previousCharacter)) {
150
+ return char === 'Е' ? 'Je' : 'je';
151
+ }
152
+ function gOrH(char) {
153
+ if (lang === 'ukr') {
154
+ return char === 'Г' ? 'H' : 'h';
155
+ }
156
+ return char === 'Г' ? 'G' : 'g';
157
+ }
158
+ function iOrJ(char, previousCharacter, isFirstCharacter, isLastCharacter) {
159
+ if (isFirstCharacter) {
160
+ // Both RUS and UKR
161
+ return char === 'Й' ? 'J' : 'j';
162
+ }
163
+ if (lang === 'ukr' && ['І', 'і'].includes(previousCharacter)) {
164
+ if (isLastCharacter) {
165
+ return '';
166
+ }
167
+ return char === 'Й' ? 'J' : 'j';
168
+ }
169
+ if (lang === 'rus' && ['и', 'И'].includes(previousCharacter)) {
170
+ if (isLastCharacter) {
171
+ return '';
172
+ }
173
+ return char === 'Й' ? 'J' : 'j';
174
+ }
175
+ return char === 'Й' ? 'I' : 'i';
176
+ }
177
+ function convertCharacter(char, i) {
178
+ const previousCharacter = word[i - 1];
179
+ const nextCharacter = word[i + 1];
180
+ const isFirstCharacter = i === 0 || !characters.some(c => c === previousCharacter);
181
+ if (['Г', 'г'].includes(char)) {
182
+ // 'gogol' vs 'hohol'
183
+ return gOrH(char);
184
+ }
185
+ if (['Е', 'е'].includes(char)) {
186
+ return eOrJe(char, previousCharacter);
187
+ }
188
+ if (['Ё', 'ё'].includes(char)) {
189
+ // RUS only
190
+ if (['ж', 'ч', 'ш', 'щ', 'Ж', 'Ч', 'Ш', 'Щ'].includes(previousCharacter)) {
191
+ return previousCharacter === 'Ё' ? 'O' : 'o';
192
+ }
193
+ return previousCharacter === 'Ё' ? 'Jo' : 'jo';
194
+ }
195
+ if (['И', 'и'].includes(char)) {
196
+ if (lang === 'ukr') {
197
+ return char === 'И' ? 'Y' : 'y';
198
+ }
199
+ if (['Ь', 'ь'].includes(previousCharacter)) {
200
+ return char === 'И' ? 'Ji' : 'ji';
201
+ }
202
+ return char === 'И' ? 'I' : 'i';
203
+ }
204
+ if (['Й', 'й'].includes(char)) {
205
+ const isLastCharacter = i === word.length - 1 || !characters.some(c => c === nextCharacter);
206
+ return iOrJ(char, previousCharacter, isFirstCharacter, isLastCharacter);
207
+ }
208
+ if (lang === 'ukr') {
209
+ if (char === 'Х') {
210
+ return 'H\'';
211
+ }
212
+ if (char === 'х') {
213
+ return 'h\'';
214
+ }
215
+ }
216
+ return convertCharacter2();
217
+ function convertCharacter2() {
218
+ const converted = map[char];
219
+ if (converted === undefined) {
220
+ warnings.push(`Character ${char} at position ${i} was not cyrillic.`); // eslint-disable-line functional/immutable-data
221
+ return char;
222
+ }
223
+ return converted;
224
+ }
225
+ }
226
+ return {
227
+ warnings,
228
+ convertCharacter
229
+ };
230
+ }
231
+ function convertToLatin(word, lang = 'rus') {
232
+ const converter = createConverter(word, lang);
233
+ const convertedWord = word.split('').map(converter.convertCharacter).join('');
234
+ return {
235
+ from: word,
236
+ result: convertedWord,
237
+ warnings: converter.warnings
238
+ };
239
+ }
240
+ function isConsonant(char) {
241
+ return consonants.includes(char);
242
+ }
243
+ //# sourceMappingURL=transliteration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transliteration.js","names":["consonants","characters","map","createConverter","word","lang","warnings","console","log","eOrJe","char","previousCharacter","isConsonant","includes","gOrH","iOrJ","isFirstCharacter","isLastCharacter","convertCharacter","i","nextCharacter","some","c","length","convertCharacter2","converted","undefined","push","convertToLatin","converter","convertedWord","split","join","from","result"],"sources":["../src/transliteration.js"],"sourcesContent":["// Based on https://fi.wikipedia.org/wiki/Ven%C3%A4j%C3%A4n_translitterointi and https://fi.wikipedia.org/wiki/Ukrainan_translitterointi\n\nconst consonants = ['б', 'в', 'г', 'ґ', 'д', 'ж', 'з', 'к', 'л', 'м', 'н', 'п', 'р', 'с', 'т', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'Б', 'В', 'Г', 'Ґ', 'Д', 'Ж', 'З', 'К', 'Л', 'М', 'Н', 'П', 'Р', 'С', 'Т', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ'];\n\nconst characters = ['А', 'а', 'Б', 'б', 'В', 'в', 'Г', 'г', 'Ґ', 'ґ', 'Д', 'д', 'Е', 'е', 'E', 'e', 'Ё', 'ё', 'Ё', 'ё', 'Є', 'є', 'Ж', 'ж', 'З', 'з', 'И', 'и', 'И', 'и', 'І', 'і', 'Ї', 'ї', 'Й', 'й', 'Й', 'й', 'Й', 'й', 'К', 'к', 'Л', 'л', 'М', 'м', 'Н', 'н', 'О', 'о', 'П', 'п', 'Р', 'р', 'С', 'с', 'Т', 'т', 'У', 'у', 'Ф', 'ф', 'Х', 'х', 'Ц', 'ц', 'Ч', 'ч', 'Ш', 'ш', 'Щ', 'щ', 'Ъ', 'ъ', 'Ы', 'ы', 'Ь', 'ь', 'Э', 'э', 'Ю', 'ю', 'Я', 'я', '’'];\n\nconst map = {\n 'А': 'A', // Both\n 'а': 'a',\n 'Б': 'B', // Both\n 'б': 'b',\n 'В': 'V', // Both\n 'в': 'v',\n 'Г': 'G', // rus, ukr h, Ґ ґ g, see code\n 'г': 'g',\n 'Ґ': 'G', // UKR-only\n 'ґ': 'g',\n 'Д': 'D', // both\n 'д': 'd',\n // 'Е': 'E', // UKR is simpler\n // 'е': 'e',\n // 'E': 'Je',\n // 'e': 'je',\n // 'Ё': 'O', // RUS only\n // 'ё': 'o',\n // 'Ё': 'Jo',\n // 'ё': 'jo',\n 'Є': 'Je', // UKR only\n 'є': 'je',\n 'Ж': 'Ž', // Both\n 'ж': 'ž',\n 'З': 'Z', // Both\n 'з': 'z',\n 'И': 'I', // RUS: 'i'/'ji'. UKR: 'y'. Default to 'i'\n 'и': 'i',\n //'И': 'Ji',\n //'и': 'ji',*/\n 'І': 'I', // UKR only\n 'і': 'i',\n 'Ї': 'Ji', // UKR only\n 'ї': 'ji',\n 'Й': 'I', // RUS and UKR both map to 'i'/'j'/'', but the rules differ slightly. Map to I/i by default\n 'й': 'i',\n //'Й': 'J',\n //'й': 'j',\n //'Й': '',\n //'й': '',\n 'К': 'K', // both\n 'к': 'k',\n 'Л': 'L', // both\n 'л': 'l',\n 'М': 'M', // both\n 'м': 'm',\n 'Н': 'N', // both\n 'н': 'n',\n 'О': 'O', // both\n 'о': 'o',\n 'П': 'P', // both\n 'п': 'p',\n 'Р': 'R', // both\n 'р': 'r',\n 'С': 'S', // both\n 'с': 's',\n 'Т': 'T', // both\n 'т': 't',\n 'У': 'U', // both\n 'у': 'u',\n 'Ф': 'F', // both\n 'ф': 'f',\n 'Х': 'H', // UKR: h’\n 'х': 'h',\n 'Ц': 'Ts', // both\n 'ц': 'ts',\n 'Ч': 'Tš', // both\n 'ч': 'tš',\n 'Ш': 'Š', // both\n 'ш': 'š',\n 'Щ': 'Štš', // both\n 'щ': 'štš',\n 'Ъ': '', // both (UKR: no longer used)\n 'ъ': '',\n 'Ы': 'Y', // RUS onlt\n 'ы': 'y',\n 'Ь': '', // both\n 'ь': '',\n 'Э': 'E', // RUS only\n 'э': 'e',\n 'Ю': 'Ju', // Both\n 'ю': 'ju',\n 'Я': 'Ja', // Both\n 'я': 'ja',\n '’': '' // UKR only\n};\n\nfunction createConverter(word, lang = 'rus') { // lang: 'rus' and 'ukr' supported\n const warnings = [];\n console.log(`LANG: ${lang}`); // eslint-disable-line no-console\n\n function eOrJe(char, previousCharacter) {\n if (lang === 'ukr') {\n return char === 'Е' ? 'E' : 'e';\n }\n if (isConsonant(previousCharacter)) {\n if (['Ъ', 'Ь', 'ъ', 'ь'].includes(previousCharacter)) {\n return char === 'Е' ? 'Je' : 'je';\n }\n return char === 'Е' ? 'E' : 'e';\n }\n\n //if (isFirstCharacter || ['Ъ','Ь','ъ','ь'].includes(previousCharacter) || !isConsonant(previousCharacter)) {\n return char === 'Е' ? 'Je' : 'je';\n }\n\n function gOrH(char) {\n if (lang === 'ukr') {\n return char === 'Г' ? 'H' : 'h';\n }\n\n return char === 'Г' ? 'G' : 'g';\n }\n function iOrJ(char, previousCharacter, isFirstCharacter, isLastCharacter) {\n if (isFirstCharacter) { // Both RUS and UKR\n return char === 'Й' ? 'J' : 'j';\n }\n\n if (lang === 'ukr' && ['І', 'і'].includes(previousCharacter)) {\n if (isLastCharacter) {\n return '';\n }\n return char === 'Й' ? 'J' : 'j';\n }\n if (lang === 'rus' && ['и', 'И'].includes(previousCharacter)) {\n if (isLastCharacter) {\n return '';\n }\n return char === 'Й' ? 'J' : 'j';\n }\n return char === 'Й' ? 'I' : 'i';\n }\n\n function convertCharacter(char, i) {\n const previousCharacter = word[i - 1];\n const nextCharacter = word[i + 1];\n\n const isFirstCharacter = i === 0 || !characters.some(c => c === previousCharacter);\n\n if (['Г', 'г'].includes(char)) { // 'gogol' vs 'hohol'\n return gOrH(char);\n }\n\n if (['Е', 'е'].includes(char)) {\n return eOrJe(char, previousCharacter);\n }\n\n if (['Ё', 'ё'].includes(char)) { // RUS only\n if (['ж', 'ч', 'ш', 'щ', 'Ж', 'Ч', 'Ш', 'Щ'].includes(previousCharacter)) {\n return previousCharacter === 'Ё' ? 'O' : 'o';\n }\n return previousCharacter === 'Ё' ? 'Jo' : 'jo';\n }\n\n if (['И', 'и'].includes(char)) {\n if (lang === 'ukr') {\n return char === 'И' ? 'Y' : 'y';\n }\n if (['Ь', 'ь'].includes(previousCharacter)) {\n return char === 'И' ? 'Ji' : 'ji';\n }\n return char === 'И' ? 'I' : 'i';\n }\n\n if (['Й', 'й'].includes(char)) {\n const isLastCharacter = i === word.length - 1 || !characters.some(c => c === nextCharacter);\n return iOrJ(char, previousCharacter, isFirstCharacter, isLastCharacter);\n }\n\n if (lang === 'ukr') {\n if (char === 'Х') {\n return 'H\\'';\n }\n if (char === 'х') {\n return 'h\\'';\n }\n }\n\n return convertCharacter2();\n\n function convertCharacter2() {\n const converted = map[char];\n\n if (converted === undefined) {\n warnings.push(`Character ${char} at position ${i} was not cyrillic.`); // eslint-disable-line functional/immutable-data\n return char;\n }\n\n return converted;\n }\n }\n\n return {\n warnings,\n convertCharacter\n };\n}\n\nexport function convertToLatin(word, lang = 'rus') {\n const converter = createConverter(word, lang);\n\n const convertedWord = word.split('').map(converter.convertCharacter).join('');\n\n return {\n from: word,\n result: convertedWord,\n warnings: converter.warnings\n };\n}\n\nfunction isConsonant(char) {\n return consonants.includes(char);\n}\n"],"mappings":";;;;;;AAAA;;AAEA,MAAMA,UAAU,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;AAErO,MAAMC,UAAU,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE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ACF;IAEA,OAAOc,iBAAiB,CAAC,CAAC;IAE1B,SAASA,iBAAiBA,CAAA,EAAG;MAC3B,MAAMC,SAAS,GAAGvB,GAAG,CAACQ,IAAI,CAAC;MAE3B,IAAIe,SAAS,KAAKC,SAAS,EAAE;QAC3BpB,QAAQ,CAACqB,IAAI,CAAC,aAAajB,IAAI,gBAAgBS,CAAC,oBAAoB,CAAC,CAAC,CAAC;QACvE,OAAOT,IAAI;MACb;MAEA,OAAOe,SAAS;IAClB;EACF;EAEA,OAAO;IACLnB,QAAQ;IACRY;EACF,CAAC;AACH;AAEO,SAASU,cAAcA,CAACxB,IAAI,EAAEC,IAAI,GAAG,KAAK,EAAE;EACjD,MAAMwB,SAAS,GAAG1B,eAAe,CAACC,IAAI,EAAEC,IAAI,CAAC;EAE7C,MAAMyB,aAAa,GAAG1B,IAAI,CAAC2B,KAAK,CAAC,EAAE,CAAC,CAAC7B,GAAG,CAAC2B,SAAS,CAACX,gBAAgB,CAAC,CAACc,IAAI,CAAC,EAAE,CAAC;EAE7E,OAAO;IACLC,IAAI,EAAE7B,IAAI;IACV8B,MAAM,EAAEJ,aAAa;IACrBxB,QAAQ,EAAEuB,SAAS,CAACvB;EACtB,CAAC;AACH;AAEA,SAASM,WAAWA,CAACF,IAAI,EAAE;EACzB,OAAOV,UAAU,CAACa,QAAQ,CAACH,IAAI,CAAC;AAClC","ignoreList":[]}
package/package.json ADDED
@@ -0,0 +1,119 @@
1
+ {
2
+ "name": "@natlibfi/sfs-4900",
3
+ "version": "1.1.0",
4
+ "license": "MIT",
5
+ "description": "Transliteration from cyrillic (Russian, Ukrainian) text to latin (Finnish) as defined in the SFS-4900 standard",
6
+ "author": "The National Library of Finland",
7
+ "contributors": [
8
+ "Pasi Tuominen <pasi.tuominen@gmail.com>",
9
+ "The National Library of Finland"
10
+ ],
11
+ "keywords": [
12
+ "SFS-4900",
13
+ "sfs4900",
14
+ "standard",
15
+ "romanization",
16
+ "Russian",
17
+ "Ukranian",
18
+ "Finnish",
19
+ "transliteration"
20
+ ],
21
+ "homepage": "https://github.com/NatLibFi/sfs-4900",
22
+ "bugs": {
23
+ "url": "https://github.com/NatLibFi/sfs-4900/issues"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+ssh://git@github.com/natlibfi/sfs-4900.git"
28
+ },
29
+ "main": "dist/transliteration.js",
30
+ "engines": {
31
+ "node": ">=18"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "scripts": {
37
+ "prepare": "npm run build",
38
+ "build": "babel ./src --source-maps --copy-files --delete-dir-on-start --out-dir=dist",
39
+ "lint": "eslint ./src",
40
+ "lint:dev": "eslint --fix ./src",
41
+ "test": "npm run lint && npm run test:base",
42
+ "test:base": "cross-env NODE_ENV=test nyc mocha",
43
+ "test:dev": "npm run lint:dev && cross-env NODE_ENV=test nyc mocha",
44
+ "dev": "nodemon",
45
+ "dev:debug": "cross-env LOG_LEVEL=debug DEBUG=@natlibfi/* NODE_ENV=test nodemon",
46
+ "coverage": "npm run cover:unit && npm run cover:report",
47
+ "cover:unit": "nyc --silent npm run test:base",
48
+ "cover:report": "nyc report"
49
+ },
50
+ "devDependencies": {
51
+ "@babel/cli": "^7.25.7",
52
+ "@babel/core": "^7.25.8",
53
+ "@babel/preset-env": "^7.25.8",
54
+ "@natlibfi/eslint-config-melinda-backend": "^3.0.5",
55
+ "@natlibfi/fixugen": "^2.0.10",
56
+ "@natlibfi/fixura": "^3.0.10",
57
+ "babel-plugin-istanbul": "^7.0.0",
58
+ "chai": "^4.5.0",
59
+ "cross-env": "^7.0.3",
60
+ "eslint": "^8.57.1",
61
+ "mocha": "^10.7.3",
62
+ "nyc": "^17.1.0"
63
+ },
64
+ "eslintConfig": {
65
+ "extends": [
66
+ "@natlibfi/melinda-backend"
67
+ ]
68
+ },
69
+ "babel": {
70
+ "presets": [
71
+ [
72
+ "@babel/preset-env",
73
+ {
74
+ "targets": "maintained node versions"
75
+ }
76
+ ]
77
+ ],
78
+ "env": {
79
+ "test": {
80
+ "plugins": [
81
+ "istanbul"
82
+ ]
83
+ }
84
+ }
85
+ },
86
+ "mocha": {
87
+ "spec": [
88
+ "test/*.spec.js"
89
+ ],
90
+ "require": [
91
+ "@babel/register"
92
+ ],
93
+ "inline-diffs": true,
94
+ "maxDiffSize": 25000,
95
+ "bail": true,
96
+ "exit": true
97
+ },
98
+ "nodemonConfig": {
99
+ "exec": "npm run test:dev",
100
+ "watch": [
101
+ "src/*",
102
+ "test/*"
103
+ ]
104
+ },
105
+ "nyc": {
106
+ "exclude": [
107
+ "test/*.spec.js"
108
+ ],
109
+ "reporter": [
110
+ "text"
111
+ ],
112
+ "sourceMap": false,
113
+ "instrument": false,
114
+ "lines": 80,
115
+ "statements": 80,
116
+ "functions": 80,
117
+ "branches": 80
118
+ }
119
+ }
@@ -0,0 +1,155 @@
1
+ import { expect } from 'chai';
2
+ import { convertToLatin } from '../src/transliteration';
3
+
4
+ const mapping = [
5
+ ['А', 'а'],['A','a'], ['Анапа', 'Anapa'],
6
+ ['Б', 'б'],['B','b'], ['Бабаево', 'Babajevo'],
7
+ ['В', 'в'],['V','v'], ['Всеволожск', 'Vsevoložsk'],
8
+ ['Г', 'г'],['G','g'], ['Гагарин, Гоголь', 'Gagarin, Gogol'],
9
+ ['Д', 'д'],['D','d'], ['Дедовск', 'Dedovsk'],
10
+ ['Е', 'е'],['E','e'], ['Дальнереченск', 'Dalneretšensk'],
11
+ ['E', 'e'],['Je','je'], ['Егорьевск, Гаджиево', 'Jegorjevsk, Gadžijevo'],
12
+ ['Ё', 'ё'],['O','o'], ['Горбачёв, Тимашёвск, Хрущёв', 'Gorbatšov, Timašovsk, Hruštšov'],
13
+ ['Ё', 'ё'],['Jo','jo'], ['Королёв', 'Koroljov'],
14
+ ['Ж', 'ж'],['Ž','ž'], ['Железнодорожный', 'Železnodorožnyi'],
15
+ ['З', 'з'],['Z','z'], ['Заозёрск', 'Zaozjorsk'],
16
+ ['И', 'и'],['I','i'], ['Ишим', 'Išim'],
17
+ ['И', 'и'],['Ji','ji'], ['Краснотурьинск', 'Krasnoturjinsk'],
18
+ ['Й', 'й'],['I','i'], ['Ясный, Валдайский район', 'Jasnyi, Valdaiski raion'],
19
+ ['Й', 'й'],['J','j'], ['Каспийск, Йошкар-Ола', 'Kaspijsk, Joškar-Ola'],
20
+ ['Й', 'й'],['', ''], ['Чайковский', 'Tšaikovski'],
21
+ ['К', 'к'],['K','k'], ['Копейск', 'Kopeisk'],
22
+ ['Л', 'л'],['L','l'], ['Лихославль', 'Lihoslavl'],
23
+ ['М', 'м'],['M','m'], ['Мурманск', 'Murmansk'],
24
+ ['Н', 'н'],['N','n'], ['Ногинск', 'Noginsk'],
25
+ ['О', 'о'],['O','o'], ['Олонец', 'Olonets'],
26
+ ['П', 'п'],['P','p'], ['Почеп', 'Potšep'],
27
+ ['Р', 'р'],['R','r'], ['Рязань', 'Rjazan'],
28
+ ['С', 'с'],['S','s'], ['Сестрорецк', 'Sestroretsk'],
29
+ ['Т', 'т'],['T','t'], ['Тольятти', 'Toljatti'],
30
+ ['У', 'у'],['U','u'], ['Уссурийск', 'Ussurijsk'],
31
+ ['Ф', 'ф'],['F','f'], ['Фатеж', 'Fatež'],
32
+ ['Х', 'х'],['H','h'], ['Хабаровск', 'Habarovsk'],
33
+ ['Ц', 'ц'],['Ts','ts'], ['Цивильск', 'Tsivilsk' ],
34
+ ['Ч', 'ч'],['Tš','tš'], ['Чита', 'Tšita'],
35
+ ['Ш', 'ш'],['Š','š'], ['Шушары', 'Šušary'],
36
+ ['Щ', 'щ'],['Štš','štš'], ['Щёлково', 'Štšolkovo'],
37
+ ['Ъ', 'ъ'],['',''], ['субъект', 'subjekt'],
38
+ ['Ы', 'ы'],['Y','y'], ['Кызыл', 'Kyzyl'],
39
+ ['Ь', 'ь'],['',''], ['Козьмодемьянск', 'Kozmodemjansk'],
40
+ ['Э', 'э'],['E','e'], ['Энгельс', 'Engels'],
41
+ ['Ю', 'ю'],['Ju','ju'], ['Юрюзань', 'Jurjuzan'],
42
+ ['Я', 'я'],['Ja','ja'], ['Ярославль', 'Jaroslavl'],
43
+
44
+ ];
45
+
46
+ const mappingUkr = [
47
+ ['А', 'а'],['A','a'], ['Алушта', 'Alušta'],
48
+ ['Б', 'б'],['B','b'], ['Бобринець', 'Bobrynets'],
49
+ ['В', 'в'],['V','v'], ['Вишневе', 'Vyšneve'],
50
+ ['Г', 'г'],['H','h'], ['Генічеськ, Гоголь', 'Henitšesk, Hohol'],
51
+ ['Ґ', 'ґ'],['G','g'], ['Ґалаґан', 'Galagan'],
52
+ ['Д', 'д'],['D','d'], ['Дніпродзержинськ', 'Dniprodzeržynsk'],
53
+ ['Е', 'е'],['E','e'], ['Енергодар', 'Enerhodar'],
54
+ ['Є', 'є'],['Je','je'], ['Єнакієве', 'Jenakijeve'],
55
+ ['Ж', 'ж'],['Ž','ž'], ['Житомир', 'Žytomyr'],
56
+ ['З', 'з'],['Z','z'], ['Запоріжжя', 'Zaporižžja'],
57
+ ['И', 'и'],['Y','y'], ['Винники', 'Vynnyky'],
58
+ ['І', 'і'],['I','i'], ['Іллічівськ', 'Illitšivsk'],
59
+ ['Ї', 'ї'],['Ji','ji'], ['Ізмаїл, Їжакевич', 'Izmajil, Jižakevytš'],
60
+ ['Й', 'й'],['J','j'], ['Красноармійськ', 'Krasnoarmijsk'],
61
+ ['Й', 'й'],['I','i'], ['Гайсин, Хмельницький', 'Haisyn, H\'melnytskyi'],
62
+ ['Й', 'й'],['-','-'], ['Григорій', 'Hryhori'],
63
+ ['К', 'к'],['K','k'], ['Красноперекопськ', 'Krasnoperekopsk'],
64
+ ['Л', 'л'],['L','l'], ['Лохвиця', 'Loh\'vytsja'],
65
+ ['М', 'м'],['M','m'], ['Миколаїв', 'Mykolajiv'],
66
+ ['Н', 'н'],['N','n'], ['Нетішин', 'Netišyn'],
67
+ ['О', 'о'],['O','o'], ['Острог', 'Ostroh'],
68
+ ['П', 'п'],['P','p'], ['Прип’ять', 'Prypjat'],
69
+ ['Р', 'р'],['R','r'], ['Рахів', 'Rah\'iv'],
70
+ ['С', 'с'],['S','s'], ['Севастополь', 'Sevastopol'],
71
+ ['Т', 'т'],['T','t'], ['Тальне', 'Talne'],
72
+ ['У', 'у'],['U','u'], ['Умань', 'Uman'],
73
+ ['Ф', 'ф'],['F','f'], ['Феодосія', 'Feodosija'],
74
+ ['Х', 'х'],['H\'', 'h\''],['Христинівка', 'H\'rystynivka'], // h ja puolilainausmerkki
75
+ ['Ц', 'ц'],['Ts','ts'], ['Цюрупинськ', 'Tsjurupynsk'],
76
+ ['Ч', 'ч'],['Tš','tš'], ['Чугуїв', 'Tšuhujiv'],
77
+ ['Ш', 'ш'],['Š','š'], ['Шепетівка', 'Šepetivka'],
78
+ ['Щ', 'щ'],['Štš','štš'], ['Щастя', 'Štšastja'],
79
+ ['Ю', 'ю'],['Ju','ju'], ['Южне', 'Južne'],
80
+ ['Я', 'я'],['Ja','ja'], ['Ялта', 'Jalta'],
81
+ ['Ь', 'ь'],['-','-'], ['Комсомольськ', 'Komsomolsk'],
82
+ ['’', '’'],['', ''], ['Куп’янськ', 'Kupjansk'] // puolilainausmerkki
83
+ //['Ъ', 'ъ'],['', ''], ei esiinny nykyortografiassa];
84
+ ];
85
+
86
+ describe('Transliteration', function() {
87
+
88
+ const testDefinitions = mapping.reduce((acc, item, i) => {
89
+ if (i%3 === 0) {
90
+ acc.push({});
91
+ }
92
+
93
+ const current = acc[acc.length-1];
94
+
95
+ switch(i%3) {
96
+ case 0: current.from = item; break;
97
+ case 1: current.to = item; break;
98
+ case 2: current.word = item; break;
99
+ }
100
+ return acc;
101
+
102
+ }, []);
103
+
104
+ testDefinitions.forEach(test => {
105
+ it(`converts ${test.from[0]} to ${test.to[0]} in ${test.word[0]} to ${test.word[1]}`, () => {
106
+ expect(convertToLatin(test.word[0]).result).to.equal(test.word[1]);
107
+ });
108
+ it(`converts ${test.from[1]} to ${test.to[1]} in ${test.word[0]} to ${test.word[1]}`, () => {
109
+ expect(convertToLatin(test.word[0]).result).to.equal(test.word[1]);
110
+ });
111
+
112
+ });
113
+
114
+ const testDefinitionsUkr = mappingUkr.reduce((acc, item, i) => {
115
+ if (i%3 === 0) {
116
+ acc.push({});
117
+ }
118
+
119
+ const current = acc[acc.length-1];
120
+
121
+ switch(i%3) {
122
+ case 0: current.from = item; break;
123
+ case 1: current.to = item; break;
124
+ case 2: current.word = item; break;
125
+ }
126
+ return acc;
127
+
128
+ }, []);
129
+
130
+ testDefinitionsUkr.forEach(test => {
131
+ it(`converts UKR ${test.from[0]} to ${test.to[0]} in ${test.word[0]} to ${test.word[1]}`, () => {
132
+ expect(convertToLatin(test.word[0], 'ukr').result).to.equal(test.word[1]);
133
+ });
134
+ it(`converts UKR ${test.from[1]} to ${test.to[1]} in ${test.word[0]} to ${test.word[1]}`, () => {
135
+ expect(convertToLatin(test.word[0], 'ukr').result).to.equal(test.word[1]);
136
+ });
137
+
138
+ });
139
+
140
+
141
+ describe('when given non-cyrillic characters', function() {
142
+ let conversion;
143
+ beforeEach(() => {
144
+ conversion = convertToLatin('Aнапа');
145
+ });
146
+
147
+ it('adds warning to result', function() {
148
+ expect(conversion.warnings).to.include('Character A at position 0 was not cyrillic.');
149
+ });
150
+ it('converts the cyrillic characters', function() {
151
+ expect(conversion.result).to.equal('Anapa');
152
+ });
153
+ });
154
+ });
155
+