trousse 3.13.1 → 3.14.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 +2 -2
- package/dist/types.d.ts +2 -1
- package/dist/urls.js +19 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,6 @@ import { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, getAnyOf, includesAnyO
|
|
|
8
8
|
import { createAcceptHeader, feedMimeTypes, genericFeedMimeTypes, genericHtmlMimeTypes, htmlMimeTypes } from "./mimes.js";
|
|
9
9
|
import { omit, pick, toMap, trimObject } from "./objects.js";
|
|
10
10
|
import { sleep } from "./timers.js";
|
|
11
|
-
import { AnyOf, DeepOmit, IsPlainObject, LocaleSegmentOptions, MaybePromise, NormalizeOptions, Nullish, ParamOptions, ParamSource, PartialNullish, Pattern, RegistrableDomainOptions, WeightedMimeType } from "./types.js";
|
|
11
|
+
import { AnyOf, DeepOmit, IsPlainObject, LocaleSegmentOptions, MaybePromise, NormalizeOptions, Nullish, ParamOptions, ParamSource, PartialNullish, Pattern, QueryParamPredicate, RegistrableDomainOptions, WeightedMimeType } from "./types.js";
|
|
12
12
|
import { addMissingProtocol, addMissingScheme, composeFragment, composeQuery, createUrlSpellings, createUrlVariants, decodeBase64, decodeBase64Binary, decodeBase64Url, decodeBase64UrlBinary, decodePercent, decodeSegment, encodePathSegment, fixMalformedHost, fixMalformedProtocol, fixMalformedQuery, fixMalformedScheme, getFragmentParam, getFragmentParamValues, getFragmentParams, getOrigin, getPathSegments, getQueryParam, getQueryParamValues, getQueryParams, getRegistrableDomain, getSubdomain, hasFragmentParam, hasQueryParam, isHostOf, isHostOrSubdomainOf, isHostname, isHttpUrl, isIpAddress, isSubdomainOf, isUtf8Binary, normalizeUrl, parseUrl, resolveFeedProtocol, resolveFeedScheme, resolveUrl, stripWww, trimUrlValues, upgradeProtocol, upgradeScheme } from "./urls.js";
|
|
13
|
-
export { type AnyOf, type DeepOmit, type IsPlainObject, type LocaleSegmentOptions, 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, decodeBase64, decodeBase64Binary, decodeBase64Url, decodeBase64UrlBinary, decodePercent, decodeSegment, documentExtensions, encodePathSegment, endsWithAnyOf, escapeHtml, escapeRegex, feedMimeTypes, fixMalformedHost, fixMalformedProtocol, fixMalformedQuery, fixMalformedScheme, flashExtensions, fontExtensions, genericFeedMimeTypes, genericHtmlMimeTypes, getAnyOf, getFragmentParam, getFragmentParamValues, getFragmentParams, getOrigin, getPathSegments, getQueryParam, getQueryParamValues, getQueryParams, getRegistrableDomain, getSubdomain, hasFragmentParam, hasQueryParam, htmlMimeTypes, imageExtensions, includesAnyOf, installerExtensions, isAnyOf, isBoolean, isFiniteNumber, isFunction, isHostOf, isHostOrSubdomainOf, isHostname, isHttpUrl, isInteger, isIpAddress, isJsonLike, isLocaleSegment, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isRegionSegment, isSameText, isString, isSubdomainOf, isUtf8Binary, isValidDate, normalizeUrl, omit, omitEmpty, parseJson, parseUrl, pick, resolveFeedProtocol, resolveFeedScheme, resolveUrl, sleep, startsWithAnyOf, stripWww, subtitleExtensions, t, toMap, trimObject, trimUrlValues, tx, upgradeProtocol, upgradeScheme, videoExtensions, webAudioExtensions, webImageExtensions, webVideoExtensions };
|
|
13
|
+
export { type AnyOf, type DeepOmit, type IsPlainObject, type LocaleSegmentOptions, type MaybePromise, type NormalizeOptions, type Nullish, type ParamOptions, type ParamSource, type PartialNullish, type Pattern, type QueryParamPredicate, type RegistrableDomainOptions, type WeightedMimeType, addMissingProtocol, addMissingScheme, anyWordMatchesAnyOf, archiveExtensions, audioExtensions, codeExtensions, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, composeFragment, composeQuery, createAcceptHeader, createUrlSpellings, createUrlVariants, decodeBase64, decodeBase64Binary, decodeBase64Url, decodeBase64UrlBinary, decodePercent, decodeSegment, documentExtensions, encodePathSegment, endsWithAnyOf, escapeHtml, escapeRegex, feedMimeTypes, fixMalformedHost, fixMalformedProtocol, fixMalformedQuery, fixMalformedScheme, flashExtensions, fontExtensions, genericFeedMimeTypes, genericHtmlMimeTypes, getAnyOf, getFragmentParam, getFragmentParamValues, getFragmentParams, getOrigin, getPathSegments, getQueryParam, getQueryParamValues, getQueryParams, getRegistrableDomain, getSubdomain, hasFragmentParam, hasQueryParam, htmlMimeTypes, imageExtensions, includesAnyOf, installerExtensions, isAnyOf, isBoolean, isFiniteNumber, isFunction, isHostOf, isHostOrSubdomainOf, isHostname, isHttpUrl, isInteger, isIpAddress, isJsonLike, isLocaleSegment, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isRegionSegment, isSameText, isString, isSubdomainOf, isUtf8Binary, isValidDate, normalizeUrl, omit, omitEmpty, parseJson, 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
|
@@ -17,6 +17,7 @@ export type LocaleSegmentOptions = {
|
|
|
17
17
|
export type RegistrableDomainOptions = {
|
|
18
18
|
suffixes?: ReadonlyArray<string>;
|
|
19
19
|
};
|
|
20
|
+
export type QueryParamPredicate = (name: string, value: string | undefined, url: URL) => boolean;
|
|
20
21
|
export type NormalizeOptions = {
|
|
21
22
|
stripScheme?: boolean;
|
|
22
23
|
/** @deprecated Use `stripScheme` instead, which wins when both are set. */
|
|
@@ -29,7 +30,7 @@ export type NormalizeOptions = {
|
|
|
29
30
|
collapseSlashes?: boolean;
|
|
30
31
|
stripHash?: boolean;
|
|
31
32
|
sortQueryParams?: boolean;
|
|
32
|
-
stripQueryParams?: ReadonlyArray<string
|
|
33
|
+
stripQueryParams?: ReadonlyArray<string> | QueryParamPredicate;
|
|
33
34
|
stripQuery?: boolean;
|
|
34
35
|
stripEmptyQuery?: boolean;
|
|
35
36
|
lowercaseQuery?: boolean;
|
package/dist/urls.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isNullish, isString } from "./is.js";
|
|
1
|
+
import { isFunction, isNullish, isString } from "./is.js";
|
|
2
2
|
import { isAnyOf, toPatternList } from "./matching.js";
|
|
3
3
|
import { decodeHTMLStrict } from "entities";
|
|
4
4
|
// src/urls.ts
|
|
@@ -546,14 +546,22 @@ const decodeAndNormalizeEncoding = (value) => {
|
|
|
546
546
|
return hex.toUpperCase();
|
|
547
547
|
});
|
|
548
548
|
};
|
|
549
|
-
const
|
|
550
|
-
const
|
|
549
|
+
const decodeQueryComponent = (component) => {
|
|
550
|
+
const spaced = component.replace(plusRegex, " ");
|
|
551
551
|
try {
|
|
552
|
-
return decodeURIComponent(
|
|
552
|
+
return decodeURIComponent(spaced);
|
|
553
553
|
} catch {
|
|
554
|
-
return
|
|
554
|
+
return spaced;
|
|
555
555
|
}
|
|
556
556
|
};
|
|
557
|
+
const decodeQueryKey = (pair) => {
|
|
558
|
+
return decodeQueryComponent(pair.split("=")[0]);
|
|
559
|
+
};
|
|
560
|
+
const decodeQueryValue = (pair) => {
|
|
561
|
+
const separatorIndex = pair.indexOf("=");
|
|
562
|
+
if (separatorIndex === -1) return;
|
|
563
|
+
return decodeQueryComponent(pair.slice(separatorIndex + 1));
|
|
564
|
+
};
|
|
557
565
|
const compareQueryPairs = (a, b) => {
|
|
558
566
|
const keyA = decodeQueryKey(a);
|
|
559
567
|
const keyB = decodeQueryKey(b);
|
|
@@ -589,7 +597,12 @@ const normalizeUrl = (url, options) => {
|
|
|
589
597
|
if (options.stripQuery) parsed.search = "";
|
|
590
598
|
if (parsed.search && (options.stripQueryParams || options.lowercaseQuery)) {
|
|
591
599
|
let pairs = parsed.search.slice(1).split("&");
|
|
592
|
-
if (options.stripQueryParams) {
|
|
600
|
+
if (isFunction(options.stripQueryParams)) {
|
|
601
|
+
const isStripped = options.stripQueryParams;
|
|
602
|
+
pairs = pairs.filter((pair) => {
|
|
603
|
+
return pair && !isStripped(decodeQueryKey(pair), decodeQueryValue(pair), parsed);
|
|
604
|
+
});
|
|
605
|
+
} else if (options.stripQueryParams) {
|
|
593
606
|
const strippedSet = getStrippedParamsSet(options.stripQueryParams);
|
|
594
607
|
pairs = pairs.filter((pair) => pair && !strippedSet.has(decodeQueryKey(pair).toLowerCase()));
|
|
595
608
|
}
|
package/package.json
CHANGED