UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

1 lines • 5.71 kB
{"version":3,"file":"validate.js","names":[],"sources":["esm/platform/audio/validate.js"],"sourcesContent":["const qualities = /* @__PURE__ */ new Set([\"low\", \"medium\", \"high\"]);\nfunction normalizeSource(source, owner) {\n if (source === null || source === void 0) return {};\n if (typeof source === \"number\") {\n throw new Error(`${owner}: assetId sources are not supported`);\n }\n if (typeof source === \"string\") {\n if (source.trim() === \"\") throw new Error(`${owner}: expected a non-empty audio uri`);\n return { uri: source };\n }\n if (typeof source !== \"object\") throw new Error(`${owner}: expected an audio source`);\n const { uri, headers, name } = source;\n if (uri !== void 0 && (typeof uri !== \"string\" || uri.trim() === \"\")) {\n throw new Error(`${owner}: expected a non-empty audio uri`);\n }\n if (name !== void 0 && typeof name !== \"string\") {\n throw new Error(`${owner}: expected a string source name`);\n }\n if (headers !== void 0) {\n if (typeof headers !== \"object\" || headers === null || Array.isArray(headers)) {\n throw new Error(`${owner}: expected source headers to be an object`);\n }\n for (const value of Object.values(headers)) {\n if (typeof value !== \"string\") {\n throw new Error(`${owner}: expected source header values to be strings`);\n }\n }\n }\n return { ...uri !== void 0 && { uri }, ...headers !== void 0 && { headers } };\n}\nfunction resolveUpdateInterval(options, owner) {\n const interval = options?.updateInterval ?? 500;\n if (typeof interval !== \"number\" || !Number.isFinite(interval) || interval <= 0) {\n throw new Error(`${owner}: expected updateInterval to be a positive number of milliseconds`);\n }\n return interval;\n}\nfunction assertCrossOrigin(crossOrigin, owner) {\n if (crossOrigin !== void 0 && crossOrigin !== \"anonymous\" && crossOrigin !== \"use-credentials\") {\n throw new Error(`${owner}: expected crossOrigin 'anonymous' or 'use-credentials'`);\n }\n}\nfunction assertRate(rate, owner) {\n if (typeof rate !== \"number\" || !Number.isFinite(rate)) {\n throw new Error(`${owner}: expected a finite playback rate`);\n }\n}\nfunction assertPitchQuality(quality, owner) {\n if (typeof quality !== \"string\" || !qualities.has(quality)) {\n throw new Error(`${owner}: expected pitch quality 'low', 'medium' or 'high'`);\n }\n}\nfunction assertVolume(volume, owner) {\n if (typeof volume !== \"number\" || !Number.isFinite(volume) || volume < 0 || volume > 1) {\n throw new Error(`${owner}: expected volume between 0 and 1`);\n }\n}\nfunction assertSeconds(seconds, owner) {\n if (typeof seconds !== \"number\" || !Number.isFinite(seconds) || seconds < 0) {\n throw new Error(`${owner}: expected a finite nonnegative seek position in seconds`);\n }\n}\nfunction assertTolerance(tolerance, owner) {\n if (typeof tolerance !== \"number\" || !Number.isFinite(tolerance) || tolerance < 0) {\n throw new Error(`${owner}: expected a finite nonnegative tolerance in milliseconds`);\n }\n}\nfunction assertFlag(value, owner) {\n if (typeof value !== \"boolean\") throw new Error(`${owner}: expected a boolean`);\n}\nfunction rateError(owner) {\n return Object.assign(new Error(`${owner}: playback rate is outside the platform range`), {\n code: \"E_AUDIO_RATE\"\n });\n}\nexport {\n assertCrossOrigin,\n assertFlag,\n assertPitchQuality,\n assertRate,\n assertSeconds,\n assertTolerance,\n assertVolume,\n normalizeSource,\n rateError,\n resolveUpdateInterval\n};\n//# sourceMappingURL=validate.js.map\n"],"mappings":";AAAA,MAAM,4BAA4B,IAAI,IAAI;CAAC;CAAO;CAAU;AAAM,CAAC;AACnE,SAAS,gBAAgB,QAAQ,OAAO;CACtC,IAAI,WAAW,QAAQ,WAAW,KAAK,GAAG,OAAO,CAAC;CAClD,IAAI,OAAO,WAAW,UAAU;EAC9B,MAAM,IAAI,MAAM,GAAG,MAAM,oCAAoC;CAC/D;CACA,IAAI,OAAO,WAAW,UAAU;EAC9B,IAAI,OAAO,KAAK,MAAM,IAAI,MAAM,IAAI,MAAM,GAAG,MAAM,iCAAiC;EACpF,OAAO,EAAE,KAAK,OAAO;CACvB;CACA,IAAI,OAAO,WAAW,UAAU,MAAM,IAAI,MAAM,GAAG,MAAM,2BAA2B;CACpF,MAAM,EAAE,KAAK,SAAS,SAAS;CAC/B,IAAI,QAAQ,KAAK,MAAM,OAAO,QAAQ,YAAY,IAA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