js-codepage/misc/cputils.js.utf7

529 lines
29 KiB
Plaintext

/+ACo cputils.js (C) 2013-present SheetJS -- http://sheetjs.com +ACo-/
/+ACo vim: set ft+AD0-javascript: +ACo-/
/+ACo-jshint newcap: false +ACo-/
(function(root, factory) +AHs
/+ACo-jshint ignore:start +ACo-/
/+ACo-eslint-disable +ACo-/
+ACI-use strict+ACIAOw
if(typeof cptable +AD0APQA9 +ACI-undefined+ACI) +AHs
if(typeof require +ACEAPQA9 +ACI-undefined+ACI)+AHs
var cpt +AD0 require('./cptable')+ADs
if (typeof module +ACEAPQA9 'undefined' +ACYAJg module.exports +ACYAJg typeof DO+AF8-NOT+AF8-EXPORT+AF8-CODEPAGE +AD0APQA9 'undefined') module.exports +AD0 factory(cpt)+ADs
else root.cptable +AD0 factory(cpt)+ADs
+AH0 else throw new Error(+ACI-cptable not found+ACI)+ADs
+AH0 else cptable +AD0 factory(cptable)+ADs
/+ACo-eslint-enable +ACo-/
/+ACo-jshint ignore:end +ACo-/
+AH0(this, function(cpt)+AHs
+ACI-use strict+ACIAOw
/+ACo-global module, Buffer +ACo-/
var magic +AD0 +AHs
+ACI-1200+ACI:+ACI-utf16le+ACI,
+ACI-1201+ACI:+ACI-utf16be+ACI,
+ACI-12000+ACI:+ACI-utf32le+ACI,
+ACI-12001+ACI:+ACI-utf32be+ACI,
+ACI-16969+ACI:+ACI-utf64le+ACI,
+ACI-20127+ACI:+ACI-ascii+ACI,
+ACI-65000+ACI:+ACI-utf7+ACI,
+ACI-65001+ACI:+ACI-utf8+ACI
+AH0AOw
var sbcs+AF8-cache +AD0 +AFs-874,1250,1251,1252,1253,1254,1255,1256,10000+AF0AOw
var dbcs+AF8-cache +AD0 +AFs-932,936,949,950+AF0AOw
var magic+AF8-cache +AD0 +AFs-65001+AF0AOw
var magic+AF8-decode +AD0 +AHsAfQA7
var magic+AF8-encode +AD0 +AHsAfQA7
var cpdcache +AD0 +AHsAfQA7
var cpecache +AD0 +AHsAfQA7
var sfcc +AD0 function sfcc(x) +AHs return String.fromCharCode(x)+ADs +AH0AOw
var cca +AD0 function cca(x) +AHs return x.charCodeAt(0)+ADs +AH0AOw
var has+AF8-buf +AD0 (typeof Buffer +ACEAPQA9 'undefined')+ADs
var Buffer+AF8-from +AD0 function()+AHsAfQA7
if(has+AF8-buf) +AHs
var nbfs +AD0 +ACE-Buffer.from+ADs
if(+ACE-nbfs) try +AHs Buffer.from(+ACI-foo+ACI, +ACI-utf8+ACI)+ADs +AH0 catch(e) +AHs nbfs +AD0 true+ADs +AH0
Buffer+AF8-from +AD0 nbfs ? function(buf, enc) +AHs return (enc) ? new Buffer(buf, enc) : new Buffer(buf)+ADs +AH0 : Buffer.from.bind(Buffer)+ADs
// +ACQ-FlowIgnore
if(+ACE-Buffer.allocUnsafe) Buffer.allocUnsafe +AD0 function(n) +AHs return new Buffer(n)+ADs +AH0AOw
var mdl +AD0 1024, mdb +AD0 Buffer.allocUnsafe(mdl)+ADs
var make+AF8-EE +AD0 function make+AF8-EE(E)+AHs
var EE +AD0 Buffer.allocUnsafe(65536)+ADs
for(var i +AD0 0+ADs i +ADw 65536+ADsAKwAr-i) EE+AFs-i+AF0 +AD0 0+ADs
var keys +AD0 Object.keys(E), len +AD0 keys.length+ADs
for(var ee +AD0 0, e +AD0 keys+AFs-ee+AF0AOw ee +ADw len+ADs +-+-ee) +AHs
if(+ACE(e +AD0 keys+AFs-ee+AF0)) continue+ADs
EE+AFs-e.charCodeAt(0)+AF0 +AD0 E+AFs-e+AF0AOw
+AH0
return EE+ADs
+AH0AOw
var sbcs+AF8-encode +AD0 function make+AF8-sbcs+AF8-encode(cp) +AHs
var EE +AD0 make+AF8-EE(cpt+AFs-cp+AF0.enc)+ADs
return function sbcs+AF8-e(data, ofmt) +AHs
var len +AD0 data.length+ADs
var out, i+AD0-0, j+AD0-0, D+AD0-0, w+AD0-0+ADs
if(typeof data +AD0APQA9 'string') +AHs
out +AD0 Buffer.allocUnsafe(len)+ADs
for(i +AD0 0+ADs i +ADw len+ADs +-+-i) out+AFs-i+AF0 +AD0 EE+AFs-data.charCodeAt(i)+AF0AOw
+AH0 else if(Buffer.isBuffer(data)) +AHs
out +AD0 Buffer.allocUnsafe(2+ACo-len)+ADs
j +AD0 0+ADs
for(i +AD0 0+ADs i +ADw len+ADs +-+-i) +AHs
D +AD0 data+AFs-i+AF0AOw
if(D +ADw 128) out+AFs-j+-+-+AF0 +AD0 EE+AFs-D+AF0AOw
else if(D +ADw 224) +AHs out+AFs-j+-+-+AF0 +AD0 EE+AFs((D+ACY-31)+ADwAPA-6)+-(data+AFs-i+-1+AF0AJg-63)+AF0AOw +-+-i+ADs +AH0
else if(D +ADw 240) +AHs out+AFs-j+-+-+AF0 +AD0 EE+AFs((D+ACY-15)+ADwAPA-12)+-((data+AFs-i+-1+AF0AJg-63)+ADwAPA-6)+-(data+AFs-i+-2+AF0AJg-63)+AF0AOw i+-+AD0-2+ADs +AH0
else +AHs
w +AD0 ((D+ACY-7)+ADwAPA-18)+-((data+AFs-i+-1+AF0AJg-63)+ADwAPA-12)+-((data+AFs-i+-2+AF0AJg-63)+ADwAPA-6)+-(data+AFs-i+-3+AF0AJg-63)+ADs i+-+AD0-3+ADs
if(w +ADw 65536) out+AFs-j+-+-+AF0 +AD0 EE+AFs-w+AF0AOw
else +AHs w -+AD0 65536+ADs out+AFs-j+-+-+AF0 +AD0 EE+AFs-0xD800 +- ((w+AD4APg-10)+ACY-1023)+AF0AOw out+AFs-j+-+-+AF0 +AD0 EE+AFs-0xDC00 +- (w+ACY-1023)+AF0AOw +AH0
+AH0
+AH0
out +AD0 out.slice(0,j)+ADs
+AH0 else +AHs
out +AD0 Buffer.allocUnsafe(len)+ADs
for(i +AD0 0+ADs i +ADw len+ADs +-+-i) out+AFs-i+AF0 +AD0 EE+AFs-data+AFs-i+AF0.charCodeAt(0)+AF0AOw
+AH0
if(+ACE-ofmt +AHwAfA ofmt +AD0APQA9 'buf') return out+ADs
if(ofmt +ACEAPQA9 'arr') return out.toString('binary')+ADs
return +AFsAXQ.slice.call(out)+ADs
+AH0AOw
+AH0AOw
var sbcs+AF8-decode +AD0 function make+AF8-sbcs+AF8-decode(cp) +AHs
var D +AD0 cpt+AFs-cp+AF0.dec+ADs
var DD +AD0 Buffer.allocUnsafe(131072), d+AD0-0, c+AD0AIgAiADs
for(d+AD0-0+ADs-d+ADw-D.length+ADsAKwAr-d) +AHs
if(+ACE(c+AD0-D+AFs-d+AF0)) continue+ADs
var w +AD0 c.charCodeAt(0)+ADs
DD+AFs-2+ACo-d+AF0 +AD0 w+ACY-255+ADs DD+AFs-2+ACo-d+-1+AF0 +AD0 w+AD4APg-8+ADs
+AH0
return function sbcs+AF8-d(data) +AHs
var len +AD0 data.length, i+AD0-0, j+AD0-0+ADs
if(2 +ACo len +AD4 mdl) +AHs mdl +AD0 2 +ACo len+ADs mdb +AD0 Buffer.allocUnsafe(mdl)+ADs +AH0
if(Buffer.isBuffer(data)) +AHs
for(i +AD0 0+ADs i +ADw len+ADs i+-+-) +AHs
j +AD0 2+ACo-data+AFs-i+AF0AOw
mdb+AFs-2+ACo-i+AF0 +AD0 DD+AFs-j+AF0AOw mdb+AFs-2+ACo-i+-1+AF0 +AD0 DD+AFs-j+-1+AF0AOw
+AH0
+AH0 else if(typeof data +AD0APQA9 +ACI-string+ACI) +AHs
for(i +AD0 0+ADs i +ADw len+ADs i+-+-) +AHs
j +AD0 2+ACo-data.charCodeAt(i)+ADs
mdb+AFs-2+ACo-i+AF0 +AD0 DD+AFs-j+AF0AOw mdb+AFs-2+ACo-i+-1+AF0 +AD0 DD+AFs-j+-1+AF0AOw
+AH0
+AH0 else +AHs
for(i +AD0 0+ADs i +ADw len+ADs i+-+-) +AHs
j +AD0 2+ACo-data+AFs-i+AF0AOw
mdb+AFs-2+ACo-i+AF0 +AD0 DD+AFs-j+AF0AOw mdb+AFs-2+ACo-i+-1+AF0 +AD0 DD+AFs-j+-1+AF0AOw
+AH0
+AH0
return mdb.slice(0, 2 +ACo len).toString('ucs2')+ADs
+AH0AOw
+AH0AOw
var dbcs+AF8-encode +AD0 function make+AF8-dbcs+AF8-encode(cp) +AHs
var E +AD0 cpt+AFs-cp+AF0.enc+ADs
var EE +AD0 Buffer.allocUnsafe(131072)+ADs
for(var i +AD0 0+ADs i +ADw 131072+ADs +-+-i) EE+AFs-i+AF0 +AD0 0+ADs
var keys +AD0 Object.keys(E)+ADs
for(var ee +AD0 0, e +AD0 keys+AFs-ee+AF0AOw ee +ADw keys.length+ADs +-+-ee) +AHs
if(+ACE(e +AD0 keys+AFs-ee+AF0)) continue+ADs
var f +AD0 e.charCodeAt(0)+ADs
EE+AFs-2+ACo-f+AF0 +AD0 E+AFs-e+AF0 +ACY 255+ADs EE+AFs-2+ACo-f+-1+AF0 +AD0 E+AFs-e+AF0APgA+-8+ADs
+AH0
return function dbcs+AF8-e(data, ofmt) +AHs
var len +AD0 data.length, out +AD0 Buffer.allocUnsafe(2+ACo-len), i+AD0-0, j+AD0-0, jj+AD0-0, k+AD0-0, D+AD0-0+ADs
if(typeof data +AD0APQA9 'string') +AHs
for(i +AD0 k +AD0 0+ADs i +ADw len+ADs +-+-i) +AHs
j +AD0 data.charCodeAt(i)+ACo-2+ADs
out+AFs-k+-+-+AF0 +AD0 EE+AFs-j+-1+AF0 +AHwAfA EE+AFs-j+AF0AOw if(EE+AFs-j+-1+AF0 +AD4 0) out+AFs-k+-+-+AF0 +AD0 EE+AFs-j+AF0AOw
+AH0
out +AD0 out.slice(0,k)+ADs
+AH0 else if(Buffer.isBuffer(data)) +AHs
for(i +AD0 k +AD0 0+ADs i +ADw len+ADs +-+-i) +AHs
D +AD0 data+AFs-i+AF0AOw
if(D +ADw 128) j +AD0 D+ADs
else if(D +ADw 224) +AHs j +AD0 ((D+ACY-31)+ADwAPA-6)+-(data+AFs-i+-1+AF0AJg-63)+ADs +-+-i+ADs +AH0
else if(D +ADw 240) +AHs j +AD0 ((D+ACY-15)+ADwAPA-12)+-((data+AFs-i+-1+AF0AJg-63)+ADwAPA-6)+-(data+AFs-i+-2+AF0AJg-63)+ADs i+-+AD0-2+ADs +AH0
else +AHs j +AD0 ((D+ACY-7)+ADwAPA-18)+-((data+AFs-i+-1+AF0AJg-63)+ADwAPA-12)+-((data+AFs-i+-2+AF0AJg-63)+ADwAPA-6)+-(data+AFs-i+-3+AF0AJg-63)+ADs i+-+AD0-3+ADs +AH0
if(j+ADw-65536) +AHs j+ACoAPQ-2+ADs out+AFs-k+-+-+AF0 +AD0 EE+AFs-j+-1+AF0 +AHwAfA EE+AFs-j+AF0AOw if(EE+AFs-j+-1+AF0 +AD4 0) out+AFs-k+-+-+AF0 +AD0 EE+AFs-j+AF0AOw +AH0
else +AHs jj +AD0 j-65536+ADs
j+AD0-2+ACo(0xD800 +- ((jj+AD4APg-10)+ACY-1023))+ADs out+AFs-k+-+-+AF0 +AD0 EE+AFs-j+-1+AF0 +AHwAfA EE+AFs-j+AF0AOw if(EE+AFs-j+-1+AF0 +AD4 0) out+AFs-k+-+-+AF0 +AD0 EE+AFs-j+AF0AOw
j+AD0-2+ACo(0xDC00 +- (jj+ACY-1023))+ADs out+AFs-k+-+-+AF0 +AD0 EE+AFs-j+-1+AF0 +AHwAfA EE+AFs-j+AF0AOw if(EE+AFs-j+-1+AF0 +AD4 0) out+AFs-k+-+-+AF0 +AD0 EE+AFs-j+AF0AOw
+AH0
+AH0
out +AD0 out.slice(0,k)+ADs
+AH0 else +AHs
for(i +AD0 k +AD0 0+ADs i +ADw len+ADs i+-+-) +AHs
j +AD0 data+AFs-i+AF0.charCodeAt(0)+ACo-2+ADs
out+AFs-k+-+-+AF0 +AD0 EE+AFs-j+-1+AF0 +AHwAfA EE+AFs-j+AF0AOw if(EE+AFs-j+-1+AF0 +AD4 0) out+AFs-k+-+-+AF0 +AD0 EE+AFs-j+AF0AOw
+AH0
+AH0
if(+ACE-ofmt +AHwAfA ofmt +AD0APQA9 'buf') return out+ADs
if(ofmt +ACEAPQA9 'arr') return out.toString('binary')+ADs
return +AFsAXQ.slice.call(out)+ADs
+AH0AOw
+AH0AOw
var dbcs+AF8-decode +AD0 function make+AF8-dbcs+AF8-decode(cp) +AHs
var D +AD0 cpt+AFs-cp+AF0.dec+ADs
var DD +AD0 Buffer.allocUnsafe(131072), d+AD0-0, c, w+AD0-0, j+AD0-0, i+AD0-0+ADs
for(i +AD0 0+ADs i +ADw 65536+ADs +-+-i) +AHs DD+AFs-2+ACo-i+AF0 +AD0 0xFF+ADs DD+AFs-2+ACo-i+-1+AF0 +AD0 0xFD+ADsAfQ
for(d +AD0 0+ADs d +ADw D.length+ADs +-+-d) +AHs
if(+ACE(c+AD0-D+AFs-d+AF0)) continue+ADs
w +AD0 c.charCodeAt(0)+ADs
j +AD0 2+ACo-d+ADs
DD+AFs-j+AF0 +AD0 w+ACY-255+ADs DD+AFs-j+-1+AF0 +AD0 w+AD4APg-8+ADs
+AH0
return function dbcs+AF8-d(data) +AHs
var len +AD0 data.length, out +AD0 Buffer.allocUnsafe(2+ACo-len), i+AD0-0, j+AD0-0, k+AD0-0+ADs
if(Buffer.isBuffer(data)) +AHs
for(i +AD0 0+ADs i +ADw len+ADs i+-+-) +AHs
j +AD0 2+ACo-data+AFs-i+AF0AOw
if(DD+AFs-j+AF0APQA9AD0-0xFF +ACYAJg DD+AFs-j+-1+AF0APQA9AD0-0xFD) +AHs j+AD0-2+ACo((data+AFs-i+AF0APAA8-8)+-data+AFs-i+-1+AF0)+ADs +-+-i+ADs +AH0
out+AFs-k+-+-+AF0 +AD0 DD+AFs-j+AF0AOw out+AFs-k+-+-+AF0 +AD0 DD+AFs-j+-1+AF0AOw
+AH0
+AH0 else if(typeof data +AD0APQA9 +ACI-string+ACI) +AHs
for(i +AD0 0+ADs i +ADw len+ADs i+-+-) +AHs
j +AD0 2+ACo-data.charCodeAt(i)+ADs
if(DD+AFs-j+AF0APQA9AD0-0xFF +ACYAJg DD+AFs-j+-1+AF0APQA9AD0-0xFD) +AHs j+AD0-2+ACo((data.charCodeAt(i)+ADwAPA-8)+-data.charCodeAt(i+-1))+ADs +-+-i+ADs +AH0
out+AFs-k+-+-+AF0 +AD0 DD+AFs-j+AF0AOw out+AFs-k+-+-+AF0 +AD0 DD+AFs-j+-1+AF0AOw
+AH0
+AH0 else +AHs
for(i +AD0 0+ADs i +ADw len+ADs i+-+-) +AHs
j +AD0 2+ACo-data+AFs-i+AF0AOw
if(DD+AFs-j+AF0APQA9AD0-0xFF +ACYAJg DD+AFs-j+-1+AF0APQA9AD0-0xFD) +AHs j+AD0-2+ACo((data+AFs-i+AF0APAA8-8)+-data+AFs-i+-1+AF0)+ADs +-+-i+ADs +AH0
out+AFs-k+-+-+AF0 +AD0 DD+AFs-j+AF0AOw out+AFs-k+-+-+AF0 +AD0 DD+AFs-j+-1+AF0AOw
+AH0
+AH0
return out.slice(0,k).toString('ucs2')+ADs
+AH0AOw
+AH0AOw
magic+AF8-decode+AFs-65001+AF0 +AD0 function utf8+AF8-d(data) +AHs
if(typeof data +AD0APQA9 +ACI-string+ACI) return utf8+AF8-d(data.split(+ACIAIg).map(cca))+ADs
var len +AD0 data.length, w +AD0 0, ww +AD0 0+ADs
if(4 +ACo len +AD4 mdl) +AHs mdl +AD0 4 +ACo len+ADs mdb +AD0 Buffer.allocUnsafe(mdl)+ADs +AH0
var i +AD0 0+ADs
if(len +AD4APQ 3 +ACYAJg data+AFs-0+AF0 +AD0APQ 0xEF) if(data+AFs-1+AF0 +AD0APQ 0xBB +ACYAJg data+AFs-2+AF0 +AD0APQ 0xBF) i +AD0 3+ADs
for(var j +AD0 1, k +AD0 0, D +AD0 0+ADs i +ADw len+ADs i+-+AD0-j) +AHs
j +AD0 1+ADs D +AD0 data+AFs-i+AF0AOw
if(D +ADw 128) w +AD0 D+ADs
else if(D +ADw 224) +AHs w+AD0(D+ACY-31)+ACo-64+-(data+AFs-i+-1+AF0AJg-63)+ADs j+AD0-2+ADs +AH0
else if(D +ADw 240) +AHs w+AD0((D+ACY-15)+ADwAPA-12)+-(data+AFs-i+-1+AF0AJg-63)+ACo-64+-(data+AFs-i+-2+AF0AJg-63)+ADs j+AD0-3+ADs +AH0
else +AHs w+AD0(D+ACY-7)+ACo-262144+-((data+AFs-i+-1+AF0AJg-63)+ADwAPA-12)+-(data+AFs-i+-2+AF0AJg-63)+ACo-64+-(data+AFs-i+-3+AF0AJg-63)+ADs j+AD0-4+ADs +AH0
if(w +ADw 65536) +AHs mdb+AFs-k+-+-+AF0 +AD0 w+ACY-255+ADs mdb+AFs-k+-+-+AF0 +AD0 w+AD4APg-8+ADs +AH0
else +AHs
w -+AD0 65536+ADs ww +AD0 0xD800 +- ((w+AD4APg-10)+ACY-1023)+ADs w +AD0 0xDC00 +- (w+ACY-1023)+ADs
mdb+AFs-k+-+-+AF0 +AD0 ww+ACY-255+ADs mdb+AFs-k+-+-+AF0 +AD0 ww+AD4APgA+-8+ADs mdb+AFs-k+-+-+AF0 +AD0 w+ACY-255+ADs mdb+AFs-k+-+-+AF0 +AD0 (w+AD4APgA+-8)+ACY-255+ADs
+AH0
+AH0
return mdb.slice(0,k).toString('ucs2')+ADs
+AH0AOw
magic+AF8-encode+AFs-65001+AF0 +AD0 function utf8+AF8-e(data, ofmt) +AHs
if(has+AF8-buf +ACYAJg Buffer.isBuffer(data)) +AHs
if(+ACE-ofmt +AHwAfA ofmt +AD0APQA9 'buf') return data+ADs
if(ofmt +ACEAPQA9 'arr') return data.toString('binary')+ADs
return +AFsAXQ.slice.call(data)+ADs
+AH0
var len +AD0 data.length, w +AD0 0, ww +AD0 0, j +AD0 0+ADs
var direct +AD0 typeof data +AD0APQA9 +ACI-string+ACIAOw
if(4 +ACo len +AD4 mdl) +AHs mdl +AD0 4 +ACo len+ADs mdb +AD0 Buffer.allocUnsafe(mdl)+ADs +AH0
for(var i +AD0 0+ADs i +ADw len+ADs +-+-i) +AHs
w +AD0 direct ? data.charCodeAt(i) : data+AFs-i+AF0.charCodeAt(0)+ADs
if(w +ADwAPQ 0x007F) mdb+AFs-j+-+-+AF0 +AD0 w+ADs
else if(w +ADwAPQ 0x07FF) +AHs
mdb+AFs-j+-+-+AF0 +AD0 192 +- (w +AD4APg 6)+ADs
mdb+AFs-j+-+-+AF0 +AD0 128 +- (w+ACY-63)+ADs
+AH0 else if(w +AD4APQ 0xD800 +ACYAJg w +ADwAPQ 0xDFFF) +AHs
w -+AD0 0xD800+ADs +-+-i+ADs
ww +AD0 (direct ? data.charCodeAt(i) : data+AFs-i+AF0.charCodeAt(0)) - 0xDC00 +- (w +ADwAPA 10)+ADs
mdb+AFs-j+-+-+AF0 +AD0 240 +- ((ww+AD4APgA+-18) +ACY 0x07)+ADs
mdb+AFs-j+-+-+AF0 +AD0 144 +- ((ww+AD4APgA+-12) +ACY 0x3F)+ADs
mdb+AFs-j+-+-+AF0 +AD0 128 +- ((ww+AD4APgA+-6) +ACY 0x3F)+ADs
mdb+AFs-j+-+-+AF0 +AD0 128 +- (ww +ACY 0x3F)+ADs
+AH0 else +AHs
mdb+AFs-j+-+-+AF0 +AD0 224 +- (w +AD4APg 12)+ADs
mdb+AFs-j+-+-+AF0 +AD0 128 +- ((w +AD4APg 6)+ACY-63)+ADs
mdb+AFs-j+-+-+AF0 +AD0 128 +- (w+ACY-63)+ADs
+AH0
+AH0
if(+ACE-ofmt +AHwAfA ofmt +AD0APQA9 'buf') return mdb.slice(0,j)+ADs
if(ofmt +ACEAPQA9 'arr') return mdb.slice(0,j).toString('binary')+ADs
return +AFsAXQ.slice.call(mdb, 0, j)+ADs
+AH0AOw
+AH0
var encache +AD0 function encache() +AHs
if(has+AF8-buf) +AHs
if(cpdcache+AFs-sbcs+AF8-cache+AFs-0+AF0AXQ) return+ADs
var i+AD0-0, s+AD0-0+ADs
for(i +AD0 0+ADs i +ADw sbcs+AF8-cache.length+ADs +-+-i) +AHs
s +AD0 sbcs+AF8-cache+AFs-i+AF0AOw
if(cpt+AFs-s+AF0) +AHs
cpdcache+AFs-s+AF0 +AD0 sbcs+AF8-decode(s)+ADs
cpecache+AFs-s+AF0 +AD0 sbcs+AF8-encode(s)+ADs
+AH0
+AH0
for(i +AD0 0+ADs i +ADw dbcs+AF8-cache.length+ADs +-+-i) +AHs
s +AD0 dbcs+AF8-cache+AFs-i+AF0AOw
if(cpt+AFs-s+AF0) +AHs
cpdcache+AFs-s+AF0 +AD0 dbcs+AF8-decode(s)+ADs
cpecache+AFs-s+AF0 +AD0 dbcs+AF8-encode(s)+ADs
+AH0
+AH0
for(i +AD0 0+ADs i +ADw magic+AF8-cache.length+ADs +-+-i) +AHs
s +AD0 magic+AF8-cache+AFs-i+AF0AOw
if(magic+AF8-decode+AFs-s+AF0) cpdcache+AFs-s+AF0 +AD0 magic+AF8-decode+AFs-s+AF0AOw
if(magic+AF8-encode+AFs-s+AF0) cpecache+AFs-s+AF0 +AD0 magic+AF8-encode+AFs-s+AF0AOw
+AH0
+AH0
+AH0AOw
var null+AF8-enc +AD0 function(data, ofmt) +AHs void ofmt+ADs return +ACIAIgA7 +AH0AOw
var cp+AF8-decache +AD0 function cp+AF8-decache(cp) +AHs delete cpdcache+AFs-cp+AF0AOw delete cpecache+AFs-cp+AF0AOw +AH0AOw
var decache +AD0 function decache() +AHs
if(has+AF8-buf) +AHs
if(+ACE-cpdcache+AFs-sbcs+AF8-cache+AFs-0+AF0AXQ) return+ADs
sbcs+AF8-cache.forEach(cp+AF8-decache)+ADs
dbcs+AF8-cache.forEach(cp+AF8-decache)+ADs
magic+AF8-cache.forEach(cp+AF8-decache)+ADs
+AH0
last+AF8-enc +AD0 null+AF8-enc+ADs last+AF8-cp +AD0 0+ADs
+AH0AOw
var cache +AD0 +AHs
encache: encache,
decache: decache,
sbcs: sbcs+AF8-cache,
dbcs: dbcs+AF8-cache
+AH0AOw
encache()+ADs
var BM +AD0 +ACI-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-/+ACIAOw
var SetD +AD0 +ACI-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'(),-./:?+ACIAOw
var last+AF8-enc +AD0 null+AF8-enc, last+AF8-cp +AD0 0+ADs
var encode +AD0 function encode(cp, data, ofmt) +AHs
if(cp +AD0APQA9 last+AF8-cp +ACYAJg last+AF8-enc) +AHs return last+AF8-enc(data, ofmt)+ADs +AH0
if(cpecache+AFs-cp+AF0) +AHs last+AF8-enc +AD0 cpecache+AFs-last+AF8-cp+AD0-cp+AF0AOw return last+AF8-enc(data, ofmt)+ADs +AH0
if(has+AF8-buf +ACYAJg Buffer.isBuffer(data)) data +AD0 data.toString('utf8')+ADs
var len +AD0 data.length+ADs
var out +AD0 has+AF8-buf ? Buffer.allocUnsafe(4+ACo-len) : +AFsAXQ, w+AD0-0, i+AD0-0, j +AD0 0, ww+AD0-0+ADs
var C +AD0 cpt+AFs-cp+AF0, E, M +AD0 +ACIAIgA7
var isstr +AD0 typeof data +AD0APQA9 'string'+ADs
if(C +ACYAJg (E+AD0-C.enc)) for(i +AD0 0+ADs i +ADw len+ADs +-+-i, +-+-j) +AHs
w +AD0 E+AFs-isstr? data.charAt(i) : data+AFs-i+AF0AXQA7
if(w +AD4 255) +AHs
out+AFs-j+AF0 +AD0 w+AD4APg-8+ADs
out+AFsAKwAr-j+AF0 +AD0 w+ACY-255+ADs
+AH0 else out+AFs-j+AF0 +AD0 w+ACY-255+ADs
+AH0
else if((M+AD0-magic+AFs-cp+AF0)) switch(M) +AHs
case +ACI-utf8+ACI:
if(has+AF8-buf +ACYAJg isstr) +AHs out +AD0 Buffer+AF8-from(data, M)+ADs j +AD0 out.length+ADs break+ADs +AH0
for(i +AD0 0+ADs i +ADw len+ADs +-+-i, +-+-j) +AHs
w +AD0 isstr ? data.charCodeAt(i) : data+AFs-i+AF0.charCodeAt(0)+ADs
if(w +ADwAPQ 0x007F) out+AFs-j+AF0 +AD0 w+ADs
else if(w +ADwAPQ 0x07FF) +AHs
out+AFs-j+AF0 +AD0 192 +- (w +AD4APg 6)+ADs
out+AFsAKwAr-j+AF0 +AD0 128 +- (w+ACY-63)+ADs
+AH0 else if(w +AD4APQ 0xD800 +ACYAJg w +ADwAPQ 0xDFFF) +AHs
w -+AD0 0xD800+ADs
ww +AD0 (isstr ? data.charCodeAt(+-+-i) : data+AFsAKwAr-i+AF0.charCodeAt(0)) - 0xDC00 +- (w +ADwAPA 10)+ADs
out+AFs-j+AF0 +AD0 240 +- ((ww+AD4APgA+-18) +ACY 0x07)+ADs
out+AFsAKwAr-j+AF0 +AD0 144 +- ((ww+AD4APgA+-12) +ACY 0x3F)+ADs
out+AFsAKwAr-j+AF0 +AD0 128 +- ((ww+AD4APgA+-6) +ACY 0x3F)+ADs
out+AFsAKwAr-j+AF0 +AD0 128 +- (ww +ACY 0x3F)+ADs
+AH0 else +AHs
out+AFs-j+AF0 +AD0 224 +- (w +AD4APg 12)+ADs
out+AFsAKwAr-j+AF0 +AD0 128 +- ((w +AD4APg 6)+ACY-63)+ADs
out+AFsAKwAr-j+AF0 +AD0 128 +- (w+ACY-63)+ADs
+AH0
+AH0
break+ADs
case +ACI-ascii+ACI:
if(has+AF8-buf +ACYAJg typeof data +AD0APQA9 +ACI-string+ACI) +AHs out +AD0 Buffer+AF8-from(data, M)+ADs j +AD0 out.length+ADs break+ADs +AH0
for(i +AD0 0+ADs i +ADw len+ADs +-+-i, +-+-j) +AHs
w +AD0 isstr ? data.charCodeAt(i) : data+AFs-i+AF0.charCodeAt(0)+ADs
if(w +ADwAPQ 0x007F) out+AFs-j+AF0 +AD0 w+ADs
else throw new Error(+ACI-bad ascii +ACI +- w)+ADs
+AH0
break+ADs
case +ACI-utf16le+ACI:
if(has+AF8-buf +ACYAJg typeof data +AD0APQA9 +ACI-string+ACI) +AHs out +AD0 Buffer+AF8-from(data, M)+ADs j +AD0 out.length+ADs break+ADs +AH0
for(i +AD0 0+ADs i +ADw len+ADs +-+-i) +AHs
w +AD0 isstr ? data.charCodeAt(i) : data+AFs-i+AF0.charCodeAt(0)+ADs
out+AFs-j+-+-+AF0 +AD0 w+ACY-255+ADs
out+AFs-j+-+-+AF0 +AD0 w+AD4APg-8+ADs
+AH0
break+ADs
case +ACI-utf16be+ACI:
for(i +AD0 0+ADs i +ADw len+ADs +-+-i) +AHs
w +AD0 isstr ? data.charCodeAt(i) : data+AFs-i+AF0.charCodeAt(0)+ADs
out+AFs-j+-+-+AF0 +AD0 w+AD4APg-8+ADs
out+AFs-j+-+-+AF0 +AD0 w+ACY-255+ADs
+AH0
break+ADs
case +ACI-utf32le+ACI:
for(i +AD0 0+ADs i +ADw len+ADs +-+-i) +AHs
w +AD0 isstr ? data.charCodeAt(i) : data+AFs-i+AF0.charCodeAt(0)+ADs
if(w +AD4APQ 0xD800 +ACYAJg w +ADwAPQ 0xDFFF) w +AD0 0x10000 +- ((w - 0xD800) +ADwAPA 10) +- (data+AFsAKwAr-i+AF0.charCodeAt(0) - 0xDC00)+ADs
out+AFs-j+-+-+AF0 +AD0 w+ACY-255+ADs w +AD4APgA9 8+ADs
out+AFs-j+-+-+AF0 +AD0 w+ACY-255+ADs w +AD4APgA9 8+ADs
out+AFs-j+-+-+AF0 +AD0 w+ACY-255+ADs w +AD4APgA9 8+ADs
out+AFs-j+-+-+AF0 +AD0 w+ACY-255+ADs
+AH0
break+ADs
case +ACI-utf32be+ACI:
for(i +AD0 0+ADs i +ADw len+ADs +-+-i) +AHs
w +AD0 isstr ? data.charCodeAt(i) : data+AFs-i+AF0.charCodeAt(0)+ADs
if(w +AD4APQ 0xD800 +ACYAJg w +ADwAPQ 0xDFFF) w +AD0 0x10000 +- ((w - 0xD800) +ADwAPA 10) +- (data+AFsAKwAr-i+AF0.charCodeAt(0) - 0xDC00)+ADs
out+AFs-j+-3+AF0 +AD0 w+ACY-255+ADs w +AD4APgA9 8+ADs
out+AFs-j+-2+AF0 +AD0 w+ACY-255+ADs w +AD4APgA9 8+ADs
out+AFs-j+-1+AF0 +AD0 w+ACY-255+ADs w +AD4APgA9 8+ADs
out+AFs-j+AF0 +AD0 w+ACY-255+ADs
j+-+AD0-4+ADs
+AH0
break+ADs
case +ACI-utf7+ACI:
for(i +AD0 0+ADs i +ADw len+ADs i+-+-) +AHs
var c +AD0 isstr ? data.charAt(i) : data+AFs-i+AF0.charAt(0)+ADs
if(c +AD0APQA9 +ACIAKwAi) +AHs out+AFs-j+-+-+AF0 +AD0 0x2b+ADs out+AFs-j+-+-+AF0 +AD0 0x2d+ADs continue+ADs +AH0
if(SetD.indexOf(c) +AD4 -1) +AHs out+AFs-j+-+-+AF0 +AD0 c.charCodeAt(0)+ADs continue+ADs +AH0
var tt +AD0 encode(1201, c)+ADs
out+AFs-j+-+-+AF0 +AD0 0x2b+ADs
out+AFs-j+-+-+AF0 +AD0 BM.charCodeAt(tt+AFs-0+AF0APgA+-2)+ADs
out+AFs-j+-+-+AF0 +AD0 BM.charCodeAt(((tt+AFs-0+AF0AJg-0x03)+ADwAPA-4) +- ((tt+AFs-1+AF0AfAB8-0)+AD4APg-4))+ADs
out+AFs-j+-+-+AF0 +AD0 BM.charCodeAt(((tt+AFs-1+AF0AJg-0x0F)+ADwAPA-2) +- ((tt+AFs-2+AF0AfAB8-0)+AD4APg-6))+ADs
out+AFs-j+-+-+AF0 +AD0 0x2d+ADs
+AH0
break+ADs
default: throw new Error(+ACI-Unsupported magic: +ACI +- cp +- +ACI +ACI +- magic+AFs-cp+AF0)+ADs
+AH0
else throw new Error(+ACI-Unrecognized CP: +ACI +- cp)+ADs
out +AD0 out.slice(0,j)+ADs
if(+ACE-has+AF8-buf) return (ofmt +AD0APQ 'str') ? (out).map(sfcc).join(+ACIAIg) : out+ADs
if(+ACE-ofmt +AHwAfA ofmt +AD0APQA9 'buf') return out+ADs
if(ofmt +ACEAPQA9 'arr') return out.toString('binary')+ADs
return +AFsAXQ.slice.call(out)+ADs
+AH0AOw
var decode +AD0 function decode(cp, data) +AHs
var F+ADs if((F+AD0-cpdcache+AFs-cp+AF0)) return F(data)+ADs
if(typeof data +AD0APQA9 +ACI-string+ACI) return decode(cp, data.split(+ACIAIg).map(cca))+ADs
var len +AD0 data.length, out +AD0 new Array(len), s+AD0AIgAi, w+AD0-0, i+AD0-0, j+AD0-1, k+AD0-0, ww+AD0-0+ADs
var C +AD0 cpt+AFs-cp+AF0, D, M+AD0AIgAiADs
if(C +ACYAJg (D+AD0-C.dec)) +AHs
for(i +AD0 0+ADs i +ADw len+ADs i+-+AD0-j) +AHs
j +AD0 2+ADs
s +AD0 D+AFs(data+AFs-i+AF0APAA8-8)+- data+AFs-i+-1+AF0AXQA7
if(+ACE-s) +AHs
j +AD0 1+ADs
s +AD0 D+AFs-data+AFs-i+AF0AXQA7
+AH0
if(+ACE-s) throw new Error('Unrecognized code: ' +- data+AFs-i+AF0 +- ' ' +- data+AFs-i+-j-1+AF0 +- ' ' +- i +- ' ' +- j +- ' ' +- D+AFs-data+AFs-i+AF0AXQ)+ADs
out+AFs-k+-+-+AF0 +AD0 s+ADs
+AH0
+AH0
else if((M+AD0-magic+AFs-cp+AF0)) switch(M) +AHs
case +ACI-utf8+ACI:
if(len +AD4APQ 3 +ACYAJg data+AFs-0+AF0 +AD0APQ 0xEF) if(data+AFs-1+AF0 +AD0APQ 0xBB +ACYAJg data+AFs-2+AF0 +AD0APQ 0xBF) i +AD0 3+ADs
for(+ADs i +ADw len+ADs i+-+AD0-j) +AHs
j +AD0 1+ADs
if(data+AFs-i+AF0 +ADw 128) w +AD0 data+AFs-i+AF0AOw
else if(data+AFs-i+AF0 +ADw 224) +AHs w+AD0(data+AFs-i+AF0AJg-31)+ACo-64+-(data+AFs-i+-1+AF0AJg-63)+ADs j+AD0-2+ADs +AH0
else if(data+AFs-i+AF0 +ADw 240) +AHs w+AD0((data+AFs-i+AF0AJg-15)+ADwAPA-12)+-(data+AFs-i+-1+AF0AJg-63)+ACo-64+-(data+AFs-i+-2+AF0AJg-63)+ADs j+AD0-3+ADs +AH0
else +AHs w+AD0(data+AFs-i+AF0AJg-7)+ACo-262144+-((data+AFs-i+-1+AF0AJg-63)+ADwAPA-12)+-(data+AFs-i+-2+AF0AJg-63)+ACo-64+-(data+AFs-i+-3+AF0AJg-63)+ADs j+AD0-4+ADs +AH0
if(w +ADw 65536) +AHs out+AFs-k+-+-+AF0 +AD0 String.fromCharCode(w)+ADs +AH0
else +AHs
w -+AD0 65536+ADs ww +AD0 0xD800 +- ((w+AD4APg-10)+ACY-1023)+ADs w +AD0 0xDC00 +- (w+ACY-1023)+ADs
out+AFs-k+-+-+AF0 +AD0 String.fromCharCode(ww)+ADs out+AFs-k+-+-+AF0 +AD0 String.fromCharCode(w)+ADs
+AH0
+AH0
break+ADs
case +ACI-ascii+ACI:
if(has+AF8-buf +ACYAJg Buffer.isBuffer(data)) return data.toString(M)+ADs
for(i +AD0 0+ADs i +ADw len+ADs i+-+-) out+AFs-i+AF0 +AD0 String.fromCharCode(data+AFs-i+AF0)+ADs
k +AD0 len+ADs break+ADs
case +ACI-utf16le+ACI:
if(len +AD4APQ 2 +ACYAJg data+AFs-0+AF0 +AD0APQ 0xFF) if(data+AFs-1+AF0 +AD0APQ 0xFE) i +AD0 2+ADs
if(has+AF8-buf +ACYAJg Buffer.isBuffer(data)) return data.toString(M)+ADs
j +AD0 2+ADs
for(+ADs i+-1 +ADw len+ADs i+-+AD0-j) +AHs
out+AFs-k+-+-+AF0 +AD0 String.fromCharCode((data+AFs-i+-1+AF0APAA8-8) +- data+AFs-i+AF0)+ADs
+AH0
break+ADs
case +ACI-utf16be+ACI:
if(len +AD4APQ 2 +ACYAJg data+AFs-0+AF0 +AD0APQ 0xFE) if(data+AFs-1+AF0 +AD0APQ 0xFF) i +AD0 2+ADs
j +AD0 2+ADs
for(+ADs i+-1 +ADw len+ADs i+-+AD0-j) +AHs
out+AFs-k+-+-+AF0 +AD0 String.fromCharCode((data+AFs-i+AF0APAA8-8) +- data+AFs-i+-1+AF0)+ADs
+AH0
break+ADs
case +ACI-utf32le+ACI:
if(len +AD4APQ 4 +ACYAJg data+AFs-0+AF0 +AD0APQ 0xFF) if(data+AFs-1+AF0 +AD0APQ 0xFE +ACYAJg data+AFs-2+AF0 +AD0APQA9 0 +ACYAJg data+AFs-3+AF0 +AD0APQA9 0) i +AD0 4+ADs
j +AD0 4+ADs
for(+ADs i +ADw len+ADs i+-+AD0-j) +AHs
w +AD0 (data+AFs-i+-3+AF0APAA8-24) +- (data+AFs-i+-2+AF0APAA8-16) +- (data+AFs-i+-1+AF0APAA8-8) +- (data+AFs-i+AF0)+ADs
if(w +AD4 0xFFFF) +AHs
w -+AD0 0x10000+ADs
out+AFs-k+-+-+AF0 +AD0 String.fromCharCode(0xD800 +- ((w +AD4APg 10) +ACY 0x3FF))+ADs
out+AFs-k+-+-+AF0 +AD0 String.fromCharCode(0xDC00 +- (w +ACY 0x3FF))+ADs
+AH0
else out+AFs-k+-+-+AF0 +AD0 String.fromCharCode(w)+ADs
+AH0
break+ADs
case +ACI-utf32be+ACI:
if(len +AD4APQ 4 +ACYAJg data+AFs-3+AF0 +AD0APQ 0xFF) if(data+AFs-2+AF0 +AD0APQ 0xFE +ACYAJg data+AFs-1+AF0 +AD0APQA9 0 +ACYAJg data+AFs-0+AF0 +AD0APQA9 0) i +AD0 4+ADs
j +AD0 4+ADs
for(+ADs i +ADw len+ADs i+-+AD0-j) +AHs
w +AD0 (data+AFs-i+AF0APAA8-24) +- (data+AFs-i+-1+AF0APAA8-16) +- (data+AFs-i+-2+AF0APAA8-8) +- (data+AFs-i+-3+AF0)+ADs
if(w +AD4 0xFFFF) +AHs
w -+AD0 0x10000+ADs
out+AFs-k+-+-+AF0 +AD0 String.fromCharCode(0xD800 +- ((w +AD4APg 10) +ACY 0x3FF))+ADs
out+AFs-k+-+-+AF0 +AD0 String.fromCharCode(0xDC00 +- (w +ACY 0x3FF))+ADs
+AH0
else out+AFs-k+-+-+AF0 +AD0 String.fromCharCode(w)+ADs
+AH0
break+ADs
case +ACI-utf7+ACI:
if(len +AD4APQ 4 +ACYAJg data+AFs-0+AF0 +AD0APQ 0x2B +ACYAJg data+AFs-1+AF0 +AD0APQ 0x2F +ACYAJg data+AFs-2+AF0 +AD0APQ 0x76) +AHs
if(len +AD4APQ 5 +ACYAJg data+AFs-3+AF0 +AD0APQ 0x38 +ACYAJg data+AFs-4+AF0 +AD0APQ 0x2D) i +AD0 5+ADs
else if(data+AFs-3+AF0 +AD0APQ 0x38 +AHwAfA data+AFs-3+AF0 +AD0APQ 0x39 +AHwAfA data+AFs-3+AF0 +AD0APQ 0x2B +AHwAfA data+AFs-3+AF0 +AD0APQ 0x2F) i +AD0 4+ADs
+AH0
for(+ADs i +ADw len+ADs i+-+AD0-j) +AHs
if(data+AFs-i+AF0 +ACEAPQA9 0x2b) +AHs j+AD0-1+ADs out+AFs-k+-+-+AF0 +AD0 String.fromCharCode(data+AFs-i+AF0)+ADs continue+ADs +AH0
j+AD0-1+ADs
if(data+AFs-i+-1+AF0 +AD0APQA9 0x2d) +AHs j +AD0 2+ADs out+AFs-k+-+-+AF0 +AD0 +ACIAKwAiADs continue+ADs +AH0
// eslint-disable-next-line no-useless-escape
while(String.fromCharCode(data+AFs-i+-j+AF0).match(/+AFs-A-Za-z0-9+-+AFw-/+AF0-/)) j+-+-+ADs
var dash +AD0 0+ADs
if(data+AFs-i+-j+AF0 +AD0APQA9 0x2d) +AHs +-+-j+ADs dash+AD0-1+ADs +AH0
var tt +AD0 +AFsAXQA7
var o64 +AD0 +ACIAIgA7
var c1+AD0-0, c2+AD0-0, c3+AD0-0+ADs
var e1+AD0-0, e2+AD0-0, e3+AD0-0, e4+AD0-0+ADs
for(var l +AD0 1+ADs l +ADw j - dash+ADs) +AHs
e1 +AD0 BM.indexOf(String.fromCharCode(data+AFs-i+-l+-+-+AF0))+ADs
e2 +AD0 BM.indexOf(String.fromCharCode(data+AFs-i+-l+-+-+AF0))+ADs
c1 +AD0 e1 +ADwAPA 2 +AHw e2 +AD4APg 4+ADs
tt.push(c1)+ADs
e3 +AD0 BM.indexOf(String.fromCharCode(data+AFs-i+-l+-+-+AF0))+ADs
if(e3 +AD0APQA9 -1) break+ADs
c2 +AD0 (e2 +ACY 15) +ADwAPA 4 +AHw e3 +AD4APg 2+ADs
tt.push(c2)+ADs
e4 +AD0 BM.indexOf(String.fromCharCode(data+AFs-i+-l+-+-+AF0))+ADs
if(e4 +AD0APQA9 -1) break+ADs
c3 +AD0 (e3 +ACY 3) +ADwAPA 6 +AHw e4+ADs
if(e4 +ADw 64) tt.push(c3)+ADs
+AH0
o64 +AD0 decode(1201, tt)+ADs
for(l +AD0 0+ADs l +ADw o64.length+ADs +-+-l) out+AFs-k+-+-+AF0 +AD0 o64.charAt(l)+ADs
+AH0
break+ADs
default: throw new Error(+ACI-Unsupported magic: +ACI +- cp +- +ACI +ACI +- magic+AFs-cp+AF0)+ADs
+AH0
else throw new Error(+ACI-Unrecognized CP: +ACI +- cp)+ADs
return out.slice(0,k).join(+ACIAIg)+ADs
+AH0AOw
var hascp +AD0 function hascp(cp) +AHs return +ACEAIQ(cpt+AFs-cp+AF0 +AHwAfA magic+AFs-cp+AF0)+ADs +AH0AOw
cpt.utils +AD0 +AHs decode: decode, encode: encode, hascp: hascp, magic: magic, cache:cache +AH0AOw
return cpt+ADs
+AH0))+ADs