trousse 2.7.0 → 2.9.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/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/mimes.d.ts +8 -0
- package/dist/mimes.js +103 -0
- package/dist/types.d.ts +5 -0
- package/dist/urls.js +4 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { omitEmpty } from "./arrays.js";
|
|
2
|
-
import { AnyOf, DeepOmit, IsPlainObject, MaybePromise, NormalizeOptions, Nullish, PartialNullish, Pattern, RegistrableDomainOptions } from "./types.js";
|
|
2
|
+
import { AnyOf, DeepOmit, IsPlainObject, MaybePromise, NormalizeOptions, Nullish, PartialNullish, Pattern, RegistrableDomainOptions, WeightedMimeType } from "./types.js";
|
|
3
3
|
import { coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString } from "./coercions.js";
|
|
4
4
|
import { archiveExtensions, audioExtensions, codeExtensions, documentExtensions, flashExtensions, fontExtensions, imageExtensions, installerExtensions, subtitleExtensions, videoExtensions } 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";
|
|
8
8
|
import { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, getAnyOf, includesAnyOf, isAnyOf, startsWithAnyOf } from "./matching.js";
|
|
9
|
+
import { createAcceptHeader, feedMimeTypes, genericFeedMimeTypes, genericHtmlMimeTypes, htmlMimeTypes } from "./mimes.js";
|
|
9
10
|
import { omit, pick, toMap, trimObject } from "./objects.js";
|
|
10
11
|
import { sleep } from "./timers.js";
|
|
11
12
|
import { addMissingProtocol, addMissingScheme, decodeSegment, fixMalformedProtocol, fixMalformedScheme, getPathSegments, getRegistrableDomain, getSubdomain, isHostOf, isHostOrSubdomainOf, isHttpUrl, isIpAddress, isSubdomainOf, normalizeUrl, parseUrl, resolveFeedProtocol, resolveFeedScheme, resolveUrl, stripWww, upgradeProtocol, upgradeScheme } from "./urls.js";
|
|
12
|
-
export { type AnyOf, type DeepOmit, type IsPlainObject, type MaybePromise, type NormalizeOptions, type Nullish, type PartialNullish, type Pattern, type RegistrableDomainOptions, addMissingProtocol, addMissingScheme, anyWordMatchesAnyOf, archiveExtensions, audioExtensions, codeExtensions, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, decodeSegment, documentExtensions, endsWithAnyOf, escapeHtml, escapeRegex, fixMalformedProtocol, fixMalformedScheme, flashExtensions, fontExtensions, getAnyOf, getPathSegments, getRegistrableDomain, getSubdomain, 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, tx, upgradeProtocol, upgradeScheme, videoExtensions };
|
|
13
|
+
export { type AnyOf, type DeepOmit, type IsPlainObject, type MaybePromise, type NormalizeOptions, type Nullish, type PartialNullish, type Pattern, type RegistrableDomainOptions, type WeightedMimeType, addMissingProtocol, addMissingScheme, anyWordMatchesAnyOf, archiveExtensions, audioExtensions, codeExtensions, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, createAcceptHeader, decodeSegment, documentExtensions, endsWithAnyOf, escapeHtml, escapeRegex, feedMimeTypes, fixMalformedProtocol, fixMalformedScheme, flashExtensions, fontExtensions, genericFeedMimeTypes, genericHtmlMimeTypes, getAnyOf, getPathSegments, getRegistrableDomain, getSubdomain, 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, tx, upgradeProtocol, upgradeScheme, videoExtensions };
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,8 @@ import { archiveExtensions, audioExtensions, codeExtensions, documentExtensions,
|
|
|
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";
|
|
8
|
+
import { createAcceptHeader, feedMimeTypes, genericFeedMimeTypes, genericHtmlMimeTypes, htmlMimeTypes } from "./mimes.js";
|
|
8
9
|
import { omit, pick, toMap, trimObject } from "./objects.js";
|
|
9
10
|
import { sleep } from "./timers.js";
|
|
10
11
|
import { addMissingProtocol, addMissingScheme, decodeSegment, fixMalformedProtocol, fixMalformedScheme, getPathSegments, getRegistrableDomain, getSubdomain, isHostOf, isHostOrSubdomainOf, isHttpUrl, isIpAddress, isSubdomainOf, normalizeUrl, parseUrl, resolveFeedProtocol, resolveFeedScheme, resolveUrl, stripWww, upgradeProtocol, upgradeScheme } from "./urls.js";
|
|
11
|
-
export { addMissingProtocol, addMissingScheme, anyWordMatchesAnyOf, archiveExtensions, audioExtensions, codeExtensions, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, decodeSegment, documentExtensions, endsWithAnyOf, escapeHtml, escapeRegex, fixMalformedProtocol, fixMalformedScheme, flashExtensions, fontExtensions, getAnyOf, getPathSegments, getRegistrableDomain, getSubdomain, 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, tx, upgradeProtocol, upgradeScheme, videoExtensions };
|
|
12
|
+
export { addMissingProtocol, addMissingScheme, anyWordMatchesAnyOf, archiveExtensions, audioExtensions, codeExtensions, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, createAcceptHeader, decodeSegment, documentExtensions, endsWithAnyOf, escapeHtml, escapeRegex, feedMimeTypes, fixMalformedProtocol, fixMalformedScheme, flashExtensions, fontExtensions, genericFeedMimeTypes, genericHtmlMimeTypes, getAnyOf, getPathSegments, getRegistrableDomain, getSubdomain, 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, tx, upgradeProtocol, upgradeScheme, videoExtensions };
|
package/dist/mimes.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { WeightedMimeType } from "./types.js";
|
|
2
|
+
//#region src/mimes.d.ts
|
|
3
|
+
export declare const feedMimeTypes: Array<WeightedMimeType>;
|
|
4
|
+
export declare const genericFeedMimeTypes: Array<WeightedMimeType>;
|
|
5
|
+
export declare const htmlMimeTypes: Array<WeightedMimeType>;
|
|
6
|
+
export declare const genericHtmlMimeTypes: Array<WeightedMimeType>;
|
|
7
|
+
export declare const createAcceptHeader: (types: ReadonlyArray<WeightedMimeType>) => string;
|
|
8
|
+
//#endregion
|
package/dist/mimes.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
//#region src/mimes.ts
|
|
2
|
+
const feedMimeTypes = [
|
|
3
|
+
{
|
|
4
|
+
mime: "application/atom+xml",
|
|
5
|
+
quality: 1
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
mime: "application/rss+xml",
|
|
9
|
+
quality: 1
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
mime: "application/feed+json",
|
|
13
|
+
quality: 1
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
mime: "application/rdf+xml",
|
|
17
|
+
quality: 1
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
mime: "application/rss",
|
|
21
|
+
quality: .9
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
mime: "text/rss",
|
|
25
|
+
quality: .9
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
mime: "text/rss+xml",
|
|
29
|
+
quality: .9
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
mime: "application/x-rss+xml",
|
|
33
|
+
quality: .9
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
mime: "application/atom",
|
|
37
|
+
quality: .9
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
mime: "application/x.atom+xml",
|
|
41
|
+
quality: .9
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
mime: "application/x-atom+xml",
|
|
45
|
+
quality: .9
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
mime: "text/atom+xml",
|
|
49
|
+
quality: .9
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
mime: "text/atom",
|
|
53
|
+
quality: .9
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
mime: "text/rdf",
|
|
57
|
+
quality: .9
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
mime: "text/rdf+xml",
|
|
61
|
+
quality: .9
|
|
62
|
+
}
|
|
63
|
+
];
|
|
64
|
+
const genericFeedMimeTypes = [
|
|
65
|
+
{
|
|
66
|
+
mime: "application/xml",
|
|
67
|
+
quality: .8
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
mime: "text/xml",
|
|
71
|
+
quality: .8
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
mime: "application/json",
|
|
75
|
+
quality: .8
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
mime: "text/plain",
|
|
79
|
+
quality: .1
|
|
80
|
+
}
|
|
81
|
+
];
|
|
82
|
+
const htmlMimeTypes = [{
|
|
83
|
+
mime: "text/html",
|
|
84
|
+
quality: 1
|
|
85
|
+
}, {
|
|
86
|
+
mime: "application/xhtml+xml",
|
|
87
|
+
quality: 1
|
|
88
|
+
}];
|
|
89
|
+
const genericHtmlMimeTypes = [{
|
|
90
|
+
mime: "application/xml",
|
|
91
|
+
quality: .9
|
|
92
|
+
}, {
|
|
93
|
+
mime: "*/*",
|
|
94
|
+
quality: .8
|
|
95
|
+
}];
|
|
96
|
+
const createAcceptHeader = (types) => {
|
|
97
|
+
return types.map((type) => {
|
|
98
|
+
if (type.quality === 1) return type.mime;
|
|
99
|
+
return `${type.mime};q=${type.quality}`;
|
|
100
|
+
}).join(", ");
|
|
101
|
+
};
|
|
102
|
+
//#endregion
|
|
103
|
+
export { createAcceptHeader, feedMimeTypes, genericFeedMimeTypes, genericHtmlMimeTypes, htmlMimeTypes };
|
package/dist/types.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export type NormalizeOptions = {
|
|
|
13
13
|
stripScheme?: boolean;
|
|
14
14
|
/** @deprecated Use `stripScheme` instead, which wins when both are set. */
|
|
15
15
|
stripProtocol?: boolean;
|
|
16
|
+
stripHostTrailingDot?: boolean;
|
|
16
17
|
stripAuthentication?: boolean;
|
|
17
18
|
stripWww?: boolean;
|
|
18
19
|
stripTrailingSlash?: boolean;
|
|
@@ -27,4 +28,8 @@ export type NormalizeOptions = {
|
|
|
27
28
|
normalizeEncoding?: boolean;
|
|
28
29
|
normalizeUnicode?: boolean;
|
|
29
30
|
};
|
|
31
|
+
export type WeightedMimeType = {
|
|
32
|
+
mime: string;
|
|
33
|
+
quality: number;
|
|
34
|
+
};
|
|
30
35
|
//#endregion
|
package/dist/urls.js
CHANGED
|
@@ -68,7 +68,7 @@ const getStrippedParamsSet = (params) => {
|
|
|
68
68
|
};
|
|
69
69
|
const ipv4Regex = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
|
|
70
70
|
const ipv6Regex = /^([0-9a-f]{0,4}:){2,7}[0-9a-f]{0,4}$/i;
|
|
71
|
-
const wwwPrefixRegex = /^www
|
|
71
|
+
const wwwPrefixRegex = /^(?:www\.)+(?=.*\.)/;
|
|
72
72
|
const ipv6BracketsRegex = /^\[|\]$/g;
|
|
73
73
|
const unreservedCharsRegex = /[a-zA-Z0-9._~-]/;
|
|
74
74
|
const httpsLetterRegex = /s/i;
|
|
@@ -94,7 +94,7 @@ const missingColonSchemeRegex = /^https?[\s=.\\]*\/\//i;
|
|
|
94
94
|
const validUrlRegex = /^https?:\/\/(?:www\.|[a-vx-z0-9])/i;
|
|
95
95
|
const schemeSeparator = String.raw`\.*[:\s=\\/][:\s=.\\/]*`;
|
|
96
96
|
const leadingSchemeSeparator = String.raw`\.*(?::[:\s=.\\/]*|[\s=\\/][:\s=.\\/]+)`;
|
|
97
|
-
const doubledSchemeRegex = /* @__PURE__ */ new RegExp(String.raw`^\/?[htps]{2,7}${leadingSchemeSeparator}([htps]{2,7})(?!:\d)(${schemeSeparator})[.,:/]*(www[./]+)?`, "i");
|
|
97
|
+
const doubledSchemeRegex = /* @__PURE__ */ new RegExp(String.raw`^\/?[htps]{2,7}${leadingSchemeSeparator}([htps]{2,7})(?!:\d|[^/?#\\]*@)(${schemeSeparator})[.,:/]*(www[./]+)?`, "i");
|
|
98
98
|
const singleMalformedRegex = /* @__PURE__ */ new RegExp(String.raw`^\/?(h[htps():]{1,10}|t{1,2}ps?)(${leadingSchemeSeparator})[.,:/]*(www[./]+)?`, "i");
|
|
99
99
|
const isSchemeToken = (token, separator) => {
|
|
100
100
|
const lowered = token.toLowerCase();
|
|
@@ -225,6 +225,7 @@ const lowercaseQueryPair = (pair) => {
|
|
|
225
225
|
const normalizeUrl = (url, options) => {
|
|
226
226
|
try {
|
|
227
227
|
const parsed = new URL(options.normalizeUnicode ? url.normalize("NFC") : url);
|
|
228
|
+
if (options.stripHostTrailingDot && parsed.hostname.endsWith(".")) parsed.hostname = parsed.hostname.slice(0, -1);
|
|
228
229
|
if (options.stripAuthentication) {
|
|
229
230
|
parsed.username = "";
|
|
230
231
|
parsed.password = "";
|
|
@@ -259,8 +260,7 @@ const normalizeUrl = (url, options) => {
|
|
|
259
260
|
}
|
|
260
261
|
};
|
|
261
262
|
const stripWww = (hostname) => {
|
|
262
|
-
|
|
263
|
-
return stripped.includes(".") ? stripped : hostname;
|
|
263
|
+
return hostname.replace(wwwPrefixRegex, "");
|
|
264
264
|
};
|
|
265
265
|
const isIpAddress = (hostname) => {
|
|
266
266
|
return ipv4Regex.test(hostname) || ipv6Regex.test(hostname.replace(ipv6BracketsRegex, ""));
|
package/package.json
CHANGED