trousse 3.0.0 → 3.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/dist/files.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export declare const audioExtensions: string[];
2
2
  export declare const videoExtensions: string[];
3
3
  export declare const imageExtensions: string[];
4
+ export declare const webImageExtensions: string[];
5
+ export declare const webVideoExtensions: string[];
6
+ export declare const webAudioExtensions: string[];
4
7
  export declare const documentExtensions: string[];
5
8
  export declare const archiveExtensions: string[];
6
9
  export declare const installerExtensions: string[];
package/dist/files.js CHANGED
@@ -48,6 +48,33 @@ const imageExtensions = [
48
48
  "tiff",
49
49
  "webp"
50
50
  ];
51
+ const webImageExtensions = [
52
+ "avif",
53
+ "gif",
54
+ "jpeg",
55
+ "jpg",
56
+ "png",
57
+ "svg",
58
+ "webp"
59
+ ];
60
+ const webVideoExtensions = [
61
+ "m4v",
62
+ "mov",
63
+ "mp4",
64
+ "ogv",
65
+ "webm"
66
+ ];
67
+ const webAudioExtensions = [
68
+ "aac",
69
+ "flac",
70
+ "m4a",
71
+ "mp3",
72
+ "oga",
73
+ "ogg",
74
+ "opus",
75
+ "wav",
76
+ "weba"
77
+ ];
51
78
  const documentExtensions = [
52
79
  "doc",
53
80
  "docx",
@@ -97,4 +124,4 @@ const fontExtensions = [
97
124
  "woff2"
98
125
  ];
99
126
  const subtitleExtensions = ["srt", "vtt"];
100
- export { archiveExtensions, audioExtensions, codeExtensions, documentExtensions, flashExtensions, fontExtensions, imageExtensions, installerExtensions, subtitleExtensions, videoExtensions };
127
+ export { archiveExtensions, audioExtensions, codeExtensions, documentExtensions, flashExtensions, fontExtensions, imageExtensions, installerExtensions, subtitleExtensions, videoExtensions, webAudioExtensions, webImageExtensions, webVideoExtensions };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { omitEmpty } from "./arrays.js";
2
- import { AnyOf, DeepOmit, IsPlainObject, MaybePromise, NormalizeOptions, Nullish, ParamSource, PartialNullish, Pattern, RegistrableDomainOptions, WeightedMimeType } from "./types.js";
2
+ import { AnyOf, DeepOmit, IsPlainObject, MaybePromise, NormalizeOptions, Nullish, ParamOptions, ParamSource, PartialNullish, Pattern, RegistrableDomainOptions, WeightedMimeType } from "./types.js";
3
3
  import { coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString } from "./coercions.js";
4
- import { archiveExtensions, audioExtensions, codeExtensions, documentExtensions, flashExtensions, fontExtensions, imageExtensions, installerExtensions, subtitleExtensions, videoExtensions } from "./files.js";
4
+ import { archiveExtensions, audioExtensions, codeExtensions, documentExtensions, flashExtensions, fontExtensions, imageExtensions, installerExtensions, subtitleExtensions, videoExtensions, webAudioExtensions, webImageExtensions, webVideoExtensions } from "./files.js";
5
5
  import { isBoolean, isFunction, isNonEmptyString, isNullish, isNumber, isObject, isPlainObject, isPresent, isString, isValidDate } from "./is.js";
6
6
  import { isJsonLike, isParseableJson } from "./json.js";
7
7
  import { escapeHtml, t, tx } from "./locales.js";
@@ -10,4 +10,4 @@ import { createAcceptHeader, feedMimeTypes, genericFeedMimeTypes, genericHtmlMim
10
10
  import { omit, pick, toMap, trimObject } from "./objects.js";
11
11
  import { sleep } from "./timers.js";
12
12
  import { addMissingProtocol, addMissingScheme, composeFragment, composeQuery, createUrlSpellings, createUrlVariants, decodePercent, decodeSegment, encodePathSegment, fixMalformedProtocol, fixMalformedQuery, fixMalformedScheme, getFragmentParam, getFragmentParamValues, getFragmentParams, getPathSegments, getQueryParam, getQueryParamValues, getQueryParams, getRegistrableDomain, getSubdomain, hasFragmentParam, hasQueryParam, isHostOf, isHostOrSubdomainOf, isHttpUrl, isIpAddress, isSubdomainOf, normalizeUrl, parseUrl, resolveFeedProtocol, resolveFeedScheme, resolveUrl, stripWww, trimUrlValues, upgradeProtocol, upgradeScheme } from "./urls.js";
13
- export { type AnyOf, type DeepOmit, type IsPlainObject, type MaybePromise, type NormalizeOptions, type Nullish, type ParamSource, type PartialNullish, type Pattern, type RegistrableDomainOptions, type WeightedMimeType, addMissingProtocol, addMissingScheme, anyWordMatchesAnyOf, archiveExtensions, audioExtensions, codeExtensions, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, composeFragment, composeQuery, createAcceptHeader, createUrlSpellings, createUrlVariants, decodePercent, decodeSegment, documentExtensions, encodePathSegment, endsWithAnyOf, escapeHtml, escapeRegex, feedMimeTypes, fixMalformedProtocol, fixMalformedQuery, fixMalformedScheme, flashExtensions, fontExtensions, genericFeedMimeTypes, genericHtmlMimeTypes, getAnyOf, getFragmentParam, getFragmentParamValues, getFragmentParams, getPathSegments, getQueryParam, getQueryParamValues, getQueryParams, getRegistrableDomain, getSubdomain, hasFragmentParam, hasQueryParam, htmlMimeTypes, imageExtensions, includesAnyOf, installerExtensions, isAnyOf, isBoolean, isFunction, isHostOf, isHostOrSubdomainOf, isHttpUrl, isIpAddress, isJsonLike, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isString, isSubdomainOf, isValidDate, normalizeUrl, omit, omitEmpty, parseUrl, pick, resolveFeedProtocol, resolveFeedScheme, resolveUrl, sleep, startsWithAnyOf, stripWww, subtitleExtensions, t, toMap, trimObject, trimUrlValues, tx, upgradeProtocol, upgradeScheme, videoExtensions };
13
+ export { type AnyOf, type DeepOmit, type IsPlainObject, type MaybePromise, type NormalizeOptions, type Nullish, type ParamOptions, type ParamSource, type PartialNullish, type Pattern, type RegistrableDomainOptions, type WeightedMimeType, addMissingProtocol, addMissingScheme, anyWordMatchesAnyOf, archiveExtensions, audioExtensions, codeExtensions, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, composeFragment, composeQuery, createAcceptHeader, createUrlSpellings, createUrlVariants, decodePercent, decodeSegment, documentExtensions, encodePathSegment, endsWithAnyOf, escapeHtml, escapeRegex, feedMimeTypes, fixMalformedProtocol, fixMalformedQuery, fixMalformedScheme, flashExtensions, fontExtensions, genericFeedMimeTypes, genericHtmlMimeTypes, getAnyOf, getFragmentParam, getFragmentParamValues, getFragmentParams, getPathSegments, getQueryParam, getQueryParamValues, getQueryParams, getRegistrableDomain, getSubdomain, hasFragmentParam, hasQueryParam, htmlMimeTypes, imageExtensions, includesAnyOf, installerExtensions, isAnyOf, isBoolean, isFunction, isHostOf, isHostOrSubdomainOf, isHttpUrl, isIpAddress, isJsonLike, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isString, isSubdomainOf, isValidDate, normalizeUrl, omit, omitEmpty, parseUrl, pick, resolveFeedProtocol, resolveFeedScheme, resolveUrl, sleep, startsWithAnyOf, stripWww, subtitleExtensions, t, toMap, trimObject, trimUrlValues, tx, upgradeProtocol, upgradeScheme, videoExtensions, webAudioExtensions, webImageExtensions, webVideoExtensions };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { isBoolean, isFunction, isNonEmptyString, isNullish, isNumber, isObject, isPlainObject, isPresent, isString, isValidDate } from "./is.js";
2
2
  import { omitEmpty } from "./arrays.js";
3
3
  import { coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString } from "./coercions.js";
4
- import { archiveExtensions, audioExtensions, codeExtensions, documentExtensions, flashExtensions, fontExtensions, imageExtensions, installerExtensions, subtitleExtensions, videoExtensions } from "./files.js";
4
+ import { archiveExtensions, audioExtensions, codeExtensions, documentExtensions, flashExtensions, fontExtensions, imageExtensions, installerExtensions, subtitleExtensions, videoExtensions, webAudioExtensions, webImageExtensions, webVideoExtensions } from "./files.js";
5
5
  import { isJsonLike, isParseableJson } from "./json.js";
6
6
  import { escapeHtml, t, tx } from "./locales.js";
7
7
  import { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, getAnyOf, includesAnyOf, isAnyOf, startsWithAnyOf } from "./matching.js";
@@ -9,4 +9,4 @@ import { createAcceptHeader, feedMimeTypes, genericFeedMimeTypes, genericHtmlMim
9
9
  import { omit, pick, toMap, trimObject } from "./objects.js";
10
10
  import { sleep } from "./timers.js";
11
11
  import { addMissingProtocol, addMissingScheme, composeFragment, composeQuery, createUrlSpellings, createUrlVariants, decodePercent, decodeSegment, encodePathSegment, fixMalformedProtocol, fixMalformedQuery, fixMalformedScheme, getFragmentParam, getFragmentParamValues, getFragmentParams, getPathSegments, getQueryParam, getQueryParamValues, getQueryParams, getRegistrableDomain, getSubdomain, hasFragmentParam, hasQueryParam, isHostOf, isHostOrSubdomainOf, isHttpUrl, isIpAddress, isSubdomainOf, normalizeUrl, parseUrl, resolveFeedProtocol, resolveFeedScheme, resolveUrl, stripWww, trimUrlValues, upgradeProtocol, upgradeScheme } from "./urls.js";
12
- export { addMissingProtocol, addMissingScheme, anyWordMatchesAnyOf, archiveExtensions, audioExtensions, codeExtensions, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, composeFragment, composeQuery, createAcceptHeader, createUrlSpellings, createUrlVariants, decodePercent, decodeSegment, documentExtensions, encodePathSegment, endsWithAnyOf, escapeHtml, escapeRegex, feedMimeTypes, fixMalformedProtocol, fixMalformedQuery, fixMalformedScheme, flashExtensions, fontExtensions, genericFeedMimeTypes, genericHtmlMimeTypes, getAnyOf, getFragmentParam, getFragmentParamValues, getFragmentParams, getPathSegments, getQueryParam, getQueryParamValues, getQueryParams, getRegistrableDomain, getSubdomain, hasFragmentParam, hasQueryParam, htmlMimeTypes, imageExtensions, includesAnyOf, installerExtensions, isAnyOf, isBoolean, isFunction, isHostOf, isHostOrSubdomainOf, isHttpUrl, isIpAddress, isJsonLike, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isString, isSubdomainOf, isValidDate, normalizeUrl, omit, omitEmpty, parseUrl, pick, resolveFeedProtocol, resolveFeedScheme, resolveUrl, sleep, startsWithAnyOf, stripWww, subtitleExtensions, t, toMap, trimObject, trimUrlValues, tx, upgradeProtocol, upgradeScheme, videoExtensions };
12
+ export { addMissingProtocol, addMissingScheme, anyWordMatchesAnyOf, archiveExtensions, audioExtensions, codeExtensions, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, composeFragment, composeQuery, createAcceptHeader, createUrlSpellings, createUrlVariants, decodePercent, decodeSegment, documentExtensions, encodePathSegment, endsWithAnyOf, escapeHtml, escapeRegex, feedMimeTypes, fixMalformedProtocol, fixMalformedQuery, fixMalformedScheme, flashExtensions, fontExtensions, genericFeedMimeTypes, genericHtmlMimeTypes, getAnyOf, getFragmentParam, getFragmentParamValues, getFragmentParams, getPathSegments, getQueryParam, getQueryParamValues, getQueryParams, getRegistrableDomain, getSubdomain, hasFragmentParam, hasQueryParam, htmlMimeTypes, imageExtensions, includesAnyOf, installerExtensions, isAnyOf, isBoolean, isFunction, isHostOf, isHostOrSubdomainOf, isHttpUrl, isIpAddress, isJsonLike, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isString, isSubdomainOf, isValidDate, normalizeUrl, omit, omitEmpty, parseUrl, pick, resolveFeedProtocol, resolveFeedScheme, resolveUrl, sleep, startsWithAnyOf, stripWww, subtitleExtensions, t, toMap, trimObject, trimUrlValues, tx, upgradeProtocol, upgradeScheme, videoExtensions, webAudioExtensions, webImageExtensions, webVideoExtensions };
package/dist/types.d.ts CHANGED
@@ -6,6 +6,11 @@ export type PartialNullish<T> = { [Key in keyof T]?: Nullish<T[Key]>; };
6
6
  export type MaybePromise<T> = T | Promise<T>;
7
7
  export type Pattern = string | RegExp;
8
8
  export type ParamSource = URL | URLSearchParams | string;
9
+ export type ParamOptions = {
10
+ decodeValues?: boolean;
11
+ trimValues?: boolean;
12
+ preserveEmptyValues?: boolean;
13
+ };
9
14
  export type RegistrableDomainOptions = {
10
15
  suffixes?: ReadonlyArray<string>;
11
16
  };
package/dist/urls.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { NormalizeOptions, Nullish, ParamSource, RegistrableDomainOptions } from "./types.js";
1
+ import { NormalizeOptions, Nullish, ParamOptions, ParamSource, RegistrableDomainOptions } from "./types.js";
2
2
  export declare const parseUrl: (value: Nullish<string | URL>, base?: string | URL) => URL | undefined;
3
3
  export declare const getPathSegments: (value: string | URL) => Array<string>;
4
4
  export declare const isHostOf: (url: string | URL, hosts: string | ReadonlyArray<string>) => boolean;
@@ -10,13 +10,13 @@ export declare const decodeSegment: (segment: string | undefined) => string | un
10
10
  export declare const decodePercent: (value: string) => string;
11
11
  export declare const encodePathSegment: (value: string) => string;
12
12
  export declare const hasQueryParam: (source: ParamSource | undefined, name: string) => boolean;
13
- export declare const getQueryParamValues: (source: ParamSource | undefined, name: string) => Array<string>;
14
- export declare const getQueryParam: (source: ParamSource | undefined, name: string) => string | undefined;
15
- export declare const getQueryParams: (source: ParamSource | undefined, names: ReadonlyArray<string>) => Record<string, string>;
13
+ export declare const getQueryParamValues: (source: ParamSource | undefined, name: string, options?: ParamOptions) => Array<string>;
14
+ export declare const getQueryParam: (source: ParamSource | undefined, name: string, options?: ParamOptions) => string | undefined;
15
+ export declare const getQueryParams: (source: ParamSource | undefined, names: ReadonlyArray<string>, options?: ParamOptions) => Record<string, string>;
16
16
  export declare const hasFragmentParam: (source: ParamSource | undefined, name: string) => boolean;
17
- export declare const getFragmentParamValues: (source: ParamSource | undefined, name: string) => Array<string>;
18
- export declare const getFragmentParam: (source: ParamSource | undefined, name: string) => string | undefined;
19
- export declare const getFragmentParams: (source: ParamSource | undefined, names: ReadonlyArray<string>) => Record<string, string>;
17
+ export declare const getFragmentParamValues: (source: ParamSource | undefined, name: string, options?: ParamOptions) => Array<string>;
18
+ export declare const getFragmentParam: (source: ParamSource | undefined, name: string, options?: ParamOptions) => string | undefined;
19
+ export declare const getFragmentParams: (source: ParamSource | undefined, names: ReadonlyArray<string>, options?: ParamOptions) => Record<string, string>;
20
20
  export declare const composeQuery: (params?: Record<string, string | number>) => string;
21
21
  export declare const composeFragment: (params?: Record<string, string | number>) => string;
22
22
  export declare const fixMalformedScheme: (url: string) => string;
package/dist/urls.js CHANGED
@@ -94,37 +94,55 @@ const pathSegmentEscapeRegex = /[/?#\\\s]/g;
94
94
  const encodePathSegment = (value) => {
95
95
  return value.replace(pathSegmentEscapeRegex, (character) => encodeURIComponent(character));
96
96
  };
97
- const readQuerySource = (source) => {
97
+ const readRawPairs = (text, prefix) => {
98
+ if (text === void 0) return;
99
+ const pairs = [];
100
+ const body = text.startsWith(prefix) ? text.slice(1) : text;
101
+ for (const pair of body.split("&")) {
102
+ if (!pair) continue;
103
+ const separator = pair.indexOf("=");
104
+ if (separator === -1) {
105
+ pairs.push([decodePercent(pair.replaceAll("+", " ")), ""]);
106
+ continue;
107
+ }
108
+ const name = decodePercent(pair.slice(0, separator).replaceAll("+", " "));
109
+ pairs.push([name, pair.slice(separator + 1)]);
110
+ }
111
+ return pairs;
112
+ };
113
+ const readQuerySource = (source, options) => {
114
+ if (options?.decodeValues === false) return readRawPairs(source instanceof URL ? source.search : source?.toString(), "?");
98
115
  if (source instanceof URL) return source.searchParams;
99
116
  if (typeof source === "string") return new URLSearchParams(source);
100
117
  return source;
101
118
  };
102
- const readFragmentSource = (source) => {
119
+ const readFragmentSource = (source, options) => {
120
+ if (options?.decodeValues === false) return readRawPairs(source instanceof URL ? source.hash : source?.toString(), "#");
103
121
  if (source instanceof URL) return new URLSearchParams(source.hash.slice(1));
104
122
  if (typeof source === "string") return new URLSearchParams(source.startsWith("#") ? source.slice(1) : source);
105
123
  return source;
106
124
  };
107
- const readParamValues = (params, name) => {
125
+ const readParamValues = (params, name, options) => {
108
126
  const values = [];
109
127
  if (!params) return values;
110
128
  const lowercaseName = name.toLowerCase();
111
129
  for (const [key, value] of params) {
112
130
  if (key.toLowerCase() !== lowercaseName) continue;
113
- const trimmed = value.trim();
114
- if (trimmed) values.push(trimmed);
131
+ const read = options?.trimValues === false ? value : value.trim();
132
+ if (read || options?.preserveEmptyValues) values.push(read);
115
133
  }
116
134
  return values;
117
135
  };
118
136
  const hasParam = (params, name) => {
119
137
  if (!params) return false;
120
138
  const lowercaseName = name.toLowerCase();
121
- for (const key of params.keys()) if (key.toLowerCase() === lowercaseName) return true;
139
+ for (const [key] of params) if (key.toLowerCase() === lowercaseName) return true;
122
140
  return false;
123
141
  };
124
- const readParams = (params, names) => {
142
+ const readParams = (params, names, options) => {
125
143
  const picked = {};
126
144
  for (const name of names) {
127
- const value = readParamValues(params, name)[0];
145
+ const value = readParamValues(params, name, options)[0];
128
146
  if (value !== void 0) picked[name] = value;
129
147
  }
130
148
  return picked;
@@ -132,26 +150,26 @@ const readParams = (params, names) => {
132
150
  const hasQueryParam = (source, name) => {
133
151
  return hasParam(readQuerySource(source), name);
134
152
  };
135
- const getQueryParamValues = (source, name) => {
136
- return readParamValues(readQuerySource(source), name);
153
+ const getQueryParamValues = (source, name, options) => {
154
+ return readParamValues(readQuerySource(source, options), name, options);
137
155
  };
138
- const getQueryParam = (source, name) => {
139
- return getQueryParamValues(source, name)[0];
156
+ const getQueryParam = (source, name, options) => {
157
+ return getQueryParamValues(source, name, options)[0];
140
158
  };
141
- const getQueryParams = (source, names) => {
142
- return readParams(readQuerySource(source), names);
159
+ const getQueryParams = (source, names, options) => {
160
+ return readParams(readQuerySource(source, options), names, options);
143
161
  };
144
162
  const hasFragmentParam = (source, name) => {
145
163
  return hasParam(readFragmentSource(source), name);
146
164
  };
147
- const getFragmentParamValues = (source, name) => {
148
- return readParamValues(readFragmentSource(source), name);
165
+ const getFragmentParamValues = (source, name, options) => {
166
+ return readParamValues(readFragmentSource(source, options), name, options);
149
167
  };
150
- const getFragmentParam = (source, name) => {
151
- return getFragmentParamValues(source, name)[0];
168
+ const getFragmentParam = (source, name, options) => {
169
+ return getFragmentParamValues(source, name, options)[0];
152
170
  };
153
- const getFragmentParams = (source, names) => {
154
- return readParams(readFragmentSource(source), names);
171
+ const getFragmentParams = (source, names, options) => {
172
+ return readParams(readFragmentSource(source, options), names, options);
155
173
  };
156
174
  const queryPartEscapeRegex = /[&#%+\s]/g;
157
175
  const composePairs = (params) => {
package/package.json CHANGED
@@ -46,5 +46,5 @@
46
46
  "dependencies": {
47
47
  "entities": "^8.1.0"
48
48
  },
49
- "version": "3.0.0"
49
+ "version": "3.2.0"
50
50
  }