trousse 2.3.0 → 2.5.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.
@@ -0,0 +1,12 @@
1
+ //#region src/files.d.ts
2
+ export declare const audioExtensions: string[];
3
+ export declare const videoExtensions: string[];
4
+ export declare const imageExtensions: string[];
5
+ export declare const documentExtensions: string[];
6
+ export declare const archiveExtensions: string[];
7
+ export declare const installerExtensions: string[];
8
+ export declare const flashExtensions: string[];
9
+ export declare const codeExtensions: string[];
10
+ export declare const fontExtensions: string[];
11
+ export declare const subtitleExtensions: string[];
12
+ //#endregion
package/dist/files.js ADDED
@@ -0,0 +1,101 @@
1
+ //#region src/files.ts
2
+ const audioExtensions = [
3
+ "aac",
4
+ "aif",
5
+ "aiff",
6
+ "amr",
7
+ "flac",
8
+ "m4a",
9
+ "m4b",
10
+ "mid",
11
+ "midi",
12
+ "mka",
13
+ "mp3",
14
+ "oga",
15
+ "ogg",
16
+ "opus",
17
+ "wav",
18
+ "weba",
19
+ "wma"
20
+ ];
21
+ const videoExtensions = [
22
+ "3gp",
23
+ "avi",
24
+ "flv",
25
+ "m4v",
26
+ "mkv",
27
+ "mov",
28
+ "mp4",
29
+ "mpeg",
30
+ "mpg",
31
+ "ogv",
32
+ "webm",
33
+ "wmv"
34
+ ];
35
+ const imageExtensions = [
36
+ "avif",
37
+ "bmp",
38
+ "gif",
39
+ "heic",
40
+ "heif",
41
+ "ico",
42
+ "jpeg",
43
+ "jpg",
44
+ "jxl",
45
+ "png",
46
+ "svg",
47
+ "tif",
48
+ "tiff",
49
+ "webp"
50
+ ];
51
+ const documentExtensions = [
52
+ "doc",
53
+ "docx",
54
+ "epub",
55
+ "mobi",
56
+ "odp",
57
+ "ods",
58
+ "odt",
59
+ "pdf",
60
+ "ppt",
61
+ "pptx",
62
+ "rtf",
63
+ "xls",
64
+ "xlsx"
65
+ ];
66
+ const archiveExtensions = [
67
+ "7z",
68
+ "bz2",
69
+ "gz",
70
+ "rar",
71
+ "tar",
72
+ "tgz",
73
+ "xz",
74
+ "zip"
75
+ ];
76
+ const installerExtensions = [
77
+ "apk",
78
+ "deb",
79
+ "dmg",
80
+ "exe",
81
+ "iso",
82
+ "msi",
83
+ "pkg",
84
+ "rpm"
85
+ ];
86
+ const flashExtensions = ["swf"];
87
+ const codeExtensions = [
88
+ "css",
89
+ "js",
90
+ "mjs"
91
+ ];
92
+ const fontExtensions = [
93
+ "eot",
94
+ "otf",
95
+ "ttf",
96
+ "woff",
97
+ "woff2"
98
+ ];
99
+ const subtitleExtensions = ["srt", "vtt"];
100
+ //#endregion
101
+ export { archiveExtensions, audioExtensions, codeExtensions, documentExtensions, flashExtensions, fontExtensions, imageExtensions, installerExtensions, subtitleExtensions, videoExtensions };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { omitEmpty } from "./arrays.js";
2
2
  import { AnyOf, DeepOmit, IsPlainObject, MaybePromise, Nullish, PartialNullish, Pattern } 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
5
  import { isBoolean, isFunction, isNonEmptyString, isNullish, isNumber, isObject, isPlainObject, isPresent, isString, isValidDate } from "./is.js";
5
6
  import { isJsonLike, isParseableJson } from "./json.js";
6
7
  import { escapeHtml, t, tx } from "./locales.js";
@@ -8,4 +9,4 @@ import { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, getAnyOf, includesAnyO
8
9
  import { omit, pick, toMap, trimObject } from "./objects.js";
9
10
  import { sleep } from "./timers.js";
10
11
  import { decodeSegment, getPathSegments, getSubdomain, isHostOf, isHostOrSubdomainOf, isHttpUrl, isSubdomainOf, parseUrl } from "./urls.js";
11
- export { type AnyOf, type DeepOmit, type IsPlainObject, type MaybePromise, type Nullish, type PartialNullish, type Pattern, anyWordMatchesAnyOf, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, decodeSegment, endsWithAnyOf, escapeHtml, escapeRegex, getAnyOf, getPathSegments, getSubdomain, includesAnyOf, isAnyOf, isBoolean, isFunction, isHostOf, isHostOrSubdomainOf, isHttpUrl, isJsonLike, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isString, isSubdomainOf, isValidDate, omit, omitEmpty, parseUrl, pick, sleep, startsWithAnyOf, t, toMap, trimObject, tx };
12
+ export { type AnyOf, type DeepOmit, type IsPlainObject, type MaybePromise, type Nullish, type PartialNullish, type Pattern, anyWordMatchesAnyOf, archiveExtensions, audioExtensions, codeExtensions, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, decodeSegment, documentExtensions, endsWithAnyOf, escapeHtml, escapeRegex, flashExtensions, fontExtensions, getAnyOf, getPathSegments, getSubdomain, imageExtensions, includesAnyOf, installerExtensions, isAnyOf, isBoolean, isFunction, isHostOf, isHostOrSubdomainOf, isHttpUrl, isJsonLike, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isString, isSubdomainOf, isValidDate, omit, omitEmpty, parseUrl, pick, sleep, startsWithAnyOf, subtitleExtensions, t, toMap, trimObject, tx, videoExtensions };
package/dist/index.js CHANGED
@@ -1,10 +1,11 @@
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
5
  import { isJsonLike, isParseableJson } from "./json.js";
5
6
  import { escapeHtml, t, tx } from "./locales.js";
6
7
  import { anyWordMatchesAnyOf, endsWithAnyOf, escapeRegex, getAnyOf, includesAnyOf, isAnyOf, startsWithAnyOf } from "./matching.js";
7
8
  import { omit, pick, toMap, trimObject } from "./objects.js";
8
9
  import { sleep } from "./timers.js";
9
10
  import { decodeSegment, getPathSegments, getSubdomain, isHostOf, isHostOrSubdomainOf, isHttpUrl, isSubdomainOf, parseUrl } from "./urls.js";
10
- export { anyWordMatchesAnyOf, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, decodeSegment, endsWithAnyOf, escapeHtml, escapeRegex, getAnyOf, getPathSegments, getSubdomain, includesAnyOf, isAnyOf, isBoolean, isFunction, isHostOf, isHostOrSubdomainOf, isHttpUrl, isJsonLike, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isString, isSubdomainOf, isValidDate, omit, omitEmpty, parseUrl, pick, sleep, startsWithAnyOf, t, toMap, trimObject, tx };
11
+ export { anyWordMatchesAnyOf, archiveExtensions, audioExtensions, codeExtensions, coerceArray, coerceBoolean, coerceDate, coerceNumber, coerceSingular, coerceString, decodeSegment, documentExtensions, endsWithAnyOf, escapeHtml, escapeRegex, flashExtensions, fontExtensions, getAnyOf, getPathSegments, getSubdomain, imageExtensions, includesAnyOf, installerExtensions, isAnyOf, isBoolean, isFunction, isHostOf, isHostOrSubdomainOf, isHttpUrl, isJsonLike, isNonEmptyString, isNullish, isNumber, isObject, isParseableJson, isPlainObject, isPresent, isString, isSubdomainOf, isValidDate, omit, omitEmpty, parseUrl, pick, sleep, startsWithAnyOf, subtitleExtensions, t, toMap, trimObject, tx, videoExtensions };
@@ -1,9 +1,9 @@
1
1
  import { Pattern } from "./types.js";
2
2
  //#region src/matching.d.ts
3
3
  export declare const escapeRegex: (value: string) => string;
4
- export declare const isAnyOf: (value: string, patterns: Pattern | ReadonlyArray<Pattern>, parser?: (value: string) => string) => boolean;
5
- export declare const getAnyOf: <T extends string>(value: string, patterns: ReadonlyArray<T>, parser?: (value: string) => string) => T | undefined;
6
- export declare const includesAnyOf: (value: string, patterns: ReadonlyArray<Pattern>, parser?: (value: string) => string) => boolean;
4
+ export declare const isAnyOf: (value: string | undefined, patterns: Pattern | ReadonlyArray<Pattern>, parser?: (value: string) => string) => boolean;
5
+ export declare const getAnyOf: <T extends string>(value: string | undefined, patterns: ReadonlyArray<T>, parser?: (value: string) => string) => T | undefined;
6
+ export declare const includesAnyOf: (value: string | undefined, patterns: ReadonlyArray<Pattern>, parser?: (value: string) => string) => boolean;
7
7
  export declare const startsWithAnyOf: (value: string, patterns: ReadonlyArray<Pattern>) => boolean;
8
8
  export declare const endsWithAnyOf: (value: string, patterns: ReadonlyArray<Pattern>) => boolean;
9
9
  export declare const anyWordMatchesAnyOf: (value: string, patterns: ReadonlyArray<Pattern>) => boolean;
package/dist/matching.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { isNullish } from "./is.js";
1
2
  //#region src/matching.ts
2
3
  const whitespaceRegex = /\s+/;
3
4
  const regexMetaCharsRegex = /[.*+?^${}()|[\]\\-]/g;
@@ -5,21 +6,24 @@ const escapeRegex = (value) => {
5
6
  return value.replace(regexMetaCharsRegex, "\\$&");
6
7
  };
7
8
  const isAnyOf = (value, patterns, parser) => {
8
- const parsedValue = parser ? parser(value) : value?.toLowerCase()?.trim();
9
+ if (isNullish(value)) return false;
10
+ const parsedValue = parser ? parser(value) : value.toLowerCase().trim();
9
11
  return (typeof patterns === "string" || patterns instanceof RegExp ? [patterns] : patterns).some((pattern) => {
10
12
  if (pattern instanceof RegExp) return pattern.test(parsedValue);
11
13
  return parsedValue === pattern.toLowerCase().trim();
12
14
  });
13
15
  };
14
16
  const getAnyOf = (value, patterns, parser) => {
15
- const parsedValue = parser ? parser(value) : value?.toLowerCase()?.trim();
17
+ if (isNullish(value)) return;
18
+ const parsedValue = parser ? parser(value) : value.toLowerCase().trim();
16
19
  return patterns.find((pattern) => parsedValue === pattern.toLowerCase().trim());
17
20
  };
18
21
  const includesAnyOf = (value, patterns, parser) => {
19
- const parsedValue = parser ? parser(value) : value?.toLowerCase();
22
+ if (isNullish(value)) return false;
23
+ const parsedValue = parser ? parser(value) : value.toLowerCase();
20
24
  return patterns.some((pattern) => {
21
25
  if (pattern instanceof RegExp) return pattern.test(parsedValue);
22
- return pattern && parsedValue?.includes(pattern.toLowerCase());
26
+ return pattern && parsedValue.includes(pattern.toLowerCase());
23
27
  });
24
28
  };
25
29
  const startsWithAnyOf = (value, patterns) => {
package/dist/urls.js CHANGED
@@ -13,7 +13,7 @@ const getPathSegments = (value) => {
13
13
  const isHostOf = (url, hosts) => {
14
14
  const hostname = parseUrl(url)?.hostname;
15
15
  if (!hostname) return false;
16
- return isAnyOf(hostname, typeof hosts === "string" ? [hosts] : hosts);
16
+ return isAnyOf(hostname, hosts);
17
17
  };
18
18
  const isSubdomainOf = (url, domains) => {
19
19
  const hostname = parseUrl(url)?.hostname;
package/package.json CHANGED
@@ -43,5 +43,5 @@
43
43
  "kvalita": "^1.24.0",
44
44
  "tsdown": "^0.23.0"
45
45
  },
46
- "version": "2.3.0"
46
+ "version": "2.5.0"
47
47
  }