qrcode.js 381 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414
  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.QRCode = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  2. // can-promise has a crash in some versions of react native that dont have
  3. // standard global objects
  4. // https://github.com/soldair/node-qrcode/issues/157
  5. module.exports = function () {
  6. return typeof Promise === 'function' && Promise.prototype && Promise.prototype.then
  7. }
  8. },{}],2:[function(require,module,exports){
  9. /**
  10. * Alignment pattern are fixed reference pattern in defined positions
  11. * in a matrix symbology, which enables the decode software to re-synchronise
  12. * the coordinate mapping of the image modules in the event of moderate amounts
  13. * of distortion of the image.
  14. *
  15. * Alignment patterns are present only in QR Code symbols of version 2 or larger
  16. * and their number depends on the symbol version.
  17. */
  18. var getSymbolSize = require('./utils').getSymbolSize
  19. /**
  20. * Calculate the row/column coordinates of the center module of each alignment pattern
  21. * for the specified QR Code version.
  22. *
  23. * The alignment patterns are positioned symmetrically on either side of the diagonal
  24. * running from the top left corner of the symbol to the bottom right corner.
  25. *
  26. * Since positions are simmetrical only half of the coordinates are returned.
  27. * Each item of the array will represent in turn the x and y coordinate.
  28. * @see {@link getPositions}
  29. *
  30. * @param {Number} version QR Code version
  31. * @return {Array} Array of coordinate
  32. */
  33. exports.getRowColCoords = function getRowColCoords (version) {
  34. if (version === 1) return []
  35. var posCount = Math.floor(version / 7) + 2
  36. var size = getSymbolSize(version)
  37. var intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2
  38. var positions = [size - 7] // Last coord is always (size - 7)
  39. for (var i = 1; i < posCount - 1; i++) {
  40. positions[i] = positions[i - 1] - intervals
  41. }
  42. positions.push(6) // First coord is always 6
  43. return positions.reverse()
  44. }
  45. /**
  46. * Returns an array containing the positions of each alignment pattern.
  47. * Each array's element represent the center point of the pattern as (x, y) coordinates
  48. *
  49. * Coordinates are calculated expanding the row/column coordinates returned by {@link getRowColCoords}
  50. * and filtering out the items that overlaps with finder pattern
  51. *
  52. * @example
  53. * For a Version 7 symbol {@link getRowColCoords} returns values 6, 22 and 38.
  54. * The alignment patterns, therefore, are to be centered on (row, column)
  55. * positions (6,22), (22,6), (22,22), (22,38), (38,22), (38,38).
  56. * Note that the coordinates (6,6), (6,38), (38,6) are occupied by finder patterns
  57. * and are not therefore used for alignment patterns.
  58. *
  59. * var pos = getPositions(7)
  60. * // [[6,22], [22,6], [22,22], [22,38], [38,22], [38,38]]
  61. *
  62. * @param {Number} version QR Code version
  63. * @return {Array} Array of coordinates
  64. */
  65. exports.getPositions = function getPositions (version) {
  66. var coords = []
  67. var pos = exports.getRowColCoords(version)
  68. var posLength = pos.length
  69. for (var i = 0; i < posLength; i++) {
  70. for (var j = 0; j < posLength; j++) {
  71. // Skip if position is occupied by finder patterns
  72. if ((i === 0 && j === 0) || // top-left
  73. (i === 0 && j === posLength - 1) || // bottom-left
  74. (i === posLength - 1 && j === 0)) { // top-right
  75. continue
  76. }
  77. coords.push([pos[i], pos[j]])
  78. }
  79. }
  80. return coords
  81. }
  82. },{"./utils":21}],3:[function(require,module,exports){
  83. var Mode = require('./mode')
  84. /**
  85. * Array of characters available in alphanumeric mode
  86. *
  87. * As per QR Code specification, to each character
  88. * is assigned a value from 0 to 44 which in this case coincides
  89. * with the array index
  90. *
  91. * @type {Array}
  92. */
  93. var ALPHA_NUM_CHARS = [
  94. '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  95. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  96. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  97. ' ', '$', '%', '*', '+', '-', '.', '/', ':'
  98. ]
  99. function AlphanumericData (data) {
  100. this.mode = Mode.ALPHANUMERIC
  101. this.data = data
  102. }
  103. AlphanumericData.getBitsLength = function getBitsLength (length) {
  104. return 11 * Math.floor(length / 2) + 6 * (length % 2)
  105. }
  106. AlphanumericData.prototype.getLength = function getLength () {
  107. return this.data.length
  108. }
  109. AlphanumericData.prototype.getBitsLength = function getBitsLength () {
  110. return AlphanumericData.getBitsLength(this.data.length)
  111. }
  112. AlphanumericData.prototype.write = function write (bitBuffer) {
  113. var i
  114. // Input data characters are divided into groups of two characters
  115. // and encoded as 11-bit binary codes.
  116. for (i = 0; i + 2 <= this.data.length; i += 2) {
  117. // The character value of the first character is multiplied by 45
  118. var value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45
  119. // The character value of the second digit is added to the product
  120. value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1])
  121. // The sum is then stored as 11-bit binary number
  122. bitBuffer.put(value, 11)
  123. }
  124. // If the number of input data characters is not a multiple of two,
  125. // the character value of the final character is encoded as a 6-bit binary number.
  126. if (this.data.length % 2) {
  127. bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6)
  128. }
  129. }
  130. module.exports = AlphanumericData
  131. },{"./mode":14}],4:[function(require,module,exports){
  132. function BitBuffer () {
  133. this.buffer = []
  134. this.length = 0
  135. }
  136. BitBuffer.prototype = {
  137. get: function (index) {
  138. var bufIndex = Math.floor(index / 8)
  139. return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) === 1
  140. },
  141. put: function (num, length) {
  142. for (var i = 0; i < length; i++) {
  143. this.putBit(((num >>> (length - i - 1)) & 1) === 1)
  144. }
  145. },
  146. getLengthInBits: function () {
  147. return this.length
  148. },
  149. putBit: function (bit) {
  150. var bufIndex = Math.floor(this.length / 8)
  151. if (this.buffer.length <= bufIndex) {
  152. this.buffer.push(0)
  153. }
  154. if (bit) {
  155. this.buffer[bufIndex] |= (0x80 >>> (this.length % 8))
  156. }
  157. this.length++
  158. }
  159. }
  160. module.exports = BitBuffer
  161. },{}],5:[function(require,module,exports){
  162. var BufferUtil = require('../utils/buffer')
  163. /**
  164. * Helper class to handle QR Code symbol modules
  165. *
  166. * @param {Number} size Symbol size
  167. */
  168. function BitMatrix (size) {
  169. if (!size || size < 1) {
  170. throw new Error('BitMatrix size must be defined and greater than 0')
  171. }
  172. this.size = size
  173. this.data = BufferUtil.alloc(size * size)
  174. this.reservedBit = BufferUtil.alloc(size * size)
  175. }
  176. /**
  177. * Set bit value at specified location
  178. * If reserved flag is set, this bit will be ignored during masking process
  179. *
  180. * @param {Number} row
  181. * @param {Number} col
  182. * @param {Boolean} value
  183. * @param {Boolean} reserved
  184. */
  185. BitMatrix.prototype.set = function (row, col, value, reserved) {
  186. var index = row * this.size + col
  187. this.data[index] = value
  188. if (reserved) this.reservedBit[index] = true
  189. }
  190. /**
  191. * Returns bit value at specified location
  192. *
  193. * @param {Number} row
  194. * @param {Number} col
  195. * @return {Boolean}
  196. */
  197. BitMatrix.prototype.get = function (row, col) {
  198. return this.data[row * this.size + col]
  199. }
  200. /**
  201. * Applies xor operator at specified location
  202. * (used during masking process)
  203. *
  204. * @param {Number} row
  205. * @param {Number} col
  206. * @param {Boolean} value
  207. */
  208. BitMatrix.prototype.xor = function (row, col, value) {
  209. this.data[row * this.size + col] ^= value
  210. }
  211. /**
  212. * Check if bit at specified location is reserved
  213. *
  214. * @param {Number} row
  215. * @param {Number} col
  216. * @return {Boolean}
  217. */
  218. BitMatrix.prototype.isReserved = function (row, col) {
  219. return this.reservedBit[row * this.size + col]
  220. }
  221. module.exports = BitMatrix
  222. },{"../utils/buffer":28}],6:[function(require,module,exports){
  223. var BufferUtil = require('../utils/buffer')
  224. var Mode = require('./mode')
  225. function ByteData (data) {
  226. this.mode = Mode.BYTE
  227. this.data = BufferUtil.from(data)
  228. }
  229. ByteData.getBitsLength = function getBitsLength (length) {
  230. return length * 8
  231. }
  232. ByteData.prototype.getLength = function getLength () {
  233. return this.data.length
  234. }
  235. ByteData.prototype.getBitsLength = function getBitsLength () {
  236. return ByteData.getBitsLength(this.data.length)
  237. }
  238. ByteData.prototype.write = function (bitBuffer) {
  239. for (var i = 0, l = this.data.length; i < l; i++) {
  240. bitBuffer.put(this.data[i], 8)
  241. }
  242. }
  243. module.exports = ByteData
  244. },{"../utils/buffer":28,"./mode":14}],7:[function(require,module,exports){
  245. var ECLevel = require('./error-correction-level')
  246. var EC_BLOCKS_TABLE = [
  247. // L M Q H
  248. 1, 1, 1, 1,
  249. 1, 1, 1, 1,
  250. 1, 1, 2, 2,
  251. 1, 2, 2, 4,
  252. 1, 2, 4, 4,
  253. 2, 4, 4, 4,
  254. 2, 4, 6, 5,
  255. 2, 4, 6, 6,
  256. 2, 5, 8, 8,
  257. 4, 5, 8, 8,
  258. 4, 5, 8, 11,
  259. 4, 8, 10, 11,
  260. 4, 9, 12, 16,
  261. 4, 9, 16, 16,
  262. 6, 10, 12, 18,
  263. 6, 10, 17, 16,
  264. 6, 11, 16, 19,
  265. 6, 13, 18, 21,
  266. 7, 14, 21, 25,
  267. 8, 16, 20, 25,
  268. 8, 17, 23, 25,
  269. 9, 17, 23, 34,
  270. 9, 18, 25, 30,
  271. 10, 20, 27, 32,
  272. 12, 21, 29, 35,
  273. 12, 23, 34, 37,
  274. 12, 25, 34, 40,
  275. 13, 26, 35, 42,
  276. 14, 28, 38, 45,
  277. 15, 29, 40, 48,
  278. 16, 31, 43, 51,
  279. 17, 33, 45, 54,
  280. 18, 35, 48, 57,
  281. 19, 37, 51, 60,
  282. 19, 38, 53, 63,
  283. 20, 40, 56, 66,
  284. 21, 43, 59, 70,
  285. 22, 45, 62, 74,
  286. 24, 47, 65, 77,
  287. 25, 49, 68, 81
  288. ]
  289. var EC_CODEWORDS_TABLE = [
  290. // L M Q H
  291. 7, 10, 13, 17,
  292. 10, 16, 22, 28,
  293. 15, 26, 36, 44,
  294. 20, 36, 52, 64,
  295. 26, 48, 72, 88,
  296. 36, 64, 96, 112,
  297. 40, 72, 108, 130,
  298. 48, 88, 132, 156,
  299. 60, 110, 160, 192,
  300. 72, 130, 192, 224,
  301. 80, 150, 224, 264,
  302. 96, 176, 260, 308,
  303. 104, 198, 288, 352,
  304. 120, 216, 320, 384,
  305. 132, 240, 360, 432,
  306. 144, 280, 408, 480,
  307. 168, 308, 448, 532,
  308. 180, 338, 504, 588,
  309. 196, 364, 546, 650,
  310. 224, 416, 600, 700,
  311. 224, 442, 644, 750,
  312. 252, 476, 690, 816,
  313. 270, 504, 750, 900,
  314. 300, 560, 810, 960,
  315. 312, 588, 870, 1050,
  316. 336, 644, 952, 1110,
  317. 360, 700, 1020, 1200,
  318. 390, 728, 1050, 1260,
  319. 420, 784, 1140, 1350,
  320. 450, 812, 1200, 1440,
  321. 480, 868, 1290, 1530,
  322. 510, 924, 1350, 1620,
  323. 540, 980, 1440, 1710,
  324. 570, 1036, 1530, 1800,
  325. 570, 1064, 1590, 1890,
  326. 600, 1120, 1680, 1980,
  327. 630, 1204, 1770, 2100,
  328. 660, 1260, 1860, 2220,
  329. 720, 1316, 1950, 2310,
  330. 750, 1372, 2040, 2430
  331. ]
  332. /**
  333. * Returns the number of error correction block that the QR Code should contain
  334. * for the specified version and error correction level.
  335. *
  336. * @param {Number} version QR Code version
  337. * @param {Number} errorCorrectionLevel Error correction level
  338. * @return {Number} Number of error correction blocks
  339. */
  340. exports.getBlocksCount = function getBlocksCount (version, errorCorrectionLevel) {
  341. switch (errorCorrectionLevel) {
  342. case ECLevel.L:
  343. return EC_BLOCKS_TABLE[(version - 1) * 4 + 0]
  344. case ECLevel.M:
  345. return EC_BLOCKS_TABLE[(version - 1) * 4 + 1]
  346. case ECLevel.Q:
  347. return EC_BLOCKS_TABLE[(version - 1) * 4 + 2]
  348. case ECLevel.H:
  349. return EC_BLOCKS_TABLE[(version - 1) * 4 + 3]
  350. default:
  351. return undefined
  352. }
  353. }
  354. /**
  355. * Returns the number of error correction codewords to use for the specified
  356. * version and error correction level.
  357. *
  358. * @param {Number} version QR Code version
  359. * @param {Number} errorCorrectionLevel Error correction level
  360. * @return {Number} Number of error correction codewords
  361. */
  362. exports.getTotalCodewordsCount = function getTotalCodewordsCount (version, errorCorrectionLevel) {
  363. switch (errorCorrectionLevel) {
  364. case ECLevel.L:
  365. return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0]
  366. case ECLevel.M:
  367. return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1]
  368. case ECLevel.Q:
  369. return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2]
  370. case ECLevel.H:
  371. return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3]
  372. default:
  373. return undefined
  374. }
  375. }
  376. },{"./error-correction-level":8}],8:[function(require,module,exports){
  377. exports.L = { bit: 1 }
  378. exports.M = { bit: 0 }
  379. exports.Q = { bit: 3 }
  380. exports.H = { bit: 2 }
  381. function fromString (string) {
  382. if (typeof string !== 'string') {
  383. throw new Error('Param is not a string')
  384. }
  385. var lcStr = string.toLowerCase()
  386. switch (lcStr) {
  387. case 'l':
  388. case 'low':
  389. return exports.L
  390. case 'm':
  391. case 'medium':
  392. return exports.M
  393. case 'q':
  394. case 'quartile':
  395. return exports.Q
  396. case 'h':
  397. case 'high':
  398. return exports.H
  399. default:
  400. throw new Error('Unknown EC Level: ' + string)
  401. }
  402. }
  403. exports.isValid = function isValid (level) {
  404. return level && typeof level.bit !== 'undefined' &&
  405. level.bit >= 0 && level.bit < 4
  406. }
  407. exports.from = function from (value, defaultValue) {
  408. if (exports.isValid(value)) {
  409. return value
  410. }
  411. try {
  412. return fromString(value)
  413. } catch (e) {
  414. return defaultValue
  415. }
  416. }
  417. },{}],9:[function(require,module,exports){
  418. var getSymbolSize = require('./utils').getSymbolSize
  419. var FINDER_PATTERN_SIZE = 7
  420. /**
  421. * Returns an array containing the positions of each finder pattern.
  422. * Each array's element represent the top-left point of the pattern as (x, y) coordinates
  423. *
  424. * @param {Number} version QR Code version
  425. * @return {Array} Array of coordinates
  426. */
  427. exports.getPositions = function getPositions (version) {
  428. var size = getSymbolSize(version)
  429. return [
  430. // top-left
  431. [0, 0],
  432. // top-right
  433. [size - FINDER_PATTERN_SIZE, 0],
  434. // bottom-left
  435. [0, size - FINDER_PATTERN_SIZE]
  436. ]
  437. }
  438. },{"./utils":21}],10:[function(require,module,exports){
  439. var Utils = require('./utils')
  440. var G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0)
  441. var G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1)
  442. var G15_BCH = Utils.getBCHDigit(G15)
  443. /**
  444. * Returns format information with relative error correction bits
  445. *
  446. * The format information is a 15-bit sequence containing 5 data bits,
  447. * with 10 error correction bits calculated using the (15, 5) BCH code.
  448. *
  449. * @param {Number} errorCorrectionLevel Error correction level
  450. * @param {Number} mask Mask pattern
  451. * @return {Number} Encoded format information bits
  452. */
  453. exports.getEncodedBits = function getEncodedBits (errorCorrectionLevel, mask) {
  454. var data = ((errorCorrectionLevel.bit << 3) | mask)
  455. var d = data << 10
  456. while (Utils.getBCHDigit(d) - G15_BCH >= 0) {
  457. d ^= (G15 << (Utils.getBCHDigit(d) - G15_BCH))
  458. }
  459. // xor final data with mask pattern in order to ensure that
  460. // no combination of Error Correction Level and data mask pattern
  461. // will result in an all-zero data string
  462. return ((data << 10) | d) ^ G15_MASK
  463. }
  464. },{"./utils":21}],11:[function(require,module,exports){
  465. var BufferUtil = require('../utils/buffer')
  466. var EXP_TABLE = BufferUtil.alloc(512)
  467. var LOG_TABLE = BufferUtil.alloc(256)
  468. /**
  469. * Precompute the log and anti-log tables for faster computation later
  470. *
  471. * For each possible value in the galois field 2^8, we will pre-compute
  472. * the logarithm and anti-logarithm (exponential) of this value
  473. *
  474. * ref {@link https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Introduction_to_mathematical_fields}
  475. */
  476. ;(function initTables () {
  477. var x = 1
  478. for (var i = 0; i < 255; i++) {
  479. EXP_TABLE[i] = x
  480. LOG_TABLE[x] = i
  481. x <<= 1 // multiply by 2
  482. // The QR code specification says to use byte-wise modulo 100011101 arithmetic.
  483. // This means that when a number is 256 or larger, it should be XORed with 0x11D.
  484. if (x & 0x100) { // similar to x >= 256, but a lot faster (because 0x100 == 256)
  485. x ^= 0x11D
  486. }
  487. }
  488. // Optimization: double the size of the anti-log table so that we don't need to mod 255 to
  489. // stay inside the bounds (because we will mainly use this table for the multiplication of
  490. // two GF numbers, no more).
  491. // @see {@link mul}
  492. for (i = 255; i < 512; i++) {
  493. EXP_TABLE[i] = EXP_TABLE[i - 255]
  494. }
  495. }())
  496. /**
  497. * Returns log value of n inside Galois Field
  498. *
  499. * @param {Number} n
  500. * @return {Number}
  501. */
  502. exports.log = function log (n) {
  503. if (n < 1) throw new Error('log(' + n + ')')
  504. return LOG_TABLE[n]
  505. }
  506. /**
  507. * Returns anti-log value of n inside Galois Field
  508. *
  509. * @param {Number} n
  510. * @return {Number}
  511. */
  512. exports.exp = function exp (n) {
  513. return EXP_TABLE[n]
  514. }
  515. /**
  516. * Multiplies two number inside Galois Field
  517. *
  518. * @param {Number} x
  519. * @param {Number} y
  520. * @return {Number}
  521. */
  522. exports.mul = function mul (x, y) {
  523. if (x === 0 || y === 0) return 0
  524. // should be EXP_TABLE[(LOG_TABLE[x] + LOG_TABLE[y]) % 255] if EXP_TABLE wasn't oversized
  525. // @see {@link initTables}
  526. return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]]
  527. }
  528. },{"../utils/buffer":28}],12:[function(require,module,exports){
  529. var Mode = require('./mode')
  530. var Utils = require('./utils')
  531. function KanjiData (data) {
  532. this.mode = Mode.KANJI
  533. this.data = data
  534. }
  535. KanjiData.getBitsLength = function getBitsLength (length) {
  536. return length * 13
  537. }
  538. KanjiData.prototype.getLength = function getLength () {
  539. return this.data.length
  540. }
  541. KanjiData.prototype.getBitsLength = function getBitsLength () {
  542. return KanjiData.getBitsLength(this.data.length)
  543. }
  544. KanjiData.prototype.write = function (bitBuffer) {
  545. var i
  546. // In the Shift JIS system, Kanji characters are represented by a two byte combination.
  547. // These byte values are shifted from the JIS X 0208 values.
  548. // JIS X 0208 gives details of the shift coded representation.
  549. for (i = 0; i < this.data.length; i++) {
  550. var value = Utils.toSJIS(this.data[i])
  551. // For characters with Shift JIS values from 0x8140 to 0x9FFC:
  552. if (value >= 0x8140 && value <= 0x9FFC) {
  553. // Subtract 0x8140 from Shift JIS value
  554. value -= 0x8140
  555. // For characters with Shift JIS values from 0xE040 to 0xEBBF
  556. } else if (value >= 0xE040 && value <= 0xEBBF) {
  557. // Subtract 0xC140 from Shift JIS value
  558. value -= 0xC140
  559. } else {
  560. throw new Error(
  561. 'Invalid SJIS character: ' + this.data[i] + '\n' +
  562. 'Make sure your charset is UTF-8')
  563. }
  564. // Multiply most significant byte of result by 0xC0
  565. // and add least significant byte to product
  566. value = (((value >>> 8) & 0xff) * 0xC0) + (value & 0xff)
  567. // Convert result to a 13-bit binary string
  568. bitBuffer.put(value, 13)
  569. }
  570. }
  571. module.exports = KanjiData
  572. },{"./mode":14,"./utils":21}],13:[function(require,module,exports){
  573. /**
  574. * Data mask pattern reference
  575. * @type {Object}
  576. */
  577. exports.Patterns = {
  578. PATTERN000: 0,
  579. PATTERN001: 1,
  580. PATTERN010: 2,
  581. PATTERN011: 3,
  582. PATTERN100: 4,
  583. PATTERN101: 5,
  584. PATTERN110: 6,
  585. PATTERN111: 7
  586. }
  587. /**
  588. * Weighted penalty scores for the undesirable features
  589. * @type {Object}
  590. */
  591. var PenaltyScores = {
  592. N1: 3,
  593. N2: 3,
  594. N3: 40,
  595. N4: 10
  596. }
  597. /**
  598. * Check if mask pattern value is valid
  599. *
  600. * @param {Number} mask Mask pattern
  601. * @return {Boolean} true if valid, false otherwise
  602. */
  603. exports.isValid = function isValid (mask) {
  604. return mask != null && mask !== '' && !isNaN(mask) && mask >= 0 && mask <= 7
  605. }
  606. /**
  607. * Returns mask pattern from a value.
  608. * If value is not valid, returns undefined
  609. *
  610. * @param {Number|String} value Mask pattern value
  611. * @return {Number} Valid mask pattern or undefined
  612. */
  613. exports.from = function from (value) {
  614. return exports.isValid(value) ? parseInt(value, 10) : undefined
  615. }
  616. /**
  617. * Find adjacent modules in row/column with the same color
  618. * and assign a penalty value.
  619. *
  620. * Points: N1 + i
  621. * i is the amount by which the number of adjacent modules of the same color exceeds 5
  622. */
  623. exports.getPenaltyN1 = function getPenaltyN1 (data) {
  624. var size = data.size
  625. var points = 0
  626. var sameCountCol = 0
  627. var sameCountRow = 0
  628. var lastCol = null
  629. var lastRow = null
  630. for (var row = 0; row < size; row++) {
  631. sameCountCol = sameCountRow = 0
  632. lastCol = lastRow = null
  633. for (var col = 0; col < size; col++) {
  634. var module = data.get(row, col)
  635. if (module === lastCol) {
  636. sameCountCol++
  637. } else {
  638. if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5)
  639. lastCol = module
  640. sameCountCol = 1
  641. }
  642. module = data.get(col, row)
  643. if (module === lastRow) {
  644. sameCountRow++
  645. } else {
  646. if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5)
  647. lastRow = module
  648. sameCountRow = 1
  649. }
  650. }
  651. if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5)
  652. if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5)
  653. }
  654. return points
  655. }
  656. /**
  657. * Find 2x2 blocks with the same color and assign a penalty value
  658. *
  659. * Points: N2 * (m - 1) * (n - 1)
  660. */
  661. exports.getPenaltyN2 = function getPenaltyN2 (data) {
  662. var size = data.size
  663. var points = 0
  664. for (var row = 0; row < size - 1; row++) {
  665. for (var col = 0; col < size - 1; col++) {
  666. var last = data.get(row, col) +
  667. data.get(row, col + 1) +
  668. data.get(row + 1, col) +
  669. data.get(row + 1, col + 1)
  670. if (last === 4 || last === 0) points++
  671. }
  672. }
  673. return points * PenaltyScores.N2
  674. }
  675. /**
  676. * Find 1:1:3:1:1 ratio (dark:light:dark:light:dark) pattern in row/column,
  677. * preceded or followed by light area 4 modules wide
  678. *
  679. * Points: N3 * number of pattern found
  680. */
  681. exports.getPenaltyN3 = function getPenaltyN3 (data) {
  682. var size = data.size
  683. var points = 0
  684. var bitsCol = 0
  685. var bitsRow = 0
  686. for (var row = 0; row < size; row++) {
  687. bitsCol = bitsRow = 0
  688. for (var col = 0; col < size; col++) {
  689. bitsCol = ((bitsCol << 1) & 0x7FF) | data.get(row, col)
  690. if (col >= 10 && (bitsCol === 0x5D0 || bitsCol === 0x05D)) points++
  691. bitsRow = ((bitsRow << 1) & 0x7FF) | data.get(col, row)
  692. if (col >= 10 && (bitsRow === 0x5D0 || bitsRow === 0x05D)) points++
  693. }
  694. }
  695. return points * PenaltyScores.N3
  696. }
  697. /**
  698. * Calculate proportion of dark modules in entire symbol
  699. *
  700. * Points: N4 * k
  701. *
  702. * k is the rating of the deviation of the proportion of dark modules
  703. * in the symbol from 50% in steps of 5%
  704. */
  705. exports.getPenaltyN4 = function getPenaltyN4 (data) {
  706. var darkCount = 0
  707. var modulesCount = data.data.length
  708. for (var i = 0; i < modulesCount; i++) darkCount += data.data[i]
  709. var k = Math.abs(Math.ceil((darkCount * 100 / modulesCount) / 5) - 10)
  710. return k * PenaltyScores.N4
  711. }
  712. /**
  713. * Return mask value at given position
  714. *
  715. * @param {Number} maskPattern Pattern reference value
  716. * @param {Number} i Row
  717. * @param {Number} j Column
  718. * @return {Boolean} Mask value
  719. */
  720. function getMaskAt (maskPattern, i, j) {
  721. switch (maskPattern) {
  722. case exports.Patterns.PATTERN000: return (i + j) % 2 === 0
  723. case exports.Patterns.PATTERN001: return i % 2 === 0
  724. case exports.Patterns.PATTERN010: return j % 3 === 0
  725. case exports.Patterns.PATTERN011: return (i + j) % 3 === 0
  726. case exports.Patterns.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0
  727. case exports.Patterns.PATTERN101: return (i * j) % 2 + (i * j) % 3 === 0
  728. case exports.Patterns.PATTERN110: return ((i * j) % 2 + (i * j) % 3) % 2 === 0
  729. case exports.Patterns.PATTERN111: return ((i * j) % 3 + (i + j) % 2) % 2 === 0
  730. default: throw new Error('bad maskPattern:' + maskPattern)
  731. }
  732. }
  733. /**
  734. * Apply a mask pattern to a BitMatrix
  735. *
  736. * @param {Number} pattern Pattern reference number
  737. * @param {BitMatrix} data BitMatrix data
  738. */
  739. exports.applyMask = function applyMask (pattern, data) {
  740. var size = data.size
  741. for (var col = 0; col < size; col++) {
  742. for (var row = 0; row < size; row++) {
  743. if (data.isReserved(row, col)) continue
  744. data.xor(row, col, getMaskAt(pattern, row, col))
  745. }
  746. }
  747. }
  748. /**
  749. * Returns the best mask pattern for data
  750. *
  751. * @param {BitMatrix} data
  752. * @return {Number} Mask pattern reference number
  753. */
  754. exports.getBestMask = function getBestMask (data, setupFormatFunc) {
  755. var numPatterns = Object.keys(exports.Patterns).length
  756. var bestPattern = 0
  757. var lowerPenalty = Infinity
  758. for (var p = 0; p < numPatterns; p++) {
  759. setupFormatFunc(p)
  760. exports.applyMask(p, data)
  761. // Calculate penalty
  762. var penalty =
  763. exports.getPenaltyN1(data) +
  764. exports.getPenaltyN2(data) +
  765. exports.getPenaltyN3(data) +
  766. exports.getPenaltyN4(data)
  767. // Undo previously applied mask
  768. exports.applyMask(p, data)
  769. if (penalty < lowerPenalty) {
  770. lowerPenalty = penalty
  771. bestPattern = p
  772. }
  773. }
  774. return bestPattern
  775. }
  776. },{}],14:[function(require,module,exports){
  777. var VersionCheck = require('./version-check')
  778. var Regex = require('./regex')
  779. /**
  780. * Numeric mode encodes data from the decimal digit set (0 - 9)
  781. * (byte values 30HEX to 39HEX).
  782. * Normally, 3 data characters are represented by 10 bits.
  783. *
  784. * @type {Object}
  785. */
  786. exports.NUMERIC = {
  787. id: 'Numeric',
  788. bit: 1 << 0,
  789. ccBits: [10, 12, 14]
  790. }
  791. /**
  792. * Alphanumeric mode encodes data from a set of 45 characters,
  793. * i.e. 10 numeric digits (0 - 9),
  794. * 26 alphabetic characters (A - Z),
  795. * and 9 symbols (SP, $, %, *, +, -, ., /, :).
  796. * Normally, two input characters are represented by 11 bits.
  797. *
  798. * @type {Object}
  799. */
  800. exports.ALPHANUMERIC = {
  801. id: 'Alphanumeric',
  802. bit: 1 << 1,
  803. ccBits: [9, 11, 13]
  804. }
  805. /**
  806. * In byte mode, data is encoded at 8 bits per character.
  807. *
  808. * @type {Object}
  809. */
  810. exports.BYTE = {
  811. id: 'Byte',
  812. bit: 1 << 2,
  813. ccBits: [8, 16, 16]
  814. }
  815. /**
  816. * The Kanji mode efficiently encodes Kanji characters in accordance with
  817. * the Shift JIS system based on JIS X 0208.
  818. * The Shift JIS values are shifted from the JIS X 0208 values.
  819. * JIS X 0208 gives details of the shift coded representation.
  820. * Each two-byte character value is compacted to a 13-bit binary codeword.
  821. *
  822. * @type {Object}
  823. */
  824. exports.KANJI = {
  825. id: 'Kanji',
  826. bit: 1 << 3,
  827. ccBits: [8, 10, 12]
  828. }
  829. /**
  830. * Mixed mode will contain a sequences of data in a combination of any of
  831. * the modes described above
  832. *
  833. * @type {Object}
  834. */
  835. exports.MIXED = {
  836. bit: -1
  837. }
  838. /**
  839. * Returns the number of bits needed to store the data length
  840. * according to QR Code specifications.
  841. *
  842. * @param {Mode} mode Data mode
  843. * @param {Number} version QR Code version
  844. * @return {Number} Number of bits
  845. */
  846. exports.getCharCountIndicator = function getCharCountIndicator (mode, version) {
  847. if (!mode.ccBits) throw new Error('Invalid mode: ' + mode)
  848. if (!VersionCheck.isValid(version)) {
  849. throw new Error('Invalid version: ' + version)
  850. }
  851. if (version >= 1 && version < 10) return mode.ccBits[0]
  852. else if (version < 27) return mode.ccBits[1]
  853. return mode.ccBits[2]
  854. }
  855. /**
  856. * Returns the most efficient mode to store the specified data
  857. *
  858. * @param {String} dataStr Input data string
  859. * @return {Mode} Best mode
  860. */
  861. exports.getBestModeForData = function getBestModeForData (dataStr) {
  862. if (Regex.testNumeric(dataStr)) return exports.NUMERIC
  863. else if (Regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC
  864. else if (Regex.testKanji(dataStr)) return exports.KANJI
  865. else return exports.BYTE
  866. }
  867. /**
  868. * Return mode name as string
  869. *
  870. * @param {Mode} mode Mode object
  871. * @returns {String} Mode name
  872. */
  873. exports.toString = function toString (mode) {
  874. if (mode && mode.id) return mode.id
  875. throw new Error('Invalid mode')
  876. }
  877. /**
  878. * Check if input param is a valid mode object
  879. *
  880. * @param {Mode} mode Mode object
  881. * @returns {Boolean} True if valid mode, false otherwise
  882. */
  883. exports.isValid = function isValid (mode) {
  884. return mode && mode.bit && mode.ccBits
  885. }
  886. /**
  887. * Get mode object from its name
  888. *
  889. * @param {String} string Mode name
  890. * @returns {Mode} Mode object
  891. */
  892. function fromString (string) {
  893. if (typeof string !== 'string') {
  894. throw new Error('Param is not a string')
  895. }
  896. var lcStr = string.toLowerCase()
  897. switch (lcStr) {
  898. case 'numeric':
  899. return exports.NUMERIC
  900. case 'alphanumeric':
  901. return exports.ALPHANUMERIC
  902. case 'kanji':
  903. return exports.KANJI
  904. case 'byte':
  905. return exports.BYTE
  906. default:
  907. throw new Error('Unknown mode: ' + string)
  908. }
  909. }
  910. /**
  911. * Returns mode from a value.
  912. * If value is not a valid mode, returns defaultValue
  913. *
  914. * @param {Mode|String} value Encoding mode
  915. * @param {Mode} defaultValue Fallback value
  916. * @return {Mode} Encoding mode
  917. */
  918. exports.from = function from (value, defaultValue) {
  919. if (exports.isValid(value)) {
  920. return value
  921. }
  922. try {
  923. return fromString(value)
  924. } catch (e) {
  925. return defaultValue
  926. }
  927. }
  928. },{"./regex":19,"./version-check":22}],15:[function(require,module,exports){
  929. var Mode = require('./mode')
  930. function NumericData (data) {
  931. this.mode = Mode.NUMERIC
  932. this.data = data.toString()
  933. }
  934. NumericData.getBitsLength = function getBitsLength (length) {
  935. return 10 * Math.floor(length / 3) + ((length % 3) ? ((length % 3) * 3 + 1) : 0)
  936. }
  937. NumericData.prototype.getLength = function getLength () {
  938. return this.data.length
  939. }
  940. NumericData.prototype.getBitsLength = function getBitsLength () {
  941. return NumericData.getBitsLength(this.data.length)
  942. }
  943. NumericData.prototype.write = function write (bitBuffer) {
  944. var i, group, value
  945. // The input data string is divided into groups of three digits,
  946. // and each group is converted to its 10-bit binary equivalent.
  947. for (i = 0; i + 3 <= this.data.length; i += 3) {
  948. group = this.data.substr(i, 3)
  949. value = parseInt(group, 10)
  950. bitBuffer.put(value, 10)
  951. }
  952. // If the number of input digits is not an exact multiple of three,
  953. // the final one or two digits are converted to 4 or 7 bits respectively.
  954. var remainingNum = this.data.length - i
  955. if (remainingNum > 0) {
  956. group = this.data.substr(i)
  957. value = parseInt(group, 10)
  958. bitBuffer.put(value, remainingNum * 3 + 1)
  959. }
  960. }
  961. module.exports = NumericData
  962. },{"./mode":14}],16:[function(require,module,exports){
  963. var BufferUtil = require('../utils/buffer')
  964. var GF = require('./galois-field')
  965. /**
  966. * Multiplies two polynomials inside Galois Field
  967. *
  968. * @param {Buffer} p1 Polynomial
  969. * @param {Buffer} p2 Polynomial
  970. * @return {Buffer} Product of p1 and p2
  971. */
  972. exports.mul = function mul (p1, p2) {
  973. var coeff = BufferUtil.alloc(p1.length + p2.length - 1)
  974. for (var i = 0; i < p1.length; i++) {
  975. for (var j = 0; j < p2.length; j++) {
  976. coeff[i + j] ^= GF.mul(p1[i], p2[j])
  977. }
  978. }
  979. return coeff
  980. }
  981. /**
  982. * Calculate the remainder of polynomials division
  983. *
  984. * @param {Buffer} divident Polynomial
  985. * @param {Buffer} divisor Polynomial
  986. * @return {Buffer} Remainder
  987. */
  988. exports.mod = function mod (divident, divisor) {
  989. var result = BufferUtil.from(divident)
  990. while ((result.length - divisor.length) >= 0) {
  991. var coeff = result[0]
  992. for (var i = 0; i < divisor.length; i++) {
  993. result[i] ^= GF.mul(divisor[i], coeff)
  994. }
  995. // remove all zeros from buffer head
  996. var offset = 0
  997. while (offset < result.length && result[offset] === 0) offset++
  998. result = result.slice(offset)
  999. }
  1000. return result
  1001. }
  1002. /**
  1003. * Generate an irreducible generator polynomial of specified degree
  1004. * (used by Reed-Solomon encoder)
  1005. *
  1006. * @param {Number} degree Degree of the generator polynomial
  1007. * @return {Buffer} Buffer containing polynomial coefficients
  1008. */
  1009. exports.generateECPolynomial = function generateECPolynomial (degree) {
  1010. var poly = BufferUtil.from([1])
  1011. for (var i = 0; i < degree; i++) {
  1012. poly = exports.mul(poly, [1, GF.exp(i)])
  1013. }
  1014. return poly
  1015. }
  1016. },{"../utils/buffer":28,"./galois-field":11}],17:[function(require,module,exports){
  1017. var BufferUtil = require('../utils/buffer')
  1018. var Utils = require('./utils')
  1019. var ECLevel = require('./error-correction-level')
  1020. var BitBuffer = require('./bit-buffer')
  1021. var BitMatrix = require('./bit-matrix')
  1022. var AlignmentPattern = require('./alignment-pattern')
  1023. var FinderPattern = require('./finder-pattern')
  1024. var MaskPattern = require('./mask-pattern')
  1025. var ECCode = require('./error-correction-code')
  1026. var ReedSolomonEncoder = require('./reed-solomon-encoder')
  1027. var Version = require('./version')
  1028. var FormatInfo = require('./format-info')
  1029. var Mode = require('./mode')
  1030. var Segments = require('./segments')
  1031. var isArray = require('isarray')
  1032. /**
  1033. * QRCode for JavaScript
  1034. *
  1035. * modified by Ryan Day for nodejs support
  1036. * Copyright (c) 2011 Ryan Day
  1037. *
  1038. * Licensed under the MIT license:
  1039. * http://www.opensource.org/licenses/mit-license.php
  1040. *
  1041. //---------------------------------------------------------------------
  1042. // QRCode for JavaScript
  1043. //
  1044. // Copyright (c) 2009 Kazuhiko Arase
  1045. //
  1046. // URL: http://www.d-project.com/
  1047. //
  1048. // Licensed under the MIT license:
  1049. // http://www.opensource.org/licenses/mit-license.php
  1050. //
  1051. // The word "QR Code" is registered trademark of
  1052. // DENSO WAVE INCORPORATED
  1053. // http://www.denso-wave.com/qrcode/faqpatent-e.html
  1054. //
  1055. //---------------------------------------------------------------------
  1056. */
  1057. /**
  1058. * Add finder patterns bits to matrix
  1059. *
  1060. * @param {BitMatrix} matrix Modules matrix
  1061. * @param {Number} version QR Code version
  1062. */
  1063. function setupFinderPattern (matrix, version) {
  1064. var size = matrix.size
  1065. var pos = FinderPattern.getPositions(version)
  1066. for (var i = 0; i < pos.length; i++) {
  1067. var row = pos[i][0]
  1068. var col = pos[i][1]
  1069. for (var r = -1; r <= 7; r++) {
  1070. if (row + r <= -1 || size <= row + r) continue
  1071. for (var c = -1; c <= 7; c++) {
  1072. if (col + c <= -1 || size <= col + c) continue
  1073. if ((r >= 0 && r <= 6 && (c === 0 || c === 6)) ||
  1074. (c >= 0 && c <= 6 && (r === 0 || r === 6)) ||
  1075. (r >= 2 && r <= 4 && c >= 2 && c <= 4)) {
  1076. matrix.set(row + r, col + c, true, true)
  1077. } else {
  1078. matrix.set(row + r, col + c, false, true)
  1079. }
  1080. }
  1081. }
  1082. }
  1083. }
  1084. /**
  1085. * Add timing pattern bits to matrix
  1086. *
  1087. * Note: this function must be called before {@link setupAlignmentPattern}
  1088. *
  1089. * @param {BitMatrix} matrix Modules matrix
  1090. */
  1091. function setupTimingPattern (matrix) {
  1092. var size = matrix.size
  1093. for (var r = 8; r < size - 8; r++) {
  1094. var value = r % 2 === 0
  1095. matrix.set(r, 6, value, true)
  1096. matrix.set(6, r, value, true)
  1097. }
  1098. }
  1099. /**
  1100. * Add alignment patterns bits to matrix
  1101. *
  1102. * Note: this function must be called after {@link setupTimingPattern}
  1103. *
  1104. * @param {BitMatrix} matrix Modules matrix
  1105. * @param {Number} version QR Code version
  1106. */
  1107. function setupAlignmentPattern (matrix, version) {
  1108. var pos = AlignmentPattern.getPositions(version)
  1109. for (var i = 0; i < pos.length; i++) {
  1110. var row = pos[i][0]
  1111. var col = pos[i][1]
  1112. for (var r = -2; r <= 2; r++) {
  1113. for (var c = -2; c <= 2; c++) {
  1114. if (r === -2 || r === 2 || c === -2 || c === 2 ||
  1115. (r === 0 && c === 0)) {
  1116. matrix.set(row + r, col + c, true, true)
  1117. } else {
  1118. matrix.set(row + r, col + c, false, true)
  1119. }
  1120. }
  1121. }
  1122. }
  1123. }
  1124. /**
  1125. * Add version info bits to matrix
  1126. *
  1127. * @param {BitMatrix} matrix Modules matrix
  1128. * @param {Number} version QR Code version
  1129. */
  1130. function setupVersionInfo (matrix, version) {
  1131. var size = matrix.size
  1132. var bits = Version.getEncodedBits(version)
  1133. var row, col, mod
  1134. for (var i = 0; i < 18; i++) {
  1135. row = Math.floor(i / 3)
  1136. col = i % 3 + size - 8 - 3
  1137. mod = ((bits >> i) & 1) === 1
  1138. matrix.set(row, col, mod, true)
  1139. matrix.set(col, row, mod, true)
  1140. }
  1141. }
  1142. /**
  1143. * Add format info bits to matrix
  1144. *
  1145. * @param {BitMatrix} matrix Modules matrix
  1146. * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
  1147. * @param {Number} maskPattern Mask pattern reference value
  1148. */
  1149. function setupFormatInfo (matrix, errorCorrectionLevel, maskPattern) {
  1150. var size = matrix.size
  1151. var bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern)
  1152. var i, mod
  1153. for (i = 0; i < 15; i++) {
  1154. mod = ((bits >> i) & 1) === 1
  1155. // vertical
  1156. if (i < 6) {
  1157. matrix.set(i, 8, mod, true)
  1158. } else if (i < 8) {
  1159. matrix.set(i + 1, 8, mod, true)
  1160. } else {
  1161. matrix.set(size - 15 + i, 8, mod, true)
  1162. }
  1163. // horizontal
  1164. if (i < 8) {
  1165. matrix.set(8, size - i - 1, mod, true)
  1166. } else if (i < 9) {
  1167. matrix.set(8, 15 - i - 1 + 1, mod, true)
  1168. } else {
  1169. matrix.set(8, 15 - i - 1, mod, true)
  1170. }
  1171. }
  1172. // fixed module
  1173. matrix.set(size - 8, 8, 1, true)
  1174. }
  1175. /**
  1176. * Add encoded data bits to matrix
  1177. *
  1178. * @param {BitMatrix} matrix Modules matrix
  1179. * @param {Buffer} data Data codewords
  1180. */
  1181. function setupData (matrix, data) {
  1182. var size = matrix.size
  1183. var inc = -1
  1184. var row = size - 1
  1185. var bitIndex = 7
  1186. var byteIndex = 0
  1187. for (var col = size - 1; col > 0; col -= 2) {
  1188. if (col === 6) col--
  1189. while (true) {
  1190. for (var c = 0; c < 2; c++) {
  1191. if (!matrix.isReserved(row, col - c)) {
  1192. var dark = false
  1193. if (byteIndex < data.length) {
  1194. dark = (((data[byteIndex] >>> bitIndex) & 1) === 1)
  1195. }
  1196. matrix.set(row, col - c, dark)
  1197. bitIndex--
  1198. if (bitIndex === -1) {
  1199. byteIndex++
  1200. bitIndex = 7
  1201. }
  1202. }
  1203. }
  1204. row += inc
  1205. if (row < 0 || size <= row) {
  1206. row -= inc
  1207. inc = -inc
  1208. break
  1209. }
  1210. }
  1211. }
  1212. }
  1213. /**
  1214. * Create encoded codewords from data input
  1215. *
  1216. * @param {Number} version QR Code version
  1217. * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
  1218. * @param {ByteData} data Data input
  1219. * @return {Buffer} Buffer containing encoded codewords
  1220. */
  1221. function createData (version, errorCorrectionLevel, segments) {
  1222. // Prepare data buffer
  1223. var buffer = new BitBuffer()
  1224. segments.forEach(function (data) {
  1225. // prefix data with mode indicator (4 bits)
  1226. buffer.put(data.mode.bit, 4)
  1227. // Prefix data with character count indicator.
  1228. // The character count indicator is a string of bits that represents the
  1229. // number of characters that are being encoded.
  1230. // The character count indicator must be placed after the mode indicator
  1231. // and must be a certain number of bits long, depending on the QR version
  1232. // and data mode
  1233. // @see {@link Mode.getCharCountIndicator}.
  1234. buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version))
  1235. // add binary data sequence to buffer
  1236. data.write(buffer)
  1237. })
  1238. // Calculate required number of bits
  1239. var totalCodewords = Utils.getSymbolTotalCodewords(version)
  1240. var ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel)
  1241. var dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8
  1242. // Add a terminator.
  1243. // If the bit string is shorter than the total number of required bits,
  1244. // a terminator of up to four 0s must be added to the right side of the string.
  1245. // If the bit string is more than four bits shorter than the required number of bits,
  1246. // add four 0s to the end.
  1247. if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {
  1248. buffer.put(0, 4)
  1249. }
  1250. // If the bit string is fewer than four bits shorter, add only the number of 0s that
  1251. // are needed to reach the required number of bits.
  1252. // After adding the terminator, if the number of bits in the string is not a multiple of 8,
  1253. // pad the string on the right with 0s to make the string's length a multiple of 8.
  1254. while (buffer.getLengthInBits() % 8 !== 0) {
  1255. buffer.putBit(0)
  1256. }
  1257. // Add pad bytes if the string is still shorter than the total number of required bits.
  1258. // Extend the buffer to fill the data capacity of the symbol corresponding to
  1259. // the Version and Error Correction Level by adding the Pad Codewords 11101100 (0xEC)
  1260. // and 00010001 (0x11) alternately.
  1261. var remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8
  1262. for (var i = 0; i < remainingByte; i++) {
  1263. buffer.put(i % 2 ? 0x11 : 0xEC, 8)
  1264. }
  1265. return createCodewords(buffer, version, errorCorrectionLevel)
  1266. }
  1267. /**
  1268. * Encode input data with Reed-Solomon and return codewords with
  1269. * relative error correction bits
  1270. *
  1271. * @param {BitBuffer} bitBuffer Data to encode
  1272. * @param {Number} version QR Code version
  1273. * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
  1274. * @return {Buffer} Buffer containing encoded codewords
  1275. */
  1276. function createCodewords (bitBuffer, version, errorCorrectionLevel) {
  1277. // Total codewords for this QR code version (Data + Error correction)
  1278. var totalCodewords = Utils.getSymbolTotalCodewords(version)
  1279. // Total number of error correction codewords
  1280. var ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel)
  1281. // Total number of data codewords
  1282. var dataTotalCodewords = totalCodewords - ecTotalCodewords
  1283. // Total number of blocks
  1284. var ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel)
  1285. // Calculate how many blocks each group should contain
  1286. var blocksInGroup2 = totalCodewords % ecTotalBlocks
  1287. var blocksInGroup1 = ecTotalBlocks - blocksInGroup2
  1288. var totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks)
  1289. var dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks)
  1290. var dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1
  1291. // Number of EC codewords is the same for both groups
  1292. var ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1
  1293. // Initialize a Reed-Solomon encoder with a generator polynomial of degree ecCount
  1294. var rs = new ReedSolomonEncoder(ecCount)
  1295. var offset = 0
  1296. var dcData = new Array(ecTotalBlocks)
  1297. var ecData = new Array(ecTotalBlocks)
  1298. var maxDataSize = 0
  1299. var buffer = BufferUtil.from(bitBuffer.buffer)
  1300. // Divide the buffer into the required number of blocks
  1301. for (var b = 0; b < ecTotalBlocks; b++) {
  1302. var dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2
  1303. // extract a block of data from buffer
  1304. dcData[b] = buffer.slice(offset, offset + dataSize)
  1305. // Calculate EC codewords for this data block
  1306. ecData[b] = rs.encode(dcData[b])
  1307. offset += dataSize
  1308. maxDataSize = Math.max(maxDataSize, dataSize)
  1309. }
  1310. // Create final data
  1311. // Interleave the data and error correction codewords from each block
  1312. var data = BufferUtil.alloc(totalCodewords)
  1313. var index = 0
  1314. var i, r
  1315. // Add data codewords
  1316. for (i = 0; i < maxDataSize; i++) {
  1317. for (r = 0; r < ecTotalBlocks; r++) {
  1318. if (i < dcData[r].length) {
  1319. data[index++] = dcData[r][i]
  1320. }
  1321. }
  1322. }
  1323. // Apped EC codewords
  1324. for (i = 0; i < ecCount; i++) {
  1325. for (r = 0; r < ecTotalBlocks; r++) {
  1326. data[index++] = ecData[r][i]
  1327. }
  1328. }
  1329. return data
  1330. }
  1331. /**
  1332. * Build QR Code symbol
  1333. *
  1334. * @param {String} data Input string
  1335. * @param {Number} version QR Code version
  1336. * @param {ErrorCorretionLevel} errorCorrectionLevel Error level
  1337. * @param {MaskPattern} maskPattern Mask pattern
  1338. * @return {Object} Object containing symbol data
  1339. */
  1340. function createSymbol (data, version, errorCorrectionLevel, maskPattern) {
  1341. var segments
  1342. if (isArray(data)) {
  1343. segments = Segments.fromArray(data)
  1344. } else if (typeof data === 'string') {
  1345. var estimatedVersion = version
  1346. if (!estimatedVersion) {
  1347. var rawSegments = Segments.rawSplit(data)
  1348. // Estimate best version that can contain raw splitted segments
  1349. estimatedVersion = Version.getBestVersionForData(rawSegments,
  1350. errorCorrectionLevel)
  1351. }
  1352. // Build optimized segments
  1353. // If estimated version is undefined, try with the highest version
  1354. segments = Segments.fromString(data, estimatedVersion || 40)
  1355. } else {
  1356. throw new Error('Invalid data')
  1357. }
  1358. // Get the min version that can contain data
  1359. var bestVersion = Version.getBestVersionForData(segments,
  1360. errorCorrectionLevel)
  1361. // If no version is found, data cannot be stored
  1362. if (!bestVersion) {
  1363. throw new Error('The amount of data is too big to be stored in a QR Code')
  1364. }
  1365. // If not specified, use min version as default
  1366. if (!version) {
  1367. version = bestVersion
  1368. // Check if the specified version can contain the data
  1369. } else if (version < bestVersion) {
  1370. throw new Error('\n' +
  1371. 'The chosen QR Code version cannot contain this amount of data.\n' +
  1372. 'Minimum version required to store current data is: ' + bestVersion + '.\n'
  1373. )
  1374. }
  1375. var dataBits = createData(version, errorCorrectionLevel, segments)
  1376. // Allocate matrix buffer
  1377. var moduleCount = Utils.getSymbolSize(version)
  1378. var modules = new BitMatrix(moduleCount)
  1379. // Add function modules
  1380. setupFinderPattern(modules, version)
  1381. setupTimingPattern(modules)
  1382. setupAlignmentPattern(modules, version)
  1383. // Add temporary dummy bits for format info just to set them as reserved.
  1384. // This is needed to prevent these bits from being masked by {@link MaskPattern.applyMask}
  1385. // since the masking operation must be performed only on the encoding region.
  1386. // These blocks will be replaced with correct values later in code.
  1387. setupFormatInfo(modules, errorCorrectionLevel, 0)
  1388. if (version >= 7) {
  1389. setupVersionInfo(modules, version)
  1390. }
  1391. // Add data codewords
  1392. setupData(modules, dataBits)
  1393. if (isNaN(maskPattern)) {
  1394. // Find best mask pattern
  1395. maskPattern = MaskPattern.getBestMask(modules,
  1396. setupFormatInfo.bind(null, modules, errorCorrectionLevel))
  1397. }
  1398. // Apply mask pattern
  1399. MaskPattern.applyMask(maskPattern, modules)
  1400. // Replace format info bits with correct values
  1401. setupFormatInfo(modules, errorCorrectionLevel, maskPattern)
  1402. return {
  1403. modules: modules,
  1404. version: version,
  1405. errorCorrectionLevel: errorCorrectionLevel,
  1406. maskPattern: maskPattern,
  1407. segments: segments
  1408. }
  1409. }
  1410. /**
  1411. * QR Code
  1412. *
  1413. * @param {String | Array} data Input data
  1414. * @param {Object} options Optional configurations
  1415. * @param {Number} options.version QR Code version
  1416. * @param {String} options.errorCorrectionLevel Error correction level
  1417. * @param {Function} options.toSJISFunc Helper func to convert utf8 to sjis
  1418. */
  1419. exports.create = function create (data, options) {
  1420. if (typeof data === 'undefined' || data === '') {
  1421. throw new Error('No input text')
  1422. }
  1423. var errorCorrectionLevel = ECLevel.M
  1424. var version
  1425. var mask
  1426. if (typeof options !== 'undefined') {
  1427. // Use higher error correction level as default
  1428. errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M)
  1429. version = Version.from(options.version)
  1430. mask = MaskPattern.from(options.maskPattern)
  1431. if (options.toSJISFunc) {
  1432. Utils.setToSJISFunction(options.toSJISFunc)
  1433. }
  1434. }
  1435. return createSymbol(data, version, errorCorrectionLevel, mask)
  1436. }
  1437. },{"../utils/buffer":28,"./alignment-pattern":2,"./bit-buffer":4,"./bit-matrix":5,"./error-correction-code":7,"./error-correction-level":8,"./finder-pattern":9,"./format-info":10,"./mask-pattern":13,"./mode":14,"./reed-solomon-encoder":18,"./segments":20,"./utils":21,"./version":23,"isarray":33}],18:[function(require,module,exports){
  1438. var BufferUtil = require('../utils/buffer')
  1439. var Polynomial = require('./polynomial')
  1440. var Buffer = require('buffer').Buffer
  1441. function ReedSolomonEncoder (degree) {
  1442. this.genPoly = undefined
  1443. this.degree = degree
  1444. if (this.degree) this.initialize(this.degree)
  1445. }
  1446. /**
  1447. * Initialize the encoder.
  1448. * The input param should correspond to the number of error correction codewords.
  1449. *
  1450. * @param {Number} degree
  1451. */
  1452. ReedSolomonEncoder.prototype.initialize = function initialize (degree) {
  1453. // create an irreducible generator polynomial
  1454. this.degree = degree
  1455. this.genPoly = Polynomial.generateECPolynomial(this.degree)
  1456. }
  1457. /**
  1458. * Encodes a chunk of data
  1459. *
  1460. * @param {Buffer} data Buffer containing input data
  1461. * @return {Buffer} Buffer containing encoded data
  1462. */
  1463. ReedSolomonEncoder.prototype.encode = function encode (data) {
  1464. if (!this.genPoly) {
  1465. throw new Error('Encoder not initialized')
  1466. }
  1467. // Calculate EC for this data block
  1468. // extends data size to data+genPoly size
  1469. var pad = BufferUtil.alloc(this.degree)
  1470. var paddedData = Buffer.concat([data, pad], data.length + this.degree)
  1471. // The error correction codewords are the remainder after dividing the data codewords
  1472. // by a generator polynomial
  1473. var remainder = Polynomial.mod(paddedData, this.genPoly)
  1474. // return EC data blocks (last n byte, where n is the degree of genPoly)
  1475. // If coefficients number in remainder are less than genPoly degree,
  1476. // pad with 0s to the left to reach the needed number of coefficients
  1477. var start = this.degree - remainder.length
  1478. if (start > 0) {
  1479. var buff = BufferUtil.alloc(this.degree)
  1480. remainder.copy(buff, start)
  1481. return buff
  1482. }
  1483. return remainder
  1484. }
  1485. module.exports = ReedSolomonEncoder
  1486. },{"../utils/buffer":28,"./polynomial":16,"buffer":30}],19:[function(require,module,exports){
  1487. var numeric = '[0-9]+'
  1488. var alphanumeric = '[A-Z $%*+\\-./:]+'
  1489. var kanji = '(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|' +
  1490. '[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|' +
  1491. '[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|' +
  1492. '[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+'
  1493. kanji = kanji.replace(/u/g, '\\u')
  1494. var byte = '(?:(?![A-Z0-9 $%*+\\-./:]|' + kanji + ')(?:.|[\r\n]))+'
  1495. exports.KANJI = new RegExp(kanji, 'g')
  1496. exports.BYTE_KANJI = new RegExp('[^A-Z0-9 $%*+\\-./:]+', 'g')
  1497. exports.BYTE = new RegExp(byte, 'g')
  1498. exports.NUMERIC = new RegExp(numeric, 'g')
  1499. exports.ALPHANUMERIC = new RegExp(alphanumeric, 'g')
  1500. var TEST_KANJI = new RegExp('^' + kanji + '$')
  1501. var TEST_NUMERIC = new RegExp('^' + numeric + '$')
  1502. var TEST_ALPHANUMERIC = new RegExp('^[A-Z0-9 $%*+\\-./:]+$')
  1503. exports.testKanji = function testKanji (str) {
  1504. return TEST_KANJI.test(str)
  1505. }
  1506. exports.testNumeric = function testNumeric (str) {
  1507. return TEST_NUMERIC.test(str)
  1508. }
  1509. exports.testAlphanumeric = function testAlphanumeric (str) {
  1510. return TEST_ALPHANUMERIC.test(str)
  1511. }
  1512. },{}],20:[function(require,module,exports){
  1513. var Mode = require('./mode')
  1514. var NumericData = require('./numeric-data')
  1515. var AlphanumericData = require('./alphanumeric-data')
  1516. var ByteData = require('./byte-data')
  1517. var KanjiData = require('./kanji-data')
  1518. var Regex = require('./regex')
  1519. var Utils = require('./utils')
  1520. var dijkstra = require('dijkstrajs')
  1521. /**
  1522. * Returns UTF8 byte length
  1523. *
  1524. * @param {String} str Input string
  1525. * @return {Number} Number of byte
  1526. */
  1527. function getStringByteLength (str) {
  1528. return unescape(encodeURIComponent(str)).length
  1529. }
  1530. /**
  1531. * Get a list of segments of the specified mode
  1532. * from a string
  1533. *
  1534. * @param {Mode} mode Segment mode
  1535. * @param {String} str String to process
  1536. * @return {Array} Array of object with segments data
  1537. */
  1538. function getSegments (regex, mode, str) {
  1539. var segments = []
  1540. var result
  1541. while ((result = regex.exec(str)) !== null) {
  1542. segments.push({
  1543. data: result[0],
  1544. index: result.index,
  1545. mode: mode,
  1546. length: result[0].length
  1547. })
  1548. }
  1549. return segments
  1550. }
  1551. /**
  1552. * Extracts a series of segments with the appropriate
  1553. * modes from a string
  1554. *
  1555. * @param {String} dataStr Input string
  1556. * @return {Array} Array of object with segments data
  1557. */
  1558. function getSegmentsFromString (dataStr) {
  1559. var numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr)
  1560. var alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr)
  1561. var byteSegs
  1562. var kanjiSegs
  1563. if (Utils.isKanjiModeEnabled()) {
  1564. byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr)
  1565. kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr)
  1566. } else {
  1567. byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr)
  1568. kanjiSegs = []
  1569. }
  1570. var segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs)
  1571. return segs
  1572. .sort(function (s1, s2) {
  1573. return s1.index - s2.index
  1574. })
  1575. .map(function (obj) {
  1576. return {
  1577. data: obj.data,
  1578. mode: obj.mode,
  1579. length: obj.length
  1580. }
  1581. })
  1582. }
  1583. /**
  1584. * Returns how many bits are needed to encode a string of
  1585. * specified length with the specified mode
  1586. *
  1587. * @param {Number} length String length
  1588. * @param {Mode} mode Segment mode
  1589. * @return {Number} Bit length
  1590. */
  1591. function getSegmentBitsLength (length, mode) {
  1592. switch (mode) {
  1593. case Mode.NUMERIC:
  1594. return NumericData.getBitsLength(length)
  1595. case Mode.ALPHANUMERIC:
  1596. return AlphanumericData.getBitsLength(length)
  1597. case Mode.KANJI:
  1598. return KanjiData.getBitsLength(length)
  1599. case Mode.BYTE:
  1600. return ByteData.getBitsLength(length)
  1601. }
  1602. }
  1603. /**
  1604. * Merges adjacent segments which have the same mode
  1605. *
  1606. * @param {Array} segs Array of object with segments data
  1607. * @return {Array} Array of object with segments data
  1608. */
  1609. function mergeSegments (segs) {
  1610. return segs.reduce(function (acc, curr) {
  1611. var prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null
  1612. if (prevSeg && prevSeg.mode === curr.mode) {
  1613. acc[acc.length - 1].data += curr.data
  1614. return acc
  1615. }
  1616. acc.push(curr)
  1617. return acc
  1618. }, [])
  1619. }
  1620. /**
  1621. * Generates a list of all possible nodes combination which
  1622. * will be used to build a segments graph.
  1623. *
  1624. * Nodes are divided by groups. Each group will contain a list of all the modes
  1625. * in which is possible to encode the given text.
  1626. *
  1627. * For example the text '12345' can be encoded as Numeric, Alphanumeric or Byte.
  1628. * The group for '12345' will contain then 3 objects, one for each
  1629. * possible encoding mode.
  1630. *
  1631. * Each node represents a possible segment.
  1632. *
  1633. * @param {Array} segs Array of object with segments data
  1634. * @return {Array} Array of object with segments data
  1635. */
  1636. function buildNodes (segs) {
  1637. var nodes = []
  1638. for (var i = 0; i < segs.length; i++) {
  1639. var seg = segs[i]
  1640. switch (seg.mode) {
  1641. case Mode.NUMERIC:
  1642. nodes.push([seg,
  1643. { data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length },
  1644. { data: seg.data, mode: Mode.BYTE, length: seg.length }
  1645. ])
  1646. break
  1647. case Mode.ALPHANUMERIC:
  1648. nodes.push([seg,
  1649. { data: seg.data, mode: Mode.BYTE, length: seg.length }
  1650. ])
  1651. break
  1652. case Mode.KANJI:
  1653. nodes.push([seg,
  1654. { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
  1655. ])
  1656. break
  1657. case Mode.BYTE:
  1658. nodes.push([
  1659. { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
  1660. ])
  1661. }
  1662. }
  1663. return nodes
  1664. }
  1665. /**
  1666. * Builds a graph from a list of nodes.
  1667. * All segments in each node group will be connected with all the segments of
  1668. * the next group and so on.
  1669. *
  1670. * At each connection will be assigned a weight depending on the
  1671. * segment's byte length.
  1672. *
  1673. * @param {Array} nodes Array of object with segments data
  1674. * @param {Number} version QR Code version
  1675. * @return {Object} Graph of all possible segments
  1676. */
  1677. function buildGraph (nodes, version) {
  1678. var table = {}
  1679. var graph = {'start': {}}
  1680. var prevNodeIds = ['start']
  1681. for (var i = 0; i < nodes.length; i++) {
  1682. var nodeGroup = nodes[i]
  1683. var currentNodeIds = []
  1684. for (var j = 0; j < nodeGroup.length; j++) {
  1685. var node = nodeGroup[j]
  1686. var key = '' + i + j
  1687. currentNodeIds.push(key)
  1688. table[key] = { node: node, lastCount: 0 }
  1689. graph[key] = {}
  1690. for (var n = 0; n < prevNodeIds.length; n++) {
  1691. var prevNodeId = prevNodeIds[n]
  1692. if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {
  1693. graph[prevNodeId][key] =
  1694. getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) -
  1695. getSegmentBitsLength(table[prevNodeId].lastCount, node.mode)
  1696. table[prevNodeId].lastCount += node.length
  1697. } else {
  1698. if (table[prevNodeId]) table[prevNodeId].lastCount = node.length
  1699. graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) +
  1700. 4 + Mode.getCharCountIndicator(node.mode, version) // switch cost
  1701. }
  1702. }
  1703. }
  1704. prevNodeIds = currentNodeIds
  1705. }
  1706. for (n = 0; n < prevNodeIds.length; n++) {
  1707. graph[prevNodeIds[n]]['end'] = 0
  1708. }
  1709. return { map: graph, table: table }
  1710. }
  1711. /**
  1712. * Builds a segment from a specified data and mode.
  1713. * If a mode is not specified, the more suitable will be used.
  1714. *
  1715. * @param {String} data Input data
  1716. * @param {Mode | String} modesHint Data mode
  1717. * @return {Segment} Segment
  1718. */
  1719. function buildSingleSegment (data, modesHint) {
  1720. var mode
  1721. var bestMode = Mode.getBestModeForData(data)
  1722. mode = Mode.from(modesHint, bestMode)
  1723. // Make sure data can be encoded
  1724. if (mode !== Mode.BYTE && mode.bit < bestMode.bit) {
  1725. throw new Error('"' + data + '"' +
  1726. ' cannot be encoded with mode ' + Mode.toString(mode) +
  1727. '.\n Suggested mode is: ' + Mode.toString(bestMode))
  1728. }
  1729. // Use Mode.BYTE if Kanji support is disabled
  1730. if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) {
  1731. mode = Mode.BYTE
  1732. }
  1733. switch (mode) {
  1734. case Mode.NUMERIC:
  1735. return new NumericData(data)
  1736. case Mode.ALPHANUMERIC:
  1737. return new AlphanumericData(data)
  1738. case Mode.KANJI:
  1739. return new KanjiData(data)
  1740. case Mode.BYTE:
  1741. return new ByteData(data)
  1742. }
  1743. }
  1744. /**
  1745. * Builds a list of segments from an array.
  1746. * Array can contain Strings or Objects with segment's info.
  1747. *
  1748. * For each item which is a string, will be generated a segment with the given
  1749. * string and the more appropriate encoding mode.
  1750. *
  1751. * For each item which is an object, will be generated a segment with the given
  1752. * data and mode.
  1753. * Objects must contain at least the property "data".
  1754. * If property "mode" is not present, the more suitable mode will be used.
  1755. *
  1756. * @param {Array} array Array of objects with segments data
  1757. * @return {Array} Array of Segments
  1758. */
  1759. exports.fromArray = function fromArray (array) {
  1760. return array.reduce(function (acc, seg) {
  1761. if (typeof seg === 'string') {
  1762. acc.push(buildSingleSegment(seg, null))
  1763. } else if (seg.data) {
  1764. acc.push(buildSingleSegment(seg.data, seg.mode))
  1765. }
  1766. return acc
  1767. }, [])
  1768. }
  1769. /**
  1770. * Builds an optimized sequence of segments from a string,
  1771. * which will produce the shortest possible bitstream.
  1772. *
  1773. * @param {String} data Input string
  1774. * @param {Number} version QR Code version
  1775. * @return {Array} Array of segments
  1776. */
  1777. exports.fromString = function fromString (data, version) {
  1778. var segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled())
  1779. var nodes = buildNodes(segs)
  1780. var graph = buildGraph(nodes, version)
  1781. var path = dijkstra.find_path(graph.map, 'start', 'end')
  1782. var optimizedSegs = []
  1783. for (var i = 1; i < path.length - 1; i++) {
  1784. optimizedSegs.push(graph.table[path[i]].node)
  1785. }
  1786. return exports.fromArray(mergeSegments(optimizedSegs))
  1787. }
  1788. /**
  1789. * Splits a string in various segments with the modes which
  1790. * best represent their content.
  1791. * The produced segments are far from being optimized.
  1792. * The output of this function is only used to estimate a QR Code version
  1793. * which may contain the data.
  1794. *
  1795. * @param {string} data Input string
  1796. * @return {Array} Array of segments
  1797. */
  1798. exports.rawSplit = function rawSplit (data) {
  1799. return exports.fromArray(
  1800. getSegmentsFromString(data, Utils.isKanjiModeEnabled())
  1801. )
  1802. }
  1803. },{"./alphanumeric-data":3,"./byte-data":6,"./kanji-data":12,"./mode":14,"./numeric-data":15,"./regex":19,"./utils":21,"dijkstrajs":31}],21:[function(require,module,exports){
  1804. var toSJISFunction
  1805. var CODEWORDS_COUNT = [
  1806. 0, // Not used
  1807. 26, 44, 70, 100, 134, 172, 196, 242, 292, 346,
  1808. 404, 466, 532, 581, 655, 733, 815, 901, 991, 1085,
  1809. 1156, 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051, 2185,
  1810. 2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706
  1811. ]
  1812. /**
  1813. * Returns the QR Code size for the specified version
  1814. *
  1815. * @param {Number} version QR Code version
  1816. * @return {Number} size of QR code
  1817. */
  1818. exports.getSymbolSize = function getSymbolSize (version) {
  1819. if (!version) throw new Error('"version" cannot be null or undefined')
  1820. if (version < 1 || version > 40) throw new Error('"version" should be in range from 1 to 40')
  1821. return version * 4 + 17
  1822. }
  1823. /**
  1824. * Returns the total number of codewords used to store data and EC information.
  1825. *
  1826. * @param {Number} version QR Code version
  1827. * @return {Number} Data length in bits
  1828. */
  1829. exports.getSymbolTotalCodewords = function getSymbolTotalCodewords (version) {
  1830. return CODEWORDS_COUNT[version]
  1831. }
  1832. /**
  1833. * Encode data with Bose-Chaudhuri-Hocquenghem
  1834. *
  1835. * @param {Number} data Value to encode
  1836. * @return {Number} Encoded value
  1837. */
  1838. exports.getBCHDigit = function (data) {
  1839. var digit = 0
  1840. while (data !== 0) {
  1841. digit++
  1842. data >>>= 1
  1843. }
  1844. return digit
  1845. }
  1846. exports.setToSJISFunction = function setToSJISFunction (f) {
  1847. if (typeof f !== 'function') {
  1848. throw new Error('"toSJISFunc" is not a valid function.')
  1849. }
  1850. toSJISFunction = f
  1851. }
  1852. exports.isKanjiModeEnabled = function () {
  1853. return typeof toSJISFunction !== 'undefined'
  1854. }
  1855. exports.toSJIS = function toSJIS (kanji) {
  1856. return toSJISFunction(kanji)
  1857. }
  1858. },{}],22:[function(require,module,exports){
  1859. /**
  1860. * Check if QR Code version is valid
  1861. *
  1862. * @param {Number} version QR Code version
  1863. * @return {Boolean} true if valid version, false otherwise
  1864. */
  1865. exports.isValid = function isValid (version) {
  1866. return !isNaN(version) && version >= 1 && version <= 40
  1867. }
  1868. },{}],23:[function(require,module,exports){
  1869. var Utils = require('./utils')
  1870. var ECCode = require('./error-correction-code')
  1871. var ECLevel = require('./error-correction-level')
  1872. var Mode = require('./mode')
  1873. var VersionCheck = require('./version-check')
  1874. var isArray = require('isarray')
  1875. // Generator polynomial used to encode version information
  1876. var G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0)
  1877. var G18_BCH = Utils.getBCHDigit(G18)
  1878. function getBestVersionForDataLength (mode, length, errorCorrectionLevel) {
  1879. for (var currentVersion = 1; currentVersion <= 40; currentVersion++) {
  1880. if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) {
  1881. return currentVersion
  1882. }
  1883. }
  1884. return undefined
  1885. }
  1886. function getReservedBitsCount (mode, version) {
  1887. // Character count indicator + mode indicator bits
  1888. return Mode.getCharCountIndicator(mode, version) + 4
  1889. }
  1890. function getTotalBitsFromDataArray (segments, version) {
  1891. var totalBits = 0
  1892. segments.forEach(function (data) {
  1893. var reservedBits = getReservedBitsCount(data.mode, version)
  1894. totalBits += reservedBits + data.getBitsLength()
  1895. })
  1896. return totalBits
  1897. }
  1898. function getBestVersionForMixedData (segments, errorCorrectionLevel) {
  1899. for (var currentVersion = 1; currentVersion <= 40; currentVersion++) {
  1900. var length = getTotalBitsFromDataArray(segments, currentVersion)
  1901. if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) {
  1902. return currentVersion
  1903. }
  1904. }
  1905. return undefined
  1906. }
  1907. /**
  1908. * Returns version number from a value.
  1909. * If value is not a valid version, returns defaultValue
  1910. *
  1911. * @param {Number|String} value QR Code version
  1912. * @param {Number} defaultValue Fallback value
  1913. * @return {Number} QR Code version number
  1914. */
  1915. exports.from = function from (value, defaultValue) {
  1916. if (VersionCheck.isValid(value)) {
  1917. return parseInt(value, 10)
  1918. }
  1919. return defaultValue
  1920. }
  1921. /**
  1922. * Returns how much data can be stored with the specified QR code version
  1923. * and error correction level
  1924. *
  1925. * @param {Number} version QR Code version (1-40)
  1926. * @param {Number} errorCorrectionLevel Error correction level
  1927. * @param {Mode} mode Data mode
  1928. * @return {Number} Quantity of storable data
  1929. */
  1930. exports.getCapacity = function getCapacity (version, errorCorrectionLevel, mode) {
  1931. if (!VersionCheck.isValid(version)) {
  1932. throw new Error('Invalid QR Code version')
  1933. }
  1934. // Use Byte mode as default
  1935. if (typeof mode === 'undefined') mode = Mode.BYTE
  1936. // Total codewords for this QR code version (Data + Error correction)
  1937. var totalCodewords = Utils.getSymbolTotalCodewords(version)
  1938. // Total number of error correction codewords
  1939. var ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel)
  1940. // Total number of data codewords
  1941. var dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8
  1942. if (mode === Mode.MIXED) return dataTotalCodewordsBits
  1943. var usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version)
  1944. // Return max number of storable codewords
  1945. switch (mode) {
  1946. case Mode.NUMERIC:
  1947. return Math.floor((usableBits / 10) * 3)
  1948. case Mode.ALPHANUMERIC:
  1949. return Math.floor((usableBits / 11) * 2)
  1950. case Mode.KANJI:
  1951. return Math.floor(usableBits / 13)
  1952. case Mode.BYTE:
  1953. default:
  1954. return Math.floor(usableBits / 8)
  1955. }
  1956. }
  1957. /**
  1958. * Returns the minimum version needed to contain the amount of data
  1959. *
  1960. * @param {Segment} data Segment of data
  1961. * @param {Number} [errorCorrectionLevel=H] Error correction level
  1962. * @param {Mode} mode Data mode
  1963. * @return {Number} QR Code version
  1964. */
  1965. exports.getBestVersionForData = function getBestVersionForData (data, errorCorrectionLevel) {
  1966. var seg
  1967. var ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M)
  1968. if (isArray(data)) {
  1969. if (data.length > 1) {
  1970. return getBestVersionForMixedData(data, ecl)
  1971. }
  1972. if (data.length === 0) {
  1973. return 1
  1974. }
  1975. seg = data[0]
  1976. } else {
  1977. seg = data
  1978. }
  1979. return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl)
  1980. }
  1981. /**
  1982. * Returns version information with relative error correction bits
  1983. *
  1984. * The version information is included in QR Code symbols of version 7 or larger.
  1985. * It consists of an 18-bit sequence containing 6 data bits,
  1986. * with 12 error correction bits calculated using the (18, 6) Golay code.
  1987. *
  1988. * @param {Number} version QR Code version
  1989. * @return {Number} Encoded version info bits
  1990. */
  1991. exports.getEncodedBits = function getEncodedBits (version) {
  1992. if (!VersionCheck.isValid(version) || version < 7) {
  1993. throw new Error('Invalid QR Code version')
  1994. }
  1995. var d = version << 12
  1996. while (Utils.getBCHDigit(d) - G18_BCH >= 0) {
  1997. d ^= (G18 << (Utils.getBCHDigit(d) - G18_BCH))
  1998. }
  1999. return (version << 12) | d
  2000. }
  2001. },{"./error-correction-code":7,"./error-correction-level":8,"./mode":14,"./utils":21,"./version-check":22,"isarray":33}],24:[function(require,module,exports){
  2002. var canPromise = require('./can-promise')
  2003. var QRCode = require('./core/qrcode')
  2004. var CanvasRenderer = require('./renderer/canvas')
  2005. var SvgRenderer = require('./renderer/svg-tag.js')
  2006. function renderCanvas (renderFunc, canvas, text, opts, cb) {
  2007. var args = [].slice.call(arguments, 1)
  2008. var argsNum = args.length
  2009. var isLastArgCb = typeof args[argsNum - 1] === 'function'
  2010. if (!isLastArgCb && !canPromise()) {
  2011. throw new Error('Callback required as last argument')
  2012. }
  2013. if (isLastArgCb) {
  2014. if (argsNum < 2) {
  2015. throw new Error('Too few arguments provided')
  2016. }
  2017. if (argsNum === 2) {
  2018. cb = text
  2019. text = canvas
  2020. canvas = opts = undefined
  2021. } else if (argsNum === 3) {
  2022. if (canvas.getContext && typeof cb === 'undefined') {
  2023. cb = opts
  2024. opts = undefined
  2025. } else {
  2026. cb = opts
  2027. opts = text
  2028. text = canvas
  2029. canvas = undefined
  2030. }
  2031. }
  2032. } else {
  2033. if (argsNum < 1) {
  2034. throw new Error('Too few arguments provided')
  2035. }
  2036. if (argsNum === 1) {
  2037. text = canvas
  2038. canvas = opts = undefined
  2039. } else if (argsNum === 2 && !canvas.getContext) {
  2040. opts = text
  2041. text = canvas
  2042. canvas = undefined
  2043. }
  2044. return new Promise(function (resolve, reject) {
  2045. try {
  2046. var data = QRCode.create(text, opts)
  2047. resolve(renderFunc(data, canvas, opts))
  2048. } catch (e) {
  2049. reject(e)
  2050. }
  2051. })
  2052. }
  2053. try {
  2054. var data = QRCode.create(text, opts)
  2055. cb(null, renderFunc(data, canvas, opts))
  2056. } catch (e) {
  2057. cb(e)
  2058. }
  2059. }
  2060. exports.create = QRCode.create
  2061. exports.toCanvas = renderCanvas.bind(null, CanvasRenderer.render)
  2062. exports.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL)
  2063. // only svg for now.
  2064. exports.toString = renderCanvas.bind(null, function (data, _, opts) {
  2065. return SvgRenderer.render(data, opts)
  2066. })
  2067. },{"./can-promise":1,"./core/qrcode":17,"./renderer/canvas":25,"./renderer/svg-tag.js":26}],25:[function(require,module,exports){
  2068. var Utils = require('./utils')
  2069. function clearCanvas (ctx, canvas, size) {
  2070. ctx.clearRect(0, 0, canvas.width, canvas.height)
  2071. if (!canvas.style) canvas.style = {}
  2072. canvas.height = size
  2073. canvas.width = size
  2074. canvas.style.height = size + 'px'
  2075. canvas.style.width = size + 'px'
  2076. }
  2077. function getCanvasElement () {
  2078. try {
  2079. return document.createElement('canvas')
  2080. } catch (e) {
  2081. throw new Error('You need to specify a canvas element')
  2082. }
  2083. }
  2084. exports.render = function render (qrData, canvas, options) {
  2085. var opts = options
  2086. var canvasEl = canvas
  2087. if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
  2088. opts = canvas
  2089. canvas = undefined
  2090. }
  2091. if (!canvas) {
  2092. canvasEl = getCanvasElement()
  2093. }
  2094. opts = Utils.getOptions(opts)
  2095. var size = Utils.getImageWidth(qrData.modules.size, opts)
  2096. var ctx = canvasEl.getContext('2d')
  2097. var image = ctx.createImageData(size, size)
  2098. Utils.qrToImageData(image.data, qrData, opts)
  2099. clearCanvas(ctx, canvasEl, size)
  2100. ctx.putImageData(image, 0, 0)
  2101. return canvasEl
  2102. }
  2103. exports.renderToDataURL = function renderToDataURL (qrData, canvas, options) {
  2104. var opts = options
  2105. if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
  2106. opts = canvas
  2107. canvas = undefined
  2108. }
  2109. if (!opts) opts = {}
  2110. var canvasEl = exports.render(qrData, canvas, opts)
  2111. var type = opts.type || 'image/png'
  2112. var rendererOpts = opts.rendererOpts || {}
  2113. return canvasEl.toDataURL(type, rendererOpts.quality)
  2114. }
  2115. },{"./utils":27}],26:[function(require,module,exports){
  2116. var Utils = require('./utils')
  2117. function getColorAttrib (color, attrib) {
  2118. var alpha = color.a / 255
  2119. var str = attrib + '="' + color.hex + '"'
  2120. return alpha < 1
  2121. ? str + ' ' + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"'
  2122. : str
  2123. }
  2124. function svgCmd (cmd, x, y) {
  2125. var str = cmd + x
  2126. if (typeof y !== 'undefined') str += ' ' + y
  2127. return str
  2128. }
  2129. function qrToPath (data, size, margin) {
  2130. var path = ''
  2131. var moveBy = 0
  2132. var newRow = false
  2133. var lineLength = 0
  2134. for (var i = 0; i < data.length; i++) {
  2135. var col = Math.floor(i % size)
  2136. var row = Math.floor(i / size)
  2137. if (!col && !newRow) newRow = true
  2138. if (data[i]) {
  2139. lineLength++
  2140. if (!(i > 0 && col > 0 && data[i - 1])) {
  2141. path += newRow
  2142. ? svgCmd('M', col + margin, 0.5 + row + margin)
  2143. : svgCmd('m', moveBy, 0)
  2144. moveBy = 0
  2145. newRow = false
  2146. }
  2147. if (!(col + 1 < size && data[i + 1])) {
  2148. path += svgCmd('h', lineLength)
  2149. lineLength = 0
  2150. }
  2151. } else {
  2152. moveBy++
  2153. }
  2154. }
  2155. return path
  2156. }
  2157. exports.render = function render (qrData, options, cb) {
  2158. var opts = Utils.getOptions(options)
  2159. var size = qrData.modules.size
  2160. var data = qrData.modules.data
  2161. var qrcodesize = size + opts.margin * 2
  2162. var bg = !opts.color.light.a
  2163. ? ''
  2164. : '<path ' + getColorAttrib(opts.color.light, 'fill') +
  2165. ' d="M0 0h' + qrcodesize + 'v' + qrcodesize + 'H0z"/>'
  2166. var path =
  2167. '<path ' + getColorAttrib(opts.color.dark, 'stroke') +
  2168. ' d="' + qrToPath(data, size, opts.margin) + '"/>'
  2169. var viewBox = 'viewBox="' + '0 0 ' + qrcodesize + ' ' + qrcodesize + '"'
  2170. var width = !opts.width ? '' : 'width="' + opts.width + '" height="' + opts.width + '" '
  2171. var svgTag = '<svg xmlns="http://www.w3.org/2000/svg" ' + width + viewBox + ' shape-rendering="crispEdges">' + bg + path + '</svg>\n'
  2172. if (typeof cb === 'function') {
  2173. cb(null, svgTag)
  2174. }
  2175. return svgTag
  2176. }
  2177. },{"./utils":27}],27:[function(require,module,exports){
  2178. function hex2rgba (hex) {
  2179. if (typeof hex === 'number') {
  2180. hex = hex.toString()
  2181. }
  2182. if (typeof hex !== 'string') {
  2183. throw new Error('Color should be defined as hex string')
  2184. }
  2185. var hexCode = hex.slice().replace('#', '').split('')
  2186. if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) {
  2187. throw new Error('Invalid hex color: ' + hex)
  2188. }
  2189. // Convert from short to long form (fff -> ffffff)
  2190. if (hexCode.length === 3 || hexCode.length === 4) {
  2191. hexCode = Array.prototype.concat.apply([], hexCode.map(function (c) {
  2192. return [c, c]
  2193. }))
  2194. }
  2195. // Add default alpha value
  2196. if (hexCode.length === 6) hexCode.push('F', 'F')
  2197. var hexValue = parseInt(hexCode.join(''), 16)
  2198. return {
  2199. r: (hexValue >> 24) & 255,
  2200. g: (hexValue >> 16) & 255,
  2201. b: (hexValue >> 8) & 255,
  2202. a: hexValue & 255,
  2203. hex: '#' + hexCode.slice(0, 6).join('')
  2204. }
  2205. }
  2206. exports.getOptions = function getOptions (options) {
  2207. if (!options) options = {}
  2208. if (!options.color) options.color = {}
  2209. var margin = typeof options.margin === 'undefined' ||
  2210. options.margin === null ||
  2211. options.margin < 0 ? 4 : options.margin
  2212. var width = options.width && options.width >= 21 ? options.width : undefined
  2213. var scale = options.scale || 4
  2214. return {
  2215. width: width,
  2216. scale: width ? 4 : scale,
  2217. margin: margin,
  2218. color: {
  2219. dark: hex2rgba(options.color.dark || '#000000ff'),
  2220. light: hex2rgba(options.color.light || '#ffffffff')
  2221. },
  2222. type: options.type,
  2223. rendererOpts: options.rendererOpts || {}
  2224. }
  2225. }
  2226. exports.getScale = function getScale (qrSize, opts) {
  2227. return opts.width && opts.width >= qrSize + opts.margin * 2
  2228. ? opts.width / (qrSize + opts.margin * 2)
  2229. : opts.scale
  2230. }
  2231. exports.getImageWidth = function getImageWidth (qrSize, opts) {
  2232. var scale = exports.getScale(qrSize, opts)
  2233. return Math.floor((qrSize + opts.margin * 2) * scale)
  2234. }
  2235. exports.qrToImageData = function qrToImageData (imgData, qr, opts) {
  2236. var size = qr.modules.size
  2237. var data = qr.modules.data
  2238. var scale = exports.getScale(size, opts)
  2239. var symbolSize = Math.floor((size + opts.margin * 2) * scale)
  2240. var scaledMargin = opts.margin * scale
  2241. var palette = [opts.color.light, opts.color.dark]
  2242. for (var i = 0; i < symbolSize; i++) {
  2243. for (var j = 0; j < symbolSize; j++) {
  2244. var posDst = (i * symbolSize + j) * 4
  2245. var pxColor = opts.color.light
  2246. if (i >= scaledMargin && j >= scaledMargin &&
  2247. i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {
  2248. var iSrc = Math.floor((i - scaledMargin) / scale)
  2249. var jSrc = Math.floor((j - scaledMargin) / scale)
  2250. pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0]
  2251. }
  2252. imgData[posDst++] = pxColor.r
  2253. imgData[posDst++] = pxColor.g
  2254. imgData[posDst++] = pxColor.b
  2255. imgData[posDst] = pxColor.a
  2256. }
  2257. }
  2258. }
  2259. },{}],28:[function(require,module,exports){
  2260. /**
  2261. * Implementation of a subset of node.js Buffer methods for the browser.
  2262. * Based on https://github.com/feross/buffer
  2263. */
  2264. /* eslint-disable no-proto */
  2265. 'use strict'
  2266. var isArray = require('isarray')
  2267. function typedArraySupport () {
  2268. // Can typed array instances be augmented?
  2269. try {
  2270. var arr = new Uint8Array(1)
  2271. arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
  2272. return arr.foo() === 42
  2273. } catch (e) {
  2274. return false
  2275. }
  2276. }
  2277. Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
  2278. var K_MAX_LENGTH = Buffer.TYPED_ARRAY_SUPPORT
  2279. ? 0x7fffffff
  2280. : 0x3fffffff
  2281. function Buffer (arg, offset, length) {
  2282. if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
  2283. return new Buffer(arg, offset, length)
  2284. }
  2285. if (typeof arg === 'number') {
  2286. return allocUnsafe(this, arg)
  2287. }
  2288. return from(this, arg, offset, length)
  2289. }
  2290. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2291. Buffer.prototype.__proto__ = Uint8Array.prototype
  2292. Buffer.__proto__ = Uint8Array
  2293. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  2294. if (typeof Symbol !== 'undefined' && Symbol.species &&
  2295. Buffer[Symbol.species] === Buffer) {
  2296. Object.defineProperty(Buffer, Symbol.species, {
  2297. value: null,
  2298. configurable: true,
  2299. enumerable: false,
  2300. writable: false
  2301. })
  2302. }
  2303. }
  2304. function checked (length) {
  2305. // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
  2306. // length is NaN (which is otherwise coerced to zero.)
  2307. if (length >= K_MAX_LENGTH) {
  2308. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  2309. 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
  2310. }
  2311. return length | 0
  2312. }
  2313. function isnan (val) {
  2314. return val !== val // eslint-disable-line no-self-compare
  2315. }
  2316. function createBuffer (that, length) {
  2317. var buf
  2318. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2319. buf = new Uint8Array(length)
  2320. buf.__proto__ = Buffer.prototype
  2321. } else {
  2322. // Fallback: Return an object instance of the Buffer class
  2323. buf = that
  2324. if (buf === null) {
  2325. buf = new Buffer(length)
  2326. }
  2327. buf.length = length
  2328. }
  2329. return buf
  2330. }
  2331. function allocUnsafe (that, size) {
  2332. var buf = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
  2333. if (!Buffer.TYPED_ARRAY_SUPPORT) {
  2334. for (var i = 0; i < size; ++i) {
  2335. buf[i] = 0
  2336. }
  2337. }
  2338. return buf
  2339. }
  2340. function fromString (that, string) {
  2341. var length = byteLength(string) | 0
  2342. var buf = createBuffer(that, length)
  2343. var actual = buf.write(string)
  2344. if (actual !== length) {
  2345. // Writing a hex string, for example, that contains invalid characters will
  2346. // cause everything after the first invalid character to be ignored. (e.g.
  2347. // 'abxxcd' will be treated as 'ab')
  2348. buf = buf.slice(0, actual)
  2349. }
  2350. return buf
  2351. }
  2352. function fromArrayLike (that, array) {
  2353. var length = array.length < 0 ? 0 : checked(array.length) | 0
  2354. var buf = createBuffer(that, length)
  2355. for (var i = 0; i < length; i += 1) {
  2356. buf[i] = array[i] & 255
  2357. }
  2358. return buf
  2359. }
  2360. function fromArrayBuffer (that, array, byteOffset, length) {
  2361. if (byteOffset < 0 || array.byteLength < byteOffset) {
  2362. throw new RangeError('\'offset\' is out of bounds')
  2363. }
  2364. if (array.byteLength < byteOffset + (length || 0)) {
  2365. throw new RangeError('\'length\' is out of bounds')
  2366. }
  2367. var buf
  2368. if (byteOffset === undefined && length === undefined) {
  2369. buf = new Uint8Array(array)
  2370. } else if (length === undefined) {
  2371. buf = new Uint8Array(array, byteOffset)
  2372. } else {
  2373. buf = new Uint8Array(array, byteOffset, length)
  2374. }
  2375. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2376. // Return an augmented `Uint8Array` instance, for best performance
  2377. buf.__proto__ = Buffer.prototype
  2378. } else {
  2379. // Fallback: Return an object instance of the Buffer class
  2380. buf = fromArrayLike(that, buf)
  2381. }
  2382. return buf
  2383. }
  2384. function fromObject (that, obj) {
  2385. if (Buffer.isBuffer(obj)) {
  2386. var len = checked(obj.length) | 0
  2387. var buf = createBuffer(that, len)
  2388. if (buf.length === 0) {
  2389. return buf
  2390. }
  2391. obj.copy(buf, 0, 0, len)
  2392. return buf
  2393. }
  2394. if (obj) {
  2395. if ((typeof ArrayBuffer !== 'undefined' &&
  2396. obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
  2397. if (typeof obj.length !== 'number' || isnan(obj.length)) {
  2398. return createBuffer(that, 0)
  2399. }
  2400. return fromArrayLike(that, obj)
  2401. }
  2402. if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
  2403. return fromArrayLike(that, obj.data)
  2404. }
  2405. }
  2406. throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
  2407. }
  2408. function utf8ToBytes (string, units) {
  2409. units = units || Infinity
  2410. var codePoint
  2411. var length = string.length
  2412. var leadSurrogate = null
  2413. var bytes = []
  2414. for (var i = 0; i < length; ++i) {
  2415. codePoint = string.charCodeAt(i)
  2416. // is surrogate component
  2417. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  2418. // last char was a lead
  2419. if (!leadSurrogate) {
  2420. // no lead yet
  2421. if (codePoint > 0xDBFF) {
  2422. // unexpected trail
  2423. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  2424. continue
  2425. } else if (i + 1 === length) {
  2426. // unpaired lead
  2427. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  2428. continue
  2429. }
  2430. // valid lead
  2431. leadSurrogate = codePoint
  2432. continue
  2433. }
  2434. // 2 leads in a row
  2435. if (codePoint < 0xDC00) {
  2436. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  2437. leadSurrogate = codePoint
  2438. continue
  2439. }
  2440. // valid surrogate pair
  2441. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  2442. } else if (leadSurrogate) {
  2443. // valid bmp char, but last char was a lead
  2444. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  2445. }
  2446. leadSurrogate = null
  2447. // encode utf8
  2448. if (codePoint < 0x80) {
  2449. if ((units -= 1) < 0) break
  2450. bytes.push(codePoint)
  2451. } else if (codePoint < 0x800) {
  2452. if ((units -= 2) < 0) break
  2453. bytes.push(
  2454. codePoint >> 0x6 | 0xC0,
  2455. codePoint & 0x3F | 0x80
  2456. )
  2457. } else if (codePoint < 0x10000) {
  2458. if ((units -= 3) < 0) break
  2459. bytes.push(
  2460. codePoint >> 0xC | 0xE0,
  2461. codePoint >> 0x6 & 0x3F | 0x80,
  2462. codePoint & 0x3F | 0x80
  2463. )
  2464. } else if (codePoint < 0x110000) {
  2465. if ((units -= 4) < 0) break
  2466. bytes.push(
  2467. codePoint >> 0x12 | 0xF0,
  2468. codePoint >> 0xC & 0x3F | 0x80,
  2469. codePoint >> 0x6 & 0x3F | 0x80,
  2470. codePoint & 0x3F | 0x80
  2471. )
  2472. } else {
  2473. throw new Error('Invalid code point')
  2474. }
  2475. }
  2476. return bytes
  2477. }
  2478. function byteLength (string) {
  2479. if (Buffer.isBuffer(string)) {
  2480. return string.length
  2481. }
  2482. if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
  2483. (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
  2484. return string.byteLength
  2485. }
  2486. if (typeof string !== 'string') {
  2487. string = '' + string
  2488. }
  2489. var len = string.length
  2490. if (len === 0) return 0
  2491. return utf8ToBytes(string).length
  2492. }
  2493. function blitBuffer (src, dst, offset, length) {
  2494. for (var i = 0; i < length; ++i) {
  2495. if ((i + offset >= dst.length) || (i >= src.length)) break
  2496. dst[i + offset] = src[i]
  2497. }
  2498. return i
  2499. }
  2500. function utf8Write (buf, string, offset, length) {
  2501. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  2502. }
  2503. function from (that, value, offset, length) {
  2504. if (typeof value === 'number') {
  2505. throw new TypeError('"value" argument must not be a number')
  2506. }
  2507. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  2508. return fromArrayBuffer(that, value, offset, length)
  2509. }
  2510. if (typeof value === 'string') {
  2511. return fromString(that, value, offset)
  2512. }
  2513. return fromObject(that, value)
  2514. }
  2515. Buffer.prototype.write = function write (string, offset, length) {
  2516. // Buffer#write(string)
  2517. if (offset === undefined) {
  2518. length = this.length
  2519. offset = 0
  2520. // Buffer#write(string, encoding)
  2521. } else if (length === undefined && typeof offset === 'string') {
  2522. length = this.length
  2523. offset = 0
  2524. // Buffer#write(string, offset[, length])
  2525. } else if (isFinite(offset)) {
  2526. offset = offset | 0
  2527. if (isFinite(length)) {
  2528. length = length | 0
  2529. } else {
  2530. length = undefined
  2531. }
  2532. }
  2533. var remaining = this.length - offset
  2534. if (length === undefined || length > remaining) length = remaining
  2535. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  2536. throw new RangeError('Attempt to write outside buffer bounds')
  2537. }
  2538. return utf8Write(this, string, offset, length)
  2539. }
  2540. Buffer.prototype.slice = function slice (start, end) {
  2541. var len = this.length
  2542. start = ~~start
  2543. end = end === undefined ? len : ~~end
  2544. if (start < 0) {
  2545. start += len
  2546. if (start < 0) start = 0
  2547. } else if (start > len) {
  2548. start = len
  2549. }
  2550. if (end < 0) {
  2551. end += len
  2552. if (end < 0) end = 0
  2553. } else if (end > len) {
  2554. end = len
  2555. }
  2556. if (end < start) end = start
  2557. var newBuf
  2558. if (Buffer.TYPED_ARRAY_SUPPORT) {
  2559. newBuf = this.subarray(start, end)
  2560. // Return an augmented `Uint8Array` instance
  2561. newBuf.__proto__ = Buffer.prototype
  2562. } else {
  2563. var sliceLen = end - start
  2564. newBuf = new Buffer(sliceLen, undefined)
  2565. for (var i = 0; i < sliceLen; ++i) {
  2566. newBuf[i] = this[i + start]
  2567. }
  2568. }
  2569. return newBuf
  2570. }
  2571. Buffer.prototype.copy = function copy (target, targetStart, start, end) {
  2572. if (!start) start = 0
  2573. if (!end && end !== 0) end = this.length
  2574. if (targetStart >= target.length) targetStart = target.length
  2575. if (!targetStart) targetStart = 0
  2576. if (end > 0 && end < start) end = start
  2577. // Copy 0 bytes; we're done
  2578. if (end === start) return 0
  2579. if (target.length === 0 || this.length === 0) return 0
  2580. // Fatal error conditions
  2581. if (targetStart < 0) {
  2582. throw new RangeError('targetStart out of bounds')
  2583. }
  2584. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
  2585. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  2586. // Are we oob?
  2587. if (end > this.length) end = this.length
  2588. if (target.length - targetStart < end - start) {
  2589. end = target.length - targetStart + start
  2590. }
  2591. var len = end - start
  2592. var i
  2593. if (this === target && start < targetStart && targetStart < end) {
  2594. // descending copy from end
  2595. for (i = len - 1; i >= 0; --i) {
  2596. target[i + targetStart] = this[i + start]
  2597. }
  2598. } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
  2599. // ascending copy from start
  2600. for (i = 0; i < len; ++i) {
  2601. target[i + targetStart] = this[i + start]
  2602. }
  2603. } else {
  2604. Uint8Array.prototype.set.call(
  2605. target,
  2606. this.subarray(start, start + len),
  2607. targetStart
  2608. )
  2609. }
  2610. return len
  2611. }
  2612. Buffer.prototype.fill = function fill (val, start, end) {
  2613. // Handle string cases:
  2614. if (typeof val === 'string') {
  2615. if (typeof start === 'string') {
  2616. start = 0
  2617. end = this.length
  2618. } else if (typeof end === 'string') {
  2619. end = this.length
  2620. }
  2621. if (val.length === 1) {
  2622. var code = val.charCodeAt(0)
  2623. if (code < 256) {
  2624. val = code
  2625. }
  2626. }
  2627. } else if (typeof val === 'number') {
  2628. val = val & 255
  2629. }
  2630. // Invalid ranges are not set to a default, so can range check early.
  2631. if (start < 0 || this.length < start || this.length < end) {
  2632. throw new RangeError('Out of range index')
  2633. }
  2634. if (end <= start) {
  2635. return this
  2636. }
  2637. start = start >>> 0
  2638. end = end === undefined ? this.length : end >>> 0
  2639. if (!val) val = 0
  2640. var i
  2641. if (typeof val === 'number') {
  2642. for (i = start; i < end; ++i) {
  2643. this[i] = val
  2644. }
  2645. } else {
  2646. var bytes = Buffer.isBuffer(val)
  2647. ? val
  2648. : new Buffer(val)
  2649. var len = bytes.length
  2650. for (i = 0; i < end - start; ++i) {
  2651. this[i + start] = bytes[i % len]
  2652. }
  2653. }
  2654. return this
  2655. }
  2656. Buffer.concat = function concat (list, length) {
  2657. if (!isArray(list)) {
  2658. throw new TypeError('"list" argument must be an Array of Buffers')
  2659. }
  2660. if (list.length === 0) {
  2661. return createBuffer(null, 0)
  2662. }
  2663. var i
  2664. if (length === undefined) {
  2665. length = 0
  2666. for (i = 0; i < list.length; ++i) {
  2667. length += list[i].length
  2668. }
  2669. }
  2670. var buffer = allocUnsafe(null, length)
  2671. var pos = 0
  2672. for (i = 0; i < list.length; ++i) {
  2673. var buf = list[i]
  2674. if (!Buffer.isBuffer(buf)) {
  2675. throw new TypeError('"list" argument must be an Array of Buffers')
  2676. }
  2677. buf.copy(buffer, pos)
  2678. pos += buf.length
  2679. }
  2680. return buffer
  2681. }
  2682. Buffer.byteLength = byteLength
  2683. Buffer.prototype._isBuffer = true
  2684. Buffer.isBuffer = function isBuffer (b) {
  2685. return !!(b != null && b._isBuffer)
  2686. }
  2687. module.exports.alloc = function (size) {
  2688. var buffer = new Buffer(size)
  2689. buffer.fill(0)
  2690. return buffer
  2691. }
  2692. module.exports.from = function (data) {
  2693. return new Buffer(data)
  2694. }
  2695. },{"isarray":33}],29:[function(require,module,exports){
  2696. 'use strict'
  2697. exports.byteLength = byteLength
  2698. exports.toByteArray = toByteArray
  2699. exports.fromByteArray = fromByteArray
  2700. var lookup = []
  2701. var revLookup = []
  2702. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  2703. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  2704. for (var i = 0, len = code.length; i < len; ++i) {
  2705. lookup[i] = code[i]
  2706. revLookup[code.charCodeAt(i)] = i
  2707. }
  2708. // Support decoding URL-safe base64 strings, as Node.js does.
  2709. // See: https://en.wikipedia.org/wiki/Base64#URL_applications
  2710. revLookup['-'.charCodeAt(0)] = 62
  2711. revLookup['_'.charCodeAt(0)] = 63
  2712. function getLens (b64) {
  2713. var len = b64.length
  2714. if (len % 4 > 0) {
  2715. throw new Error('Invalid string. Length must be a multiple of 4')
  2716. }
  2717. // Trim off extra bytes after placeholder bytes are found
  2718. // See: https://github.com/beatgammit/base64-js/issues/42
  2719. var validLen = b64.indexOf('=')
  2720. if (validLen === -1) validLen = len
  2721. var placeHoldersLen = validLen === len
  2722. ? 0
  2723. : 4 - (validLen % 4)
  2724. return [validLen, placeHoldersLen]
  2725. }
  2726. // base64 is 4/3 + up to two characters of the original data
  2727. function byteLength (b64) {
  2728. var lens = getLens(b64)
  2729. var validLen = lens[0]
  2730. var placeHoldersLen = lens[1]
  2731. return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
  2732. }
  2733. function _byteLength (b64, validLen, placeHoldersLen) {
  2734. return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
  2735. }
  2736. function toByteArray (b64) {
  2737. var tmp
  2738. var lens = getLens(b64)
  2739. var validLen = lens[0]
  2740. var placeHoldersLen = lens[1]
  2741. var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
  2742. var curByte = 0
  2743. // if there are placeholders, only get up to the last complete 4 chars
  2744. var len = placeHoldersLen > 0
  2745. ? validLen - 4
  2746. : validLen
  2747. var i
  2748. for (i = 0; i < len; i += 4) {
  2749. tmp =
  2750. (revLookup[b64.charCodeAt(i)] << 18) |
  2751. (revLookup[b64.charCodeAt(i + 1)] << 12) |
  2752. (revLookup[b64.charCodeAt(i + 2)] << 6) |
  2753. revLookup[b64.charCodeAt(i + 3)]
  2754. arr[curByte++] = (tmp >> 16) & 0xFF
  2755. arr[curByte++] = (tmp >> 8) & 0xFF
  2756. arr[curByte++] = tmp & 0xFF
  2757. }
  2758. if (placeHoldersLen === 2) {
  2759. tmp =
  2760. (revLookup[b64.charCodeAt(i)] << 2) |
  2761. (revLookup[b64.charCodeAt(i + 1)] >> 4)
  2762. arr[curByte++] = tmp & 0xFF
  2763. }
  2764. if (placeHoldersLen === 1) {
  2765. tmp =
  2766. (revLookup[b64.charCodeAt(i)] << 10) |
  2767. (revLookup[b64.charCodeAt(i + 1)] << 4) |
  2768. (revLookup[b64.charCodeAt(i + 2)] >> 2)
  2769. arr[curByte++] = (tmp >> 8) & 0xFF
  2770. arr[curByte++] = tmp & 0xFF
  2771. }
  2772. return arr
  2773. }
  2774. function tripletToBase64 (num) {
  2775. return lookup[num >> 18 & 0x3F] +
  2776. lookup[num >> 12 & 0x3F] +
  2777. lookup[num >> 6 & 0x3F] +
  2778. lookup[num & 0x3F]
  2779. }
  2780. function encodeChunk (uint8, start, end) {
  2781. var tmp
  2782. var output = []
  2783. for (var i = start; i < end; i += 3) {
  2784. tmp =
  2785. ((uint8[i] << 16) & 0xFF0000) +
  2786. ((uint8[i + 1] << 8) & 0xFF00) +
  2787. (uint8[i + 2] & 0xFF)
  2788. output.push(tripletToBase64(tmp))
  2789. }
  2790. return output.join('')
  2791. }
  2792. function fromByteArray (uint8) {
  2793. var tmp
  2794. var len = uint8.length
  2795. var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
  2796. var parts = []
  2797. var maxChunkLength = 16383 // must be multiple of 3
  2798. // go through the array every three bytes, we'll deal with trailing stuff later
  2799. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  2800. parts.push(encodeChunk(
  2801. uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)
  2802. ))
  2803. }
  2804. // pad the end with zeros, but make sure to not forget the extra bytes
  2805. if (extraBytes === 1) {
  2806. tmp = uint8[len - 1]
  2807. parts.push(
  2808. lookup[tmp >> 2] +
  2809. lookup[(tmp << 4) & 0x3F] +
  2810. '=='
  2811. )
  2812. } else if (extraBytes === 2) {
  2813. tmp = (uint8[len - 2] << 8) + uint8[len - 1]
  2814. parts.push(
  2815. lookup[tmp >> 10] +
  2816. lookup[(tmp >> 4) & 0x3F] +
  2817. lookup[(tmp << 2) & 0x3F] +
  2818. '='
  2819. )
  2820. }
  2821. return parts.join('')
  2822. }
  2823. },{}],30:[function(require,module,exports){
  2824. /*!
  2825. * The buffer module from node.js, for the browser.
  2826. *
  2827. * @author Feross Aboukhadijeh <https://feross.org>
  2828. * @license MIT
  2829. */
  2830. /* eslint-disable no-proto */
  2831. 'use strict'
  2832. var base64 = require('base64-js')
  2833. var ieee754 = require('ieee754')
  2834. var customInspectSymbol =
  2835. (typeof Symbol === 'function' && typeof Symbol.for === 'function')
  2836. ? Symbol.for('nodejs.util.inspect.custom')
  2837. : null
  2838. exports.Buffer = Buffer
  2839. exports.SlowBuffer = SlowBuffer
  2840. exports.INSPECT_MAX_BYTES = 50
  2841. var K_MAX_LENGTH = 0x7fffffff
  2842. exports.kMaxLength = K_MAX_LENGTH
  2843. /**
  2844. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  2845. * === true Use Uint8Array implementation (fastest)
  2846. * === false Print warning and recommend using `buffer` v4.x which has an Object
  2847. * implementation (most compatible, even IE6)
  2848. *
  2849. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  2850. * Opera 11.6+, iOS 4.2+.
  2851. *
  2852. * We report that the browser does not support typed arrays if the are not subclassable
  2853. * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
  2854. * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
  2855. * for __proto__ and has a buggy typed array implementation.
  2856. */
  2857. Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
  2858. if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
  2859. typeof console.error === 'function') {
  2860. console.error(
  2861. 'This browser lacks typed array (Uint8Array) support which is required by ' +
  2862. '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
  2863. )
  2864. }
  2865. function typedArraySupport () {
  2866. // Can typed array instances can be augmented?
  2867. try {
  2868. var arr = new Uint8Array(1)
  2869. var proto = { foo: function () { return 42 } }
  2870. Object.setPrototypeOf(proto, Uint8Array.prototype)
  2871. Object.setPrototypeOf(arr, proto)
  2872. return arr.foo() === 42
  2873. } catch (e) {
  2874. return false
  2875. }
  2876. }
  2877. Object.defineProperty(Buffer.prototype, 'parent', {
  2878. enumerable: true,
  2879. get: function () {
  2880. if (!Buffer.isBuffer(this)) return undefined
  2881. return this.buffer
  2882. }
  2883. })
  2884. Object.defineProperty(Buffer.prototype, 'offset', {
  2885. enumerable: true,
  2886. get: function () {
  2887. if (!Buffer.isBuffer(this)) return undefined
  2888. return this.byteOffset
  2889. }
  2890. })
  2891. function createBuffer (length) {
  2892. if (length > K_MAX_LENGTH) {
  2893. throw new RangeError('The value "' + length + '" is invalid for option "size"')
  2894. }
  2895. // Return an augmented `Uint8Array` instance
  2896. var buf = new Uint8Array(length)
  2897. Object.setPrototypeOf(buf, Buffer.prototype)
  2898. return buf
  2899. }
  2900. /**
  2901. * The Buffer constructor returns instances of `Uint8Array` that have their
  2902. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  2903. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  2904. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  2905. * returns a single octet.
  2906. *
  2907. * The `Uint8Array` prototype remains unmodified.
  2908. */
  2909. function Buffer (arg, encodingOrOffset, length) {
  2910. // Common case.
  2911. if (typeof arg === 'number') {
  2912. if (typeof encodingOrOffset === 'string') {
  2913. throw new TypeError(
  2914. 'The "string" argument must be of type string. Received type number'
  2915. )
  2916. }
  2917. return allocUnsafe(arg)
  2918. }
  2919. return from(arg, encodingOrOffset, length)
  2920. }
  2921. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  2922. if (typeof Symbol !== 'undefined' && Symbol.species != null &&
  2923. Buffer[Symbol.species] === Buffer) {
  2924. Object.defineProperty(Buffer, Symbol.species, {
  2925. value: null,
  2926. configurable: true,
  2927. enumerable: false,
  2928. writable: false
  2929. })
  2930. }
  2931. Buffer.poolSize = 8192 // not used by this implementation
  2932. function from (value, encodingOrOffset, length) {
  2933. if (typeof value === 'string') {
  2934. return fromString(value, encodingOrOffset)
  2935. }
  2936. if (ArrayBuffer.isView(value)) {
  2937. return fromArrayLike(value)
  2938. }
  2939. if (value == null) {
  2940. throw new TypeError(
  2941. 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
  2942. 'or Array-like Object. Received type ' + (typeof value)
  2943. )
  2944. }
  2945. if (isInstance(value, ArrayBuffer) ||
  2946. (value && isInstance(value.buffer, ArrayBuffer))) {
  2947. return fromArrayBuffer(value, encodingOrOffset, length)
  2948. }
  2949. if (typeof value === 'number') {
  2950. throw new TypeError(
  2951. 'The "value" argument must not be of type number. Received type number'
  2952. )
  2953. }
  2954. var valueOf = value.valueOf && value.valueOf()
  2955. if (valueOf != null && valueOf !== value) {
  2956. return Buffer.from(valueOf, encodingOrOffset, length)
  2957. }
  2958. var b = fromObject(value)
  2959. if (b) return b
  2960. if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
  2961. typeof value[Symbol.toPrimitive] === 'function') {
  2962. return Buffer.from(
  2963. value[Symbol.toPrimitive]('string'), encodingOrOffset, length
  2964. )
  2965. }
  2966. throw new TypeError(
  2967. 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
  2968. 'or Array-like Object. Received type ' + (typeof value)
  2969. )
  2970. }
  2971. /**
  2972. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  2973. * if value is a number.
  2974. * Buffer.from(str[, encoding])
  2975. * Buffer.from(array)
  2976. * Buffer.from(buffer)
  2977. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  2978. **/
  2979. Buffer.from = function (value, encodingOrOffset, length) {
  2980. return from(value, encodingOrOffset, length)
  2981. }
  2982. // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
  2983. // https://github.com/feross/buffer/pull/148
  2984. Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype)
  2985. Object.setPrototypeOf(Buffer, Uint8Array)
  2986. function assertSize (size) {
  2987. if (typeof size !== 'number') {
  2988. throw new TypeError('"size" argument must be of type number')
  2989. } else if (size < 0) {
  2990. throw new RangeError('The value "' + size + '" is invalid for option "size"')
  2991. }
  2992. }
  2993. function alloc (size, fill, encoding) {
  2994. assertSize(size)
  2995. if (size <= 0) {
  2996. return createBuffer(size)
  2997. }
  2998. if (fill !== undefined) {
  2999. // Only pay attention to encoding if it's a string. This
  3000. // prevents accidentally sending in a number that would
  3001. // be interpretted as a start offset.
  3002. return typeof encoding === 'string'
  3003. ? createBuffer(size).fill(fill, encoding)
  3004. : createBuffer(size).fill(fill)
  3005. }
  3006. return createBuffer(size)
  3007. }
  3008. /**
  3009. * Creates a new filled Buffer instance.
  3010. * alloc(size[, fill[, encoding]])
  3011. **/
  3012. Buffer.alloc = function (size, fill, encoding) {
  3013. return alloc(size, fill, encoding)
  3014. }
  3015. function allocUnsafe (size) {
  3016. assertSize(size)
  3017. return createBuffer(size < 0 ? 0 : checked(size) | 0)
  3018. }
  3019. /**
  3020. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  3021. * */
  3022. Buffer.allocUnsafe = function (size) {
  3023. return allocUnsafe(size)
  3024. }
  3025. /**
  3026. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  3027. */
  3028. Buffer.allocUnsafeSlow = function (size) {
  3029. return allocUnsafe(size)
  3030. }
  3031. function fromString (string, encoding) {
  3032. if (typeof encoding !== 'string' || encoding === '') {
  3033. encoding = 'utf8'
  3034. }
  3035. if (!Buffer.isEncoding(encoding)) {
  3036. throw new TypeError('Unknown encoding: ' + encoding)
  3037. }
  3038. var length = byteLength(string, encoding) | 0
  3039. var buf = createBuffer(length)
  3040. var actual = buf.write(string, encoding)
  3041. if (actual !== length) {
  3042. // Writing a hex string, for example, that contains invalid characters will
  3043. // cause everything after the first invalid character to be ignored. (e.g.
  3044. // 'abxxcd' will be treated as 'ab')
  3045. buf = buf.slice(0, actual)
  3046. }
  3047. return buf
  3048. }
  3049. function fromArrayLike (array) {
  3050. var length = array.length < 0 ? 0 : checked(array.length) | 0
  3051. var buf = createBuffer(length)
  3052. for (var i = 0; i < length; i += 1) {
  3053. buf[i] = array[i] & 255
  3054. }
  3055. return buf
  3056. }
  3057. function fromArrayBuffer (array, byteOffset, length) {
  3058. if (byteOffset < 0 || array.byteLength < byteOffset) {
  3059. throw new RangeError('"offset" is outside of buffer bounds')
  3060. }
  3061. if (array.byteLength < byteOffset + (length || 0)) {
  3062. throw new RangeError('"length" is outside of buffer bounds')
  3063. }
  3064. var buf
  3065. if (byteOffset === undefined && length === undefined) {
  3066. buf = new Uint8Array(array)
  3067. } else if (length === undefined) {
  3068. buf = new Uint8Array(array, byteOffset)
  3069. } else {
  3070. buf = new Uint8Array(array, byteOffset, length)
  3071. }
  3072. // Return an augmented `Uint8Array` instance
  3073. Object.setPrototypeOf(buf, Buffer.prototype)
  3074. return buf
  3075. }
  3076. function fromObject (obj) {
  3077. if (Buffer.isBuffer(obj)) {
  3078. var len = checked(obj.length) | 0
  3079. var buf = createBuffer(len)
  3080. if (buf.length === 0) {
  3081. return buf
  3082. }
  3083. obj.copy(buf, 0, 0, len)
  3084. return buf
  3085. }
  3086. if (obj.length !== undefined) {
  3087. if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
  3088. return createBuffer(0)
  3089. }
  3090. return fromArrayLike(obj)
  3091. }
  3092. if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
  3093. return fromArrayLike(obj.data)
  3094. }
  3095. }
  3096. function checked (length) {
  3097. // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
  3098. // length is NaN (which is otherwise coerced to zero.)
  3099. if (length >= K_MAX_LENGTH) {
  3100. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  3101. 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
  3102. }
  3103. return length | 0
  3104. }
  3105. function SlowBuffer (length) {
  3106. if (+length != length) { // eslint-disable-line eqeqeq
  3107. length = 0
  3108. }
  3109. return Buffer.alloc(+length)
  3110. }
  3111. Buffer.isBuffer = function isBuffer (b) {
  3112. return b != null && b._isBuffer === true &&
  3113. b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
  3114. }
  3115. Buffer.compare = function compare (a, b) {
  3116. if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)
  3117. if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)
  3118. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  3119. throw new TypeError(
  3120. 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
  3121. )
  3122. }
  3123. if (a === b) return 0
  3124. var x = a.length
  3125. var y = b.length
  3126. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  3127. if (a[i] !== b[i]) {
  3128. x = a[i]
  3129. y = b[i]
  3130. break
  3131. }
  3132. }
  3133. if (x < y) return -1
  3134. if (y < x) return 1
  3135. return 0
  3136. }
  3137. Buffer.isEncoding = function isEncoding (encoding) {
  3138. switch (String(encoding).toLowerCase()) {
  3139. case 'hex':
  3140. case 'utf8':
  3141. case 'utf-8':
  3142. case 'ascii':
  3143. case 'latin1':
  3144. case 'binary':
  3145. case 'base64':
  3146. case 'ucs2':
  3147. case 'ucs-2':
  3148. case 'utf16le':
  3149. case 'utf-16le':
  3150. return true
  3151. default:
  3152. return false
  3153. }
  3154. }
  3155. Buffer.concat = function concat (list, length) {
  3156. if (!Array.isArray(list)) {
  3157. throw new TypeError('"list" argument must be an Array of Buffers')
  3158. }
  3159. if (list.length === 0) {
  3160. return Buffer.alloc(0)
  3161. }
  3162. var i
  3163. if (length === undefined) {
  3164. length = 0
  3165. for (i = 0; i < list.length; ++i) {
  3166. length += list[i].length
  3167. }
  3168. }
  3169. var buffer = Buffer.allocUnsafe(length)
  3170. var pos = 0
  3171. for (i = 0; i < list.length; ++i) {
  3172. var buf = list[i]
  3173. if (isInstance(buf, Uint8Array)) {
  3174. buf = Buffer.from(buf)
  3175. }
  3176. if (!Buffer.isBuffer(buf)) {
  3177. throw new TypeError('"list" argument must be an Array of Buffers')
  3178. }
  3179. buf.copy(buffer, pos)
  3180. pos += buf.length
  3181. }
  3182. return buffer
  3183. }
  3184. function byteLength (string, encoding) {
  3185. if (Buffer.isBuffer(string)) {
  3186. return string.length
  3187. }
  3188. if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
  3189. return string.byteLength
  3190. }
  3191. if (typeof string !== 'string') {
  3192. throw new TypeError(
  3193. 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
  3194. 'Received type ' + typeof string
  3195. )
  3196. }
  3197. var len = string.length
  3198. var mustMatch = (arguments.length > 2 && arguments[2] === true)
  3199. if (!mustMatch && len === 0) return 0
  3200. // Use a for loop to avoid recursion
  3201. var loweredCase = false
  3202. for (;;) {
  3203. switch (encoding) {
  3204. case 'ascii':
  3205. case 'latin1':
  3206. case 'binary':
  3207. return len
  3208. case 'utf8':
  3209. case 'utf-8':
  3210. return utf8ToBytes(string).length
  3211. case 'ucs2':
  3212. case 'ucs-2':
  3213. case 'utf16le':
  3214. case 'utf-16le':
  3215. return len * 2
  3216. case 'hex':
  3217. return len >>> 1
  3218. case 'base64':
  3219. return base64ToBytes(string).length
  3220. default:
  3221. if (loweredCase) {
  3222. return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
  3223. }
  3224. encoding = ('' + encoding).toLowerCase()
  3225. loweredCase = true
  3226. }
  3227. }
  3228. }
  3229. Buffer.byteLength = byteLength
  3230. function slowToString (encoding, start, end) {
  3231. var loweredCase = false
  3232. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  3233. // property of a typed array.
  3234. // This behaves neither like String nor Uint8Array in that we set start/end
  3235. // to their upper/lower bounds if the value passed is out of range.
  3236. // undefined is handled specially as per ECMA-262 6th Edition,
  3237. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  3238. if (start === undefined || start < 0) {
  3239. start = 0
  3240. }
  3241. // Return early if start > this.length. Done here to prevent potential uint32
  3242. // coercion fail below.
  3243. if (start > this.length) {
  3244. return ''
  3245. }
  3246. if (end === undefined || end > this.length) {
  3247. end = this.length
  3248. }
  3249. if (end <= 0) {
  3250. return ''
  3251. }
  3252. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  3253. end >>>= 0
  3254. start >>>= 0
  3255. if (end <= start) {
  3256. return ''
  3257. }
  3258. if (!encoding) encoding = 'utf8'
  3259. while (true) {
  3260. switch (encoding) {
  3261. case 'hex':
  3262. return hexSlice(this, start, end)
  3263. case 'utf8':
  3264. case 'utf-8':
  3265. return utf8Slice(this, start, end)
  3266. case 'ascii':
  3267. return asciiSlice(this, start, end)
  3268. case 'latin1':
  3269. case 'binary':
  3270. return latin1Slice(this, start, end)
  3271. case 'base64':
  3272. return base64Slice(this, start, end)
  3273. case 'ucs2':
  3274. case 'ucs-2':
  3275. case 'utf16le':
  3276. case 'utf-16le':
  3277. return utf16leSlice(this, start, end)
  3278. default:
  3279. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  3280. encoding = (encoding + '').toLowerCase()
  3281. loweredCase = true
  3282. }
  3283. }
  3284. }
  3285. // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
  3286. // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
  3287. // reliably in a browserify context because there could be multiple different
  3288. // copies of the 'buffer' package in use. This method works even for Buffer
  3289. // instances that were created from another copy of the `buffer` package.
  3290. // See: https://github.com/feross/buffer/issues/154
  3291. Buffer.prototype._isBuffer = true
  3292. function swap (b, n, m) {
  3293. var i = b[n]
  3294. b[n] = b[m]
  3295. b[m] = i
  3296. }
  3297. Buffer.prototype.swap16 = function swap16 () {
  3298. var len = this.length
  3299. if (len % 2 !== 0) {
  3300. throw new RangeError('Buffer size must be a multiple of 16-bits')
  3301. }
  3302. for (var i = 0; i < len; i += 2) {
  3303. swap(this, i, i + 1)
  3304. }
  3305. return this
  3306. }
  3307. Buffer.prototype.swap32 = function swap32 () {
  3308. var len = this.length
  3309. if (len % 4 !== 0) {
  3310. throw new RangeError('Buffer size must be a multiple of 32-bits')
  3311. }
  3312. for (var i = 0; i < len; i += 4) {
  3313. swap(this, i, i + 3)
  3314. swap(this, i + 1, i + 2)
  3315. }
  3316. return this
  3317. }
  3318. Buffer.prototype.swap64 = function swap64 () {
  3319. var len = this.length
  3320. if (len % 8 !== 0) {
  3321. throw new RangeError('Buffer size must be a multiple of 64-bits')
  3322. }
  3323. for (var i = 0; i < len; i += 8) {
  3324. swap(this, i, i + 7)
  3325. swap(this, i + 1, i + 6)
  3326. swap(this, i + 2, i + 5)
  3327. swap(this, i + 3, i + 4)
  3328. }
  3329. return this
  3330. }
  3331. Buffer.prototype.toString = function toString () {
  3332. var length = this.length
  3333. if (length === 0) return ''
  3334. if (arguments.length === 0) return utf8Slice(this, 0, length)
  3335. return slowToString.apply(this, arguments)
  3336. }
  3337. Buffer.prototype.toLocaleString = Buffer.prototype.toString
  3338. Buffer.prototype.equals = function equals (b) {
  3339. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  3340. if (this === b) return true
  3341. return Buffer.compare(this, b) === 0
  3342. }
  3343. Buffer.prototype.inspect = function inspect () {
  3344. var str = ''
  3345. var max = exports.INSPECT_MAX_BYTES
  3346. str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()
  3347. if (this.length > max) str += ' ... '
  3348. return '<Buffer ' + str + '>'
  3349. }
  3350. if (customInspectSymbol) {
  3351. Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect
  3352. }
  3353. Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  3354. if (isInstance(target, Uint8Array)) {
  3355. target = Buffer.from(target, target.offset, target.byteLength)
  3356. }
  3357. if (!Buffer.isBuffer(target)) {
  3358. throw new TypeError(
  3359. 'The "target" argument must be one of type Buffer or Uint8Array. ' +
  3360. 'Received type ' + (typeof target)
  3361. )
  3362. }
  3363. if (start === undefined) {
  3364. start = 0
  3365. }
  3366. if (end === undefined) {
  3367. end = target ? target.length : 0
  3368. }
  3369. if (thisStart === undefined) {
  3370. thisStart = 0
  3371. }
  3372. if (thisEnd === undefined) {
  3373. thisEnd = this.length
  3374. }
  3375. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  3376. throw new RangeError('out of range index')
  3377. }
  3378. if (thisStart >= thisEnd && start >= end) {
  3379. return 0
  3380. }
  3381. if (thisStart >= thisEnd) {
  3382. return -1
  3383. }
  3384. if (start >= end) {
  3385. return 1
  3386. }
  3387. start >>>= 0
  3388. end >>>= 0
  3389. thisStart >>>= 0
  3390. thisEnd >>>= 0
  3391. if (this === target) return 0
  3392. var x = thisEnd - thisStart
  3393. var y = end - start
  3394. var len = Math.min(x, y)
  3395. var thisCopy = this.slice(thisStart, thisEnd)
  3396. var targetCopy = target.slice(start, end)
  3397. for (var i = 0; i < len; ++i) {
  3398. if (thisCopy[i] !== targetCopy[i]) {
  3399. x = thisCopy[i]
  3400. y = targetCopy[i]
  3401. break
  3402. }
  3403. }
  3404. if (x < y) return -1
  3405. if (y < x) return 1
  3406. return 0
  3407. }
  3408. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  3409. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  3410. //
  3411. // Arguments:
  3412. // - buffer - a Buffer to search
  3413. // - val - a string, Buffer, or number
  3414. // - byteOffset - an index into `buffer`; will be clamped to an int32
  3415. // - encoding - an optional encoding, relevant is val is a string
  3416. // - dir - true for indexOf, false for lastIndexOf
  3417. function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
  3418. // Empty buffer means no match
  3419. if (buffer.length === 0) return -1
  3420. // Normalize byteOffset
  3421. if (typeof byteOffset === 'string') {
  3422. encoding = byteOffset
  3423. byteOffset = 0
  3424. } else if (byteOffset > 0x7fffffff) {
  3425. byteOffset = 0x7fffffff
  3426. } else if (byteOffset < -0x80000000) {
  3427. byteOffset = -0x80000000
  3428. }
  3429. byteOffset = +byteOffset // Coerce to Number.
  3430. if (numberIsNaN(byteOffset)) {
  3431. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  3432. byteOffset = dir ? 0 : (buffer.length - 1)
  3433. }
  3434. // Normalize byteOffset: negative offsets start from the end of the buffer
  3435. if (byteOffset < 0) byteOffset = buffer.length + byteOffset
  3436. if (byteOffset >= buffer.length) {
  3437. if (dir) return -1
  3438. else byteOffset = buffer.length - 1
  3439. } else if (byteOffset < 0) {
  3440. if (dir) byteOffset = 0
  3441. else return -1
  3442. }
  3443. // Normalize val
  3444. if (typeof val === 'string') {
  3445. val = Buffer.from(val, encoding)
  3446. }
  3447. // Finally, search either indexOf (if dir is true) or lastIndexOf
  3448. if (Buffer.isBuffer(val)) {
  3449. // Special case: looking for empty string/buffer always fails
  3450. if (val.length === 0) {
  3451. return -1
  3452. }
  3453. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  3454. } else if (typeof val === 'number') {
  3455. val = val & 0xFF // Search for a byte value [0-255]
  3456. if (typeof Uint8Array.prototype.indexOf === 'function') {
  3457. if (dir) {
  3458. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  3459. } else {
  3460. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  3461. }
  3462. }
  3463. return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
  3464. }
  3465. throw new TypeError('val must be string, number or Buffer')
  3466. }
  3467. function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
  3468. var indexSize = 1
  3469. var arrLength = arr.length
  3470. var valLength = val.length
  3471. if (encoding !== undefined) {
  3472. encoding = String(encoding).toLowerCase()
  3473. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  3474. encoding === 'utf16le' || encoding === 'utf-16le') {
  3475. if (arr.length < 2 || val.length < 2) {
  3476. return -1
  3477. }
  3478. indexSize = 2
  3479. arrLength /= 2
  3480. valLength /= 2
  3481. byteOffset /= 2
  3482. }
  3483. }
  3484. function read (buf, i) {
  3485. if (indexSize === 1) {
  3486. return buf[i]
  3487. } else {
  3488. return buf.readUInt16BE(i * indexSize)
  3489. }
  3490. }
  3491. var i
  3492. if (dir) {
  3493. var foundIndex = -1
  3494. for (i = byteOffset; i < arrLength; i++) {
  3495. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  3496. if (foundIndex === -1) foundIndex = i
  3497. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  3498. } else {
  3499. if (foundIndex !== -1) i -= i - foundIndex
  3500. foundIndex = -1
  3501. }
  3502. }
  3503. } else {
  3504. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
  3505. for (i = byteOffset; i >= 0; i--) {
  3506. var found = true
  3507. for (var j = 0; j < valLength; j++) {
  3508. if (read(arr, i + j) !== read(val, j)) {
  3509. found = false
  3510. break
  3511. }
  3512. }
  3513. if (found) return i
  3514. }
  3515. }
  3516. return -1
  3517. }
  3518. Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
  3519. return this.indexOf(val, byteOffset, encoding) !== -1
  3520. }
  3521. Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  3522. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  3523. }
  3524. Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
  3525. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  3526. }
  3527. function hexWrite (buf, string, offset, length) {
  3528. offset = Number(offset) || 0
  3529. var remaining = buf.length - offset
  3530. if (!length) {
  3531. length = remaining
  3532. } else {
  3533. length = Number(length)
  3534. if (length > remaining) {
  3535. length = remaining
  3536. }
  3537. }
  3538. var strLen = string.length
  3539. if (length > strLen / 2) {
  3540. length = strLen / 2
  3541. }
  3542. for (var i = 0; i < length; ++i) {
  3543. var parsed = parseInt(string.substr(i * 2, 2), 16)
  3544. if (numberIsNaN(parsed)) return i
  3545. buf[offset + i] = parsed
  3546. }
  3547. return i
  3548. }
  3549. function utf8Write (buf, string, offset, length) {
  3550. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  3551. }
  3552. function asciiWrite (buf, string, offset, length) {
  3553. return blitBuffer(asciiToBytes(string), buf, offset, length)
  3554. }
  3555. function latin1Write (buf, string, offset, length) {
  3556. return asciiWrite(buf, string, offset, length)
  3557. }
  3558. function base64Write (buf, string, offset, length) {
  3559. return blitBuffer(base64ToBytes(string), buf, offset, length)
  3560. }
  3561. function ucs2Write (buf, string, offset, length) {
  3562. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  3563. }
  3564. Buffer.prototype.write = function write (string, offset, length, encoding) {
  3565. // Buffer#write(string)
  3566. if (offset === undefined) {
  3567. encoding = 'utf8'
  3568. length = this.length
  3569. offset = 0
  3570. // Buffer#write(string, encoding)
  3571. } else if (length === undefined && typeof offset === 'string') {
  3572. encoding = offset
  3573. length = this.length
  3574. offset = 0
  3575. // Buffer#write(string, offset[, length][, encoding])
  3576. } else if (isFinite(offset)) {
  3577. offset = offset >>> 0
  3578. if (isFinite(length)) {
  3579. length = length >>> 0
  3580. if (encoding === undefined) encoding = 'utf8'
  3581. } else {
  3582. encoding = length
  3583. length = undefined
  3584. }
  3585. } else {
  3586. throw new Error(
  3587. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  3588. )
  3589. }
  3590. var remaining = this.length - offset
  3591. if (length === undefined || length > remaining) length = remaining
  3592. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  3593. throw new RangeError('Attempt to write outside buffer bounds')
  3594. }
  3595. if (!encoding) encoding = 'utf8'
  3596. var loweredCase = false
  3597. for (;;) {
  3598. switch (encoding) {
  3599. case 'hex':
  3600. return hexWrite(this, string, offset, length)
  3601. case 'utf8':
  3602. case 'utf-8':
  3603. return utf8Write(this, string, offset, length)
  3604. case 'ascii':
  3605. return asciiWrite(this, string, offset, length)
  3606. case 'latin1':
  3607. case 'binary':
  3608. return latin1Write(this, string, offset, length)
  3609. case 'base64':
  3610. // Warning: maxLength not taken into account in base64Write
  3611. return base64Write(this, string, offset, length)
  3612. case 'ucs2':
  3613. case 'ucs-2':
  3614. case 'utf16le':
  3615. case 'utf-16le':
  3616. return ucs2Write(this, string, offset, length)
  3617. default:
  3618. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  3619. encoding = ('' + encoding).toLowerCase()
  3620. loweredCase = true
  3621. }
  3622. }
  3623. }
  3624. Buffer.prototype.toJSON = function toJSON () {
  3625. return {
  3626. type: 'Buffer',
  3627. data: Array.prototype.slice.call(this._arr || this, 0)
  3628. }
  3629. }
  3630. function base64Slice (buf, start, end) {
  3631. if (start === 0 && end === buf.length) {
  3632. return base64.fromByteArray(buf)
  3633. } else {
  3634. return base64.fromByteArray(buf.slice(start, end))
  3635. }
  3636. }
  3637. function utf8Slice (buf, start, end) {
  3638. end = Math.min(buf.length, end)
  3639. var res = []
  3640. var i = start
  3641. while (i < end) {
  3642. var firstByte = buf[i]
  3643. var codePoint = null
  3644. var bytesPerSequence = (firstByte > 0xEF) ? 4
  3645. : (firstByte > 0xDF) ? 3
  3646. : (firstByte > 0xBF) ? 2
  3647. : 1
  3648. if (i + bytesPerSequence <= end) {
  3649. var secondByte, thirdByte, fourthByte, tempCodePoint
  3650. switch (bytesPerSequence) {
  3651. case 1:
  3652. if (firstByte < 0x80) {
  3653. codePoint = firstByte
  3654. }
  3655. break
  3656. case 2:
  3657. secondByte = buf[i + 1]
  3658. if ((secondByte & 0xC0) === 0x80) {
  3659. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
  3660. if (tempCodePoint > 0x7F) {
  3661. codePoint = tempCodePoint
  3662. }
  3663. }
  3664. break
  3665. case 3:
  3666. secondByte = buf[i + 1]
  3667. thirdByte = buf[i + 2]
  3668. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  3669. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
  3670. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  3671. codePoint = tempCodePoint
  3672. }
  3673. }
  3674. break
  3675. case 4:
  3676. secondByte = buf[i + 1]
  3677. thirdByte = buf[i + 2]
  3678. fourthByte = buf[i + 3]
  3679. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  3680. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
  3681. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  3682. codePoint = tempCodePoint
  3683. }
  3684. }
  3685. }
  3686. }
  3687. if (codePoint === null) {
  3688. // we did not generate a valid codePoint so insert a
  3689. // replacement char (U+FFFD) and advance only 1 byte
  3690. codePoint = 0xFFFD
  3691. bytesPerSequence = 1
  3692. } else if (codePoint > 0xFFFF) {
  3693. // encode to utf16 (surrogate pair dance)
  3694. codePoint -= 0x10000
  3695. res.push(codePoint >>> 10 & 0x3FF | 0xD800)
  3696. codePoint = 0xDC00 | codePoint & 0x3FF
  3697. }
  3698. res.push(codePoint)
  3699. i += bytesPerSequence
  3700. }
  3701. return decodeCodePointsArray(res)
  3702. }
  3703. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  3704. // the lowest limit is Chrome, with 0x10000 args.
  3705. // We go 1 magnitude less, for safety
  3706. var MAX_ARGUMENTS_LENGTH = 0x1000
  3707. function decodeCodePointsArray (codePoints) {
  3708. var len = codePoints.length
  3709. if (len <= MAX_ARGUMENTS_LENGTH) {
  3710. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  3711. }
  3712. // Decode in chunks to avoid "call stack size exceeded".
  3713. var res = ''
  3714. var i = 0
  3715. while (i < len) {
  3716. res += String.fromCharCode.apply(
  3717. String,
  3718. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  3719. )
  3720. }
  3721. return res
  3722. }
  3723. function asciiSlice (buf, start, end) {
  3724. var ret = ''
  3725. end = Math.min(buf.length, end)
  3726. for (var i = start; i < end; ++i) {
  3727. ret += String.fromCharCode(buf[i] & 0x7F)
  3728. }
  3729. return ret
  3730. }
  3731. function latin1Slice (buf, start, end) {
  3732. var ret = ''
  3733. end = Math.min(buf.length, end)
  3734. for (var i = start; i < end; ++i) {
  3735. ret += String.fromCharCode(buf[i])
  3736. }
  3737. return ret
  3738. }
  3739. function hexSlice (buf, start, end) {
  3740. var len = buf.length
  3741. if (!start || start < 0) start = 0
  3742. if (!end || end < 0 || end > len) end = len
  3743. var out = ''
  3744. for (var i = start; i < end; ++i) {
  3745. out += hexSliceLookupTable[buf[i]]
  3746. }
  3747. return out
  3748. }
  3749. function utf16leSlice (buf, start, end) {
  3750. var bytes = buf.slice(start, end)
  3751. var res = ''
  3752. for (var i = 0; i < bytes.length; i += 2) {
  3753. res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
  3754. }
  3755. return res
  3756. }
  3757. Buffer.prototype.slice = function slice (start, end) {
  3758. var len = this.length
  3759. start = ~~start
  3760. end = end === undefined ? len : ~~end
  3761. if (start < 0) {
  3762. start += len
  3763. if (start < 0) start = 0
  3764. } else if (start > len) {
  3765. start = len
  3766. }
  3767. if (end < 0) {
  3768. end += len
  3769. if (end < 0) end = 0
  3770. } else if (end > len) {
  3771. end = len
  3772. }
  3773. if (end < start) end = start
  3774. var newBuf = this.subarray(start, end)
  3775. // Return an augmented `Uint8Array` instance
  3776. Object.setPrototypeOf(newBuf, Buffer.prototype)
  3777. return newBuf
  3778. }
  3779. /*
  3780. * Need to make sure that buffer isn't trying to write out of bounds.
  3781. */
  3782. function checkOffset (offset, ext, length) {
  3783. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  3784. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  3785. }
  3786. Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  3787. offset = offset >>> 0
  3788. byteLength = byteLength >>> 0
  3789. if (!noAssert) checkOffset(offset, byteLength, this.length)
  3790. var val = this[offset]
  3791. var mul = 1
  3792. var i = 0
  3793. while (++i < byteLength && (mul *= 0x100)) {
  3794. val += this[offset + i] * mul
  3795. }
  3796. return val
  3797. }
  3798. Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  3799. offset = offset >>> 0
  3800. byteLength = byteLength >>> 0
  3801. if (!noAssert) {
  3802. checkOffset(offset, byteLength, this.length)
  3803. }
  3804. var val = this[offset + --byteLength]
  3805. var mul = 1
  3806. while (byteLength > 0 && (mul *= 0x100)) {
  3807. val += this[offset + --byteLength] * mul
  3808. }
  3809. return val
  3810. }
  3811. Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  3812. offset = offset >>> 0
  3813. if (!noAssert) checkOffset(offset, 1, this.length)
  3814. return this[offset]
  3815. }
  3816. Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  3817. offset = offset >>> 0
  3818. if (!noAssert) checkOffset(offset, 2, this.length)
  3819. return this[offset] | (this[offset + 1] << 8)
  3820. }
  3821. Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  3822. offset = offset >>> 0
  3823. if (!noAssert) checkOffset(offset, 2, this.length)
  3824. return (this[offset] << 8) | this[offset + 1]
  3825. }
  3826. Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  3827. offset = offset >>> 0
  3828. if (!noAssert) checkOffset(offset, 4, this.length)
  3829. return ((this[offset]) |
  3830. (this[offset + 1] << 8) |
  3831. (this[offset + 2] << 16)) +
  3832. (this[offset + 3] * 0x1000000)
  3833. }
  3834. Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  3835. offset = offset >>> 0
  3836. if (!noAssert) checkOffset(offset, 4, this.length)
  3837. return (this[offset] * 0x1000000) +
  3838. ((this[offset + 1] << 16) |
  3839. (this[offset + 2] << 8) |
  3840. this[offset + 3])
  3841. }
  3842. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  3843. offset = offset >>> 0
  3844. byteLength = byteLength >>> 0
  3845. if (!noAssert) checkOffset(offset, byteLength, this.length)
  3846. var val = this[offset]
  3847. var mul = 1
  3848. var i = 0
  3849. while (++i < byteLength && (mul *= 0x100)) {
  3850. val += this[offset + i] * mul
  3851. }
  3852. mul *= 0x80
  3853. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  3854. return val
  3855. }
  3856. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  3857. offset = offset >>> 0
  3858. byteLength = byteLength >>> 0
  3859. if (!noAssert) checkOffset(offset, byteLength, this.length)
  3860. var i = byteLength
  3861. var mul = 1
  3862. var val = this[offset + --i]
  3863. while (i > 0 && (mul *= 0x100)) {
  3864. val += this[offset + --i] * mul
  3865. }
  3866. mul *= 0x80
  3867. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  3868. return val
  3869. }
  3870. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  3871. offset = offset >>> 0
  3872. if (!noAssert) checkOffset(offset, 1, this.length)
  3873. if (!(this[offset] & 0x80)) return (this[offset])
  3874. return ((0xff - this[offset] + 1) * -1)
  3875. }
  3876. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  3877. offset = offset >>> 0
  3878. if (!noAssert) checkOffset(offset, 2, this.length)
  3879. var val = this[offset] | (this[offset + 1] << 8)
  3880. return (val & 0x8000) ? val | 0xFFFF0000 : val
  3881. }
  3882. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  3883. offset = offset >>> 0
  3884. if (!noAssert) checkOffset(offset, 2, this.length)
  3885. var val = this[offset + 1] | (this[offset] << 8)
  3886. return (val & 0x8000) ? val | 0xFFFF0000 : val
  3887. }
  3888. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  3889. offset = offset >>> 0
  3890. if (!noAssert) checkOffset(offset, 4, this.length)
  3891. return (this[offset]) |
  3892. (this[offset + 1] << 8) |
  3893. (this[offset + 2] << 16) |
  3894. (this[offset + 3] << 24)
  3895. }
  3896. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  3897. offset = offset >>> 0
  3898. if (!noAssert) checkOffset(offset, 4, this.length)
  3899. return (this[offset] << 24) |
  3900. (this[offset + 1] << 16) |
  3901. (this[offset + 2] << 8) |
  3902. (this[offset + 3])
  3903. }
  3904. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  3905. offset = offset >>> 0
  3906. if (!noAssert) checkOffset(offset, 4, this.length)
  3907. return ieee754.read(this, offset, true, 23, 4)
  3908. }
  3909. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  3910. offset = offset >>> 0
  3911. if (!noAssert) checkOffset(offset, 4, this.length)
  3912. return ieee754.read(this, offset, false, 23, 4)
  3913. }
  3914. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  3915. offset = offset >>> 0
  3916. if (!noAssert) checkOffset(offset, 8, this.length)
  3917. return ieee754.read(this, offset, true, 52, 8)
  3918. }
  3919. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  3920. offset = offset >>> 0
  3921. if (!noAssert) checkOffset(offset, 8, this.length)
  3922. return ieee754.read(this, offset, false, 52, 8)
  3923. }
  3924. function checkInt (buf, value, offset, ext, max, min) {
  3925. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  3926. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  3927. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  3928. }
  3929. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  3930. value = +value
  3931. offset = offset >>> 0
  3932. byteLength = byteLength >>> 0
  3933. if (!noAssert) {
  3934. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  3935. checkInt(this, value, offset, byteLength, maxBytes, 0)
  3936. }
  3937. var mul = 1
  3938. var i = 0
  3939. this[offset] = value & 0xFF
  3940. while (++i < byteLength && (mul *= 0x100)) {
  3941. this[offset + i] = (value / mul) & 0xFF
  3942. }
  3943. return offset + byteLength
  3944. }
  3945. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  3946. value = +value
  3947. offset = offset >>> 0
  3948. byteLength = byteLength >>> 0
  3949. if (!noAssert) {
  3950. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  3951. checkInt(this, value, offset, byteLength, maxBytes, 0)
  3952. }
  3953. var i = byteLength - 1
  3954. var mul = 1
  3955. this[offset + i] = value & 0xFF
  3956. while (--i >= 0 && (mul *= 0x100)) {
  3957. this[offset + i] = (value / mul) & 0xFF
  3958. }
  3959. return offset + byteLength
  3960. }
  3961. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  3962. value = +value
  3963. offset = offset >>> 0
  3964. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  3965. this[offset] = (value & 0xff)
  3966. return offset + 1
  3967. }
  3968. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  3969. value = +value
  3970. offset = offset >>> 0
  3971. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  3972. this[offset] = (value & 0xff)
  3973. this[offset + 1] = (value >>> 8)
  3974. return offset + 2
  3975. }
  3976. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  3977. value = +value
  3978. offset = offset >>> 0
  3979. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  3980. this[offset] = (value >>> 8)
  3981. this[offset + 1] = (value & 0xff)
  3982. return offset + 2
  3983. }
  3984. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  3985. value = +value
  3986. offset = offset >>> 0
  3987. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  3988. this[offset + 3] = (value >>> 24)
  3989. this[offset + 2] = (value >>> 16)
  3990. this[offset + 1] = (value >>> 8)
  3991. this[offset] = (value & 0xff)
  3992. return offset + 4
  3993. }
  3994. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  3995. value = +value
  3996. offset = offset >>> 0
  3997. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  3998. this[offset] = (value >>> 24)
  3999. this[offset + 1] = (value >>> 16)
  4000. this[offset + 2] = (value >>> 8)
  4001. this[offset + 3] = (value & 0xff)
  4002. return offset + 4
  4003. }
  4004. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  4005. value = +value
  4006. offset = offset >>> 0
  4007. if (!noAssert) {
  4008. var limit = Math.pow(2, (8 * byteLength) - 1)
  4009. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  4010. }
  4011. var i = 0
  4012. var mul = 1
  4013. var sub = 0
  4014. this[offset] = value & 0xFF
  4015. while (++i < byteLength && (mul *= 0x100)) {
  4016. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  4017. sub = 1
  4018. }
  4019. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  4020. }
  4021. return offset + byteLength
  4022. }
  4023. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  4024. value = +value
  4025. offset = offset >>> 0
  4026. if (!noAssert) {
  4027. var limit = Math.pow(2, (8 * byteLength) - 1)
  4028. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  4029. }
  4030. var i = byteLength - 1
  4031. var mul = 1
  4032. var sub = 0
  4033. this[offset + i] = value & 0xFF
  4034. while (--i >= 0 && (mul *= 0x100)) {
  4035. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  4036. sub = 1
  4037. }
  4038. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  4039. }
  4040. return offset + byteLength
  4041. }
  4042. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  4043. value = +value
  4044. offset = offset >>> 0
  4045. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  4046. if (value < 0) value = 0xff + value + 1
  4047. this[offset] = (value & 0xff)
  4048. return offset + 1
  4049. }
  4050. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  4051. value = +value
  4052. offset = offset >>> 0
  4053. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  4054. this[offset] = (value & 0xff)
  4055. this[offset + 1] = (value >>> 8)
  4056. return offset + 2
  4057. }
  4058. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  4059. value = +value
  4060. offset = offset >>> 0
  4061. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  4062. this[offset] = (value >>> 8)
  4063. this[offset + 1] = (value & 0xff)
  4064. return offset + 2
  4065. }
  4066. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  4067. value = +value
  4068. offset = offset >>> 0
  4069. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  4070. this[offset] = (value & 0xff)
  4071. this[offset + 1] = (value >>> 8)
  4072. this[offset + 2] = (value >>> 16)
  4073. this[offset + 3] = (value >>> 24)
  4074. return offset + 4
  4075. }
  4076. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  4077. value = +value
  4078. offset = offset >>> 0
  4079. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  4080. if (value < 0) value = 0xffffffff + value + 1
  4081. this[offset] = (value >>> 24)
  4082. this[offset + 1] = (value >>> 16)
  4083. this[offset + 2] = (value >>> 8)
  4084. this[offset + 3] = (value & 0xff)
  4085. return offset + 4
  4086. }
  4087. function checkIEEE754 (buf, value, offset, ext, max, min) {
  4088. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  4089. if (offset < 0) throw new RangeError('Index out of range')
  4090. }
  4091. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  4092. value = +value
  4093. offset = offset >>> 0
  4094. if (!noAssert) {
  4095. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  4096. }
  4097. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  4098. return offset + 4
  4099. }
  4100. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  4101. return writeFloat(this, value, offset, true, noAssert)
  4102. }
  4103. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  4104. return writeFloat(this, value, offset, false, noAssert)
  4105. }
  4106. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  4107. value = +value
  4108. offset = offset >>> 0
  4109. if (!noAssert) {
  4110. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  4111. }
  4112. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  4113. return offset + 8
  4114. }
  4115. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  4116. return writeDouble(this, value, offset, true, noAssert)
  4117. }
  4118. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  4119. return writeDouble(this, value, offset, false, noAssert)
  4120. }
  4121. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  4122. Buffer.prototype.copy = function copy (target, targetStart, start, end) {
  4123. if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
  4124. if (!start) start = 0
  4125. if (!end && end !== 0) end = this.length
  4126. if (targetStart >= target.length) targetStart = target.length
  4127. if (!targetStart) targetStart = 0
  4128. if (end > 0 && end < start) end = start
  4129. // Copy 0 bytes; we're done
  4130. if (end === start) return 0
  4131. if (target.length === 0 || this.length === 0) return 0
  4132. // Fatal error conditions
  4133. if (targetStart < 0) {
  4134. throw new RangeError('targetStart out of bounds')
  4135. }
  4136. if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
  4137. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  4138. // Are we oob?
  4139. if (end > this.length) end = this.length
  4140. if (target.length - targetStart < end - start) {
  4141. end = target.length - targetStart + start
  4142. }
  4143. var len = end - start
  4144. if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
  4145. // Use built-in when available, missing from IE11
  4146. this.copyWithin(targetStart, start, end)
  4147. } else if (this === target && start < targetStart && targetStart < end) {
  4148. // descending copy from end
  4149. for (var i = len - 1; i >= 0; --i) {
  4150. target[i + targetStart] = this[i + start]
  4151. }
  4152. } else {
  4153. Uint8Array.prototype.set.call(
  4154. target,
  4155. this.subarray(start, end),
  4156. targetStart
  4157. )
  4158. }
  4159. return len
  4160. }
  4161. // Usage:
  4162. // buffer.fill(number[, offset[, end]])
  4163. // buffer.fill(buffer[, offset[, end]])
  4164. // buffer.fill(string[, offset[, end]][, encoding])
  4165. Buffer.prototype.fill = function fill (val, start, end, encoding) {
  4166. // Handle string cases:
  4167. if (typeof val === 'string') {
  4168. if (typeof start === 'string') {
  4169. encoding = start
  4170. start = 0
  4171. end = this.length
  4172. } else if (typeof end === 'string') {
  4173. encoding = end
  4174. end = this.length
  4175. }
  4176. if (encoding !== undefined && typeof encoding !== 'string') {
  4177. throw new TypeError('encoding must be a string')
  4178. }
  4179. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  4180. throw new TypeError('Unknown encoding: ' + encoding)
  4181. }
  4182. if (val.length === 1) {
  4183. var code = val.charCodeAt(0)
  4184. if ((encoding === 'utf8' && code < 128) ||
  4185. encoding === 'latin1') {
  4186. // Fast path: If `val` fits into a single byte, use that numeric value.
  4187. val = code
  4188. }
  4189. }
  4190. } else if (typeof val === 'number') {
  4191. val = val & 255
  4192. } else if (typeof val === 'boolean') {
  4193. val = Number(val)
  4194. }
  4195. // Invalid ranges are not set to a default, so can range check early.
  4196. if (start < 0 || this.length < start || this.length < end) {
  4197. throw new RangeError('Out of range index')
  4198. }
  4199. if (end <= start) {
  4200. return this
  4201. }
  4202. start = start >>> 0
  4203. end = end === undefined ? this.length : end >>> 0
  4204. if (!val) val = 0
  4205. var i
  4206. if (typeof val === 'number') {
  4207. for (i = start; i < end; ++i) {
  4208. this[i] = val
  4209. }
  4210. } else {
  4211. var bytes = Buffer.isBuffer(val)
  4212. ? val
  4213. : Buffer.from(val, encoding)
  4214. var len = bytes.length
  4215. if (len === 0) {
  4216. throw new TypeError('The value "' + val +
  4217. '" is invalid for argument "value"')
  4218. }
  4219. for (i = 0; i < end - start; ++i) {
  4220. this[i + start] = bytes[i % len]
  4221. }
  4222. }
  4223. return this
  4224. }
  4225. // HELPER FUNCTIONS
  4226. // ================
  4227. var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
  4228. function base64clean (str) {
  4229. // Node takes equal signs as end of the Base64 encoding
  4230. str = str.split('=')[0]
  4231. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  4232. str = str.trim().replace(INVALID_BASE64_RE, '')
  4233. // Node converts strings with length < 2 to ''
  4234. if (str.length < 2) return ''
  4235. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  4236. while (str.length % 4 !== 0) {
  4237. str = str + '='
  4238. }
  4239. return str
  4240. }
  4241. function utf8ToBytes (string, units) {
  4242. units = units || Infinity
  4243. var codePoint
  4244. var length = string.length
  4245. var leadSurrogate = null
  4246. var bytes = []
  4247. for (var i = 0; i < length; ++i) {
  4248. codePoint = string.charCodeAt(i)
  4249. // is surrogate component
  4250. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  4251. // last char was a lead
  4252. if (!leadSurrogate) {
  4253. // no lead yet
  4254. if (codePoint > 0xDBFF) {
  4255. // unexpected trail
  4256. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  4257. continue
  4258. } else if (i + 1 === length) {
  4259. // unpaired lead
  4260. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  4261. continue
  4262. }
  4263. // valid lead
  4264. leadSurrogate = codePoint
  4265. continue
  4266. }
  4267. // 2 leads in a row
  4268. if (codePoint < 0xDC00) {
  4269. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  4270. leadSurrogate = codePoint
  4271. continue
  4272. }
  4273. // valid surrogate pair
  4274. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  4275. } else if (leadSurrogate) {
  4276. // valid bmp char, but last char was a lead
  4277. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  4278. }
  4279. leadSurrogate = null
  4280. // encode utf8
  4281. if (codePoint < 0x80) {
  4282. if ((units -= 1) < 0) break
  4283. bytes.push(codePoint)
  4284. } else if (codePoint < 0x800) {
  4285. if ((units -= 2) < 0) break
  4286. bytes.push(
  4287. codePoint >> 0x6 | 0xC0,
  4288. codePoint & 0x3F | 0x80
  4289. )
  4290. } else if (codePoint < 0x10000) {
  4291. if ((units -= 3) < 0) break
  4292. bytes.push(
  4293. codePoint >> 0xC | 0xE0,
  4294. codePoint >> 0x6 & 0x3F | 0x80,
  4295. codePoint & 0x3F | 0x80
  4296. )
  4297. } else if (codePoint < 0x110000) {
  4298. if ((units -= 4) < 0) break
  4299. bytes.push(
  4300. codePoint >> 0x12 | 0xF0,
  4301. codePoint >> 0xC & 0x3F | 0x80,
  4302. codePoint >> 0x6 & 0x3F | 0x80,
  4303. codePoint & 0x3F | 0x80
  4304. )
  4305. } else {
  4306. throw new Error('Invalid code point')
  4307. }
  4308. }
  4309. return bytes
  4310. }
  4311. function asciiToBytes (str) {
  4312. var byteArray = []
  4313. for (var i = 0; i < str.length; ++i) {
  4314. // Node's code seems to be doing this and not & 0x7F..
  4315. byteArray.push(str.charCodeAt(i) & 0xFF)
  4316. }
  4317. return byteArray
  4318. }
  4319. function utf16leToBytes (str, units) {
  4320. var c, hi, lo
  4321. var byteArray = []
  4322. for (var i = 0; i < str.length; ++i) {
  4323. if ((units -= 2) < 0) break
  4324. c = str.charCodeAt(i)
  4325. hi = c >> 8
  4326. lo = c % 256
  4327. byteArray.push(lo)
  4328. byteArray.push(hi)
  4329. }
  4330. return byteArray
  4331. }
  4332. function base64ToBytes (str) {
  4333. return base64.toByteArray(base64clean(str))
  4334. }
  4335. function blitBuffer (src, dst, offset, length) {
  4336. for (var i = 0; i < length; ++i) {
  4337. if ((i + offset >= dst.length) || (i >= src.length)) break
  4338. dst[i + offset] = src[i]
  4339. }
  4340. return i
  4341. }
  4342. // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
  4343. // the `instanceof` check but they should be treated as of that type.
  4344. // See: https://github.com/feross/buffer/issues/166
  4345. function isInstance (obj, type) {
  4346. return obj instanceof type ||
  4347. (obj != null && obj.constructor != null && obj.constructor.name != null &&
  4348. obj.constructor.name === type.name)
  4349. }
  4350. function numberIsNaN (obj) {
  4351. // For IE11 support
  4352. return obj !== obj // eslint-disable-line no-self-compare
  4353. }
  4354. // Create lookup table for `toString('hex')`
  4355. // See: https://github.com/feross/buffer/issues/219
  4356. var hexSliceLookupTable = (function () {
  4357. var alphabet = '0123456789abcdef'
  4358. var table = new Array(256)
  4359. for (var i = 0; i < 16; ++i) {
  4360. var i16 = i * 16
  4361. for (var j = 0; j < 16; ++j) {
  4362. table[i16 + j] = alphabet[i] + alphabet[j]
  4363. }
  4364. }
  4365. return table
  4366. })()
  4367. },{"base64-js":29,"ieee754":32}],31:[function(require,module,exports){
  4368. 'use strict';
  4369. /******************************************************************************
  4370. * Created 2008-08-19.
  4371. *
  4372. * Dijkstra path-finding functions. Adapted from the Dijkstar Python project.
  4373. *
  4374. * Copyright (C) 2008
  4375. * Wyatt Baldwin <self@wyattbaldwin.com>
  4376. * All rights reserved
  4377. *
  4378. * Licensed under the MIT license.
  4379. *
  4380. * http://www.opensource.org/licenses/mit-license.php
  4381. *
  4382. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  4383. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  4384. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  4385. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  4386. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  4387. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  4388. * THE SOFTWARE.
  4389. *****************************************************************************/
  4390. var dijkstra = {
  4391. single_source_shortest_paths: function(graph, s, d) {
  4392. // Predecessor map for each node that has been encountered.
  4393. // node ID => predecessor node ID
  4394. var predecessors = {};
  4395. // Costs of shortest paths from s to all nodes encountered.
  4396. // node ID => cost
  4397. var costs = {};
  4398. costs[s] = 0;
  4399. // Costs of shortest paths from s to all nodes encountered; differs from
  4400. // `costs` in that it provides easy access to the node that currently has
  4401. // the known shortest path from s.
  4402. // XXX: Do we actually need both `costs` and `open`?
  4403. var open = dijkstra.PriorityQueue.make();
  4404. open.push(s, 0);
  4405. var closest,
  4406. u, v,
  4407. cost_of_s_to_u,
  4408. adjacent_nodes,
  4409. cost_of_e,
  4410. cost_of_s_to_u_plus_cost_of_e,
  4411. cost_of_s_to_v,
  4412. first_visit;
  4413. while (!open.empty()) {
  4414. // In the nodes remaining in graph that have a known cost from s,
  4415. // find the node, u, that currently has the shortest path from s.
  4416. closest = open.pop();
  4417. u = closest.value;
  4418. cost_of_s_to_u = closest.cost;
  4419. // Get nodes adjacent to u...
  4420. adjacent_nodes = graph[u] || {};
  4421. // ...and explore the edges that connect u to those nodes, updating
  4422. // the cost of the shortest paths to any or all of those nodes as
  4423. // necessary. v is the node across the current edge from u.
  4424. for (v in adjacent_nodes) {
  4425. if (adjacent_nodes.hasOwnProperty(v)) {
  4426. // Get the cost of the edge running from u to v.
  4427. cost_of_e = adjacent_nodes[v];
  4428. // Cost of s to u plus the cost of u to v across e--this is *a*
  4429. // cost from s to v that may or may not be less than the current
  4430. // known cost to v.
  4431. cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;
  4432. // If we haven't visited v yet OR if the current known cost from s to
  4433. // v is greater than the new cost we just found (cost of s to u plus
  4434. // cost of u to v across e), update v's cost in the cost list and
  4435. // update v's predecessor in the predecessor list (it's now u).
  4436. cost_of_s_to_v = costs[v];
  4437. first_visit = (typeof costs[v] === 'undefined');
  4438. if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {
  4439. costs[v] = cost_of_s_to_u_plus_cost_of_e;
  4440. open.push(v, cost_of_s_to_u_plus_cost_of_e);
  4441. predecessors[v] = u;
  4442. }
  4443. }
  4444. }
  4445. }
  4446. if (typeof d !== 'undefined' && typeof costs[d] === 'undefined') {
  4447. var msg = ['Could not find a path from ', s, ' to ', d, '.'].join('');
  4448. throw new Error(msg);
  4449. }
  4450. return predecessors;
  4451. },
  4452. extract_shortest_path_from_predecessor_list: function(predecessors, d) {
  4453. var nodes = [];
  4454. var u = d;
  4455. var predecessor;
  4456. while (u) {
  4457. nodes.push(u);
  4458. predecessor = predecessors[u];
  4459. u = predecessors[u];
  4460. }
  4461. nodes.reverse();
  4462. return nodes;
  4463. },
  4464. find_path: function(graph, s, d) {
  4465. var predecessors = dijkstra.single_source_shortest_paths(graph, s, d);
  4466. return dijkstra.extract_shortest_path_from_predecessor_list(
  4467. predecessors, d);
  4468. },
  4469. /**
  4470. * A very naive priority queue implementation.
  4471. */
  4472. PriorityQueue: {
  4473. make: function (opts) {
  4474. var T = dijkstra.PriorityQueue,
  4475. t = {},
  4476. key;
  4477. opts = opts || {};
  4478. for (key in T) {
  4479. if (T.hasOwnProperty(key)) {
  4480. t[key] = T[key];
  4481. }
  4482. }
  4483. t.queue = [];
  4484. t.sorter = opts.sorter || T.default_sorter;
  4485. return t;
  4486. },
  4487. default_sorter: function (a, b) {
  4488. return a.cost - b.cost;
  4489. },
  4490. /**
  4491. * Add a new item to the queue and ensure the highest priority element
  4492. * is at the front of the queue.
  4493. */
  4494. push: function (value, cost) {
  4495. var item = {value: value, cost: cost};
  4496. this.queue.push(item);
  4497. this.queue.sort(this.sorter);
  4498. },
  4499. /**
  4500. * Return the highest priority element in the queue.
  4501. */
  4502. pop: function () {
  4503. return this.queue.shift();
  4504. },
  4505. empty: function () {
  4506. return this.queue.length === 0;
  4507. }
  4508. }
  4509. };
  4510. // node.js module exports
  4511. if (typeof module !== 'undefined') {
  4512. module.exports = dijkstra;
  4513. }
  4514. },{}],32:[function(require,module,exports){
  4515. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  4516. var e, m
  4517. var eLen = (nBytes * 8) - mLen - 1
  4518. var eMax = (1 << eLen) - 1
  4519. var eBias = eMax >> 1
  4520. var nBits = -7
  4521. var i = isLE ? (nBytes - 1) : 0
  4522. var d = isLE ? -1 : 1
  4523. var s = buffer[offset + i]
  4524. i += d
  4525. e = s & ((1 << (-nBits)) - 1)
  4526. s >>= (-nBits)
  4527. nBits += eLen
  4528. for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
  4529. m = e & ((1 << (-nBits)) - 1)
  4530. e >>= (-nBits)
  4531. nBits += mLen
  4532. for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
  4533. if (e === 0) {
  4534. e = 1 - eBias
  4535. } else if (e === eMax) {
  4536. return m ? NaN : ((s ? -1 : 1) * Infinity)
  4537. } else {
  4538. m = m + Math.pow(2, mLen)
  4539. e = e - eBias
  4540. }
  4541. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  4542. }
  4543. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  4544. var e, m, c
  4545. var eLen = (nBytes * 8) - mLen - 1
  4546. var eMax = (1 << eLen) - 1
  4547. var eBias = eMax >> 1
  4548. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  4549. var i = isLE ? 0 : (nBytes - 1)
  4550. var d = isLE ? 1 : -1
  4551. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  4552. value = Math.abs(value)
  4553. if (isNaN(value) || value === Infinity) {
  4554. m = isNaN(value) ? 1 : 0
  4555. e = eMax
  4556. } else {
  4557. e = Math.floor(Math.log(value) / Math.LN2)
  4558. if (value * (c = Math.pow(2, -e)) < 1) {
  4559. e--
  4560. c *= 2
  4561. }
  4562. if (e + eBias >= 1) {
  4563. value += rt / c
  4564. } else {
  4565. value += rt * Math.pow(2, 1 - eBias)
  4566. }
  4567. if (value * c >= 2) {
  4568. e++
  4569. c /= 2
  4570. }
  4571. if (e + eBias >= eMax) {
  4572. m = 0
  4573. e = eMax
  4574. } else if (e + eBias >= 1) {
  4575. m = ((value * c) - 1) * Math.pow(2, mLen)
  4576. e = e + eBias
  4577. } else {
  4578. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  4579. e = 0
  4580. }
  4581. }
  4582. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  4583. e = (e << mLen) | m
  4584. eLen += mLen
  4585. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  4586. buffer[offset + i - d] |= s * 128
  4587. }
  4588. },{}],33:[function(require,module,exports){
  4589. var toString = {}.toString;
  4590. module.exports = Array.isArray || function (arr) {
  4591. return toString.call(arr) == '[object Array]';
  4592. };
  4593. },{}]},{},[24])(24)
  4594. });
  4595. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJsaWIvY2FuLXByb21pc2UuanMiLCJsaWIvY29yZS9hbGlnbm1lbnQtcGF0dGVybi5qcyIsImxpYi9jb3JlL2FscGhhbnVtZXJpYy1kYXRhLmpzIiwibGliL2NvcmUvYml0LWJ1ZmZlci5qcyIsImxpYi9jb3JlL2JpdC1tYXRyaXguanMiLCJsaWIvY29yZS9ieXRlLWRhdGEuanMiLCJsaWIvY29yZS9lcnJvci1jb3JyZWN0aW9uLWNvZGUuanMiLCJsaWIvY29yZS9lcnJvci1jb3JyZWN0aW9uLWxldmVsLmpzIiwibGliL2NvcmUvZmluZGVyLXBhdHRlcm4uanMiLCJsaWIvY29yZS9mb3JtYXQtaW5mby5qcyIsImxpYi9jb3JlL2dhbG9pcy1maWVsZC5qcyIsImxpYi9jb3JlL2thbmppLWRhdGEuanMiLCJsaWIvY29yZS9tYXNrLXBhdHRlcm4uanMiLCJsaWIvY29yZS9tb2RlLmpzIiwibGliL2NvcmUvbnVtZXJpYy1kYXRhLmpzIiwibGliL2NvcmUvcG9seW5vbWlhbC5qcyIsImxpYi9jb3JlL3FyY29kZS5qcyIsImxpYi9jb3JlL3JlZWQtc29sb21vbi1lbmNvZGVyLmpzIiwibGliL2NvcmUvcmVnZXguanMiLCJsaWIvY29yZS9zZWdtZW50cy5qcyIsImxpYi9jb3JlL3V0aWxzLmpzIiwibGliL2NvcmUvdmVyc2lvbi1jaGVjay5qcyIsImxpYi9jb3JlL3ZlcnNpb24uanMiLCJsaWIvaW5kZXguanMiLCJsaWIvcmVuZGVyZXIvY2FudmFzLmpzIiwibGliL3Jlbm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2R1bGVzIG1hdHJpeFxuICogQHBhcmFtICB7QnVmZmVyfSAgICBkYXRhICAgRGF0YSBjb2Rld29yZHNcbiAqL1xuZnVuY3Rpb24gc2V0dXBEYXRhIChtYXRyaXgsIGRhdGEpIHtcbiAgdmFyIHNpemUgPSBtYXRyaXguc2l6ZVxuICB2YXIgaW5jID0gLTFcbiAgdmFyIHJvdyA9IHNpemUgLSAxXG4gIHZhciBiaXRJbmRleCA9IDdcbiAgdmFyIGJ5dGVJbmRleCA9IDBcblxuICBmb3IgKHZhciBjb2wgPSBzaXplIC0gMTsgY29sID4gMDsgY29sIC09IDIpIHtcbiAgICBpZiAoY29sID09PSA2KSBjb2wtLVxuXG4gICAgd2hpbGUgKHRydWUpIHtcbiAgICAgIGZvciAodmFyIGMgPSAwOyBjIDwgMjsgYysrKSB7XG4gICAgICAgIGlmICghbWF0cml4LmlzUmVzZXJ2ZWQocm93LCBjb2wgLSBjKSkge1xuICAgICAgICAgIHZhciBkYXJrID0gZmFsc2VcblxuICAgICAgICAgIGlmIChieXRlSW5kZXggPCBkYXRhLmxlbmd0aCkge1xuICAgICAgICAgICAgZGFyayA9ICgoKGRhdGFbYnl0ZUluZGV4XSA+Pj4gYml0SW5kZXgpICYgMSkgPT09IDEpXG4gICAgICAgICAgfVxuXG4gICAgICAgICAgbWF0cml4LnNldChyb3csIGNvbCAtIGMsIGRhcmspXG4gICAgICAgICAgYml0SW5kZXgtLVxuXG4gICAgICAgICAgaWYgKGJpdEluZGV4ID09PSAtMSkge1xuICAgICAgICAgICAgYnl0ZUluZGV4KytcbiAgICAgICAgICAgIGJpdEluZGV4ID0gN1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgfVxuXG4gICAgICByb3cgKz0gaW5jXG5cbiAgICAgIGlmIChyb3cgPCAwIHx8IHNpemUgPD0gcm93KSB7XG4gICAgICAgIHJvdyAtPSBpbmNcbiAgICAgICAgaW5jID0gLWluY1xuICAgICAgICBicmVha1xuICAgICAgfVxuICAg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