Skip to content

Commit

Permalink
Merge pull request #19 from versh23/add-space-subject
Browse files Browse the repository at this point in the history
add support to translation tag with space
  • Loading branch information
Vitalii Goma authored Jul 4, 2020
2 parents 1f452c4 + f4f2e02 commit ebeb476
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/constants/issuer-tags-translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const ISSUER_TAGS_TRANSLATIONS: TagsTranslations[] = [
{ possibleNames: ['ОГРН', 'OGRN'], translation: 'ОГРН' },
{ possibleNames: ['ОГРНИП', 'OGRNIP'], translation: 'ОГРНИП' },
{ possibleNames: ['СНИЛС', 'SNILS'], translation: 'СНИЛС' },
{ possibleNames: ['ИНН', 'INN'], translation: 'ИНН' },
{ possibleNames: ['ИНН', 'INN', 'ИНН организации'], translation: 'ИНН' },
{ possibleNames: ['E'], translation: 'Email' },
{ possibleNames: ['L'], translation: 'Город' },
];
2 changes: 1 addition & 1 deletion src/constants/subject-tags-translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const SUBJECT_TAGS_TRANSLATIONS: TagsTranslations[] = [
{ possibleNames: ['ОГРН', 'OGRN'], translation: 'ОГРН' },
{ possibleNames: ['ОГРНИП', 'OGRNIP'], translation: 'ОГРНИП' },
{ possibleNames: ['СНИЛС', 'SNILS'], translation: 'СНИЛС' },
{ possibleNames: ['ИНН', 'INN'], translation: 'ИНН' },
{ possibleNames: ['ИНН', 'INN', 'ИНН организации'], translation: 'ИНН' },
{ possibleNames: ['E'], translation: 'Email' },
{ possibleNames: ['L'], translation: 'Город' },
];
12 changes: 12 additions & 0 deletions src/helpers/_parseCertInfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('_parseCertInfo', () => {
'UNKNOWN=неизвестный тэг',
'[email protected]',
'INN=007811514257',
'ИНН организации=007811514257',
'OGRN=1127847087885',
'SNILS=11617693460',
].join(', ');
Expand Down Expand Up @@ -99,6 +100,11 @@ describe('_parseCertInfo', () => {
title: 'ИНН',
isTranslated: true,
},
{
description: '007811514257',
title: 'ИНН',
isTranslated: true,
},
{
description: '1127847087885',
title: 'ОГРН',
Expand All @@ -123,6 +129,7 @@ describe('_parseCertInfo', () => {
'S=78 Санкт-Петербург',
'C=RU',
'INN=007813317783',
'ИНН организации=007813317783',
'OGRN=1057810150892',
'[email protected]',
].join(', ');
Expand Down Expand Up @@ -173,6 +180,11 @@ describe('_parseCertInfo', () => {
title: 'ИНН',
isTranslated: true,
},
{
description: '007813317783',
title: 'ИНН',
isTranslated: true,
},
{
description: '1057810150892',
title: 'ОГРН',
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/_parseCertInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export interface TagTranslation {
* @returns расшифрованная информация по отдельным тэгам
*/
export const _parseCertInfo = (tagsTranslations: TagsTranslations[], rawInfo: string): TagTranslation[] => {
const extractedEntities: string[] = rawInfo.match(/([а-яА-Яa-zA-Z0-9.]+)=(?:("[^"]+?")|(.+?))(?:,|$)/g);
const extractedEntities: string[] = rawInfo.match(/([а-яА-Яa-zA-Z0-9\s.]+)=(?:("[^"]+?")|(.+?))(?:,|$)/g);

if (extractedEntities) {
return extractedEntities.map((group) => {
const segmentsMatch = group.match(/^([а-яА-Яa-zA-Z0-9.]+)=(.+?),?$/);
const segmentsMatch = group.trim().match(/^([а-яА-Яa-zA-Z0-9\s.]+)=(.+?),?$/);
let title = segmentsMatch?.[1];
// Вырезаем лишние кавычки
const description = segmentsMatch?.[2]?.replace(/^"(.*)"/, '$1')?.replace(/"{2}/g, '"');
Expand Down

0 comments on commit ebeb476

Please sign in to comment.