trousse 2.8.0 → 2.10.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 +4 -3
- package/dist/index.js +3 -2
- package/dist/mimes.d.ts +8 -0
- package/dist/mimes.js +103 -0
- package/dist/types.d.ts +4 -0
- package/dist/urls.d.ts +1 -0
- package/dist/urls.js +22 -1
- 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
|
-
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 };
|
|
12
|
+
import { addMissingProtocol, addMissingScheme, createUrlVariants, decodeSegment, fixMalformedProtocol, fixMalformedScheme, getPathSegments, getRegistrableDomain, getSubdomain, isHostOf, isHostOrSubdomainOf, isHttpUrl, isIpAddress, isSubdomainOf, normalizeUrl, parseUrl, resolveFeedProtocol, resolveFeedScheme, resolveUrl, stripWww, upgradeProtocol, upgradeScheme } from "./urls.js";
|
|
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, createUrlVariants, 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
|
-
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 };
|
|
11
|
+
import { addMissingProtocol, addMissingScheme, createUrlVariants, decodeSegment, fixMalformedProtocol, fixMalformedScheme, getPathSegments, getRegistrableDomain, getSubdomain, isHostOf, isHostOrSubdomainOf, isHttpUrl, isIpAddress, isSubdomainOf, normalizeUrl, parseUrl, resolveFeedProtocol, resolveFeedScheme, resolveUrl, stripWww, upgradeProtocol, upgradeScheme } from "./urls.js";
|
|
12
|
+
export { addMissingProtocol, addMissingScheme, anyWordMatchesAnyOf, archiveExtensions, audioExtensions, codeExtensions, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, createAcceptHeader, createUrlVariants, 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
package/dist/urls.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare const resolveUrl: (url: string, base?: string) => string | undefi
|
|
|
16
16
|
export declare const normalizeUrl: (url: string, options: NormalizeOptions) => string;
|
|
17
17
|
export declare const stripWww: (hostname: string) => string;
|
|
18
18
|
export declare const isIpAddress: (hostname: string) => boolean;
|
|
19
|
+
export declare const createUrlVariants: (url: string) => Array<string>;
|
|
19
20
|
export declare const getRegistrableDomain: (url: string | URL, options?: RegistrableDomainOptions) => string | undefined;
|
|
20
21
|
/** @deprecated Use `fixMalformedScheme` instead. */
|
|
21
22
|
export declare const fixMalformedProtocol: typeof fixMalformedScheme;
|
package/dist/urls.js
CHANGED
|
@@ -70,6 +70,7 @@ 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
71
|
const wwwPrefixRegex = /^(?:www\.)+(?=.*\.)/;
|
|
72
72
|
const ipv6BracketsRegex = /^\[|\]$/g;
|
|
73
|
+
const fileExtensionRegex = /\.[a-z][a-z0-9]{0,5}$/i;
|
|
73
74
|
const unreservedCharsRegex = /[a-zA-Z0-9._~-]/;
|
|
74
75
|
const httpsLetterRegex = /s/i;
|
|
75
76
|
const schemePrefixRegex = /^https?:\/\//;
|
|
@@ -265,6 +266,26 @@ const stripWww = (hostname) => {
|
|
|
265
266
|
const isIpAddress = (hostname) => {
|
|
266
267
|
return ipv4Regex.test(hostname) || ipv6Regex.test(hostname.replace(ipv6BracketsRegex, ""));
|
|
267
268
|
};
|
|
269
|
+
const createUrlVariants = (url) => {
|
|
270
|
+
const parsed = parseUrl(url);
|
|
271
|
+
if (!parsed || !isHttpUrl(parsed)) return [];
|
|
272
|
+
const hostname = stripWww(parsed.hostname);
|
|
273
|
+
const hostnames = [hostname];
|
|
274
|
+
if (hostname.includes(".") && !isIpAddress(hostname)) hostnames.push(`www.${hostname}`);
|
|
275
|
+
const hasTrailingSlash = parsed.pathname.endsWith("/");
|
|
276
|
+
const pathname = hasTrailingSlash ? parsed.pathname.slice(0, -1) : parsed.pathname;
|
|
277
|
+
const pathnames = [pathname];
|
|
278
|
+
if (pathname && (hasTrailingSlash || !fileExtensionRegex.test(pathname))) pathnames.push(`${pathname}/`);
|
|
279
|
+
const variants = [];
|
|
280
|
+
for (const scheme of ["https:", "http:"]) for (const variantHostname of hostnames) for (const variantPathname of pathnames) {
|
|
281
|
+
const variant = new URL(parsed.href);
|
|
282
|
+
variant.protocol = scheme;
|
|
283
|
+
variant.hostname = variantHostname;
|
|
284
|
+
variant.pathname = variantPathname;
|
|
285
|
+
variants.push(variant.href);
|
|
286
|
+
}
|
|
287
|
+
return variants;
|
|
288
|
+
};
|
|
268
289
|
const genericSecondLevels = [
|
|
269
290
|
"ac",
|
|
270
291
|
"co",
|
|
@@ -334,4 +355,4 @@ const addMissingProtocol = addMissingScheme;
|
|
|
334
355
|
/** @deprecated Use `upgradeScheme` instead. */
|
|
335
356
|
const upgradeProtocol = upgradeScheme;
|
|
336
357
|
//#endregion
|
|
337
|
-
export { addMissingProtocol, addMissingScheme, decodeSegment, fixMalformedProtocol, fixMalformedScheme, getPathSegments, getRegistrableDomain, getSubdomain, isHostOf, isHostOrSubdomainOf, isHttpUrl, isIpAddress, isSubdomainOf, normalizeUrl, parseUrl, resolveFeedProtocol, resolveFeedScheme, resolveUrl, stripWww, upgradeProtocol, upgradeScheme };
|
|
358
|
+
export { addMissingProtocol, addMissingScheme, createUrlVariants, decodeSegment, fixMalformedProtocol, fixMalformedScheme, getPathSegments, getRegistrableDomain, getSubdomain, isHostOf, isHostOrSubdomainOf, isHttpUrl, isIpAddress, isSubdomainOf, normalizeUrl, parseUrl, resolveFeedProtocol, resolveFeedScheme, resolveUrl, stripWww, upgradeProtocol, upgradeScheme };
|
package/package.json
CHANGED