UNPKG

china-id-mask

Version:

A utility to mask Chinese ID card numbers by replacing birth date with asterisks

24 lines (19 loc) 846 B
const assert = require('chai').assert; const maskId = require('../index'); describe('china-id-mask', function() { it('should mask 18-digit ID correctly', function() { assert.equal(maskId('11010519491231002X'), '110105********002X'); }); it('should mask 15-digit ID correctly', function() { assert.equal(maskId('110105491231002'), '110105******002'); }); it('should handle numeric input', function() { assert.equal(maskId(11010519491231002), '110105********1002'); }); it('should throw error for invalid length', function() { assert.throws(() => maskId('123456'), 'Invalid Chinese ID card length. Must be 15 or 18 digits.'); }); it('should throw error for invalid format', function() { assert.throws(() => maskId('ABCDEFGHIJKLMNOPQR'), 'Invalid Chinese ID card format.'); }); });