From f2ffe97f3c52b44f1f4e5f60a1293d936fbf46ae Mon Sep 17 00:00:00 2001 From: "xu.chenhui" Date: Sat, 5 Apr 2014 04:57:55 -0400 Subject: [PATCH] Fix the function of judging the commonJS environment --- cptable.js | 2 +- cputils.js | 20 +++++++++++++++----- sbcs.js | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/cptable.js b/cptable.js index 1f1709e..849c0c9 100644 --- a/cptable.js +++ b/cptable.js @@ -833,4 +833,4 @@ cptable[28606] = (function(){ var d = "\u0000\u0001\u0002\u0003\u0004\u0005\u000 cptable[858] = (function(){ var d = "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜø£Ø׃áíóúñѪº¿®¬½¼¡«»░▒▓│┤ÁÂÀ©╣║╗╝¢¥┐└┴┬├─┼ãÃ╚╔╩╦╠═╬¤ðÐÊËÈ€ÍÎÏ┘┌█▄¦Ì▀ÓßÔÒõÕµþÞÚÛÙýݯ´­±‗¾¶§÷¸°¨·¹³²■ ".split(""), e = {}; for(var i=0;i!=d.length;++i) if(d[i].charCodeAt(0) !== 0xFFFD)e[d[i]] = i; return {"enc": e, "dec": d }; })(); cptable[708] = (function(){ var d = "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~│┤éâ╡à╢çêëèïî╖╕╣║╗╝ô╜╛ûù┐└�������┴┬├¤─┼╞╟╚╔╩،╦«»░▒▓╠═╬╧╨╤╥╙؛╘╒╓؟╫ءآأؤإئابةتثجحخدذرزسشصضطظعغ█▄▌▐▀ـفقكلمنهوىيًٌٍَُِّْ������╪┘┌µ£■ ".split(""), e = {}; for(var i=0;i!=d.length;++i) if(d[i].charCodeAt(0) !== 0xFFFD)e[d[i]] = i; return {"enc": e, "dec": d }; })(); cptable[720] = (function(){ var d = "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~��éâ�à�çêëèïî����ّْô¤ـûùءآأؤ£إئابةتثجحخدذرزسشص«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀ضطظعغفµقكلمنهوىي≡ًٌٍَُِ≈°∙·√ⁿ²■ ".split(""), e = {}; for(var i=0;i!=d.length;++i) if(d[i].charCodeAt(0) !== 0xFFFD)e[d[i]] = i; return {"enc": e, "dec": d }; })(); -if(typeof module !== 'undefined') module.exports = cptable; +if (typeof module !== 'undefined' && module.exports) module.exports = cptable; diff --git a/cputils.js b/cputils.js index b0c73c8..8dc39b3 100644 --- a/cputils.js +++ b/cputils.js @@ -1,6 +1,16 @@ -if(typeof cptable === "undefined" && typeof require !== "undefined") var cptable = require('./cptable'); - -(function(cpt){ +(function(root, factory){ + "use strict"; + if(typeof cptable === "undefined" && typeof require !== "undefined"){ + var cpt = require('./cptable'); + if (typeof module !== 'undefined' && module.exports){ + module.exports = factory(cpt); + }else{ + root.cptable = factory(cpt); + } + }else{ + throw "cptable not found"; + } +}(this, function(cpt){ var magic = { "1200":"utf16le", "1201":"utf16be", @@ -72,6 +82,6 @@ if(typeof cptable === "undefined" && typeof require !== "undefined") var cptable return cpt[cp] || magic[cp]; }; cpt.utils = { decode: decode, encode: encode, hascp: hascp, magic: magic }; -})(cptable); + return cpt; +})); -if(typeof module !== "undefined") module.exports = cptable; diff --git a/sbcs.js b/sbcs.js index 40d28c8..2708323 100644 --- a/sbcs.js +++ b/sbcs.js @@ -53,4 +53,4 @@ cptable[28606] = (function(){ var d = "\u0000\u0001\u0002\u0003\u0004\u0005\u000 cptable[858] = (function(){ var d = "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜø£Ø׃áíóúñѪº¿®¬½¼¡«»░▒▓│┤ÁÂÀ©╣║╗╝¢¥┐└┴┬├─┼ãÃ╚╔╩╦╠═╬¤ðÐÊËÈ€ÍÎÏ┘┌█▄¦Ì▀ÓßÔÒõÕµþÞÚÛÙýݯ´­±‗¾¶§÷¸°¨·¹³²■ ".split(""), e = {}; for(var i=0;i!=d.length;++i) if(d[i].charCodeAt(0) !== 0xFFFD)e[d[i]] = i; return {"enc": e, "dec": d }; })(); cptable[708] = (function(){ var d = "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~│┤éâ╡à╢çêëèïî╖╕╣║╗╝ô╜╛ûù┐└�������┴┬├¤─┼╞╟╚╔╩،╦«»░▒▓╠═╬╧╨╤╥╙؛╘╒╓؟╫ءآأؤإئابةتثجحخدذرزسشصضطظعغ█▄▌▐▀ـفقكلمنهوىيًٌٍَُِّْ������╪┘┌µ£■ ".split(""), e = {}; for(var i=0;i!=d.length;++i) if(d[i].charCodeAt(0) !== 0xFFFD)e[d[i]] = i; return {"enc": e, "dec": d }; })(); cptable[720] = (function(){ var d = "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~��éâ�à�çêëèïî����ّْô¤ـûùءآأؤ£إئابةتثجحخدذرزسشص«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀ضطظعغفµقكلمنهوىي≡ًٌٍَُِ≈°∙·√ⁿ²■ ".split(""), e = {}; for(var i=0;i!=d.length;++i) if(d[i].charCodeAt(0) !== 0xFFFD)e[d[i]] = i; return {"enc": e, "dec": d }; })(); -if(typeof module !== 'undefined') module.exports = cptable; +if (typeof module !== 'undefined' && module.exports) module.exports = cptable;