@travetto/web 6.0.0 → 6.0.2

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/src/util/mime.ts DELETED
@@ -1,36 +0,0 @@
1
- import { Util } from '@travetto/runtime';
2
-
3
- export type MimeType = { type: string, subtype: string, full: string, parameters: Record<string, string> };
4
-
5
- /**
6
- * Utils for checking mime patterns
7
- */
8
- export class MimeUtil {
9
-
10
- static #convert(rule: string): RegExp {
11
- const core = (rule.endsWith('/*') || !rule.includes('/')) ?
12
- `${rule.replace(/[/].{0,20}$/, '')}\/.*` : rule;
13
- return new RegExp(`^${core}[ ]{0,10}(;|$)`);
14
- }
15
-
16
- static parse(mimeType?: string): MimeType | undefined {
17
- if (mimeType) {
18
- const [full, ...params] = mimeType.split(/;/).map(x => x.trim());
19
- const [type, subtype] = full.split('/');
20
- const parameters = Object.fromEntries(params.map(v => v.split('=')).map(([k, v]) => [k.toLowerCase(), v]));
21
- return { type, subtype, full, parameters };
22
- }
23
- }
24
-
25
- /**
26
- * Build matcher
27
- */
28
- static matcher(rules: string[] | string = []): (contentType: string) => boolean {
29
- return Util.allowDeny<RegExp, [string]>(
30
- rules,
31
- this.#convert.bind(this),
32
- (regex, mime) => regex.test(mime),
33
- k => k
34
- );
35
- }
36
- }