@@ -4,35 +4,25 @@ const CH_9 = '9'.charCodeAt (0)
44
55module . exports = class {
66
7- raise ( s , o ) {
8-
9- const err = Error ( s )
10-
11- for ( const k in o ) err [ k ] = o [ k ]
12-
13- throw err
14-
15- }
16-
177 verify ( str ) {
188
19- const type = typeof str ; if ( type !== 'string' ) this . raise ( `CadNum must be of type string` , { str, type, code : 'type' } )
9+ const type = typeof str ; if ( type !== 'string' ) return [ `CadNum must be of type string` , { str, type, code : 'type' } ]
2010
21- const { length} = str ; if ( length < 14 ) this . raise ( `CadNum must be at least 14 charaters long` , { str, asis : length , code : 'length' } )
11+ const { length} = str ; if ( length < 14 ) return [ `CadNum must be at least 14 charaters long` , { str, asis : length , code : 'length' } ]
2212
2313 const lastColonIndex = str . lastIndexOf ( ':' )
2414
2515 switch ( lastColonIndex ) {
2616
2717 case - 1 :
28- this . raise ( `Invalid CadNum "${ str } ": colon not found` , { str, pos : lastColonIndex , code : 'format' } )
18+ return [ `Invalid CadNum "${ str } ": colon not found` , { str, pos : lastColonIndex , code : 'format' } ]
2919
3020 case 12 :
3121 case 13 :
3222 break
3323
3424 default :
35- this . raise ( `Invalid CadNum "${ str } ": the last colon found at position ${ lastColonIndex } ` , { str, pos : lastColonIndex , code : 'format' } )
25+ return [ `Invalid CadNum "${ str } ": the last colon found at position ${ lastColonIndex } ` , { str, pos : lastColonIndex , code : 'format' } ]
3626
3727 }
3828
@@ -44,11 +34,11 @@ module.exports = class {
4434
4535 case 2 :
4636 case 5 :
47- if ( c !== CH_COLON ) this . raise ( `Invalid CadNum "${ str } ": not a colon at position ${ pos } ` , { str, pos, code : 'char' } )
37+ if ( c !== CH_COLON ) return [ `Invalid CadNum "${ str } ": not a colon at position ${ pos } ` , { str, pos, code : 'char' } ]
4838 break
4939
5040 default :
51- if ( c < CH_0 || c > CH_9 ) this . raise ( `Invalid CadNum "${ str } ": not a digit at position ${ pos } ` , { str, pos, code : 'char' } )
41+ if ( c < CH_0 || c > CH_9 ) return [ `Invalid CadNum "${ str } ": not a digit at position ${ pos } ` , { str, pos, code : 'char' } ]
5242
5343 }
5444
0 commit comments