-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: import single-file 3rd party modules
This commit allows to: - provide an ESM version of those modules ([1]) - reduce the attack surface in case of supply chain attacks - reduce the size of the bundle with tree-shaking As a downside, we won't receive security updates for those modules anymore. [1]: socketio/socket.io-client#1536
- Loading branch information
1 parent
b4b3ed5
commit df32277
Showing
13 changed files
with
197 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
test/support/public/engine.io.min.js | ||
lib/contrib/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// imported from https://github.com/component/has-cors | ||
let value = false; | ||
|
||
try { | ||
value = typeof XMLHttpRequest !== 'undefined' && | ||
'withCredentials' in new XMLHttpRequest(); | ||
} catch (err) { | ||
// if XMLHttp support is disabled in IE then it will throw | ||
// when trying to create | ||
} | ||
|
||
export const hasCORS = value; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// imported from https://github.com/galkn/querystring | ||
/** | ||
* Compiles a querystring | ||
* Returns string representation of the object | ||
* | ||
* @param {Object} | ||
* @api private | ||
*/ | ||
|
||
export function encode (obj) { | ||
let str = ''; | ||
|
||
for (let i in obj) { | ||
if (obj.hasOwnProperty(i)) { | ||
if (str.length) str += '&'; | ||
str += encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]); | ||
} | ||
} | ||
|
||
return str; | ||
} | ||
|
||
/** | ||
* Parses a simple querystring into an object | ||
* | ||
* @param {String} qs | ||
* @api private | ||
*/ | ||
|
||
export function decode (qs) { | ||
let qry = {}; | ||
let pairs = qs.split('&'); | ||
for (let i = 0, l = pairs.length; i < l; i++) { | ||
let pair = pairs[i].split('='); | ||
qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]); | ||
} | ||
return qry; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// imported from https://github.com/galkn/parseuri | ||
/** | ||
* Parses an URI | ||
* | ||
* @author Steven Levithan <stevenlevithan.com> (MIT license) | ||
* @api private | ||
*/ | ||
const re = /^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/; | ||
|
||
const parts = [ | ||
'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor' | ||
]; | ||
|
||
export function parse(str) { | ||
const src = str, | ||
b = str.indexOf('['), | ||
e = str.indexOf(']'); | ||
|
||
if (b != -1 && e != -1) { | ||
str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length); | ||
} | ||
|
||
let m = re.exec(str || ''), | ||
uri = {} as any, | ||
i = 14; | ||
|
||
while (i--) { | ||
uri[parts[i]] = m[i] || ''; | ||
} | ||
|
||
if (b != -1 && e != -1) { | ||
uri.source = src; | ||
uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':'); | ||
uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':'); | ||
uri.ipv6uri = true; | ||
} | ||
|
||
uri.pathNames = pathNames(uri, uri['path']); | ||
uri.queryKey = queryKey(uri, uri['query']); | ||
|
||
return uri; | ||
} | ||
|
||
function pathNames(obj, path) { | ||
const regx = /\/{2,9}/g, | ||
names = path.replace(regx, "/").split("/"); | ||
|
||
if (path.substr(0, 1) == '/' || path.length === 0) { | ||
names.splice(0, 1); | ||
} | ||
if (path.substr(path.length - 1, 1) == '/') { | ||
names.splice(names.length - 1, 1); | ||
} | ||
|
||
return names; | ||
} | ||
|
||
function queryKey(uri, query) { | ||
const data = {}; | ||
|
||
query.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function ($0, $1, $2) { | ||
if ($1) { | ||
data[$1] = $2; | ||
} | ||
}); | ||
|
||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// imported from https://github.com/unshiftio/yeast | ||
'use strict'; | ||
|
||
const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'.split('') | ||
, length = 64 | ||
, map = {}; | ||
let seed = 0 | ||
, i = 0 | ||
, prev; | ||
|
||
/** | ||
* Return a string representing the specified number. | ||
* | ||
* @param {Number} num The number to convert. | ||
* @returns {String} The string representation of the number. | ||
* @api public | ||
*/ | ||
export function encode(num) { | ||
let encoded = ''; | ||
|
||
do { | ||
encoded = alphabet[num % length] + encoded; | ||
num = Math.floor(num / length); | ||
} while (num > 0); | ||
|
||
return encoded; | ||
} | ||
|
||
/** | ||
* Return the integer value specified by the given string. | ||
* | ||
* @param {String} str The string to convert. | ||
* @returns {Number} The integer value represented by the string. | ||
* @api public | ||
*/ | ||
export function decode(str) { | ||
let decoded = 0; | ||
|
||
for (i = 0; i < str.length; i++) { | ||
decoded = decoded * length + map[str.charAt(i)]; | ||
} | ||
|
||
return decoded; | ||
} | ||
|
||
/** | ||
* Yeast: A tiny growing id generator. | ||
* | ||
* @returns {String} A unique id. | ||
* @api public | ||
*/ | ||
export function yeast() { | ||
const now = encode(+new Date()); | ||
|
||
if (now !== prev) return seed = 0, prev = now; | ||
return now +'.'+ encode(seed++); | ||
} | ||
|
||
// | ||
// Map each character to its index. | ||
// | ||
for (; i < length; i++) map[alphabet[i]] = i; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters