@amazon/vinyl-hls-parser 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -0
- package/dist/hlsTestAssets/types/current/tsconfig.tsbuildinfo +1 -1
- package/dist/index.cjs +8 -1
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +9 -2
- package/dist/index.js.map +3 -3
- package/dist/test/benchmark.es5.js +56 -248
- package/dist/test/benchmark.js +164 -972
- package/dist/test/benchmark.js.map +4 -4
- package/dist/types/current/parse/parseMainPlaylist.d.ts.map +1 -1
- package/dist/types/current/parse/parseMainPlaylist.js +16 -2
- package/dist/types/current/parse/parseMediaPlaylist.d.ts.map +1 -1
- package/dist/types/current/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -13
- package/dist/test/benchmark.css +0 -71
- package/dist/test/benchmark.html +0 -67
- package/dist/test/favicon.png +0 -0
- package/dist/test/index.html +0 -61
- package/dist/test/integ.es5.js +0 -410
- package/dist/test/integ.js +0 -2127
- package/dist/test/integ.js.map +0 -7
- package/dist/test/jasmine.css +0 -304
- package/dist/test/jasmineHtml.es5.js +0 -670
- package/dist/test/jasmineHtml.js +0 -10851
- package/dist/test/jasmineHtml.js.map +0 -7
- package/dist/test/styles.css +0 -42
- package/dist/unit/types/current/index.d.ts +0 -7
- package/dist/unit/types/current/index.d.ts.map +0 -1
- package/dist/unit/types/current/index.js +0 -6
- package/dist/unit/types/current/parse/parseAttributes.test.d.ts +0 -2
- package/dist/unit/types/current/parse/parseAttributes.test.d.ts.map +0 -1
- package/dist/unit/types/current/parse/parseAttributes.test.js +0 -70
- package/dist/unit/types/current/parse/parseMainPlaylist.test.d.ts +0 -2
- package/dist/unit/types/current/parse/parseMainPlaylist.test.d.ts.map +0 -1
- package/dist/unit/types/current/parse/parseMainPlaylist.test.js +0 -194
- package/dist/unit/types/current/parse/parseMediaPlaylist.test.d.ts +0 -2
- package/dist/unit/types/current/parse/parseMediaPlaylist.test.d.ts.map +0 -1
- package/dist/unit/types/current/parse/parseMediaPlaylist.test.js +0 -401
- package/dist/unit/types/current/parse/parseUtil.test.d.ts +0 -2
- package/dist/unit/types/current/parse/parseUtil.test.d.ts.map +0 -1
- package/dist/unit/types/current/parse/parseUtil.test.js +0 -67
- package/dist/unit/types/current/setup.d.ts +0 -2
- package/dist/unit/types/current/setup.d.ts.map +0 -1
- package/dist/unit/types/current/setup.js +0 -19
- package/dist/unit/types/current/tsconfig.tsbuildinfo +0 -1
package/dist/test/integ.es5.js
DELETED
|
@@ -1,410 +0,0 @@
|
|
|
1
|
-
"use strict";function _slicedToArray(r,e){return _arrayWithHoles(r)||_iterableToArrayLimit(r,e)||_unsupportedIterableToArray(r,e)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _iterableToArrayLimit(r,l){var t=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=t){var e,n,i,u,a=[],f=!0,o=!1;try{if(i=(t=t.call(r)).next,0===l){if(Object(t)!==t)return;f=!1}else for(;!(f=(e=i.call(t)).done)&&(a.push(e.value),a.length!==l);f=!0);}catch(r){o=!0,n=r}finally{try{if(!f&&null!=t.return&&(u=t.return(),Object(u)!==u))return}finally{if(o)throw n}}return a}}function _arrayWithHoles(r){if(Array.isArray(r))return r}function _toConsumableArray(r){return _arrayWithoutHoles(r)||_iterableToArray(r)||_unsupportedIterableToArray(r)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _iterableToArray(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}function _arrayWithoutHoles(r){if(Array.isArray(r))return _arrayLikeToArray(r)}function _superPropGet(t,o,e,r){var p=_get(_getPrototypeOf(1&r?t.prototype:t),o,e);return 2&r&&"function"==typeof p?function(t){return p.apply(e,t)}:p}function _get(){return _get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var p=_superPropBase(e,t);if(p){var n=Object.getOwnPropertyDescriptor(p,t);return n.get?n.get.call(arguments.length<3?e:r):n.value}},_get.apply(null,arguments)}function _superPropBase(t,o){for(;!{}.hasOwnProperty.call(t,o)&&null!==(t=_getPrototypeOf(t)););return t}function _classCallCheck(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,_toPropertyKey(o.key),o)}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+""}function _toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}function _callSuper(t,o,e){return o=_getPrototypeOf(o),_possibleConstructorReturn(t,_isNativeReflectConstruct()?Reflect.construct(o,e||[],_getPrototypeOf(t).constructor):o.apply(t,e))}function _possibleConstructorReturn(t,e){if(e&&("object"==_typeof(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(t)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&_setPrototypeOf(t,e)}function _wrapNativeSuper(t){var r="function"==typeof Map?new Map:void 0;return _wrapNativeSuper=function _wrapNativeSuper(t){if(null===t||!_isNativeFunction(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,Wrapper)}function Wrapper(){return _construct(t,arguments,_getPrototypeOf(this).constructor)}return Wrapper.prototype=Object.create(t.prototype,{constructor:{value:Wrapper,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(Wrapper,t)},_wrapNativeSuper(t)}function _construct(t,e,r){if(_isNativeReflectConstruct())return Reflect.construct.apply(null,arguments);var o=[null];o.push.apply(o,e);var p=new(t.bind.apply(t,o));return r&&_setPrototypeOf(p,r.prototype),p}function _isNativeReflectConstruct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(_isNativeReflectConstruct=function _isNativeReflectConstruct(){return!!t})()}function _isNativeFunction(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(n){return"function"==typeof t}}function _setPrototypeOf(t,e){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},_setPrototypeOf(t,e)}function _getPrototypeOf(t){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},_getPrototypeOf(t)}function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},_typeof(o)}function _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var _n=0,F=function F(){};return{s:F,n:function n(){return _n>=r.length?{done:!0}:{done:!1,value:r[_n++]}},e:function e(r){throw r},f:F}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,u=!1;return{s:function s(){t=t.call(r)},n:function n(){var r=t.next();return a=r.done,r},e:function e(r){u=!0,o=r},f:function f(){try{a||null==t.return||t.return()}finally{if(u)throw o}}}}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0}}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n}(function(){var __defProp=Object.defineProperty;var __defProps=Object.defineProperties;var __getOwnPropDescs=Object.getOwnPropertyDescriptors;var __getOwnPropSymbols=Object.getOwnPropertySymbols;var __hasOwnProp=Object.prototype.hasOwnProperty;var __propIsEnum=Object.prototype.propertyIsEnumerable;var __defNormalProp=function __defNormalProp(obj,key,value){return key in obj?__defProp(obj,key,{enumerable:true,configurable:true,writable:true,value:value}):obj[key]=value};var __spreadValues=function __spreadValues(a,b){for(var prop in b||(b={}))if(__hasOwnProp.call(b,prop))__defNormalProp(a,prop,b[prop]);if(__getOwnPropSymbols){var _iterator=_createForOfIteratorHelper(__getOwnPropSymbols(b)),_step;try{for(_iterator.s();!(_step=_iterator.n()).done;){var prop=_step.value;if(__propIsEnum.call(b,prop))__defNormalProp(a,prop,b[prop])}}catch(err){_iterator.e(err)}finally{_iterator.f()}}return a};var __spreadProps=function __spreadProps(a,b){return __defProps(a,__getOwnPropDescs(b))};// ../vinyl-util/dist/index.js
|
|
2
|
-
var __defProp2=Object.defineProperty;var __defProps2=Object.defineProperties;var __getOwnPropDescs2=Object.getOwnPropertyDescriptors;var __getOwnPropSymbols2=Object.getOwnPropertySymbols;var __hasOwnProp2=Object.prototype.hasOwnProperty;var __propIsEnum2=Object.prototype.propertyIsEnumerable;var __defNormalProp2=function __defNormalProp2(obj,key,value){return key in obj?__defProp2(obj,key,{enumerable:true,configurable:true,writable:true,value:value}):obj[key]=value};var __spreadValues2=function __spreadValues2(a,b){for(var prop in b||(b={}))if(__hasOwnProp2.call(b,prop))__defNormalProp2(a,prop,b[prop]);if(__getOwnPropSymbols2){var _iterator2=_createForOfIteratorHelper(__getOwnPropSymbols2(b)),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var prop=_step2.value;if(__propIsEnum2.call(b,prop))__defNormalProp2(a,prop,b[prop])}}catch(err){_iterator2.e(err)}finally{_iterator2.f()}}return a};var __spreadProps2=function __spreadProps2(a,b){return __defProps2(a,__getOwnPropDescs2(b))};var __publicField=function __publicField(obj,key,value){return __defNormalProp2(obj,_typeof(key)!=="symbol"?key+"":key,value)};function invariant(){return void 0}var ErrorOrigin={/**
|
|
3
|
-
* The error originated from Vinyl and was reported from the uncaught exception or promise
|
|
4
|
-
* rejection handlers.
|
|
5
|
-
*/UNCAUGHT:"uncaught",/**
|
|
6
|
-
* The error originated from Vinyl and was caught.
|
|
7
|
-
*/INTERNAL:"internal",/**
|
|
8
|
-
* A Vinyl interface was used incorrectly by a consumer.
|
|
9
|
-
*/API:"api",/**
|
|
10
|
-
* The error originated from a failed service call (500 errors).
|
|
11
|
-
*/SERVICE_EXTERNAL:"serviceExternal",/**
|
|
12
|
-
* The error originated from a failed service call (400 errors).
|
|
13
|
-
*/SERVICE_INTERNAL:"serviceInternal",/**
|
|
14
|
-
* The error originated from a problem playing provided media.
|
|
15
|
-
* The reporter is from a component such as the element, source buffer, media source, etc.
|
|
16
|
-
*/MEDIA:"media",/**
|
|
17
|
-
* The error originated from a problem parsing input data.
|
|
18
|
-
* Such as a malformed Dash or HLS manifest.
|
|
19
|
-
*/PARSING:"parsing",/**
|
|
20
|
-
* The error originated from an incompatibility with browser APIs,
|
|
21
|
-
* such as EME.
|
|
22
|
-
*/COMPATIBILITY:"compatibility",/**
|
|
23
|
-
* The error originated from DRM.
|
|
24
|
-
* This does not include internal or service errors, only errors from the creation of media keys or media key
|
|
25
|
-
* sessions.
|
|
26
|
-
*/DRM:"drm"};var ReportableError=/*#__PURE__*/function(_Error){function _ReportableError(message){var _this;var origin=arguments.length>1&&arguments[1]!==undefined?arguments[1]:ErrorOrigin.INTERNAL;var level=arguments.length>2&&arguments[2]!==undefined?arguments[2]:"fatal";_classCallCheck(this,_ReportableError);_this=_callSuper(this,_ReportableError,[message]);_this.origin=origin;_this.level=level;Object.setPrototypeOf(_this,_ReportableError.prototype);return _this}_inherits(_ReportableError,_Error);return _createClass(_ReportableError,[{key:Symbol.toStringTag,get:function get(){return"ReportableError"}},{key:"name",get:function get(){return this[Symbol.toStringTag]}/**
|
|
27
|
-
* All ReportableError instances must be serializable.
|
|
28
|
-
*/},{key:"toJSON",value:function toJSON(){return{level:this.level,message:this.message,name:this.name,origin:this.origin,stack:this.stack}}}])}(/*#__PURE__*/_wrapNativeSuper(Error));var IllegalArgumentError=/*#__PURE__*/function(_ReportableError2){function _IllegalArgumentError(message){var _this2;var isInternal=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;_classCallCheck(this,_IllegalArgumentError);_this2=_callSuper(this,_IllegalArgumentError,[message,isInternal?ErrorOrigin.INTERNAL:ErrorOrigin.API]);_this2.isInternal=isInternal;Object.setPrototypeOf(_this2,_IllegalArgumentError.prototype);return _this2}_inherits(_IllegalArgumentError,_ReportableError2);return _createClass(_IllegalArgumentError,[{key:Symbol.toStringTag,get:function get(){return"IllegalArgumentError"}}])}(ReportableError);var locale={variableNotDefined:"Variable '{name}' is not defined"};var DEFAULT_SUBSTITUTE_PATTERN=/\{(\w+)}/g;function substitute(str,variables){var pattern=arguments.length>2&&arguments[2]!==undefined?arguments[2]:DEFAULT_SUBSTITUTE_PATTERN;return str.replace(pattern,function(_,name){if(!(name in variables)){throw new IllegalArgumentError(locale.variableNotDefined.replace("{name}",String(name)))}return String(variables[name])})}function isWhitespaceChar(charCode){return charCode===32||// ' ' (space)
|
|
29
|
-
charCode===9||// '\t' (tab)
|
|
30
|
-
charCode===13||// '\r' (carriage return)
|
|
31
|
-
charCode===10}function eqStr(a,b){var ignoreCase=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;if(a==null&&b==null)return true;if(a==null||b==null)return false;if(a===b)return true;if(ignoreCase)return a.length===b.length&&a.toLowerCase()===b.toLowerCase();return false}function char(str){return str.charCodeAt(0)}function truncate(str,maxLength){var indicator=arguments.length>2&&arguments[2]!==undefined?arguments[2]:"\u2026";if(str==null)return str;if(str.length>maxLength)return str.substring(0,maxLength-indicator.length)+indicator;return str}function clamp(value,min2,max2){return Math.min(Math.max(value,min2),max2)}function printStringPosition(str,index,options){var _a;var caret=(options==null?void 0:options.caret)||"^";index=clamp(index,0,str.length);var minIndex=str.lastIndexOf("\n",index-1)+1;var maxIndex=str.indexOf("\n",index);if(maxIndex===-1)maxIndex=str.length;var split=(options==null?void 0:options.split)===void 0?0.6:options.split;var cols=((_a=options==null?void 0:options.maxColumns)!=null?_a:60)-caret.length;var leadingChars=cols*split;var trailingChars=cols*(1-split);var maxLeadingChars=index-minIndex;var maxTrailingChars=maxIndex-index;if(leadingChars>maxLeadingChars){trailingChars+=leadingChars-maxLeadingChars;leadingChars=maxLeadingChars;if(trailingChars>maxTrailingChars)trailingChars=maxTrailingChars}else if(trailingChars>maxTrailingChars){leadingChars+=trailingChars-maxTrailingChars;trailingChars=maxTrailingChars;if(leadingChars>maxLeadingChars)leadingChars=maxLeadingChars}var out=str.substring(index-leadingChars,index+trailingChars)+"\n";out+=" ".repeat(leadingChars)+caret;return out}var StringReader=/*#__PURE__*/function(){/**
|
|
32
|
-
* @param data The string to read.
|
|
33
|
-
*/function StringReader(data){_classCallCheck(this,StringReader);this.data=data;__publicField(this,"position",0)}/**
|
|
34
|
-
* Returns true if the current {@link position} is less than the source data's length.
|
|
35
|
-
*/return _createClass(StringReader,[{key:"hasNext",value:function hasNext(){return this.position<this.data.length}/**
|
|
36
|
-
* Returns the number of characters remaining to be read.
|
|
37
|
-
*/},{key:"remaining",get:function get(){return this.data.length-this.position}/**
|
|
38
|
-
* Returns the length of {@link data}.
|
|
39
|
-
*/},{key:"length",get:function get(){return this.data.length}/**
|
|
40
|
-
* Throws a {@link StringParseError} where the location uses {@link printStringPosition} to
|
|
41
|
-
* show a friendly message indicating the current position.
|
|
42
|
-
*
|
|
43
|
-
* @param message
|
|
44
|
-
* @param offset The offset to add to the current position.
|
|
45
|
-
*/},{key:"err",value:function err(message){var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;throw new StringParseError(this.data,this.position+offset,message)}/**
|
|
46
|
-
* Reads and returns the character code at the current position.
|
|
47
|
-
* To read the next character without advancing the cursor, use {@link peek}
|
|
48
|
-
*
|
|
49
|
-
* Note:
|
|
50
|
-
* This method has no bounds checking; if {@link position} is greater than or equal to
|
|
51
|
-
* `str.length` then NaN will be returned and {@link position} will still be incremented.
|
|
52
|
-
*
|
|
53
|
-
* @see String.charCodeAt
|
|
54
|
-
*/},{key:"next",value:function next(){return this.data.charCodeAt(this.position++)}/**
|
|
55
|
-
* Reads characters until the predicate returns false or the data length has been reached.
|
|
56
|
-
*
|
|
57
|
-
* @param predicate Given the char code at the cursor index, returns true if the character
|
|
58
|
-
* should be included in the substring result.
|
|
59
|
-
* @returns number The start position.
|
|
60
|
-
*/},{key:"while",value:function _while(predicate){var start=this.position;var i=start;var n=this.data.length;while(i<n&&predicate(this.data.charCodeAt(i)))i++;this.position=i;return start}/**
|
|
61
|
-
* Reads characters until the predicate returns true or the string length has been reached.
|
|
62
|
-
*
|
|
63
|
-
* @param predicate
|
|
64
|
-
* @returns number Returns the start index.
|
|
65
|
-
*/},{key:"until",value:function until(predicate){return this.while(function(charCode){return!predicate(charCode)})}/**
|
|
66
|
-
* Reads characters until the given character has been found or the string length has been
|
|
67
|
-
* reached.
|
|
68
|
-
*
|
|
69
|
-
* @param charCode
|
|
70
|
-
* @return number Returns the start index.
|
|
71
|
-
*/},{key:"untilChar",value:function untilChar(charCode){return this.until(function(cc){return cc===charCode})}/**
|
|
72
|
-
* Reads characters until the given string has been found or the string length has been
|
|
73
|
-
* reached.
|
|
74
|
-
*
|
|
75
|
-
* @param string The string to match
|
|
76
|
-
* @return number Returns the start index.
|
|
77
|
-
*/},{key:"untilString",value:function untilString(string){var start=this.position;var index=this.data.indexOf(string,this.position);this.position=index===-1?this.data.length:index;return start}/**
|
|
78
|
-
* The same as {@link while} except returns the read substring as a result.
|
|
79
|
-
*/},{key:"substringWhile",value:function substringWhile(predicate){return this.data.substring(this.while(predicate),this.position)}/**
|
|
80
|
-
* The same as {@link until} except returns the read substring as a result.
|
|
81
|
-
*/},{key:"substringUntil",value:function substringUntil(predicate){return this.substringWhile(function(charCode){return!predicate(charCode)})}/**
|
|
82
|
-
* The same as {@link untilChar} except returns the read substring as a result.
|
|
83
|
-
*/},{key:"substringUntilChar",value:function substringUntilChar(charCode){return this.substringWhile(function(iCharCode){return charCode!==iCharCode})}/**
|
|
84
|
-
* Reads the substring from the current index with the given length.
|
|
85
|
-
*
|
|
86
|
-
* @param length
|
|
87
|
-
*/},{key:"substr",value:function substr(length){var sub=this.data.substring(this.position,this.position+length);this.position+=sub.length;return sub}/**
|
|
88
|
-
* Reads the expected string from the current position.
|
|
89
|
-
* If the read string doesn't match the given string, a {@link StringParseError} is thrown.
|
|
90
|
-
*
|
|
91
|
-
* @param str The string required to match at the current position.
|
|
92
|
-
* @param ignoreCase If true, the comparison will be case-insensitive.
|
|
93
|
-
*/},{key:"read",value:function read(str){var ignoreCase=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var actual=this.substr(str.length);if(!eqStr(actual,str,ignoreCase))this.err("Expected '".concat(str,"', actual: '").concat(actual,"'"));return actual}/**
|
|
94
|
-
* Reads the expected char code from the current position.
|
|
95
|
-
* If the read character doesn't match the given character, a {@link StringParseError} is
|
|
96
|
-
* thrown.
|
|
97
|
-
*
|
|
98
|
-
* @param charCode The character code required to match at the current position.
|
|
99
|
-
*/},{key:"readChar",value:function readChar(charCode){var actual=this.next();if(actual!==charCode)this.err("Expected '".concat(String.fromCharCode(charCode),"', actual: '").concat(String.fromCharCode(actual),"'"));return actual}/**
|
|
100
|
-
* Returns the character at the current position without advancing the cursor.
|
|
101
|
-
*
|
|
102
|
-
* Note:
|
|
103
|
-
* This method has no bounds checking; if {@link position} is greater than or equal to
|
|
104
|
-
* `str.length` then `NaN` will be returned.
|
|
105
|
-
*
|
|
106
|
-
* @see String.charCodeAt
|
|
107
|
-
*/},{key:"peek",get:function get(){return this.data.charCodeAt(this.position)}/**
|
|
108
|
-
* Reads through all whitespace characters, returning the starting index.
|
|
109
|
-
*/},{key:"white",value:function white(){return this.while(isWhitespaceChar)}/**
|
|
110
|
-
* If {@link peek} equals the given character code, returns true and advances the index by
|
|
111
|
-
* one.
|
|
112
|
-
*
|
|
113
|
-
* @param charCode
|
|
114
|
-
*/},{key:"charIf",value:function charIf(charCode){if(this.peek===charCode){this.next();return true}else{return false}}/**
|
|
115
|
-
* If the given string matches the substring at the current position, returns true and advances
|
|
116
|
-
* the index by the string's length.
|
|
117
|
-
*/},{key:"stringIf",value:function stringIf(string){var ignoreCase=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(this.remaining<string.length)return false;var substr=this.data.substring(this.position,this.position+string.length);var match=eqStr(substr,string,ignoreCase);if(match)this.position+=string.length;return match}}])}();var locale2={messageSeparator:", at: \n"};var StringParseError=/*#__PURE__*/function(_ReportableError3){function _StringParseError(str,position,reason){var _this3;_classCallCheck(this,_StringParseError);var location2=printStringPosition(str,position);_this3=_callSuper(this,_StringParseError,["".concat(reason).concat(locale2.messageSeparator).concat(location2),ErrorOrigin.PARSING]);_this3.position=position;_this3.reason=reason;__publicField(_this3,"location");_this3.location=location2;Object.setPrototypeOf(_this3,_StringParseError.prototype);return _this3}_inherits(_StringParseError,_ReportableError3);return _createClass(_StringParseError,[{key:Symbol.toStringTag,get:function get(){return"StringParseError"}},{key:"toJSON",value:function toJSON(){return __spreadProps2(__spreadValues2({},_superPropGet(_StringParseError,"toJSON",this,3)([])),{position:this.position,location:this.location,reason:this.reason})}}])}(ReportableError);function ownKeys(obj){if(!obj)return/* @__PURE__ */new Set;if(typeof Reflect!=="undefined")return new Set(Reflect.ownKeys(obj));var properties=/* @__PURE__ */new Set;Object.getOwnPropertyNames(obj).forEach(function(item){return properties.add(item)});Object.getOwnPropertySymbols(obj).forEach(function(item){return properties.add(item)});return properties}function isPlainObject(value){if(!value||_typeof(value)!=="object"||Array.isArray(value))return false;var proto=Object.getPrototypeOf(value);return!proto||!Object.getPrototypeOf(proto)}function toJson(value){return toJsonInternal(value,/* @__PURE__ */new Set)}function toJsonInternal(value,visited){switch(_typeof(value)){case"object":return objectToJsonInternal(value,visited);case"undefined":case"boolean":case"number":case"string":return value;case"function":return"[function ".concat(value.name,"]");case"symbol":return"[symbol ".concat(value.toString().slice(7,-1),"]");case"bigint":return value.toString()}}function objectToJsonInternal(value,visited){if(value==null)return value;if(visited.has(value))return"<circular reference: ".concat(String(value),">");visited.add(value);if("toJSON"in value&&typeof value.toJSON==="function")return value.toJSON();if(value instanceof Set){return Array.from(value).map(function(e){return toJsonInternal(e,visited)})}else if(Array.isArray(value)){return value.map(function(e){return toJsonInternal(e,visited)})}else{if(isPlainObject(value)){var o={};for(var key in value){o[key]=toJsonInternal(value[key],visited)}return o}else if(value instanceof Error){return{name:value.name,message:value.message,stack:value.stack}}else{return value.toString()}}}function stringifyForPrint(value,maxLength){var indicator=arguments.length>2&&arguments[2]!==undefined?arguments[2]:"\u2026";var str=JSON.stringify(toJson(value),function(_,value2){var type=_typeof(value2);if(["undefined"].includes(type)){return"{{".concat(String(value2),"}}")}if(type==="number"){if(Number.isNaN(value2)||!Number.isFinite(value2))return"{{".concat(value2.toString(),"}}")}return value2}," ");str=str.replace(/("\{\{.*}}")/g,function(_,s){return s.substring(3,s.length-3)});if(maxLength)str=truncate(str,maxLength,indicator);return str}function merge(){var _Array$prototype;for(var _len=arguments.length,sources=new Array(_len),_key=0;_key<_len;_key++){sources[_key]=arguments[_key]}if(!sources.length)return void 0;if(Array.isArray(sources[0]))return(_Array$prototype=Array.prototype).concat.apply(_Array$prototype,sources);return Object.assign.apply(Object,[{}].concat(sources))}var ValidationError=/*#__PURE__*/function(_ReportableError4){/**
|
|
118
|
-
* @param message The validation error message.
|
|
119
|
-
* @param origin The error origin, typically API (default) or SERVICE_EXTERNAL
|
|
120
|
-
* @param path The property path to the invalid field.
|
|
121
|
-
*/function _ValidationError(message){var _this4;var origin=arguments.length>1&&arguments[1]!==undefined?arguments[1]:ErrorOrigin.API;var path=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];_classCallCheck(this,_ValidationError);_this4=_callSuper(this,_ValidationError,[message,origin]);_this4.path=path;Object.setPrototypeOf(_this4,_ValidationError.prototype);return _this4}_inherits(_ValidationError,_ReportableError4);return _createClass(_ValidationError,[{key:Symbol.toStringTag,get:function get(){return"ValidationError"}},{key:"toJSON",value:function toJSON(){return __spreadProps2(__spreadValues2({},_superPropGet(_ValidationError,"toJSON",this,3)([])),{origin:this.origin,path:this.path})}}])}(ReportableError);// ../vinyl-validation/dist/index.js
|
|
122
|
-
var __defProp3=Object.defineProperty;var __defProps3=Object.defineProperties;var __getOwnPropDescs3=Object.getOwnPropertyDescriptors;var __getOwnPropSymbols3=Object.getOwnPropertySymbols;var __hasOwnProp3=Object.prototype.hasOwnProperty;var __propIsEnum3=Object.prototype.propertyIsEnumerable;var __defNormalProp3=function __defNormalProp3(obj,key,value){return key in obj?__defProp3(obj,key,{enumerable:true,configurable:true,writable:true,value:value}):obj[key]=value};var __spreadValues3=function __spreadValues3(a,b){for(var prop in b||(b={}))if(__hasOwnProp3.call(b,prop))__defNormalProp3(a,prop,b[prop]);if(__getOwnPropSymbols3){var _iterator3=_createForOfIteratorHelper(__getOwnPropSymbols3(b)),_step3;try{for(_iterator3.s();!(_step3=_iterator3.n()).done;){var prop=_step3.value;if(__propIsEnum3.call(b,prop))__defNormalProp3(a,prop,b[prop])}}catch(err){_iterator3.e(err)}finally{_iterator3.f()}}return a};var __spreadProps3=function __spreadProps3(a,b){return __defProps3(a,__getOwnPropDescs3(b))};var __publicField2=function __publicField2(obj,key,value){return __defNormalProp3(obj,_typeof(key)!=="symbol"?key+"":key,value)};var validatorLocale={/**
|
|
123
|
-
* The expectation template string with the following replacement tokens:
|
|
124
|
-
*
|
|
125
|
-
* `{expected}` - The expected description.
|
|
126
|
-
* `{actual}` - The actual value.
|
|
127
|
-
* `{path}` - The path, dot separated.
|
|
128
|
-
*/template:"Expected: {expected}, but was: {actual}. At: {path}"};function createValidationExpectationMessage(expectationMessage,input,path){var inputStringify=arguments.length>3&&arguments[3]!==undefined?arguments[3]:function(input2){return stringifyForPrint(input2,500)};return substitute(validatorLocale.template,{expected:expectationMessage,actual:inputStringify(input),path:path.join(".")})}function createValidator(expectationMessage,_isValid){var inputStringify=arguments.length>2&&arguments[2]!==undefined?arguments[2]:function(input){return stringifyForPrint(input,500)};return{description:expectationMessage,isValid:function isValid(input){return _isValid(input)},validate:function validate(input,_){var path=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];if(!_isValid(input)){return[{message:createValidationExpectationMessage(expectationMessage,input,path,inputStringify),path:path}]}return[]},assert:function assert(input,origin){var path=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];if(!_isValid(input)){throw new ValidationError(createValidationExpectationMessage(expectationMessage,input,path,inputStringify),origin,path)}}}}function createDeepValidator(description,_validate){return{description:description,isValid:function isValid(input){return _validate(input,{all:false},[]).length===0},validate:function validate(input,options){var path=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];return _validate(input,options!=null?options:{all:false},path)},assert:function assert(input,origin){var path=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];var errors=_validate(input,{all:false},path);if(errors.length){var error=errors[0];throw new ValidationError(error.message,origin,error.path)}}}}var locale3={/**
|
|
129
|
-
* {value} The child validators' descriptions, joined with `separator`.
|
|
130
|
-
*
|
|
131
|
-
* groupings of and validators is unimportant,
|
|
132
|
-
* and(and(a, b), c) is the same as and(a, and(b, c)), so `a & b & c` is an accurate
|
|
133
|
-
* representation for either.
|
|
134
|
-
*/template:"{value}",/**
|
|
135
|
-
* The separator with which to join child validator descriptions.
|
|
136
|
-
*/separator:" & "};function andValidators(){for(var _len2=arguments.length,validators=new Array(_len2),_key2=0;_key2<_len2;_key2++){validators[_key2]=arguments[_key2]}return createDeepValidator(substitute(locale3.template,{value:validators.map(function(v){return v.description}).join(locale3.separator)}),function(input,options,path){for(var _i=0,_validators=validators;_i<_validators.length;_i++){var validator=_validators[_i];var errors=validator.validate(input,options,path);if(errors.length)return errors}return[]})}var locale22={/**
|
|
137
|
-
* {value} - The child validators' descriptions, joined with `separator`.
|
|
138
|
-
*/template:"({value})",/**
|
|
139
|
-
* The separator with which to join child validator descriptions.
|
|
140
|
-
*/separator:" | "};function orValidators(){for(var _len3=arguments.length,validators=new Array(_len3),_key3=0;_key3<_len3;_key3++){validators[_key3]=arguments[_key3]}var description=substitute(locale22.template,{value:validators.map(function(v){return v.description}).join(locale22.separator)});return createDeepValidator(description,function(input,options,path){var longestErrors=[];var longestPath=0;for(var _i2=0,_validators2=validators;_i2<_validators2.length;_i2++){var validator=_validators2[_i2];var errors=validator.validate(input,options,path);if(!errors.length)return errors;var pathLength=errors.reduce(function(max,m){return Math.max(m.path.length,max)},0);if(pathLength>=longestPath){longestErrors=errors;longestPath=pathLength}}return longestPath>path.length?longestErrors:[{message:createValidationExpectationMessage(description,input,path),path:path}]})}var requiredValidationOptions={optional:false};var SchemaBase=/*#__PURE__*/function(){function SchemaBase(currentValidator,previousSchema,operation){var _this5=this;_classCallCheck(this,SchemaBase);this.currentValidator=currentValidator;this.previousSchema=previousSchema;this.operation=operation;__publicField2(this,"__type",/* @__PURE__ */invariant());__publicField2(this,"validator");__publicField2(this,"_options",requiredValidationOptions);__publicField2(this,"assert",function(input,origin,path){_this5.validator.assert(input,origin,path)});__publicField2(this,"isValid",function(input){return _this5.validator.isValid(input)});__publicField2(this,"validate",function(input,options,path){return _this5.validator.validate(input,options,path)});this.validator=operation==null?currentValidator:operation(previousSchema,currentValidator)}return _createClass(SchemaBase,[{key:"options",get:function get(){return this._options}},{key:"description",get:function get(){return this.validator.description}/**
|
|
141
|
-
* Clones this schema, transforming all validators with the given mutator.
|
|
142
|
-
*
|
|
143
|
-
* @param transform A transformer which takes an existing validator in the chain and returns
|
|
144
|
-
* a new one. Validators should be considered to be immutable; transform should not change the
|
|
145
|
-
* input but instead return a new validator.
|
|
146
|
-
*/},{key:"clone",value:function clone(){var transform=arguments.length>0&&arguments[0]!==undefined?arguments[0]:function(v){return v};var cloned=this.operation?this.self(transform(this.currentValidator),this.previousSchema.clone(transform),this.operation):this.self(transform(this.currentValidator));cloned._options=this._options;return cloned}},{key:"self",value:function self(current,previous,operation){if(this.constructor.length>3){throw new IllegalArgumentError("constructor should have at most three required arguments")}return new this.constructor(current,previous,operation)}/**
|
|
147
|
-
* Constructs a new schema with a validator chaining the current validator with the
|
|
148
|
-
* provided next in an AND operation.
|
|
149
|
-
*
|
|
150
|
-
* @param nextValidator The validator to run after the current.
|
|
151
|
-
* @return Returns a new Schema instance the same class with a new validator chaining the
|
|
152
|
-
* current validator with the given next in an AND operation.
|
|
153
|
-
*/},{key:"chain",value:function chain(nextValidator){return this.self(nextValidator,this,andValidators)}},{key:"optional",value:function optional(){var cloned=this.clone();cloned._options=__spreadProps3(__spreadValues3({},cloned.options),{optional:true});return cloned}},{key:"required",value:function required(){var cloned=this.clone();cloned._options=__spreadProps3(__spreadValues3({},cloned.options),{optional:false});return cloned}}])}();var locale32={null:"null",nullish:"nullish",undefined:"undefined"};var valueValidators={any:function any(){return createValidator("",function(){return true})},/**
|
|
154
|
-
* Creates a validator that asserts that the input is nullish.
|
|
155
|
-
*/nullish:function nullish(){return createValidator(locale32.nullish,function(input){return input==null})},/**
|
|
156
|
-
* Creates a validator that asserts that the input is strictly null.
|
|
157
|
-
*/null:function _null(){return createValidator(locale32.null,function(input){return input===null})},/**
|
|
158
|
-
* Creates a validator that asserts that the input is strictly undefined.
|
|
159
|
-
*/undefined:function undefined(){return createValidator(locale32.undefined,function(input){return input===void 0})}};var ValueSchema=/*#__PURE__*/function(_SchemaBase){function _ValueSchema(){_classCallCheck(this,_ValueSchema);return _callSuper(this,_ValueSchema,arguments)}_inherits(_ValueSchema,_SchemaBase);return _createClass(_ValueSchema,[{key:"maybe",value:/**
|
|
160
|
-
* Prepends this validator allowing for null or undefined.
|
|
161
|
-
*/function maybe(){return this.or(valueValidators.nullish())}/**
|
|
162
|
-
* Prepends this validator allowing for null.
|
|
163
|
-
*/},{key:"orNull",value:function orNull(){return this.or(valueValidators.null())}/**
|
|
164
|
-
* Prepends this validator allowing for undefined.
|
|
165
|
-
*/},{key:"orUndefined",value:function orUndefined(){return this.or(valueValidators.undefined())}/**
|
|
166
|
-
* Returns a validator that asserts if this validator and the next passes.
|
|
167
|
-
*
|
|
168
|
-
* @see andValidators
|
|
169
|
-
*
|
|
170
|
-
* @param nextValidator The validator to run after the current.
|
|
171
|
-
* @return Returns a new ValueSchema intersecting this validator and the next.
|
|
172
|
-
*/},{key:"and",value:function and(nextValidator){return new _ValueSchema(nextValidator,this,andValidators)}/**
|
|
173
|
-
* Returns a validator that asserts if this validator or the next passes.
|
|
174
|
-
*
|
|
175
|
-
* Implementation note:
|
|
176
|
-
* subclasses should not change the schema instance returned unless all chainable validators
|
|
177
|
-
* accept input type 'unknown'.
|
|
178
|
-
*
|
|
179
|
-
* @param nextValidator The validator to run after the current.
|
|
180
|
-
* @return Returns a new ValueSchema providing the union of this validator and the next.
|
|
181
|
-
*/},{key:"or",value:function or(nextValidator){return new _ValueSchema(nextValidator,this,orValidators)}}])}(SchemaBase);var locale4={array:"array",minLength:"at least {value} elements",maxLength:"at most {value} elements",exactlyLength:"exactly {value} elements",actualLength:"length {value}",withElements:"({value})[]",tuple:"[{value}]"};var arrayValidators={/**
|
|
182
|
-
* Creates a validator that asserts that the input is an array.
|
|
183
|
-
*
|
|
184
|
-
* Note: arrays can only be readonly by type system, there is no native readonly
|
|
185
|
-
* js array. This validator assumes mutability, use the ArraySchema readonly() method
|
|
186
|
-
* to cast to a readonly array.
|
|
187
|
-
*/isArray:function isArray(){return createValidator(locale4.array,function(input){return Array.isArray(input)})},/**
|
|
188
|
-
* Creates a validator that asserts that every element passes the given validator.
|
|
189
|
-
*
|
|
190
|
-
* @param elementValidator
|
|
191
|
-
*/withElements:function withElements(elementValidator){return createDeepValidator(substitute(locale4.withElements,{value:elementValidator.description}),function(input,options,path){var errors=[];for(var i=0;i<input.length;i++){var element=input[i];errors.push.apply(errors,_toConsumableArray(elementValidator.validate(element,options,path.concat(i.toString()))));if(!options.all&&errors.length)return errors}return errors})},/**
|
|
192
|
-
* Creates a validator that asserts that the input array is a tuple whose elements match
|
|
193
|
-
* the given validators.
|
|
194
|
-
*
|
|
195
|
-
* @param validators
|
|
196
|
-
*/tuple:function tuple(){for(var _len4=arguments.length,validators=new Array(_len4),_key4=0;_key4<_len4;_key4++){validators[_key4]=arguments[_key4]}var lengthValidator=createValidator(substitute(locale4.exactlyLength,{value:validators.length}),function(length){return length===validators.length});return createDeepValidator(substitute(locale4.tuple,{value:validators.join(", ")}),function(input,options,path){var errors=[];errors.push.apply(errors,_toConsumableArray(lengthValidator.validate(input.length,options,path)));if(!options.all&&errors.length)return errors;var n=Math.min(validators.length,input.length);for(var i=0;i<n;i++){var element=input[i];var validator=validators[i];errors.push.apply(errors,_toConsumableArray(validator.validate(element,options,path.concat(i.toString()))));if(!options.all&&errors.length)return errors}return errors})},/**
|
|
197
|
-
* Creates a validator that validates the input array has the given minimum length.
|
|
198
|
-
* @param min The minimum number of elements (inclusive)
|
|
199
|
-
*/minLength:function minLength(min){return createValidator(substitute(locale4.minLength,{value:min}),function(input){return input.length>=min},function(input){return substitute(locale4.actualLength,{value:input.length})})},/**
|
|
200
|
-
*
|
|
201
|
-
* Creates a validator that validates the input array has the given maximum length.
|
|
202
|
-
* @param max The maximum number of elements (inclusive)
|
|
203
|
-
*/maxLength:function maxLength(max){return createValidator(substitute(locale4.maxLength,{value:max}),function(input){return input.length<=max},function(input){return substitute(locale4.actualLength,{value:input.length})})}};var _ArraySchema=/*#__PURE__*/function(_ValueSchema2){function _ArraySchema2(){_classCallCheck(this,_ArraySchema2);return _callSuper(this,_ArraySchema2,arguments)}_inherits(_ArraySchema2,_ValueSchema2);return _createClass(_ArraySchema2,[{key:"withElements",value:/**
|
|
204
|
-
* Creates a validator that asserts that every element passes the given validator.
|
|
205
|
-
*
|
|
206
|
-
* @param elementValidator
|
|
207
|
-
*/function withElements(elementValidator){return this.chain(arrayValidators.withElements(elementValidator))}/**
|
|
208
|
-
* Creates a validator that asserts that the input array is a tuple whose elements match
|
|
209
|
-
* the given validators.
|
|
210
|
-
*
|
|
211
|
-
* @param validators
|
|
212
|
-
*/},{key:"tuple",value:function tuple(){return this.chain(arrayValidators.tuple.apply(arrayValidators,arguments))}/**
|
|
213
|
-
* Creates a validator that validates the input array has the given minimum length.
|
|
214
|
-
* @param min The minimum number of elements (inclusive)
|
|
215
|
-
*/},{key:"minLength",value:function minLength(min){return this.chain(arrayValidators.minLength(min))}/**
|
|
216
|
-
*
|
|
217
|
-
* Creates a validator that validates the input array has the given maximum length.
|
|
218
|
-
* @param max The maximum number of elements (inclusive)
|
|
219
|
-
*/},{key:"maxLength",value:function maxLength(max){return this.chain(arrayValidators.maxLength(max))}/**
|
|
220
|
-
* Casts to a readonly array.
|
|
221
|
-
* This is a shallow cast, elements of the array will not be changed.
|
|
222
|
-
*/},{key:"readonly",value:function readonly(){return this}/**
|
|
223
|
-
* Casts the type parameter.
|
|
224
|
-
*/},{key:"cast",value:function cast(){return this}}],[{key:"base",get:/**
|
|
225
|
-
* The base ArraySchema instance validating that the input is an Array.
|
|
226
|
-
*/function get(){if(this._base==null)this._base=new _ArraySchema2(arrayValidators.isArray());return this._base}}])}(ValueSchema);__publicField2(_ArraySchema,"_base",null);var locale5={template:"type {value}"};function typeOfValidator(expected){return createValidator(substitute(locale5.template,{value:expected}),function(input){return input!=null&&_typeof(input)===expected})}var typeOfValidatorCache={};function cachedTypeOfValidator(type){if(!(type in typeOfValidatorCache)){typeOfValidatorCache[type]=typeOfValidator(type)}return typeOfValidatorCache[type]}var typeOfValidators={get boolean(){return cachedTypeOfValidator("boolean")},get func(){return cachedTypeOfValidator("function")},get number(){return cachedTypeOfValidator("number")},get object(){return cachedTypeOfValidator("object")},get string(){return cachedTypeOfValidator("string")},get symbol(){return cachedTypeOfValidator("symbol")}};var locale6={length:"at most {value} arguments",actualLength:"{value} arguments"};var functionValidators={length:function length(max){return createValidator(substitute(locale6.length,{value:max}),function(input){return input.length<=max},function(input){return substitute(locale6.actualLength,{value:input.length})})}};var _FunctionSchema=/*#__PURE__*/function(_ValueSchema3){function _FunctionSchema2(){_classCallCheck(this,_FunctionSchema2);return _callSuper(this,_FunctionSchema2,arguments)}_inherits(_FunctionSchema2,_ValueSchema3);return _createClass(_FunctionSchema2,[{key:"length",value:function length(max){return this.chain(functionValidators.length(max))}/**
|
|
227
|
-
* Casts the function signature.
|
|
228
|
-
* Function signatures, except for their required number of parameters, cannot be
|
|
229
|
-
* meaningfully validated.
|
|
230
|
-
*/},{key:"cast",value:function cast(){return this}}],[{key:"base",get:/**
|
|
231
|
-
* The base Function validator validating that the input is a function.
|
|
232
|
-
*/function get(){if(this._base==null)this._base=new _FunctionSchema2(typeOfValidators.func);return this._base}}])}(ValueSchema);__publicField2(_FunctionSchema,"_base",null);var locale7={set:"Set",withElements:"Set<{value}>"};var setValidators={/**
|
|
233
|
-
* Creates a validator that asserts that the input is a set.
|
|
234
|
-
*/isSet:function isSet(){return createValidator(locale7.set,function(input){return input instanceof Set})},/**
|
|
235
|
-
* Creates a validator that asserts that every element passes the given validator.
|
|
236
|
-
*
|
|
237
|
-
* @param elementValidator
|
|
238
|
-
*/withElements:function withElements(elementValidator){return createDeepValidator(substitute(locale7.withElements,{value:elementValidator.description}),function(input,options,path){var errors=[];var i=0;var _iterator4=_createForOfIteratorHelper(input),_step4;try{for(_iterator4.s();!(_step4=_iterator4.n()).done;){var element=_step4.value;errors.push.apply(errors,_toConsumableArray(elementValidator.validate(element,options,path.concat(i.toString()))));if(!options.all&&errors.length)return errors;i++}}catch(err){_iterator4.e(err)}finally{_iterator4.f()}return errors})}};var _SetSchema=/*#__PURE__*/function(_ValueSchema4){function _SetSchema2(){_classCallCheck(this,_SetSchema2);return _callSuper(this,_SetSchema2,arguments)}_inherits(_SetSchema2,_ValueSchema4);return _createClass(_SetSchema2,[{key:"withElements",value:/**
|
|
239
|
-
* Creates a validator that asserts that every element passes the given validator.
|
|
240
|
-
*
|
|
241
|
-
* @param elementValidator
|
|
242
|
-
*/function withElements(elementValidator){return this.chain(setValidators.withElements(elementValidator))}/**
|
|
243
|
-
* Casts to a readonly set.
|
|
244
|
-
* This is a shallow cast, elements of the array will not be changed.
|
|
245
|
-
*/},{key:"readonly",value:function readonly(){return this}/**
|
|
246
|
-
* Casts the parameter type.
|
|
247
|
-
*/},{key:"cast",value:function cast(){return this}}],[{key:"base",get:/**
|
|
248
|
-
* The base SetSchema instance validating that the input is a Set.
|
|
249
|
-
*/function get(){if(this._base==null)this._base=new _SetSchema2(setValidators.isSet());return this._base}}])}(ValueSchema);__publicField2(_SetSchema,"_base",null);var locale8={gte:"at least {value}",gt:"greater than {value}",lte:"at most {value}",lt:"less than {value}",within:"within {min} and {max}",safeInteger:"safe integer",finite:"finite"};var numberValidators={/**
|
|
250
|
-
* Creates a validator that asserts that the input number is at least the provided minimum
|
|
251
|
-
* value.
|
|
252
|
-
*
|
|
253
|
-
* @param min The minimum (inclusive) the value may be.
|
|
254
|
-
*/gte:function gte(min){return createValidator(substitute(locale8.gte,{value:min}),function(input){return input>=min})},/**
|
|
255
|
-
* Creates a validator that asserts that the input number is greater than the provided minimum
|
|
256
|
-
* value.
|
|
257
|
-
*
|
|
258
|
-
* @param min The minimum (exclusive) the value may be.
|
|
259
|
-
*/gt:function gt(min){return createValidator(substitute(locale8.gt,{value:min}),function(input){return input>min})},/**
|
|
260
|
-
* Creates a validator that asserts that the input number is at most the provided maximum
|
|
261
|
-
* value.
|
|
262
|
-
*
|
|
263
|
-
* @param max The maximum (inclusive) the value may be.
|
|
264
|
-
*/lte:function lte(max){return createValidator(substitute(locale8.lte,{value:max}),function(input){return input<=max})},/**
|
|
265
|
-
* Creates a validator that asserts that the input number is less than the provided maximum
|
|
266
|
-
* value.
|
|
267
|
-
*
|
|
268
|
-
* @param max The maximum (exclusive) the value may be.
|
|
269
|
-
*/lt:function lt(max){return createValidator(substitute(locale8.lt,{value:max}),function(input){return input<max})},/**
|
|
270
|
-
* Creates a validator that asserts that the input number is at least the provided minimum
|
|
271
|
-
* and at most the provided maximum values.
|
|
272
|
-
*
|
|
273
|
-
* @param min The minimum (inclusive) value the input may be.
|
|
274
|
-
* @param max The maximum (inclusive) value the input may be.
|
|
275
|
-
*/within:function within(min,max){return createValidator(substitute(locale8.within,{min:min,max:max}),function(input){return input>=min&&input<=max})},/**
|
|
276
|
-
* Creates a validator that asserts that the input number is finite.
|
|
277
|
-
*/finite:function finite(){return createValidator(locale8.finite,function(input){return Number.isFinite(input)})},/**
|
|
278
|
-
* Creates a validator that asserts that the input number is a safe integer.
|
|
279
|
-
*/safeInteger:function safeInteger(){return createValidator(locale8.safeInteger,function(input){return Number.isSafeInteger(input)})}};var _NumberSchema=/*#__PURE__*/function(_ValueSchema5){function _NumberSchema2(){_classCallCheck(this,_NumberSchema2);return _callSuper(this,_NumberSchema2,arguments)}_inherits(_NumberSchema2,_ValueSchema5);return _createClass(_NumberSchema2,[{key:"gte",value:/**
|
|
280
|
-
* Creates a validator that asserts that the input number is at least the provided minimum
|
|
281
|
-
* value.
|
|
282
|
-
*
|
|
283
|
-
* @param min The minimum (inclusive) the value may be.
|
|
284
|
-
*/function gte(min){return this.chain(numberValidators.gte(min))}/**
|
|
285
|
-
* Creates a validator that asserts that the input number is greater than the provided minimum
|
|
286
|
-
* value.
|
|
287
|
-
*
|
|
288
|
-
* @param min The minimum (exclusive) the value may be.
|
|
289
|
-
*/},{key:"gt",value:function gt(min){return this.chain(numberValidators.gt(min))}/**
|
|
290
|
-
* Creates a validator that asserts that the input number is at most the provided maximum
|
|
291
|
-
* value.
|
|
292
|
-
*
|
|
293
|
-
* @param max The maximum (inclusive) the value may be.
|
|
294
|
-
*/},{key:"lte",value:function lte(max){return this.chain(numberValidators.lte(max))}/**
|
|
295
|
-
* Creates a validator that asserts that the input number is less than the provided maximum
|
|
296
|
-
* value.
|
|
297
|
-
*
|
|
298
|
-
* @param max The maximum (exclusive) the value may be.
|
|
299
|
-
*/},{key:"lt",value:function lt(max){return this.chain(numberValidators.lt(max))}/**
|
|
300
|
-
* Creates a validator that asserts that the input number is at least the provided minimum
|
|
301
|
-
* and at most the provided maximum values.
|
|
302
|
-
*
|
|
303
|
-
* @param min The minimum (inclusive) value the input may be.
|
|
304
|
-
* @param max The maximum (inclusive) value the input may be.
|
|
305
|
-
*/},{key:"within",value:function within(min,max){return this.chain(numberValidators.within(min,max))}/**
|
|
306
|
-
* Creates a validator that asserts that the input number is finite.
|
|
307
|
-
*/},{key:"finite",value:function finite(){return this.chain(numberValidators.finite())}/**
|
|
308
|
-
* Creates a validator that asserts that the input number is a safe integer.
|
|
309
|
-
*/},{key:"safeInteger",value:function safeInteger(){return this.chain(numberValidators.safeInteger())}}],[{key:"base",get:/**
|
|
310
|
-
* The base Object validator validating that the input is an object.
|
|
311
|
-
*/function get(){if(this._base==null)this._base=new _NumberSchema2(typeOfValidators.number);return this._base}}])}(ValueSchema);__publicField2(_NumberSchema,"_base",null);function isValidatorWithPartial(validator){return"partial"in validator&&"partialDeep"in validator}function maybeToDeepPartial(validator){return isValidatorWithPartial(validator)?validator.partialDeep():validator}function maybeToPartial(validator){return isValidatorWithPartial(validator)?validator.partial():validator}var locale9={extend:"{\n{body}\n}",prop:"{key}: {value}",propSeparator:",\n",indent:" ",required:"property '{key}' is required"};var objectValidators={/**
|
|
312
|
-
* Creates a validator that validates the input has properties that pass their respective
|
|
313
|
-
* validators.
|
|
314
|
-
*
|
|
315
|
-
* @param propertyValidators
|
|
316
|
-
*/properties:function properties(propertyValidators){var propertiesDescriptions=[];var keys=ownKeys(propertyValidators);var _iterator5=_createForOfIteratorHelper(keys),_step5;try{for(_iterator5.s();!(_step5=_iterator5.n()).done;){var key=_step5.value;var validator2=propertyValidators[key];propertiesDescriptions.push(substitute(locale9.prop,{key:String(key)+(validator2.options.optional?"?":""),value:validator2.description}))}}catch(err){_iterator5.e(err)}finally{_iterator5.f()}var description=substitute(locale9.extend,{body:propertiesDescriptions.join(locale9.propSeparator).split("\n").map(function(line){return locale9.indent+line}).join("\n")});var validator=createDeepValidator(description,function(input,options,path){var errors=[];var _iterator6=_createForOfIteratorHelper(keys),_step6;try{for(_iterator6.s();!(_step6=_iterator6.n()).done;){var key=_step6.value;var validator2=propertyValidators[key];if(key in input){var value=input[key];errors.push.apply(errors,_toConsumableArray(validator2.validate(value,options,path.concat(String(key)))))}else{if(!validator2.options.optional){errors.push({message:substitute(locale9.required,{key:key}),path:path.concat(String(key))})}}if(!options.all&&errors.length)return errors}}catch(err){_iterator6.e(err)}finally{_iterator6.f()}return errors});return merge(validator,{partial:function partial(){var optionalPropertyValidators={};var _iterator7=_createForOfIteratorHelper(keys),_step7;try{for(_iterator7.s();!(_step7=_iterator7.n()).done;){var key=_step7.value;optionalPropertyValidators[key]=propertyValidators[key].optional()}}catch(err){_iterator7.e(err)}finally{_iterator7.f()}return objectValidators.properties(optionalPropertyValidators)},partialDeep:function partialDeep(){var optionalPropertyValidators={};var _iterator8=_createForOfIteratorHelper(keys),_step8;try{for(_iterator8.s();!(_step8=_iterator8.n()).done;){var key=_step8.value;optionalPropertyValidators[key]=maybeToDeepPartial(propertyValidators[key].optional())}}catch(err){_iterator8.e(err)}finally{_iterator8.f()}return objectValidators.properties(optionalPropertyValidators)}})}};var _ObjectSchema=/*#__PURE__*/function(_ValueSchema6){function _ObjectSchema2(){_classCallCheck(this,_ObjectSchema2);return _callSuper(this,_ObjectSchema2,arguments)}_inherits(_ObjectSchema2,_ValueSchema6);return _createClass(_ObjectSchema2,[{key:"extend",value:/**
|
|
317
|
-
* Creates a validator that validates the input has properties that pass their respective
|
|
318
|
-
* validators.
|
|
319
|
-
*
|
|
320
|
-
* @param propertyValidators
|
|
321
|
-
*/function extend(propertyValidators){return this.chain(objectValidators.properties(propertyValidators))}/**
|
|
322
|
-
* Allows all properties to be undefined.
|
|
323
|
-
*/},{key:"partial",value:function partial(){return this.clone(maybeToPartial)}/**
|
|
324
|
-
* Allows all recursive properties to be undefined.
|
|
325
|
-
*/},{key:"partialDeep",value:function partialDeep(){return this.clone(maybeToDeepPartial)}/**
|
|
326
|
-
* Casts the type parameter.
|
|
327
|
-
*/},{key:"cast",value:function cast(){return this}}],[{key:"base",get:/**
|
|
328
|
-
* The base Object validator validating that the input is an object.
|
|
329
|
-
*/function get(){if(this._base==null)this._base=new _ObjectSchema2(typeOfValidators.object);return this._base}}])}(ValueSchema);__publicField2(_ObjectSchema,"_base",null);var locale10={notEmpty:"not empty",minLength:"at least {value} characters",maxLength:"at most {value} characters",noWhitespace:"no whitespace characters",matches:"matches {value}"};var stringValidators={/**
|
|
330
|
-
* Creates a validator that asserts that the input is not empty.
|
|
331
|
-
*/notEmpty:function notEmpty(){return createValidator(locale10.notEmpty,function(input){return input!==""})},/**
|
|
332
|
-
* Creates a validator that asserts that the input string has at least the given minimum
|
|
333
|
-
* length.
|
|
334
|
-
*
|
|
335
|
-
* @param min The string must be at least this length.
|
|
336
|
-
*/minLength:function minLength(min){return createValidator(substitute(locale10.minLength,{value:min}),function(input){return input.length>=min})},/**
|
|
337
|
-
* Creates a validator that asserts that the input string has at most the given maximum
|
|
338
|
-
* length.
|
|
339
|
-
*
|
|
340
|
-
* @param max The string must be at most this length.
|
|
341
|
-
*/maxLength:function maxLength(max){return createValidator(substitute(locale10.maxLength,{value:max}),function(input){return input.length<=max})},/**
|
|
342
|
-
* Creates a validator that asserts that the input string has no whitespace characters.
|
|
343
|
-
* Whitespace characters include space, new line, carriage return, and tab.
|
|
344
|
-
*/noWhitespace:function noWhitespace(){return createValidator(locale10.noWhitespace,function(input){return input.search(/\s/g)===-1})},/**
|
|
345
|
-
* Creates a validator that asserts that the input string matches the given regex.
|
|
346
|
-
* @param regex
|
|
347
|
-
*/matches:function matches(regex){return createValidator(substitute(locale10.matches,{value:regex.toString()}),function(input){return regex.test(input)})}};var _StringSchema=/*#__PURE__*/function(_ValueSchema7){function _StringSchema2(){_classCallCheck(this,_StringSchema2);return _callSuper(this,_StringSchema2,arguments)}_inherits(_StringSchema2,_ValueSchema7);return _createClass(_StringSchema2,[{key:"notEmpty",value:/**
|
|
348
|
-
* Creates a validator that asserts that the input is not empty.
|
|
349
|
-
*/function notEmpty(){return this.chain(stringValidators.notEmpty())}/**
|
|
350
|
-
* Creates a validator that asserts that the input string has at least the given minimum
|
|
351
|
-
* length.
|
|
352
|
-
*
|
|
353
|
-
* @param min The string must be at least this length.
|
|
354
|
-
*/},{key:"minLength",value:function minLength(min){return this.chain(stringValidators.minLength(min))}/**
|
|
355
|
-
* Creates a validator that asserts that the input string has at most the given maximum
|
|
356
|
-
* length.
|
|
357
|
-
*
|
|
358
|
-
* @param max The string must be at most this length.
|
|
359
|
-
*/},{key:"maxLength",value:function maxLength(max){return this.chain(stringValidators.maxLength(max))}/**
|
|
360
|
-
* Creates a validator that asserts that the input string has no whitespace characters.
|
|
361
|
-
* Whitespace characters include space, new line, carriage return, and tab.
|
|
362
|
-
*/},{key:"noWhitespace",value:function noWhitespace(){return this.chain(stringValidators.noWhitespace())}/**
|
|
363
|
-
* Creates a validator that asserts that the input string matches the given regex.
|
|
364
|
-
* @param regex
|
|
365
|
-
*/},{key:"matches",value:function matches(regex){return this.chain(stringValidators.matches(regex))}}],[{key:"base",get:/**
|
|
366
|
-
* The base SetSchema instance validating that the input is a Set.
|
|
367
|
-
*/function get(){if(this._base==null)this._base=new _StringSchema2(typeOfValidators.string);return this._base}}])}(ValueSchema);__publicField2(_StringSchema,"_base",null);var StringSchema=_StringSchema;var locale11={record:"{ [key: {key}]: {value} }"};var recordValidators={/**
|
|
368
|
-
* Returns a validator that asserts that the object's own enumerable properties has keys and
|
|
369
|
-
* values that match their respective validators.
|
|
370
|
-
*
|
|
371
|
-
* Prototype members are not included.
|
|
372
|
-
* Numeric keys are validated as strings. For example the object `{ [0]: 1 }` will be passed
|
|
373
|
-
* to the key validator as '0'.
|
|
374
|
-
*
|
|
375
|
-
* @param keyValidator Validates each key.
|
|
376
|
-
* @param valueValidator Validates each value.
|
|
377
|
-
*/record:function record(keyValidator,valueValidator){return createDeepValidator(substitute(locale11.record,{key:keyValidator.description,value:valueValidator.description}),function(input,options,path){var errors=[];var _iterator9=_createForOfIteratorHelper(ownKeys(input)),_step9;try{for(_iterator9.s();!(_step9=_iterator9.n()).done;){var key=_step9.value;var keyStr=String(key);errors.push.apply(errors,_toConsumableArray(keyValidator.validate(key,options,path.concat("[".concat(keyStr,"]")))));if(!options.all&&errors.length)return errors;var value=input[key];errors.push.apply(errors,_toConsumableArray(valueValidator.validate(value,options,path.concat(keyStr))));if(!options.all&&errors.length)return errors}}catch(err){_iterator9.e(err)}finally{_iterator9.f()}return errors})}};var _RecordSchema=/*#__PURE__*/function(_ValueSchema8){function _RecordSchema2(){_classCallCheck(this,_RecordSchema2);return _callSuper(this,_RecordSchema2,arguments)}_inherits(_RecordSchema2,_ValueSchema8);return _createClass(_RecordSchema2,[{key:"record",value:/**
|
|
378
|
-
* Returns a validator that asserts that the object's own enumerable properties has keys and
|
|
379
|
-
* values that match their respective validators.
|
|
380
|
-
*
|
|
381
|
-
* Prototype members are not included.
|
|
382
|
-
* Numeric keys are validated as strings. For example the object `{ [0]: 1 }` will be passed
|
|
383
|
-
* to the key validator as '0'.
|
|
384
|
-
*
|
|
385
|
-
* @param keyValidator Validates each key.
|
|
386
|
-
* @param valueValidator Validates each value.
|
|
387
|
-
*/function record(keyValidator,valueValidator){return this.chain(recordValidators.record(keyValidator,valueValidator))}/**
|
|
388
|
-
* Returns a validator that asserts that the object's own enumerable properties has
|
|
389
|
-
* string keys and values that match the given validator.
|
|
390
|
-
*
|
|
391
|
-
* Prototype members are not included.
|
|
392
|
-
*
|
|
393
|
-
* @param valueValidator Validates each value.
|
|
394
|
-
*/},{key:"recordValues",value:function recordValues(valueValidator){return this.record(_RecordSchema2.defaultKeyValidator,valueValidator)}/**
|
|
395
|
-
* Casts to a ReadonlyRecord
|
|
396
|
-
*/},{key:"readonly",value:function readonly(){return this}/**
|
|
397
|
-
* Casts the type parameter.
|
|
398
|
-
*/},{key:"cast",value:function cast(){return this}}],[{key:"base",get:/**
|
|
399
|
-
* The base Object validator validating that the input is an object.
|
|
400
|
-
*/function get(){if(this._base==null)this._base=new _RecordSchema2(typeOfValidators.object);return this._base}},{key:"defaultKeyValidator",get:function get(){return StringSchema.base}}])}(ValueSchema);__publicField2(_RecordSchema,"_base",null);var locale12={isOneOf:"one of: {value}",instanceOf:"instance of {value}",oneOfSeparator:" | "};function isOneOf(){for(var _len5=arguments.length,possibleValues=new Array(_len5),_key5=0;_key5<_len5;_key5++){possibleValues[_key5]=arguments[_key5]}return new ValueSchema(createValidator(substitute(locale12.isOneOf,{value:possibleValues.join(locale12.oneOfSeparator)}),function(input){return possibleValues.includes(input)}))}// src/types/EncryptionKey.ts
|
|
401
|
-
var encryptionMethodValidator=isOneOf("NONE","AES-128","SAMPLE-AES","SAMPLE-AES-CTR");// src/types/AlternativeRendition.ts
|
|
402
|
-
var renditionTypeValidator=isOneOf("AUDIO","VIDEO","SUBTITLES","CLOSED-CAPTIONS");// src/parse/parseUtil.ts
|
|
403
|
-
var LF=char("\n");var CR=char("\r");function readLine(reader){var line=reader.substringUntil(function(cc){return cc===LF||cc===CR});if(reader.hasNext()&&reader.peek===CR)reader.next();if(reader.hasNext()&&reader.peek===LF)reader.next();return line}function skipWhitespaceLine(reader){var start=reader.position;reader.while(function(cc){return isWhitespaceChar(cc)&&cc!==LF&&cc!==CR});if(!reader.hasNext()||reader.peek===LF||reader.peek===CR){if(reader.hasNext()){if(reader.peek===CR)reader.next();if(reader.hasNext()&&reader.peek===LF)reader.next()}return true}reader.position=start;return false}function addIfPresent(obj,attrs,mappings){for(var _i3=0,_Object$entries=Object.entries(mappings);_i3<_Object$entries.length;_i3++){var _Object$entries$_i=_slicedToArray(_Object$entries[_i3],2),attrKey=_Object$entries$_i[0],objKey=_Object$entries$_i[1];if(attrs[attrKey]){;obj[objKey]=attrs[attrKey]}}return obj}// src/parse/parseAttributes.ts
|
|
404
|
-
var EQUALS=char("=");var COMMA=char(",");var QUOTE=char("\"");function parseAttributes(reader){var attrs={};while(reader.hasNext()&&reader.peek!==char("\n")&&reader.peek!==char("\r")){var key=reader.substringUntilChar(EQUALS);if(!key||!reader.hasNext())break;reader.next();var value=void 0;if(reader.peek===QUOTE){reader.next();value=reader.substringUntilChar(QUOTE);if(reader.hasNext())reader.next()}else{value=reader.substringUntil(function(cc){return cc===COMMA||cc===char("\n")||cc===char("\r")})}attrs[key]=value;if(reader.hasNext()&&reader.peek===COMMA){reader.next()}}return attrs}// src/parse/parseMediaPlaylist.ts
|
|
405
|
-
var HLS_VARIABLE_PATTERN=/\{\$([^}]+)}/g;var EXTM3U="#EXTM3U";var EXTINF="#EXTINF:";var EXT_X_TARGETDURATION="#EXT-X-TARGETDURATION:";var EXT_X_MEDIA_SEQUENCE="#EXT-X-MEDIA-SEQUENCE:";var EXT_X_ENDLIST="#EXT-X-ENDLIST";var EXT_X_PLAYLIST_TYPE="#EXT-X-PLAYLIST-TYPE:";var EXT_X_VERSION="#EXT-X-VERSION:";var EXT_X_KEY="#EXT-X-KEY:";var EXT_X_BYTERANGE="#EXT-X-BYTERANGE:";var EXT_X_DISCONTINUITY="#EXT-X-DISCONTINUITY";var EXT_X_PROGRAM_DATE_TIME="#EXT-X-PROGRAM-DATE-TIME:";var EXT_X_MAP="#EXT-X-MAP:";function parseMediaPlaylist(text,variables){var reader=new StringReader(text);reader.white();if(!reader.stringIf(EXTM3U)){reader.err("Expected #EXTM3U")}readLine(reader);var version=1;var targetDuration=0;var mediaSequence=0;var playlistType="LIVE";var ended=false;var currentKey;var currentMap;var pendingByteRange;var pendingDiscontinuity=false;var pendingDateTime;var segments=[];var sequenceCounter=0;while(reader.hasNext()){if(skipWhitespaceLine(reader))continue;var line=readLine(reader);var trimmed=line.trim();if(!trimmed)continue;if(trimmed.startsWith(EXTINF)){var durationStr=trimmed.substring(EXTINF.length).split(",")[0];var duration=Number(durationStr);var uri="";while(reader.hasNext()){if(skipWhitespaceLine(reader))continue;var nextLine=readLine(reader).trim();if(!nextLine.startsWith("#")){uri=variables?substitute(nextLine,variables,HLS_VARIABLE_PATTERN):nextLine;break}if(nextLine.startsWith(EXT_X_BYTERANGE)){var rangeStr=nextLine.substring(EXT_X_BYTERANGE.length);pendingByteRange=parseByteRangeString(rangeStr)}else if(nextLine===EXT_X_DISCONTINUITY){pendingDiscontinuity=true}else if(nextLine.startsWith(EXT_X_PROGRAM_DATE_TIME)){pendingDateTime=nextLine.substring(EXT_X_PROGRAM_DATE_TIME.length)}else if(nextLine.startsWith(EXT_X_MAP)){var attrStr=nextLine.substring(EXT_X_MAP.length);var attrReader=new StringReader(attrStr);var attrs=parseAttributes(attrReader);var mapUri=attrs["URI"];if(mapUri){var byteRangeStr=attrs["BYTERANGE"];currentMap=__spreadValues({uri:mapUri},byteRangeStr&&{byteRange:parseByteRangeString(byteRangeStr)})}}}segments.push(__spreadValues(__spreadProps(__spreadValues(__spreadValues(__spreadValues({uri:uri,duration:duration,sequenceNumber:mediaSequence+sequenceCounter},currentKey&&{key:currentKey}),currentMap&&{map:currentMap}),pendingByteRange&&{byteRange:pendingByteRange}),{discontinuity:pendingDiscontinuity}),pendingDateTime&&{programDateTime:pendingDateTime}));sequenceCounter++;pendingByteRange=void 0;pendingDiscontinuity=false;pendingDateTime=void 0}else if(trimmed.startsWith(EXT_X_TARGETDURATION)){targetDuration=Number(trimmed.substring(EXT_X_TARGETDURATION.length))}else if(trimmed.startsWith(EXT_X_MEDIA_SEQUENCE)){mediaSequence=Number(trimmed.substring(EXT_X_MEDIA_SEQUENCE.length))}else if(trimmed===EXT_X_ENDLIST){ended=true}else if(trimmed.startsWith(EXT_X_PLAYLIST_TYPE)){var val=trimmed.substring(EXT_X_PLAYLIST_TYPE.length).trim();if(val==="VOD"||val==="EVENT"){playlistType=val}}else if(trimmed.startsWith(EXT_X_VERSION)){version=Number(trimmed.substring(EXT_X_VERSION.length))}else if(trimmed.startsWith(EXT_X_KEY)){var _attrStr=trimmed.substring(EXT_X_KEY.length);var _attrReader=new StringReader(_attrStr);var _attrs=parseAttributes(_attrReader);var method=_attrs["METHOD"];encryptionMethodValidator.assert(method);currentKey=addIfPresent({method:method},_attrs,{URI:"uri",IV:"iv",KEYFORMAT:"keyFormat",KEYFORMATVERSIONS:"keyFormatVersions"})}else if(trimmed.startsWith(EXT_X_MAP)){var _attrStr2=trimmed.substring(EXT_X_MAP.length);var _attrReader2=new StringReader(_attrStr2);var _attrs2=parseAttributes(_attrReader2);var _mapUri=_attrs2["URI"];if(_mapUri){var _byteRangeStr=_attrs2["BYTERANGE"];currentMap=__spreadValues({uri:_mapUri},_byteRangeStr&&{byteRange:parseByteRangeString(_byteRangeStr)})}}else if(trimmed.startsWith(EXT_X_BYTERANGE)){var _rangeStr=trimmed.substring(EXT_X_BYTERANGE.length);pendingByteRange=parseByteRangeString(_rangeStr)}else if(trimmed===EXT_X_DISCONTINUITY){pendingDiscontinuity=true}else if(trimmed.startsWith(EXT_X_PROGRAM_DATE_TIME)){pendingDateTime=trimmed.substring(EXT_X_PROGRAM_DATE_TIME.length)}}return{version:version,targetDuration:targetDuration,mediaSequence:mediaSequence,playlistType:playlistType,ended:ended,segments:segments}}function parseByteRangeString(str){var parts=str.split("@");return{length:Number(parts[0]),offset:parts.length>1?Number(parts[1]):0}}// src/parse/parseMainPlaylist.ts
|
|
406
|
-
var EXTM3U2="#EXTM3U";var EXT_X_STREAM_INF="#EXT-X-STREAM-INF:";var EXT_X_MEDIA="#EXT-X-MEDIA:";var EXT_X_SESSION_DATA="#EXT-X-SESSION-DATA:";var EXT_X_DEFINE="#EXT-X-DEFINE:";function parseMainPlaylist(text){var reader=new StringReader(text);reader.white();if(!reader.stringIf(EXTM3U2)){reader.err("Expected #EXTM3U")}readLine(reader);var variants=[];var alternativeRenditions=[];var sessionData=[];var defines={};while(reader.hasNext()){if(skipWhitespaceLine(reader))continue;var line=readLine(reader);var trimmed=line.trim();if(!trimmed)continue;if(trimmed.startsWith(EXT_X_STREAM_INF)){var attrStr=trimmed.substring(EXT_X_STREAM_INF.length);var attrReader=new StringReader(attrStr);var attrs=parseAttributes(attrReader);var uri="";while(reader.hasNext()){if(skipWhitespaceLine(reader))continue;uri=readLine(reader).trim();break}variants.push(addIfPresent(__spreadValues(__spreadValues({bandwidth:Number(attrs["BANDWIDTH"]),uri:uri},attrs["FRAME-RATE"]&&{frameRate:Number(attrs["FRAME-RATE"])}),attrs.RESOLUTION&&parseResolution(attrs.RESOLUTION)),attrs,{CODECS:"codecs",AUDIO:"audioGroup",VIDEO:"videoGroup",SUBTITLES:"subtitlesGroup","CLOSED-CAPTIONS":"closedCaptionsGroup"}))}else if(trimmed.startsWith(EXT_X_MEDIA)){var _attrStr3=trimmed.substring(EXT_X_MEDIA.length);var _attrReader3=new StringReader(_attrStr3);var _attrs3=parseAttributes(_attrReader3);var type=_attrs3["TYPE"];renditionTypeValidator.assert(type);alternativeRenditions.push(addIfPresent(__spreadValues(__spreadValues({type:type,groupId:_attrs3["GROUP-ID"],name:_attrs3["NAME"]},_attrs3["DEFAULT"]&&{default:_attrs3["DEFAULT"]==="YES"}),_attrs3["AUTOSELECT"]&&{autoSelect:_attrs3["AUTOSELECT"]==="YES"}),_attrs3,{URI:"uri",LANGUAGE:"language"}))}else if(trimmed.startsWith(EXT_X_SESSION_DATA)){var _attrStr4=trimmed.substring(EXT_X_SESSION_DATA.length);var _attrReader4=new StringReader(_attrStr4);var _attrs4=parseAttributes(_attrReader4);sessionData.push(addIfPresent({dataId:_attrs4["DATA-ID"]},_attrs4,{VALUE:"value",URI:"uri",LANGUAGE:"language"}))}else if(trimmed.startsWith(EXT_X_DEFINE)){var _attrStr5=trimmed.substring(EXT_X_DEFINE.length);var _attrReader5=new StringReader(_attrStr5);var _attrs5=parseAttributes(_attrReader5);if(_attrs5["NAME"]&&_attrs5["VALUE"]){defines[_attrs5["NAME"]]=_attrs5["VALUE"]}}}return{variants:variants,alternativeRenditions:alternativeRenditions,sessionData:sessionData,defines:defines}}function parseResolution(resolution){var parts=resolution.split("x");if(parts.length!==2){throw new ValidationError("Invalid resolution format, expected WIDTHxHEIGHT")}var width=Number(parts[0]);var height=Number(parts[1]);if(!Number.isInteger(width)||!Number.isInteger(height)||width<=0||height<=0){throw new ValidationError("Invalid resolution values, width and height must be positive integers")}return{width:width,height:height}}// test/hlsTestAssets/hls_mainPlaylist.ts
|
|
407
|
-
var hls_mainPlaylist="#EXTM3U\n#EXT-X-VERSION:6\n#EXT-X-INDEPENDENT-SEGMENTS\n\n#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"audio\",NAME=\"English\",LANGUAGE=\"en\",DEFAULT=YES,AUTOSELECT=YES,URI=\"audio/en.m3u8\"\n#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"audio\",NAME=\"Spanish\",LANGUAGE=\"es\",DEFAULT=NO,AUTOSELECT=NO,URI=\"audio/es.m3u8\"\n#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID=\"subs\",NAME=\"English\",LANGUAGE=\"en\",DEFAULT=YES,AUTOSELECT=YES,URI=\"subtitles/en.m3u8\"\n\n#EXT-X-STREAM-INF:BANDWIDTH=1280000,CODECS=\"avc1.42e00a,mp4a.40.2\",RESOLUTION=640x360,FRAME-RATE=29.97,AUDIO=\"audio\",SUBTITLES=\"subs\"\nlow/index.m3u8\n#EXT-X-STREAM-INF:BANDWIDTH=2560000,CODECS=\"avc1.42e01e,mp4a.40.2\",RESOLUTION=854x480,FRAME-RATE=29.97,AUDIO=\"audio\",SUBTITLES=\"subs\"\nmid/index.m3u8\n#EXT-X-STREAM-INF:BANDWIDTH=7680000,CODECS=\"avc1.42e01f,mp4a.40.2\",RESOLUTION=1280x720,FRAME-RATE=29.97,AUDIO=\"audio\",SUBTITLES=\"subs\"\nhigh/index.m3u8";// test/hlsTestAssets/hls_mediaPlaylist.ts
|
|
408
|
-
var hls_mediaPlaylist="#EXTM3U\n#EXT-X-VERSION:3\n#EXT-X-TARGETDURATION:10\n#EXT-X-MEDIA-SEQUENCE:0\n#EXT-X-PLAYLIST-TYPE:VOD\n\n#EXT-X-KEY:METHOD=AES-128,URI=\"https://example.com/key.bin\",IV=0x99b74007b6254e4bd1c6e03631cad15b\n\n#EXTINF:9.009,\nsegment00000.ts\n#EXTINF:9.009,\nsegment00001.ts\n#EXTINF:9.009,\nsegment00002.ts\n#EXTINF:9.009,\nsegment00003.ts\n#EXTINF:9.009,\nsegment00004.ts\n#EXTINF:5.005,\nsegment00005.ts\n\n#EXT-X-ENDLIST";// test/hlsTestAssets/hls_mediaPlaylistWithByteRanges.ts
|
|
409
|
-
var hls_mediaPlaylistWithByteRanges="#EXTM3U\n#EXT-X-VERSION:4\n#EXT-X-TARGETDURATION:10\n#EXT-X-MEDIA-SEQUENCE:0\n\n#EXTINF:10.0,\n#EXT-X-BYTERANGE:1000000@0\nsegment.ts\n#EXTINF:10.0,\n#EXT-X-BYTERANGE:1000000@1000000\nsegment.ts\n#EXT-X-DISCONTINUITY\n#EXTINF:10.0,\n#EXT-X-BYTERANGE:1000000@2000000\nsegment.ts\n\n#EXT-X-ENDLIST";// test/integ/parseHlsManifest.integ.ts
|
|
410
|
-
describe("HLS Parser Integration Tests",function(){it("parses HLS main playlist test asset",function(){var result=parseMainPlaylist(hls_mainPlaylist);expect(result.variants.length).toBe(3);expect(result.alternativeRenditions.length).toBe(3);expect(result.variants[0].bandwidth).toBe(128e4);expect(result.variants[0].uri).toBe("low/index.m3u8");expect(result.variants[0].codecs).toBe("avc1.42e00a,mp4a.40.2");expect(result.variants[0].width).toBe(640);expect(result.variants[0].height).toBe(360);var audioRenditions=result.alternativeRenditions.filter(function(r){return r.type==="AUDIO"});expect(audioRenditions.length).toBe(2);expect(audioRenditions[0].name).toBe("English");expect(audioRenditions[0].language).toBe("en");expect(audioRenditions[0].default).toBe(true)});it("parses HLS media playlist test asset",function(){var result=parseMediaPlaylist(hls_mediaPlaylist);expect(result.version).toBe(3);expect(result.targetDuration).toBe(10);expect(result.mediaSequence).toBe(0);expect(result.playlistType).toBe("VOD");expect(result.ended).toBe(true);expect(result.segments.length).toBe(6);expect(result.segments[0].uri).toBe("segment00000.ts");expect(result.segments[0].duration).toBe(9.009);expect(result.segments[0].sequenceNumber).toBe(0);expect(result.segments[5].duration).toBe(5.005)});it("parses HLS media playlist with byte ranges",function(){var _a,_b,_c;var result=parseMediaPlaylist(hls_mediaPlaylistWithByteRanges);expect(result.segments.length).toBe(3);expect((_a=result.segments[0].byteRange)==null?void 0:_a.length).toBe(1e6);expect((_b=result.segments[0].byteRange)==null?void 0:_b.offset).toBe(0);expect((_c=result.segments[1].byteRange)==null?void 0:_c.offset).toBe(1e6);expect(result.segments[2].discontinuity).toBe(true)});it("keeps URIs relative in parsed results",function(){var result=parseMainPlaylist(hls_mainPlaylist);expect(result.variants[0].uri).toBe("low/index.m3u8");expect(result.variants[1].uri).toBe("mid/index.m3u8");expect(result.variants[2].uri).toBe("high/index.m3u8")})})})();
|