@@ -46,8 +46,10 @@ SOFTWARE.
4646 Object . freeze ( root . JSSC ) ;
4747 }
4848} ( typeof self !== 'undefined' ? self : this , function ( JUSTC ) {
49+ const name__ = 'JSSC' ;
50+ const prefix = name__ + ': ' ;
4951 if ( ( String . fromCharCode ( 65536 ) . charCodeAt ( 0 ) === 65536 ) || ! ( String . fromCharCode ( 256 ) . charCodeAt ( 0 ) === 256 ) ) {
50- throw new Error ( 'Supported UTF-16 only!' )
52+ throw new Error ( prefix + 'Supported UTF-16 only!' )
5153 }
5254
5355 function stringCodes ( str ) {
@@ -428,7 +430,7 @@ SOFTWARE.
428430 let output = { } ;
429431 for ( const [ name , func ] of Object . entries ( _JSSC ) ) {
430432 if ( typeof func === 'function' && ! name . startsWith ( '_' ) && name != 'use' ) {
431- output [ 'JSSC' + name ] = func ;
433+ output [ name__ + name ] = func ;
432434 }
433435 }
434436 Object . freeze ( output ) ;
@@ -689,7 +691,7 @@ SOFTWARE.
689691 const parts = compressedText . split ( splitter ) ;
690692
691693 if ( parts . length < 2 ) {
692- throw new Error ( 'Invalid freqMap data: splitter not found' ) ;
694+ throw new Error ( prefix + 'Invalid freqMap data: splitter not found' ) ;
693695 }
694696
695697 const headerPart = parts [ 0 ] ;
@@ -823,7 +825,7 @@ SOFTWARE.
823825 * @since 1.0.0
824826 */
825827 async function compress ( input , options ) {
826- if ( typeof input != 'string' && typeof input != 'object' && typeof input != 'number' ) throw new Error ( 'Invalid input.' ) ;
828+ if ( typeof input != 'string' && typeof input != 'object' && typeof input != 'number' ) throw new Error ( prefix + 'Invalid input.' ) ;
827829 const opts = {
828830 segmentation : true ,
829831 recursivecompression : true ,
@@ -832,14 +834,15 @@ SOFTWARE.
832834
833835 /* Read options */
834836 if ( options ) {
835- if ( typeof options != 'object' ) throw new Error ( 'Invalid options input.' ) ;
837+ if ( typeof options != 'object' ) throw new Error ( prefix + 'Invalid options input.' ) ;
836838 for ( const [ key , value ] of Object . entries ( options ) ) {
837- if ( typeof value != 'boolean' ) throw new Error ( 'Invalid options input.' ) ;
839+ if ( typeof value == 'undefined' ) continue ;
840+ if ( typeof value != 'boolean' ) throw new Error ( prefix + 'Invalid options input.' ) ;
838841 if ( key . toLowerCase ( ) in opts ) {
839842 opts [ key . toLowerCase ( ) ] = value ;
840843 continue ;
841844 }
842- console . warn ( `Unknown option: "${ key } ".` ) ;
845+ console . warn ( prefix + `Unknown option: "${ key } ".` ) ;
843846 }
844847 }
845848
@@ -850,7 +853,7 @@ SOFTWARE.
850853 if ( typeof str === 'number' ) {
851854 isNum = true ;
852855 str = str . toString ( ) ;
853- if ( str . includes ( '.' ) ) throw new Error ( 'Invalid input.' ) ;
856+ if ( str . includes ( '.' ) ) throw new Error ( prefix + 'Invalid input.' ) ;
854857 }
855858
856859 let repeatBefore = false ;
@@ -898,7 +901,7 @@ SOFTWARE.
898901 code3 = 6 ;
899902 }
900903 } catch ( error ) {
901- const msg = new Error ( 'Invalid input.' ) ;
904+ const msg = new Error ( prefix + 'Invalid input.' ) ;
902905 throw new AggregateError ( [ msg , error ] , msg . message ) ;
903906 } else
904907 /* JSON Object (as string) */
@@ -1356,7 +1359,7 @@ SOFTWARE.
13561359 const possibleCharEncoding = strcode2charencoding [ id ] ;
13571360 if ( possibleCharEncoding ) {
13581361 const characterEncodings_ = new _JSSC . use ( ) ;
1359- const characterEncoding = characterEncodings_ [ 'JSSC' + possibleCharEncoding ] ( ) ;
1362+ const characterEncoding = characterEncodings_ [ name__ + possibleCharEncoding ] ( ) ;
13601363 let output = '' ;
13611364 for ( const characters of realstr . split ( '' ) ) {
13621365 const characterCode = characters . charCodeAt ( ) ;
@@ -1413,7 +1416,7 @@ SOFTWARE.
14131416 * @since 1.0.0
14141417 */
14151418 async function decompress ( str , stringify = false ) {
1416- if ( typeof str != 'string' ) throw new Error ( 'Invalid input.' ) ;
1419+ if ( typeof str != 'string' ) throw new Error ( prefix + 'Invalid input.' ) ;
14171420 const strcodes = cryptCharCode ( str . charCodeAt ( 0 ) - 32 , true ) ;
14181421 const strcode = strcodes . code ;
14191422
@@ -1530,7 +1533,7 @@ SOFTWARE.
15301533 const decoded = characterEncodings ( strcodes . code2 , realstr ) ;
15311534 if ( decoded ) {
15321535 return await processOutput ( decoded ) ;
1533- } else throw new Error ( 'Invalid compressed string' ) ;
1536+ } else throw new Error ( prefix + 'Invalid compressed string' ) ;
15341537 case 7 :
15351538 const splitter = freqMapSplitters [ binToDec ( decToBin ( strcodes . code2 ) . slice ( 1 ) ) ] ;
15361539 output = freqMap . decompress ( realstr , splitter ) ;
@@ -1597,7 +1600,7 @@ SOFTWARE.
15971600 const meta = cryptCharCode ( first , true ) ;
15981601
15991602 if ( meta . code === 31 ) {
1600- throw new Error ( 'Attempt to nested recursive compression' ) ;
1603+ throw new Error ( prefix + 'Attempt to nested recursive compression' ) ;
16011604 }
16021605
16031606 out = await decompress ( out , true ) ;
@@ -1606,15 +1609,15 @@ SOFTWARE.
16061609 return out ;
16071610 }
16081611 default :
1609- throw new Error ( 'Invalid compressed string' ) ;
1612+ throw new Error ( prefix + 'Invalid compressed string' ) ;
16101613 }
16111614 }
16121615
16131616 return {
16141617 compress,
16151618 decompress,
16161619 get [ Symbol . toStringTag ] ( ) {
1617- return 'JSSC' ;
1620+ return name__ ;
16181621 }
16191622 } ;
16201623
0 commit comments