@@ -16,39 +16,39 @@ module.exports = class {
1616
1717 verify ( str ) {
1818
19- const type = typeof str ; if ( type !== 'string' ) this . raise ( `CadNum must be of type string` , { str, type} )
19+ const type = typeof str ; if ( type !== 'string' ) this . raise ( `CadNum must be of type string` , { str, type, code : 'type' } )
2020
21- const { length} = str ; if ( length < 14 ) this . raise ( `CadNum must be at least 14 charaters long` , { str, length} )
21+ const { length} = str ; if ( length < 14 ) this . raise ( `CadNum must be at least 14 charaters long` , { str, asis : length , code : 'length' } )
2222
2323 const lastColonIndex = str . lastIndexOf ( ':' )
2424
2525 switch ( lastColonIndex ) {
2626
2727 case - 1 :
28- this . raise ( `Invalid CadNum "${ str } ": colon not found` , { str, lastColonIndex} )
28+ this . raise ( `Invalid CadNum "${ str } ": colon not found` , { str, pos : lastColonIndex , code : 'format' } )
2929
3030 case 12 :
3131 case 13 :
3232 break
3333
3434 default :
35- this . raise ( `Invalid CadNum "${ str } ": the last colon found at position ${ lastColonIndex } ` , { str, lastColonIndex} )
35+ this . raise ( `Invalid CadNum "${ str } ": the last colon found at position ${ lastColonIndex } ` , { str, pos : lastColonIndex , code : 'format' } )
3636
3737 }
3838
39- for ( let index = 0 ; index < length ; index ++ ) if ( index !== lastColonIndex ) {
39+ for ( let pos = 0 ; pos < length ; pos ++ ) if ( pos !== lastColonIndex ) {
4040
41- const c = str . charCodeAt ( index )
41+ const c = str . charCodeAt ( pos )
4242
43- switch ( index ) {
43+ switch ( pos ) {
4444
4545 case 2 :
4646 case 5 :
47- if ( c !== CH_COLON ) this . raise ( `Invalid CadNum "${ str } ": not a colon at position ${ index } ` , { str, index } )
47+ if ( c !== CH_COLON ) this . raise ( `Invalid CadNum "${ str } ": not a colon at position ${ pos } ` , { str, pos , code : 'char' } )
4848 break
4949
5050 default :
51- if ( c < CH_0 || c > CH_9 ) this . raise ( `Invalid CadNum "${ str } ": not a digit at position ${ index } ` , { str, index } )
51+ if ( c < CH_0 || c > CH_9 ) this . raise ( `Invalid CadNum "${ str } ": not a digit at position ${ pos } ` , { str, pos , code : 'char' } )
5252
5353 }
5454
0 commit comments