Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mrz

Package Overview
Dependencies
Maintainers
4
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mrz - npm Package Compare versions

Comparing version 3.1.0 to 3.1.2

CHANGELOG.md

25

package.json
{
"name": "mrz",
"version": "3.1.0",
"version": "3.1.2",
"description": "Parse MRZ (Machine Readable Zone) from identity documents",

@@ -12,8 +12,7 @@ "main": "./src/index.js",

"eslint-fix": "npm run eslint -- --fix",
"test": "npm run test-only && npm run eslint",
"test": "npm run test-coverage && npm run eslint",
"test-coverage": "jest --coverage",
"test-travis": "npm run test-coverage && npm run eslint",
"test-only": "jest",
"build": "npm run buildStates && cheminfo build",
"prepublish": "npm run buildStates",
"build": "npm run buildStates && cheminfo-build",
"prepublishOnly": "npm run buildStates",
"buildStates": "node builder/createStatesJs.js"

@@ -23,3 +22,3 @@ },

"type": "git",
"url": "https://github.com/cheminfo-js/mrz.git"
"url": "https://github.com/cheminfo/mrz.git"
},

@@ -39,12 +38,12 @@ "keywords": [

"bugs": {
"url": "https://github.com/cheminfo-js/mrz/issues"
"url": "https://github.com/cheminfo/mrz/issues"
},
"homepage": "https://github.com/cheminfo-js/mrz#readme",
"homepage": "https://github.com/cheminfo/mrz#readme",
"devDependencies": {
"cheminfo-tools": "^1.20.2",
"eslint": "^4.16.0",
"eslint-config-cheminfo": "^1.15.1",
"eslint-plugin-jest": "^21.7.0",
"jest": "^22.1.4"
"cheminfo-build": "^1.1.9",
"eslint": "^7.20.0",
"eslint-config-cheminfo": "^5.2.3",
"jest": "^26.6.3",
"prettier": "^2.2.1"
}
}
# mrz
[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![David deps][david-image]][david-url]
[![build status][ci-image]][ci-url]
[![npm download][download-image]][download-url]

@@ -13,3 +11,3 @@

`$ npm install --save mrz`
`$ npm install mrz`

@@ -24,3 +22,3 @@ ## Example

'7408122F1204159UTO<<<<<<<<<<<6',
'ERIKSSON<<ANNA<MARIA<<<<<<<<<<'
'ERIKSSON<<ANNA<MARIA<<<<<<<<<<',
];

@@ -46,7 +44,7 @@

* TD1 (identity card with three MRZ lines)
* TD2 (identity card with two MRZ lines)
* TD3 (passport)
* SWISS_DRIVING_LICENSE
* FRENCH_NATIONAL_ID
- TD1 (identity card with three MRZ lines)
- TD2 (identity card with two MRZ lines)
- TD3 (passport)
- SWISS_DRIVING_LICENSE
- FRENCH_NATIONAL_ID

@@ -67,11 +65,11 @@ #### result.valid

* label {string} - Full english term for the field.
* field {string} - Name of the field in `result.fields`.
* value {string} - Value of the field or `null`.
* valid {boolean}
* ranges {Array} - Array of ranges that are necessary to compute this field.
- label {string} - Full english term for the field.
- field {string} - Name of the field in `result.fields`.
- value {string} - Value of the field or `null`.
- valid {boolean}
- ranges {Array} - Array of ranges that are necessary to compute this field.
Ranges are objects with `line`, `start`, `end` and `raw`.
* line {number} - Index of the line where the field is located.
* start {number} - Index of the start of the field in `line`.
* end {number} - Index of the end of the field in `line`.
- line {number} - Index of the line where the field is located.
- start {number} - Index of the start of the field in `line`.
- end {number} - Index of the end of the field in `line`.

@@ -104,11 +102,7 @@ ### formats

[npm-image]: https://img.shields.io/npm/v/mrz.svg?style=flat-square
[npm-image]: https://img.shields.io/npm/v/mrz.svg
[npm-url]: https://npmjs.org/package/mrz
[travis-image]: https://img.shields.io/travis/cheminfo-js/mrz/master.svg?style=flat-square
[travis-url]: https://travis-ci.org/cheminfo-js/mrz
[coveralls-image]: https://img.shields.io/coveralls/cheminfo-js/mrz.svg?style=flat-square
[coveralls-url]: https://coveralls.io/github/cheminfo-js/mrz
[david-image]: https://img.shields.io/david/cheminfo-js/mrz.svg?style=flat-square
[david-url]: https://david-dm.org/cheminfo-js/mrz
[download-image]: https://img.shields.io/npm/dm/mrz.svg?style=flat-square
[ci-image]: https://github.com/cheminfo/mrz/workflows/Node.js%20CI/badge.svg?branch=master
[ci-url]: https://github.com/cheminfo/mrz/actions?query=workflow%3A%22Node.js+CI%22
[download-image]: https://img.shields.io/npm/dm/mrz.svg
[download-url]: https://npmjs.org/package/mrz

@@ -8,3 +8,3 @@ 'use strict';

SWISS_DRIVING_LICENSE: 'SWISS_DRIVING_LICENSE',
FRENCH_NATIONAL_ID: 'FRENCH_NATIONAL_ID'
FRENCH_NATIONAL_ID: 'FRENCH_NATIONAL_ID',
};

@@ -11,0 +11,0 @@ Object.freeze(formats);

'use strict';
const formats = require('./formats');
const states = require('./generated/states');
const formats = require('./formats');
const parse = require('./parse/parse');

@@ -10,3 +10,3 @@

formats,
parse
parse,
};

@@ -9,9 +9,9 @@ 'use strict';

'IDFRATEST<NAME<<<<<<<<<<<<<<<<0CHE02',
'1710GVA123451ROBERTA<<<<<<<9112311F2'
'1710GVA123451ROBERTA<<<<<<<9112311F2',
];
var result = parse(MRZ);
let result = parse(MRZ);
expect(result.format).toBe('FRENCH_NATIONAL_ID');
// expect(result.valid).toEqual(true);
// expect(result.valid).toStrictEqual(true);
expect(result.details.filter((a) => !a.valid)).toHaveLength(0);
expect(result.fields).toEqual({
expect(result.fields).toStrictEqual({
documentCode: 'ID',

@@ -29,5 +29,5 @@ issuingState: 'FRA',

sex: 'female',
compositeCheckDigit: '2'
compositeCheckDigit: '2',
});
});
});

@@ -10,9 +10,9 @@ 'use strict';

'FACHE305142128097<<800126<<<<<',
'MARCHAND<<FABIENNE<<<<<<<<<<<<'
'MARCHAND<<FABIENNE<<<<<<<<<<<<',
];
var result = parse(MRZ);
let result = parse(MRZ);
expect(result.format).toBe('SWISS_DRIVING_LICENSE');
expect(result.valid).toEqual(true);
expect(result.valid).toStrictEqual(true);
expect(result.details.filter((a) => !a.valid)).toHaveLength(0);
expect(result.details[0]).toEqual({
expect(result.details[0]).toStrictEqual({
label: 'Document number',

@@ -25,5 +25,5 @@ field: 'documentNumber',

value: 'AAA001D',
valid: true
valid: true,
});
expect(result.details[result.details.length - 1]).toEqual({
expect(result.details[result.details.length - 1]).toStrictEqual({
label: 'First name',

@@ -38,10 +38,10 @@ field: 'firstName',

end: 30,
raw: 'MARCHAND<<FABIENNE<<<<<<<<<<<<'
}
raw: 'MARCHAND<<FABIENNE<<<<<<<<<<<<',
},
],
line: 2,
start: 10,
end: 18
end: 18,
});
expect(result.fields).toEqual({
expect(result.fields).toStrictEqual({
documentNumber: 'AAA001D',

@@ -55,5 +55,5 @@ languageCode: 'D',

firstName: 'FABIENNE',
lastName: 'MARCHAND'
lastName: 'MARCHAND',
});
});
});

@@ -10,3 +10,3 @@ 'use strict';

'7510256M2009018CHE<<<<<<<<<<<8',
'SMITH<<JOHN<ALBERT<<<<<<<<<<<<'
'SMITH<<JOHN<ALBERT<<<<<<<<<<<<',
];

@@ -17,5 +17,5 @@

format: 'TD1',
valid: true
valid: true,
});
expect(result.fields).toEqual({
expect(result.fields).toStrictEqual({
documentCode: 'ID',

@@ -35,7 +35,7 @@ issuingState: 'CHE',

lastName: 'SMITH',
firstName: 'JOHN ALBERT'
firstName: 'JOHN ALBERT',
});
const optional1Details = result.details.find(
(f) => f.field === 'optional1'
(f) => f.field === 'optional1',
);

@@ -46,3 +46,3 @@ expect(optional1Details).toMatchObject({

start: 15,
end: 15
end: 15,
});

@@ -55,3 +55,3 @@ });

'7408122F1204159UTO<<<<<<<<<<<1',
'ERIKSSON<<ANNA<MARIA<<<<<<<<<<'
'ERIKSSON<<ANNA<MARIA<<<<<<<<<<',
];

@@ -61,3 +61,3 @@

expect(result.details.filter((a) => !a.valid)).toHaveLength(2);
expect(result.fields).toEqual({
expect(result.fields).toStrictEqual({
firstName: 'ANNA MARIA',

@@ -77,8 +77,8 @@ lastName: 'ERIKSSON',

optional2: '',
compositeCheckDigit: '1'
compositeCheckDigit: '1',
});
expect(result.valid).toEqual(false);
expect(result.valid).toStrictEqual(false);
expect(
result.details.find((a) => a.field === 'issuingState').valid
).toEqual(false);
result.details.find((a) => a.field === 'issuingState').valid,
).toStrictEqual(false);

@@ -90,3 +90,3 @@ const optional1 = result.details.find((a) => a.field === 'optional1');

start: 15,
end: 18
end: 18,
});

@@ -99,3 +99,3 @@

start: 18,
end: 18
end: 18,
});

@@ -108,3 +108,3 @@ });

'7408122F1204159UTO<<<<<<<<<<<8',
'ERIKSSON<<ANNA<MARIA<<<<<<<<<<'
'ERIKSSON<<ANNA<MARIA<<<<<<<<<<',
];

@@ -115,5 +115,5 @@ const result = parse(MRZ);

const documentNumberDetails = result.details.find(
(d) => d.field === 'documentNumber'
(d) => d.field === 'documentNumber',
);
expect(documentNumberDetails).toEqual({
expect(documentNumberDetails).toStrictEqual({
label: 'Document number',

@@ -126,13 +126,13 @@ field: 'documentNumber',

{ line: 0, start: 14, end: 15, raw: '<' },
{ line: 0, start: 15, end: 30, raw: '1240<XYZ<<<<<<<' }
{ line: 0, start: 15, end: 30, raw: '1240<XYZ<<<<<<<' },
],
line: 0,
start: 5,
end: 18
end: 18,
});
expect(result.fields.documentNumber).toEqual('D23145890124');
expect(result.fields.documentNumberCheckDigit).toEqual('0');
expect(result.fields.documentNumber).toStrictEqual('D23145890124');
expect(result.fields.documentNumberCheckDigit).toStrictEqual('0');
const documentNumberCheckDigitDetails = result.details.find(
(d) => d.field === 'documentNumberCheckDigit'
(d) => d.field === 'documentNumberCheckDigit',
);

@@ -143,5 +143,18 @@ expect(documentNumberCheckDigitDetails).toMatchObject({

end: 19,
value: '0'
value: '0',
});
});
it('No last name', () => {
const MRZ = [
'I<CHED231458907ABC<<<<<<<<<<<<',
'7408122F1204159CHE<<<<<<<<<<<1',
'<<ANNA<MARIA<<<<<<<<<<<<<<<<<<',
];
const result = parse(MRZ);
expect(result.valid).toBe(true);
expect(result.fields.lastName).toBe('');
expect(result.fields.firstName).toBe('ANNA MARIA');
});
});

@@ -9,3 +9,3 @@ 'use strict';

'I<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<',
'D231458907UTO7408122F1204159<<<<<<<6'
'D231458907UTO7408122F1204159<<<<<<<6',
];

@@ -17,6 +17,6 @@

format: 'TD2',
valid: false
valid: false,
});
expect(failed).toHaveLength(2);
expect(result.fields).toEqual({
expect(result.fields).toStrictEqual({
firstName: 'ANNA MARIA',

@@ -35,6 +35,6 @@ lastName: 'ERIKSSON',

compositeCheckDigit: '6',
optional: ''
optional: '',
});
expect(result.valid).toEqual(false);
expect(result.valid).toStrictEqual(false);
});
});

@@ -9,3 +9,3 @@ 'use strict';

'P<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<',
'L898902C36UTO7408122F1204159ZE184226B<<<<<10'
'L898902C36UTO7408122F1204159ZE184226B<<<<<10',
];

@@ -16,3 +16,3 @@

valid: false,
format: 'TD3'
format: 'TD3',
});

@@ -22,3 +22,3 @@ expect(result.valid).toBe(false);

expect(errors).toHaveLength(2);
expect(result.fields).toEqual({
expect(result.fields).toStrictEqual({
documentCode: 'P',

@@ -38,9 +38,9 @@ firstName: 'ANNA MARIA',

issuingState: null,
compositeCheckDigit: '0'
compositeCheckDigit: '0',
});
const personalNumberDetails = result.details.find(
(d) => d.field === 'personalNumber'
(d) => d.field === 'personalNumber',
);
expect(personalNumberDetails).toEqual({
expect(personalNumberDetails).toStrictEqual({
label: 'Personal number',

@@ -53,6 +53,6 @@ field: 'personalNumber',

start: 28,
end: 37
end: 37,
});
expect(errors[0]).toEqual({
expect(errors[0]).toStrictEqual({
label: 'Issuing state',

@@ -66,3 +66,3 @@ field: 'issuingState',

end: 5,
error: 'invalid state code: UTO'
error: 'invalid state code: UTO',
});

@@ -74,3 +74,3 @@ });

'P<D<<MUSTERMANN<<ERIKA<<<<<<<<<<<<<<<<<<<<<<',
'C01X0006H1D<<6408125F1710319<<<<<<<<<<<<<<<0'
'C01X0006H1D<<6408125F1710319<<<<<<<<<<<<<<<0',
];

@@ -80,3 +80,3 @@

expect(result.valid).toBe(true);
expect(result.fields).toEqual({
expect(result.fields).toStrictEqual({
documentCode: 'P',

@@ -96,5 +96,32 @@ issuingState: 'D',

personalNumberCheckDigit: '<',
compositeCheckDigit: '0'
compositeCheckDigit: '0',
});
});
it('No last name', () => {
const MRZ = [
'P<IND<<FIRST<NAME<<<<<<<<<<<<<<<<<<<<<<<<<<<',
'C01X0006H1D<<6408125F1710319<<<<<<<<<<<<<<<0',
];
const result = parse.TD3(MRZ);
expect(result.valid).toBe(true);
expect(result.fields).toStrictEqual({
documentCode: 'P',
issuingState: 'IND',
lastName: '',
firstName: 'FIRST NAME',
documentNumber: 'C01X0006H',
documentNumberCheckDigit: '1',
nationality: 'D',
birthDate: '640812',
birthDateCheckDigit: '5',
sex: 'female',
expirationDate: '171031',
expirationDateCheckDigit: '9',
personalNumber: '',
personalNumberCheckDigit: '<',
compositeCheckDigit: '0',
});
});
});

@@ -13,3 +13,3 @@ 'use strict';

throw new TypeError(
'lines must be composed of only alphanumerical characters and "<"'
'lines must be composed of only alphanumerical characters and "<"',
);

@@ -16,0 +16,0 @@ }

@@ -17,4 +17,4 @@ 'use strict';

start: fieldOptions.start,
end: fieldOptions.end
}
end: fieldOptions.end,
},
];

@@ -43,4 +43,4 @@ if (Array.isArray(fieldOptions.related)) {

end: range.end,
raw: getText(lines, range)
}))
raw: getText(lines, range),
})),
};

@@ -47,0 +47,0 @@ const range = result.ranges[0];

@@ -6,3 +6,3 @@ 'use strict';

field: 'documentNumber',
parser: require('../parsers/parseDocumentNumber')
parser: require('../parsers/parseDocumentNumber'),
};

@@ -13,3 +13,3 @@

field: 'documentNumberCheckDigit',
parser: require('../parsers/parseDocumentNumberCheckDigit')
parser: require('../parsers/parseDocumentNumberCheckDigit'),
};

@@ -19,3 +19,3 @@

label: 'Document code',
field: 'documentCode'
field: 'documentCode',
};

@@ -26,3 +26,3 @@

field: 'nationality',
parser: require('../parsers/parseState')
parser: require('../parsers/parseState'),
};

@@ -33,3 +33,3 @@

field: 'sex',
parser: require('../parsers/parseSex')
parser: require('../parsers/parseSex'),
};

@@ -40,3 +40,3 @@

field: 'expirationDate',
parser: require('../parsers/parseDate')
parser: require('../parsers/parseDate'),
};

@@ -47,3 +47,3 @@

field: 'expirationDateCheckDigit',
parser: require('../parsers/parseDateCheckDigit')
parser: require('../parsers/parseDateCheckDigit'),
};

@@ -54,3 +54,3 @@

field: 'compositeCheckDigit',
parser: require('../parsers/parseCompositeCheckDigit')
parser: require('../parsers/parseCompositeCheckDigit'),
};

@@ -61,3 +61,3 @@

field: 'birthDate',
parser: require('../parsers/parseDate')
parser: require('../parsers/parseDate'),
};

@@ -68,3 +68,3 @@

field: 'birthDateCheckDigit',
parser: require('../parsers/parseDateCheckDigit')
parser: require('../parsers/parseDateCheckDigit'),
};

@@ -75,3 +75,3 @@

field: 'issueDate',
parser: require('../parsers/parseDate')
parser: require('../parsers/parseDate'),
};

@@ -82,3 +82,3 @@

field: 'firstName',
parser: require('../parsers/parseFirstName')
parser: require('../parsers/parseFirstName'),
};

@@ -89,3 +89,3 @@

field: 'lastName',
parser: require('../parsers/parseLastName')
parser: require('../parsers/parseLastName'),
};

@@ -96,3 +96,3 @@

field: 'issuingState',
parser: require('../parsers/parseState')
parser: require('../parsers/parseState'),
};

@@ -114,3 +114,3 @@

lastNameTemplate,
issuingStateTemplate
issuingStateTemplate,
};
'use strict';
const { FRENCH_NATIONAL_ID } = require('../formats');
const checkLines = require('./checkLines');
const frenchNationalIdFields = require('./frenchNationalIdFields');
const getResult = require('./getResult');
const { FRENCH_NATIONAL_ID } = require('../formats');
const frenchNationalIdFields = require('./frenchNationalIdFields');

@@ -12,5 +13,3 @@ module.exports = function parseFrenchNationalId(lines) {

throw new Error(
`invalid number of lines: ${
lines.length
}: Must be 2 for ${FRENCH_NATIONAL_ID}`
`invalid number of lines: ${lines.length}: Must be 2 for ${FRENCH_NATIONAL_ID}`,
);

@@ -23,3 +22,3 @@ }

line.length
}. Must be 36 for ${FRENCH_NATIONAL_ID}`
}. Must be 36 for ${FRENCH_NATIONAL_ID}`,
);

@@ -26,0 +25,0 @@ }

@@ -6,2 +6,4 @@ 'use strict';

const parseOptional = require('../parsers/parseOptional');
const createFieldParser = require('./createFieldParser');
const {

@@ -18,5 +20,4 @@ documentCodeTemplate,

sexTemplate,
compositeCheckDigitTemplate
compositeCheckDigitTemplate,
} = require('./fieldTemplates');
const createFieldParser = require('./createFieldParser');

@@ -28,3 +29,3 @@ module.exports = [

end: 2,
parser: parseDocumentCode
parser: parseDocumentCode,
}),

@@ -34,3 +35,3 @@ Object.assign({}, issuingStateTemplate, {

start: 2,
end: 5
end: 5,
}),

@@ -41,3 +42,3 @@ Object.assign({}, lastNameTemplate, {

end: 30,
parser: parseAlpha
parser: parseAlpha,
}),

@@ -50,3 +51,3 @@ {

end: 36,
parser: parseOptional
parser: parseOptional,
},

@@ -56,3 +57,3 @@ Object.assign({}, issueDateTemplate, {

start: 0,
end: 4
end: 4,
}),

@@ -65,3 +66,3 @@ {

end: 7,
parser: parseOptional
parser: parseOptional,
},

@@ -71,3 +72,3 @@ Object.assign({}, documentNumberTemplate, {

start: 7,
end: 12
end: 12,
}),

@@ -82,5 +83,5 @@ Object.assign({}, documentNumberCheckDigitTemplate, {

start: 0,
end: 12
}
]
end: 12,
},
],
}),

@@ -91,3 +92,3 @@ Object.assign({}, firstNameTemplate, {

end: 27,
parser: parseAlpha
parser: parseAlpha,
}),

@@ -97,3 +98,3 @@ Object.assign({}, birthDateTemplate, {

start: 27,
end: 33
end: 33,
}),

@@ -108,5 +109,5 @@ Object.assign({}, birthDateCheckDigitTemplate, {

start: 27,
end: 33
}
]
end: 33,
},
],
}),

@@ -116,3 +117,3 @@ Object.assign({}, sexTemplate, {

start: 34,
end: 35
end: 35,
}),

@@ -127,3 +128,3 @@ Object.assign({}, compositeCheckDigitTemplate, {

start: 0,
end: 36
end: 36,
},

@@ -133,6 +134,6 @@ {

start: 0,
end: 35
}
]
})
end: 35,
},
],
}),
].map(createFieldParser);

@@ -30,3 +30,3 @@ 'use strict';

fields: fields.fields,
valid: fields.valid
valid: fields.valid,
};

@@ -33,0 +33,0 @@ return result;

'use strict';
const formats = require('../formats');
const checkLines = require('./checkLines');
const formats = require('../formats');
const parsers = require('./parsers');

@@ -29,3 +30,3 @@

throw new Error(
'unrecognized document format. First line of input must have 30 (TD1), 36 (TD2 or French National Id), 44 (TD3) or 9 (Swiss Driving License) characters'
'unrecognized document format. First line of input must have 30 (TD1), 36 (TD2 or French National Id), 44 (TD3) or 9 (Swiss Driving License) characters',
);

@@ -36,5 +37,3 @@ }

throw new Error(
`unrecognized document format. Input must have two or three lines, found${
lines.length
}`
`unrecognized document format. Input must have two or three lines, found${lines.length}`,
);

@@ -41,0 +40,0 @@ }

'use strict';
const parseFrenchNationalId = require('./frenchNationalId');
const parseSwissDrivingLicense = require('./swissDrivingLicense');
const parseTD1 = require('./td1');
const parseTD2 = require('./td2');
const parseTD3 = require('./td3');
const parseSwissDrivingLicense = require('./swissDrivingLicense');
const parseFrenchNationalId = require('./frenchNationalId');

@@ -14,3 +14,3 @@ module.exports = {

SWISS_DRIVING_LICENSE: parseSwissDrivingLicense,
FRENCH_NATIONAL_ID: parseFrenchNationalId
FRENCH_NATIONAL_ID: parseFrenchNationalId,
};
'use strict';
const { SWISS_DRIVING_LICENSE } = require('../formats');
const checkLines = require('./checkLines');
const getResult = require('./getResult');
const { SWISS_DRIVING_LICENSE } = require('../formats');
const swissDrivingLicenseFields = require('./swissDrivingLicenseFields');

@@ -12,5 +13,3 @@

throw new Error(
`invalid number of lines: ${
lines.length
}: Must be 3 for ${SWISS_DRIVING_LICENSE}`
`invalid number of lines: ${lines.length}: Must be 3 for ${SWISS_DRIVING_LICENSE}`,
);

@@ -20,5 +19,3 @@ }

throw new Error(
`invalid number of characters for line 1: ${
lines[0].length
}. Must be 9 for ${SWISS_DRIVING_LICENSE}`
`invalid number of characters for line 1: ${lines[0].length}. Must be 9 for ${SWISS_DRIVING_LICENSE}`,
);

@@ -28,5 +25,3 @@ }

throw new Error(
`invalid number of characters for line 2: ${
lines[1].length
}. Must be 30 for ${SWISS_DRIVING_LICENSE}`
`invalid number of characters for line 2: ${lines[1].length}. Must be 30 for ${SWISS_DRIVING_LICENSE}`,
);

@@ -37,5 +32,3 @@ }

throw new Error(
`invalid number of characters for line 3: ${
lines[2].length
}. Must be 30 for ${SWISS_DRIVING_LICENSE}`
`invalid number of characters for line 3: ${lines[2].length}. Must be 30 for ${SWISS_DRIVING_LICENSE}`,
);

@@ -42,0 +35,0 @@ }

'use strict';
const parseNumber = require('../parsers/parseNumber');
const checkSeparator = require('../parsers/swissDrivingLicense/checkSeparator');
const parseDocumentCode = require('../parsers/swissDrivingLicense/parseDocumentCode');
const parseDocumentNumber = require('../parsers/swissDrivingLicense/parseDocumentNumber');
const parseIssuingState = require('../parsers/swissDrivingLicense/parseIssuingState');
const parseLanguageCode = require('../parsers/swissDrivingLicense/parseLanguageCode');
const parseDocumentCode = require('../parsers/swissDrivingLicense/parseDocumentCode');
const parseIssuingState = require('../parsers/swissDrivingLicense/parseIssuingState');
const parseNumber = require('../parsers/parseNumber');
const checkSeparator = require('../parsers/swissDrivingLicense/checkSeparator');
const createFieldParser = require('./createFieldParser');
const {

@@ -15,5 +17,4 @@ documentNumberTemplate,

lastNameTemplate,
firstNameTemplate
firstNameTemplate,
} = require('./fieldTemplates');
const createFieldParser = require('./createFieldParser');

@@ -25,3 +26,3 @@ module.exports = [

end: 9,
parser: parseDocumentNumber
parser: parseDocumentNumber,
}),

@@ -34,3 +35,3 @@ {

end: 7,
parser: parseLanguageCode
parser: parseLanguageCode,
},

@@ -41,3 +42,3 @@ Object.assign({}, documentCodeTemplate, {

end: 2,
parser: parseDocumentCode
parser: parseDocumentCode,
}),

@@ -48,3 +49,3 @@ Object.assign({}, issuingStateTemplate, {

end: 5,
parser: parseIssuingState
parser: parseIssuingState,
}),

@@ -57,3 +58,3 @@ {

end: 14,
parser: parseNumber
parser: parseNumber,
},

@@ -66,3 +67,3 @@ {

end: 17,
parser: parseNumber
parser: parseNumber,
},

@@ -75,3 +76,3 @@ {

end: 19,
parser: checkSeparator
parser: checkSeparator,
},

@@ -81,3 +82,3 @@ Object.assign({}, birthDateTemplate, {

start: 19,
end: 25
end: 25,
}),

@@ -90,3 +91,3 @@ {

end: 30,
parser: checkSeparator
parser: checkSeparator,
},

@@ -96,3 +97,3 @@ Object.assign({}, lastNameTemplate, {

start: 0,
end: 30
end: 30,
}),

@@ -102,4 +103,4 @@ Object.assign({}, firstNameTemplate, {

start: 0,
end: 30
})
end: 30,
}),
].map(createFieldParser);
'use strict';
const { TD1 } = require('../formats');
const checkLines = require('./checkLines');
const getResult = require('./getResult');
const { TD1 } = require('../formats');
const TD1Fields = require('./td1Fields');

@@ -12,3 +13,3 @@

throw new Error(
`invalid number of lines: ${lines.length}: Must be 3 for ${TD1}`
`invalid number of lines: ${lines.length}: Must be 3 for ${TD1}`,
);

@@ -21,3 +22,3 @@ }

line.length
}. Must be 30 for ${TD1}`
}. Must be 30 for ${TD1}`,
);

@@ -24,0 +25,0 @@ }

'use strict';
const parseDocumentCode = require('../parsers/parseDocumentCodeId');
const parseDocumentNumberOptional = require('../parsers/parseDocumentNumberOptional');
const parseOptional = require('../parsers/parseOptional');
const parseDocumentNumberOptional = require('../parsers/parseDocumentNumberOptional');
const createFieldParser = require('./createFieldParser');
const {

@@ -19,5 +21,4 @@ documentCodeTemplate,

lastNameTemplate,
firstNameTemplate
firstNameTemplate,
} = require('./fieldTemplates');
const createFieldParser = require('./createFieldParser');

@@ -29,3 +30,3 @@ module.exports = [

end: 2,
parser: parseDocumentCode
parser: parseDocumentCode,
}),

@@ -35,3 +36,3 @@ Object.assign({}, issuingStateTemplate, {

start: 2,
end: 5
end: 5,
}),

@@ -46,3 +47,3 @@ Object.assign({}, documentNumberTemplate, {

start: 14,
end: 15
end: 15,
},

@@ -52,5 +53,5 @@ {

start: 15,
end: 30
}
]
end: 30,
},
],
}),

@@ -65,3 +66,3 @@ Object.assign(documentNumberCheckDigitTemplate, {

start: 5,
end: 14
end: 14,
},

@@ -71,5 +72,5 @@ {

start: 15,
end: 30
}
]
end: 30,
},
],
}),

@@ -86,3 +87,3 @@ {

start: 5,
end: 14
end: 14,
},

@@ -92,6 +93,6 @@ {

start: 14,
end: 15
}
end: 15,
},
],
parser: parseDocumentNumberOptional
parser: parseDocumentNumberOptional,
},

@@ -101,3 +102,3 @@ Object.assign({}, birthDateTemplate, {

end: 6,
line: 1
line: 1,
}),

@@ -112,5 +113,5 @@ Object.assign({}, birthDateCheckDigitTemplate, {

start: 0,
end: 6
}
]
end: 6,
},
],
}),

@@ -120,3 +121,3 @@ Object.assign({}, sexTemplate, {

start: 7,
end: 8
end: 8,
}),

@@ -126,3 +127,3 @@ Object.assign({}, expirationDateTemplate, {

start: 8,
end: 14
end: 14,
}),

@@ -137,5 +138,5 @@ Object.assign({}, expirationDateCheckDigitTemplate, {

start: 8,
end: 14
}
]
end: 14,
},
],
}),

@@ -145,3 +146,3 @@ Object.assign({}, nationalityTemplate, {

start: 15,
end: 18
end: 18,
}),

@@ -154,3 +155,3 @@ {

end: 29,
parser: parseOptional
parser: parseOptional,
},

@@ -165,3 +166,3 @@ Object.assign({}, compositeCheckDigitTemplate, {

start: 5,
end: 30
end: 30,
},

@@ -171,3 +172,3 @@ {

start: 0,
end: 7
end: 7,
},

@@ -177,3 +178,3 @@ {

start: 8,
end: 15
end: 15,
},

@@ -183,5 +184,5 @@ {

start: 18,
end: 29
}
]
end: 29,
},
],
}),

@@ -191,3 +192,3 @@ Object.assign({}, lastNameTemplate, {

start: 0,
end: 30
end: 30,
}),

@@ -197,4 +198,4 @@ Object.assign({}, firstNameTemplate, {

start: 0,
end: 30
})
end: 30,
}),
].map(createFieldParser);
'use strict';
const { TD2 } = require('../formats');
const checkLines = require('./checkLines');
const getResult = require('./getResult');
const { TD2 } = require('../formats');
const TD2Fields = require('./td2Fields');

@@ -12,3 +13,3 @@

throw new Error(
`invalid number of lines: ${lines.length}: Must be 2 for ${TD2}`
`invalid number of lines: ${lines.length}: Must be 2 for ${TD2}`,
);

@@ -21,3 +22,3 @@ }

line.length
}. Must be 36 for TD2`
}. Must be 36 for TD2`,
);

@@ -24,0 +25,0 @@ }

@@ -5,2 +5,4 @@ 'use strict';

const parseOptional = require('../parsers/parseOptional');
const createFieldParser = require('./createFieldParser');
const {

@@ -19,5 +21,4 @@ documentCodeTemplate,

expirationDateCheckDigitTemplate,
compositeCheckDigitTemplate
compositeCheckDigitTemplate,
} = require('./fieldTemplates');
const createFieldParser = require('./createFieldParser');

@@ -29,3 +30,3 @@ module.exports = [

end: 2,
parser: parseDocumentCode
parser: parseDocumentCode,
}),

@@ -35,3 +36,3 @@ Object.assign({}, issuingStateTemplate, {

start: 2,
end: 5
end: 5,
}),

@@ -41,3 +42,3 @@ Object.assign({}, lastNameTemplate, {

start: 5,
end: 36
end: 36,
}),

@@ -47,3 +48,3 @@ Object.assign({}, firstNameTemplate, {

start: 5,
end: 36
end: 36,
}),

@@ -58,3 +59,3 @@ Object.assign({}, documentNumberTemplate, {

start: 9,
end: 10
end: 10,
},

@@ -64,5 +65,5 @@ {

start: 28,
end: 35
}
]
end: 35,
},
],
}),

@@ -77,3 +78,3 @@ Object.assign({}, documentNumberCheckDigitTemplate, {

start: 0,
end: 9
end: 9,
},

@@ -83,5 +84,5 @@ {

start: 28,
end: 35
}
]
end: 35,
},
],
}),

@@ -91,3 +92,3 @@ Object.assign({}, nationalityTemplate, {

start: 10,
end: 13
end: 13,
}),

@@ -97,3 +98,3 @@ Object.assign({}, birthDateTemplate, {

start: 13,
end: 19
end: 19,
}),

@@ -108,5 +109,5 @@ Object.assign({}, birthDateCheckDigitTemplate, {

start: 13,
end: 19
}
]
end: 19,
},
],
}),

@@ -116,3 +117,3 @@ Object.assign({}, sexTemplate, {

start: 20,
end: 21
end: 21,
}),

@@ -122,3 +123,3 @@ Object.assign({}, expirationDateTemplate, {

start: 21,
end: 27
end: 27,
}),

@@ -133,5 +134,5 @@ Object.assign({}, expirationDateCheckDigitTemplate, {

start: 21,
end: 27
}
]
end: 27,
},
],
}),

@@ -144,3 +145,3 @@ {

end: 35,
parser: parseOptional
parser: parseOptional,
},

@@ -155,3 +156,3 @@ Object.assign({}, compositeCheckDigitTemplate, {

start: 0,
end: 10
end: 10,
},

@@ -161,3 +162,3 @@ {

start: 13,
end: 20
end: 20,
},

@@ -167,6 +168,6 @@ {

start: 21,
end: 35
}
]
})
end: 35,
},
],
}),
].map(createFieldParser);
'use strict';
const { TD3 } = require('../formats');
const checkLines = require('./checkLines');
const getResult = require('./getResult');
const { TD3 } = require('../formats');
const TD3Fields = require('./td3Fields');

@@ -12,3 +13,3 @@

throw new Error(
`invalid number of lines: ${lines.length}: Must be 2 for ${TD3}`
`invalid number of lines: ${lines.length}: Must be 2 for ${TD3}`,
);

@@ -21,3 +22,3 @@ }

line.length
}. Must be 44 for TD3`
}. Must be 44 for TD3`,
);

@@ -24,0 +25,0 @@ }

@@ -6,2 +6,4 @@ 'use strict';

const parsePersonalNumberCheckDigit = require('../parsers/parsePersonalNumberCheckDigit');
const createFieldParser = require('./createFieldParser');
const {

@@ -20,5 +22,4 @@ documentCodeTemplate,

expirationDateCheckDigitTemplate,
compositeCheckDigitTemplate
compositeCheckDigitTemplate,
} = require('./fieldTemplates');
const createFieldParser = require('./createFieldParser');

@@ -30,3 +31,3 @@ module.exports = [

end: 2,
parser: parseDocumentCode
parser: parseDocumentCode,
}),

@@ -36,3 +37,3 @@ Object.assign({}, issuingStateTemplate, {

start: 2,
end: 5
end: 5,
}),

@@ -42,3 +43,3 @@ Object.assign({}, lastNameTemplate, {

start: 5,
end: 44
end: 44,
}),

@@ -48,3 +49,3 @@ Object.assign({}, firstNameTemplate, {

start: 5,
end: 44
end: 44,
}),

@@ -54,3 +55,3 @@ Object.assign({}, documentNumberTemplate, {

start: 0,
end: 9
end: 9,
}),

@@ -65,5 +66,5 @@ Object.assign({}, documentNumberCheckDigitTemplate, {

start: 0,
end: 9
}
]
end: 9,
},
],
}),

@@ -73,3 +74,3 @@ Object.assign({}, nationalityTemplate, {

start: 10,
end: 13
end: 13,
}),

@@ -79,3 +80,3 @@ Object.assign({}, birthDateTemplate, {

start: 13,
end: 19
end: 19,
}),

@@ -90,5 +91,5 @@ Object.assign({}, birthDateCheckDigitTemplate, {

start: 13,
end: 19
}
]
end: 19,
},
],
}),

@@ -98,3 +99,3 @@ Object.assign({}, sexTemplate, {

start: 20,
end: 21
end: 21,
}),

@@ -104,3 +105,3 @@ Object.assign({}, expirationDateTemplate, {

start: 21,
end: 27
end: 27,
}),

@@ -115,5 +116,5 @@ Object.assign({}, expirationDateCheckDigitTemplate, {

start: 21,
end: 27
}
]
end: 27,
},
],
}),

@@ -126,3 +127,3 @@ {

end: 42,
parser: parsePersonalNumber
parser: parsePersonalNumber,
},

@@ -139,6 +140,6 @@ {

start: 28,
end: 42
}
end: 42,
},
],
parser: parsePersonalNumberCheckDigit
parser: parsePersonalNumberCheckDigit,
},

@@ -153,3 +154,3 @@ Object.assign({}, compositeCheckDigitTemplate, {

start: 0,
end: 10
end: 10,
},

@@ -159,3 +160,3 @@ {

start: 13,
end: 20
end: 20,
},

@@ -165,6 +166,6 @@ {

start: 21,
end: 43
}
]
})
end: 43,
},
],
}),
].map(createFieldParser);

@@ -5,3 +5,3 @@ 'use strict';

test('test check digits', () => {
test('check digits', () => {
expect(() => check('592166117<231', 8)).not.toThrow();

@@ -8,0 +8,0 @@ expect(() => check('592166111<773', 5)).not.toThrow();

'use strict';
module.exports = function check(string, value) {
var code = 0;
var factors = [7, 3, 1];
for (var i = 0; i < string.length; i++) {
var charCode = string.charCodeAt(i);
let code = 0;
let factors = [7, 3, 1];
for (let i = 0; i < string.length; i++) {
let charCode = string.charCodeAt(i);
if (charCode === 60) charCode = 0;

@@ -9,0 +9,0 @@ if (charCode >= 65) charCode -= 55;

@@ -8,3 +8,3 @@ 'use strict';

throw new Error(
`invalid text: ${source}. Must be only alphabetical with <`
`invalid text: ${source}. Must be only alphabetical with <`,
);

@@ -11,0 +11,0 @@ }

'use strict';
var check = require('./check');
let check = require('./check');

@@ -5,0 +5,0 @@ module.exports = function parseCompositeCheckDigit(checkDigit, ...sources) {

@@ -7,3 +7,3 @@ 'use strict';

throw new Error(
`invalid document code: ${source}. First character must be A, C or I`
`invalid document code: ${source}. First character must be A, C or I`,
);

@@ -15,3 +15,3 @@ }

throw new Error(
`invalid document code: ${source}. Second character may not be V`
`invalid document code: ${source}. Second character may not be V`,
);

@@ -24,3 +24,3 @@ }

start: 0,
end: 1
end: 1,
};

@@ -27,0 +27,0 @@ } else {

@@ -7,3 +7,3 @@ 'use strict';

throw new Error(
`invalid document code: ${source}. First character must be P`
`invalid document code: ${source}. First character must be P`,
);

@@ -15,3 +15,3 @@ }

throw new Error(
`invalid document code: ${source}. Second character must be a letter or <`
`invalid document code: ${source}. Second character must be a letter or <`,
);

@@ -23,3 +23,3 @@ }

start: 0,
end: 1
end: 1,
};

@@ -26,0 +26,0 @@ } else {

@@ -19,4 +19,4 @@ 'use strict';

start: 0,
end
end,
};
};
'use strict';
var check = require('./check');
let check = require('./check');

@@ -8,3 +8,3 @@ module.exports = function parseDocumentNumberCheckDigit(

source,
optional
optional,
) {

@@ -20,3 +20,3 @@ if (checkDigit === '<' && optional) {

start: firstFiller,
end: firstFiller + 1
end: firstFiller + 1,
};

@@ -23,0 +23,0 @@ } else {

'use strict';
var parseText = require('./parseText');
let parseText = require('./parseText');

@@ -8,3 +8,3 @@ module.exports = function parseDocumentNumberOptional(

documentNumber,
checkDigit
checkDigit,
) {

@@ -17,3 +17,3 @@ if (checkDigit === '<') {

start: firstFiller + 1,
end: firstFiller + 1 + value.length
end: firstFiller + 1 + value.length,
};

@@ -25,5 +25,5 @@ } else {

start: 0,
end: 0 + value.length
end: 0 + value.length,
};
}
};
'use strict';
var parseText = require('./parseText');
let parseText = require('./parseText');

@@ -12,4 +12,4 @@ module.exports = function parseFirstName(source) {

start,
end: start + value.length
end: start + value.length,
};
};
'use strict';
var parseText = require('./parseText');
let parseText = require('./parseText');
module.exports = function parseLastName(source) {
const parsed = parseText(source.replace(/<{2}.*/, ''), /^[A-Z<]+<*$/);
const parsed = parseText(source.replace(/<{2}.*/, ''), /^[A-Z<]*<*$/);
return {
value: parsed,
start: 0,
end: parsed.length
end: parsed.length,
};
};
'use strict';
var parseText = require('./parseText');
let parseText = require('./parseText');

@@ -11,4 +11,4 @@ module.exports = function parseOptional(source) {

start: 0,
end: 0 + value.length
end: 0 + value.length,
};
};
'use strict';
var parseText = require('./parseText');
let parseText = require('./parseText');

@@ -10,4 +10,4 @@ module.exports = function parsePersonalNumber(source) {

start: 0,
end: value.length
end: value.length,
};
};
'use strict';
var check = require('./check');
let check = require('./check');
const cleanText = require('./cleanText');

@@ -8,3 +8,3 @@

checkDigit,
personalNumber
personalNumber,
) {

@@ -11,0 +11,0 @@ const cleanNumber = cleanText(personalNumber);

'use strict';
const STATES = require('../generated/states');
const cleanText = require('./cleanText');

@@ -8,3 +9,3 @@

source = cleanText(source);
var state = STATES[source];
let state = STATES[source];
if (!state) {

@@ -16,4 +17,4 @@ throw new Error(`invalid state code: ${source}`);

start: 0,
end: source.length
end: source.length,
};
};

@@ -8,3 +8,3 @@ 'use strict';

throw new Error(
`invalid text: ${source}. Must match the following regular expression: ${regexp}`
`invalid text: ${source}. Must match the following regular expression: ${regexp}`,
);

@@ -11,0 +11,0 @@ }

@@ -6,3 +6,3 @@ 'use strict';

throw new Error(
`invalid separator: ${source}. Must be composed only of "<"`
`invalid separator: ${source}. Must be composed only of "<"`,
);

@@ -9,0 +9,0 @@ }

@@ -7,10 +7,10 @@ 'use strict';

// swiss driving license number
var first = source.substring(0, 3);
var second = source.substring(3, 6);
var languageCode = source.charAt(6);
var end = source.substring(7);
let first = source.substring(0, 3);
let second = source.substring(3, 6);
let languageCode = source.charAt(6);
let end = source.substring(7);
if (!first.match(/^[A-Z0-9]{3}$/)) {
throw new Error(
`invalid document number: ${source}. Must start with three alphanumeric digits`
`invalid document number: ${source}. Must start with three alphanumeric digits`,
);

@@ -20,3 +20,3 @@ }

throw new Error(
`invalid document number: ${source}. Must have numeric digits in positions 4, 5 and 6`
`invalid document number: ${source}. Must have numeric digits in positions 4, 5 and 6`,
);

@@ -33,4 +33,4 @@ }

start: 0,
end: 7
end: 7,
};
};

@@ -12,5 +12,5 @@ 'use strict';

throw new Error(
`invalid languageCode code: ${languageCode}. Must be D, F, I or R`
`invalid languageCode code: ${languageCode}. Must be D, F, I or R`,
);
}
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc