Merged in m3u-packages (pull request #332)

mjpeg-player: made node.js packages compatible for es6 import/exports

Approved-by: Saxon Milton
Approved-by: Scott Barnard
This commit is contained in:
Trek Hopton 2020-01-24 08:44:25 +00:00
commit 1b7e817266
2 changed files with 140 additions and 159 deletions

View File

@ -10,7 +10,7 @@ var has = Object.prototype.hasOwnProperty
* @constructor * @constructor
* @private * @private
*/ */
function Events() {} function Events() { }
// //
// We try to not inherit from `Object.prototype`. In some engines creating an // We try to not inherit from `Object.prototype`. In some engines creating an
@ -185,7 +185,7 @@ EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true; case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
} }
for (i = 1, args = new Array(len -1); i < len; i++) { for (i = 1, args = new Array(len - 1); i < len; i++) {
args[i - 1] = arguments[i]; args[i - 1] = arguments[i];
} }
@ -203,7 +203,7 @@ EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break; case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break; case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
default: default:
if (!args) for (j = 1, args = new Array(len -1); j < len; j++) { if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) {
args[j - 1] = arguments[j]; args[j - 1] = arguments[j];
} }
@ -328,9 +328,4 @@ EventEmitter.prefixed = prefix;
// //
EventEmitter.EventEmitter = EventEmitter; EventEmitter.EventEmitter = EventEmitter;
// export default EventEmitter;
// Expose the module.
//
if ('undefined' !== typeof module) {
module.exports = EventEmitter;
}

View File

@ -1,163 +1,149 @@
// see https://tools.ietf.org/html/rfc1808 // see https://tools.ietf.org/html/rfc1808
/* jshint ignore:start */ var URL_REGEX = /^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/\?#]*\/)*.*?)??(;.*?)?(\?.*?)?(#.*?)?$/;
(function(root) { var FIRST_SEGMENT_REGEX = /^([^\/?#]*)(.*)$/;
/* jshint ignore:end */ var SLASH_DOT_REGEX = /(?:\/|^)\.(?=\/)/g;
var SLASH_DOT_DOT_REGEX = /(?:\/|^)\.\.\/(?!\.\.\/).*?(?=\/)/g;
var URL_REGEX = /^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/\?#]*\/)*.*?)??(;.*?)?(\?.*?)?(#.*?)?$/; var URLToolkit = { // jshint ignore:line
var FIRST_SEGMENT_REGEX = /^([^\/?#]*)(.*)$/; // If opts.alwaysNormalize is true then the path will always be normalized even when it starts with / or //
var SLASH_DOT_REGEX = /(?:\/|^)\.(?=\/)/g; // E.g
var SLASH_DOT_DOT_REGEX = /(?:\/|^)\.\.\/(?!\.\.\/).*?(?=\/)/g; // With opts.alwaysNormalize = false (default, spec compliant)
// http://a.com/b/cd + /e/f/../g => http://a.com/e/f/../g
var URLToolkit = { // jshint ignore:line // With opts.alwaysNormalize = true (not spec compliant)
// If opts.alwaysNormalize is true then the path will always be normalized even when it starts with / or // // http://a.com/b/cd + /e/f/../g => http://a.com/e/g
// E.g buildAbsoluteURL: function (baseURL, relativeURL, opts) {
// With opts.alwaysNormalize = false (default, spec compliant) opts = opts || {};
// http://a.com/b/cd + /e/f/../g => http://a.com/e/f/../g // remove any remaining space and CRLF
// With opts.alwaysNormalize = true (not spec compliant) baseURL = baseURL.trim();
// http://a.com/b/cd + /e/f/../g => http://a.com/e/g relativeURL = relativeURL.trim();
buildAbsoluteURL: function(baseURL, relativeURL, opts) { if (!relativeURL) {
opts = opts || {}; // 2a) If the embedded URL is entirely empty, it inherits the
// remove any remaining space and CRLF // entire base URL (i.e., is set equal to the base URL)
baseURL = baseURL.trim(); // and we are done.
relativeURL = relativeURL.trim(); if (!opts.alwaysNormalize) {
if (!relativeURL) { return baseURL;
// 2a) If the embedded URL is entirely empty, it inherits the
// entire base URL (i.e., is set equal to the base URL)
// and we are done.
if (!opts.alwaysNormalize) {
return baseURL;
}
var basePartsForNormalise = URLToolkit.parseURL(baseURL);
if (!basePartsForNormalise) {
throw new Error('Error trying to parse base URL.');
}
basePartsForNormalise.path = URLToolkit.normalizePath(basePartsForNormalise.path);
return URLToolkit.buildURLFromParts(basePartsForNormalise);
} }
var relativeParts = URLToolkit.parseURL(relativeURL); var basePartsForNormalise = URLToolkit.parseURL(baseURL);
if (!relativeParts) { if (!basePartsForNormalise) {
throw new Error('Error trying to parse relative URL.');
}
if (relativeParts.scheme) {
// 2b) If the embedded URL starts with a scheme name, it is
// interpreted as an absolute URL and we are done.
if (!opts.alwaysNormalize) {
return relativeURL;
}
relativeParts.path = URLToolkit.normalizePath(relativeParts.path);
return URLToolkit.buildURLFromParts(relativeParts);
}
var baseParts = URLToolkit.parseURL(baseURL);
if (!baseParts) {
throw new Error('Error trying to parse base URL.'); throw new Error('Error trying to parse base URL.');
} }
if (!baseParts.netLoc && baseParts.path && baseParts.path[0] !== '/') { basePartsForNormalise.path = URLToolkit.normalizePath(basePartsForNormalise.path);
// If netLoc missing and path doesn't start with '/', assume everthing before the first '/' is the netLoc return URLToolkit.buildURLFromParts(basePartsForNormalise);
// This causes 'example.com/a' to be handled as '//example.com/a' instead of '/example.com/a' }
var pathParts = FIRST_SEGMENT_REGEX.exec(baseParts.path); var relativeParts = URLToolkit.parseURL(relativeURL);
baseParts.netLoc = pathParts[1]; if (!relativeParts) {
baseParts.path = pathParts[2]; throw new Error('Error trying to parse relative URL.');
}
if (relativeParts.scheme) {
// 2b) If the embedded URL starts with a scheme name, it is
// interpreted as an absolute URL and we are done.
if (!opts.alwaysNormalize) {
return relativeURL;
} }
if (baseParts.netLoc && !baseParts.path) { relativeParts.path = URLToolkit.normalizePath(relativeParts.path);
baseParts.path = '/'; return URLToolkit.buildURLFromParts(relativeParts);
} }
var builtParts = { var baseParts = URLToolkit.parseURL(baseURL);
// 2c) Otherwise, the embedded URL inherits the scheme of if (!baseParts) {
// the base URL. throw new Error('Error trying to parse base URL.');
scheme: baseParts.scheme, }
netLoc: relativeParts.netLoc, if (!baseParts.netLoc && baseParts.path && baseParts.path[0] !== '/') {
path: null, // If netLoc missing and path doesn't start with '/', assume everthing before the first '/' is the netLoc
params: relativeParts.params, // This causes 'example.com/a' to be handled as '//example.com/a' instead of '/example.com/a'
query: relativeParts.query, var pathParts = FIRST_SEGMENT_REGEX.exec(baseParts.path);
fragment: relativeParts.fragment baseParts.netLoc = pathParts[1];
}; baseParts.path = pathParts[2];
if (!relativeParts.netLoc) { }
// 3) If the embedded URL's <net_loc> is non-empty, we skip to if (baseParts.netLoc && !baseParts.path) {
// Step 7. Otherwise, the embedded URL inherits the <net_loc> baseParts.path = '/';
// (if any) of the base URL. }
builtParts.netLoc = baseParts.netLoc; var builtParts = {
// 4) If the embedded URL path is preceded by a slash "/", the // 2c) Otherwise, the embedded URL inherits the scheme of
// path is not relative and we skip to Step 7. // the base URL.
if (relativeParts.path[0] !== '/') { scheme: baseParts.scheme,
if (!relativeParts.path) { netLoc: relativeParts.netLoc,
// 5) If the embedded URL path is empty (and not preceded by a path: null,
// slash), then the embedded URL inherits the base URL path params: relativeParts.params,
builtParts.path = baseParts.path; query: relativeParts.query,
// 5a) if the embedded URL's <params> is non-empty, we skip to fragment: relativeParts.fragment
// step 7; otherwise, it inherits the <params> of the base };
// URL (if any) and if (!relativeParts.netLoc) {
if (!relativeParts.params) { // 3) If the embedded URL's <net_loc> is non-empty, we skip to
builtParts.params = baseParts.params; // Step 7. Otherwise, the embedded URL inherits the <net_loc>
// 5b) if the embedded URL's <query> is non-empty, we skip to // (if any) of the base URL.
// step 7; otherwise, it inherits the <query> of the base builtParts.netLoc = baseParts.netLoc;
// URL (if any) and we skip to step 7. // 4) If the embedded URL path is preceded by a slash "/", the
if (!relativeParts.query) { // path is not relative and we skip to Step 7.
builtParts.query = baseParts.query; if (relativeParts.path[0] !== '/') {
} if (!relativeParts.path) {
// 5) If the embedded URL path is empty (and not preceded by a
// slash), then the embedded URL inherits the base URL path
builtParts.path = baseParts.path;
// 5a) if the embedded URL's <params> is non-empty, we skip to
// step 7; otherwise, it inherits the <params> of the base
// URL (if any) and
if (!relativeParts.params) {
builtParts.params = baseParts.params;
// 5b) if the embedded URL's <query> is non-empty, we skip to
// step 7; otherwise, it inherits the <query> of the base
// URL (if any) and we skip to step 7.
if (!relativeParts.query) {
builtParts.query = baseParts.query;
} }
} else {
// 6) The last segment of the base URL's path (anything
// following the rightmost slash "/", or the entire path if no
// slash is present) is removed and the embedded URL's path is
// appended in its place.
var baseURLPath = baseParts.path;
var newPath = baseURLPath.substring(0, baseURLPath.lastIndexOf('/') + 1) + relativeParts.path;
builtParts.path = URLToolkit.normalizePath(newPath);
} }
} else {
// 6) The last segment of the base URL's path (anything
// following the rightmost slash "/", or the entire path if no
// slash is present) is removed and the embedded URL's path is
// appended in its place.
var baseURLPath = baseParts.path;
var newPath = baseURLPath.substring(0, baseURLPath.lastIndexOf('/') + 1) + relativeParts.path;
builtParts.path = URLToolkit.normalizePath(newPath);
} }
} }
if (builtParts.path === null) {
builtParts.path = opts.alwaysNormalize ? URLToolkit.normalizePath(relativeParts.path) : relativeParts.path;
}
return URLToolkit.buildURLFromParts(builtParts);
},
parseURL: function(url) {
var parts = URL_REGEX.exec(url);
if (!parts) {
return null;
}
return {
scheme: parts[1] || '',
netLoc: parts[2] || '',
path: parts[3] || '',
params: parts[4] || '',
query: parts[5] || '',
fragment: parts[6] || ''
};
},
normalizePath: function(path) {
// The following operations are
// then applied, in order, to the new path:
// 6a) All occurrences of "./", where "." is a complete path
// segment, are removed.
// 6b) If the path ends with "." as a complete path segment,
// that "." is removed.
path = path.split('').reverse().join('').replace(SLASH_DOT_REGEX, '');
// 6c) All occurrences of "<segment>/../", where <segment> is a
// complete path segment not equal to "..", are removed.
// Removal of these path segments is performed iteratively,
// removing the leftmost matching pattern on each iteration,
// until no matching pattern remains.
// 6d) If the path ends with "<segment>/..", where <segment> is a
// complete path segment not equal to "..", that
// "<segment>/.." is removed.
while (path.length !== (path = path.replace(SLASH_DOT_DOT_REGEX, '')).length) {} // jshint ignore:line
return path.split('').reverse().join('');
},
buildURLFromParts: function(parts) {
return parts.scheme + parts.netLoc + parts.path + parts.params + parts.query + parts.fragment;
} }
}; if (builtParts.path === null) {
builtParts.path = opts.alwaysNormalize ? URLToolkit.normalizePath(relativeParts.path) : relativeParts.path;
}
return URLToolkit.buildURLFromParts(builtParts);
},
parseURL: function (url) {
var parts = URL_REGEX.exec(url);
if (!parts) {
return null;
}
return {
scheme: parts[1] || '',
netLoc: parts[2] || '',
path: parts[3] || '',
params: parts[4] || '',
query: parts[5] || '',
fragment: parts[6] || ''
};
},
normalizePath: function (path) {
// The following operations are
// then applied, in order, to the new path:
// 6a) All occurrences of "./", where "." is a complete path
// segment, are removed.
// 6b) If the path ends with "." as a complete path segment,
// that "." is removed.
path = path.split('').reverse().join('').replace(SLASH_DOT_REGEX, '');
// 6c) All occurrences of "<segment>/../", where <segment> is a
// complete path segment not equal to "..", are removed.
// Removal of these path segments is performed iteratively,
// removing the leftmost matching pattern on each iteration,
// until no matching pattern remains.
// 6d) If the path ends with "<segment>/..", where <segment> is a
// complete path segment not equal to "..", that
// "<segment>/.." is removed.
while (path.length !== (path = path.replace(SLASH_DOT_DOT_REGEX, '')).length) { } // jshint ignore:line
return path.split('').reverse().join('');
},
buildURLFromParts: function (parts) {
return parts.scheme + parts.netLoc + parts.path + parts.params + parts.query + parts.fragment;
}
};
/* jshint ignore:start */ export default URLToolkit;
if(typeof exports === 'object' && typeof module === 'object')
module.exports = URLToolkit;
else if(typeof define === 'function' && define.amd)
define([], function() { return URLToolkit; });
else if(typeof exports === 'object')
exports["URLToolkit"] = URLToolkit;
else
root["URLToolkit"] = URLToolkit;
})(this);
/* jshint ignore:end */