trousse 3.15.0 → 3.16.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/matching.d.ts +7 -7
- package/dist/urls.js +5 -6
- package/package.json +1 -1
package/dist/matching.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Pattern } from "./types.js";
|
|
1
|
+
import { Nullish, Pattern } from "./types.js";
|
|
2
2
|
export declare const escapeRegex: (value: string) => string;
|
|
3
|
-
export declare const isAnyOf: (value: string
|
|
4
|
-
export declare const isSameText: (value: string
|
|
5
|
-
export declare const getAnyOf: <T extends string>(value: string
|
|
6
|
-
export declare const includesAnyOf: (value: string
|
|
7
|
-
export declare const startsWithAnyOf: (value: string
|
|
8
|
-
export declare const endsWithAnyOf: (value: string
|
|
3
|
+
export declare const isAnyOf: (value: Nullish<string>, patterns: Pattern | ReadonlyArray<Pattern>, parser?: (value: string) => string) => boolean;
|
|
4
|
+
export declare const isSameText: (value: Nullish<string>, other: Nullish<string>) => boolean;
|
|
5
|
+
export declare const getAnyOf: <T extends string>(value: Nullish<string>, patterns: ReadonlyArray<T>, parser?: (value: string) => string) => T | undefined;
|
|
6
|
+
export declare const includesAnyOf: (value: Nullish<string>, patterns: Pattern | ReadonlyArray<Pattern>, parser?: (value: string) => string) => boolean;
|
|
7
|
+
export declare const startsWithAnyOf: (value: Nullish<string>, patterns: Pattern | ReadonlyArray<Pattern>) => boolean;
|
|
8
|
+
export declare const endsWithAnyOf: (value: Nullish<string>, patterns: Pattern | ReadonlyArray<Pattern>) => boolean;
|
|
9
9
|
export declare const anyWordMatchesAnyOf: (value: string, patterns: ReadonlyArray<Pattern>) => boolean;
|
package/dist/urls.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isFunction, isNullish, isString } from "./is.js";
|
|
2
|
-
import { isAnyOf, toPatternList } from "./matching.js";
|
|
2
|
+
import { includesAnyOf, isAnyOf, toPatternList } from "./matching.js";
|
|
3
3
|
import { decodeHTMLStrict } from "entities";
|
|
4
4
|
// src/urls.ts
|
|
5
5
|
const httpSchemes = ["http:", "https:"];
|
|
@@ -289,7 +289,6 @@ const ipv6BracketsRegex = /^\[|\]$/g;
|
|
|
289
289
|
const hostnameLabelRegex = /^[a-z0-9_-]+$/i;
|
|
290
290
|
const fileExtensionRegex = /\.[a-z][a-z0-9]{0,5}$/i;
|
|
291
291
|
const unreservedCharsRegex = /[a-zA-Z0-9._~-]/;
|
|
292
|
-
const httpsLetterRegex = /s/i;
|
|
293
292
|
const schemePrefixRegex = /^https?:\/\//;
|
|
294
293
|
const percentEscapeOrLettersRegex = /%[0-9A-Fa-f]{2}|[A-Z]+/g;
|
|
295
294
|
const plusRegex = /\+/g;
|
|
@@ -301,6 +300,7 @@ const leadingWhitespaceChars = [
|
|
|
301
300
|
" ",
|
|
302
301
|
"\n"
|
|
303
302
|
];
|
|
303
|
+
const httpsLetter = "s";
|
|
304
304
|
const relativeLeadChars = [
|
|
305
305
|
"/",
|
|
306
306
|
".",
|
|
@@ -317,8 +317,7 @@ const leadingSchemeSeparator = String.raw`\.*(?::${separatorChar}*|[\s=\\/]${sep
|
|
|
317
317
|
const doubledSchemeRegex = /* @__PURE__ */ new RegExp(String.raw`^\/?[htps]{2,7}${leadingSchemeSeparator}([htps]{2,7})(?!:\d|[^/?#\\]*@)(${schemeSeparator})(www[./]+)?`, "i");
|
|
318
318
|
const singleMalformedRegex = /* @__PURE__ */ new RegExp(String.raw`^\/?(h[htps():]{1,10}|t{1,2}ps?)(${leadingSchemeSeparator})(www[./]+)?`, "i");
|
|
319
319
|
const isSchemeToken = (token, separator) => {
|
|
320
|
-
|
|
321
|
-
return `${token}${separator}`.includes(":") || lowered.includes("t") && lowered.includes("p");
|
|
320
|
+
return `${token}${separator}`.includes(":") || includesAnyOf(token, "t") && includesAnyOf(token, "p");
|
|
322
321
|
};
|
|
323
322
|
const brokenSlashEscapeRegex = /^[^/]*\/[,.]/;
|
|
324
323
|
const fixMalformedScheme = (url) => {
|
|
@@ -329,7 +328,7 @@ const fixMalformedScheme = (url) => {
|
|
|
329
328
|
const www = doubledMatch[3];
|
|
330
329
|
const rest = url.slice(doubledMatch[0].length);
|
|
331
330
|
if (brokenSlashEscapeRegex.test(`${doubledMatch[2]}${rest}`)) return url;
|
|
332
|
-
return `${
|
|
331
|
+
return `${includesAnyOf(inner, httpsLetter) ? "https://" : "http://"}${www ? "www." : ""}${rest}`;
|
|
333
332
|
}
|
|
334
333
|
const singleMatch = singleMalformedRegex.exec(url);
|
|
335
334
|
if (singleMatch && isSchemeToken(singleMatch[1], singleMatch[2])) {
|
|
@@ -337,7 +336,7 @@ const fixMalformedScheme = (url) => {
|
|
|
337
336
|
const www = singleMatch[3];
|
|
338
337
|
const rest = url.slice(fullMatch.length);
|
|
339
338
|
if (brokenSlashEscapeRegex.test(`${singleMatch[2]}${rest}`)) return url;
|
|
340
|
-
return `${
|
|
339
|
+
return `${includesAnyOf(fullMatch, httpsLetter) ? "https://" : "http://"}${www ? "www." : ""}${rest}`;
|
|
341
340
|
}
|
|
342
341
|
return url;
|
|
343
342
|
};
|
package/package.json
CHANGED