@@ -139,7 +139,7 @@ const validatorMap = {
139139const validate = ( code , type ) => {
140140 // 1980s era UPC codes were apparently 11 digits, not using a checksum. So, if we get 11, I
141141 // guess there's not much we can do besides pass it with a 0 prefixing it and hope it works.
142- const modifiedCode = code . length === 11 ? `0${ code } ` : code ;
142+ let modifiedCode = code . length === 11 ? `0${ code } ` : code ;
143143 if ( ! type ) {
144144 type = getTypeOfBarcode ( modifiedCode ) ;
145145 }
@@ -148,11 +148,11 @@ const validate = (code, type) => {
148148 if ( modifiedCode . startsWith ( '290' ) ) {
149149 const [ junk1 , junk2 , junk3 , ...rest ] = modifiedCode ;
150150 const baseCode = rest . join ( '' ) ;
151- modifiedCode = `978${ baseCode } ${ getIsbn13Checksum ( `978${ baseCode } ` ) } ` ;
151+ modifiedCode = `978${ baseCode . slice ( 0 , - 1 ) } ${ getIsbn13Checksum ( `978${ baseCode } ` ) } ` ;
152152 } else if ( modifiedCode . startsWith ( '291' ) ) {
153153 const [ junk1 , junk2 , junk3 , ...rest ] = modifiedCode ;
154154 const baseCode = rest . join ( '' ) ;
155- modifiedCode = `979${ baseCode } ${ getIsbn13Checksum ( `979${ baseCode } ` ) } `
155+ modifiedCode = `979${ baseCode . slice ( 0 , - 1 ) } ${ getIsbn13Checksum ( `979${ baseCode } ` ) } `
156156 }
157157 }
158158 let valid = false ;
@@ -176,4 +176,6 @@ const validate = (code, type) => {
176176// console.warn(validate('BOOTSTRA P')); // should be an invalid ASIN
177177// console.warn(getUpcChecksum('02035616631'));
178178// console.warn(validate('Test random text'));
179+ // console.warn(validate('2900077274312'));
180+ // console.warn(validate('2900538754575'));
179181module . exports = validate ;
0 commit comments