nuxtseo-shared 0.2.0 → 0.4.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/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.16.0"
6
6
  },
7
- "version": "0.1.9",
7
+ "version": "0.4.0",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -0,0 +1,3 @@
1
+ import type { NitroRouteRules } from 'nitropack';
2
+ export declare function withoutQuery(path: string): string;
3
+ export declare function createNitroRouteRuleMatcher(): (path: string) => NitroRouteRules;
@@ -0,0 +1,9 @@
1
+ interface CreateFilterOptions {
2
+ include?: (string | RegExp)[];
3
+ exclude?: (string | RegExp)[];
4
+ }
5
+ declare function createFilter(options?: CreateFilterOptions): (path: string) => boolean;
6
+ declare function withoutQuery(path: string): string;
7
+
8
+ export { createFilter, withoutQuery };
9
+ export type { CreateFilterOptions };
@@ -0,0 +1,9 @@
1
+ interface CreateFilterOptions {
2
+ include?: (string | RegExp)[];
3
+ exclude?: (string | RegExp)[];
4
+ }
5
+ declare function createFilter(options?: CreateFilterOptions): (path: string) => boolean;
6
+ declare function withoutQuery(path: string): string;
7
+
8
+ export { createFilter, withoutQuery };
9
+ export type { CreateFilterOptions };
@@ -1,5 +1,6 @@
1
- import { createRouter, toRouteMatcher } from "radix3";
2
- export function createFilter(options = {}) {
1
+ import { toRouteMatcher, createRouter } from 'radix3';
2
+
3
+ function createFilter(options = {}) {
3
4
  const include = options.include || [];
4
5
  const exclude = options.exclude || [];
5
6
  if (include.length === 0 && exclude.length === 0)
@@ -34,3 +35,8 @@ export function createFilter(options = {}) {
34
35
  return include.length === 0;
35
36
  };
36
37
  }
38
+ function withoutQuery(path) {
39
+ return path.split("?")[0];
40
+ }
41
+
42
+ export { createFilter, withoutQuery };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxtseo-shared",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.4.0",
5
5
  "description": "Shared utilities for Nuxt SEO modules.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -38,6 +38,10 @@
38
38
  "types": "./dist/telemetry.d.mts",
39
39
  "import": "./dist/telemetry.mjs"
40
40
  },
41
+ "./utils": {
42
+ "types": "./dist/utils.d.mts",
43
+ "import": "./dist/utils.mjs"
44
+ },
41
45
  "./package.json": "./package.json"
42
46
  },
43
47
  "main": "./dist/module.mjs",
File without changes
@@ -1,57 +0,0 @@
1
- import { createRouter, toRouteMatcher } from 'radix3'
2
-
3
- export interface CreateFilterOptions {
4
- include?: (string | RegExp)[]
5
- exclude?: (string | RegExp)[]
6
- }
7
-
8
- export function createFilter(options: CreateFilterOptions = {}): (path: string) => boolean {
9
- const include = options.include || []
10
- const exclude = options.exclude || []
11
- if (include.length === 0 && exclude.length === 0)
12
- return () => true
13
-
14
- // Pre-compute regex and string rules once
15
- const excludeRegex = exclude.filter(r => r instanceof RegExp) as RegExp[]
16
- const includeRegex = include.filter(r => r instanceof RegExp) as RegExp[]
17
- const excludeStrings = exclude.filter(r => typeof r === 'string') as string[]
18
- const includeStrings = include.filter(r => typeof r === 'string') as string[]
19
-
20
- // Pre-create routers once (expensive operation)
21
- const excludeMatcher = excludeStrings.length > 0
22
- ? toRouteMatcher(createRouter({
23
- routes: Object.fromEntries(excludeStrings.map(r => [r, true])),
24
- strictTrailingSlash: false,
25
- }))
26
- : null
27
- const includeMatcher = includeStrings.length > 0
28
- ? toRouteMatcher(createRouter({
29
- routes: Object.fromEntries(includeStrings.map(r => [r, true])),
30
- strictTrailingSlash: false,
31
- }))
32
- : null
33
-
34
- // Pre-create Sets for O(1) exact match lookups
35
- const excludeExact = new Set(excludeStrings)
36
- const includeExact = new Set(includeStrings)
37
-
38
- return function (path: string): boolean {
39
- // Check exclude rules first
40
- if (excludeRegex.some(r => r.test(path)))
41
- return false
42
- if (excludeExact.has(path))
43
- return false
44
- if (excludeMatcher && excludeMatcher.matchAll(path).length > 0)
45
- return false
46
-
47
- // Check include rules
48
- if (includeRegex.some(r => r.test(path)))
49
- return true
50
- if (includeExact.has(path))
51
- return true
52
- if (includeMatcher && includeMatcher.matchAll(path).length > 0)
53
- return true
54
-
55
- return include.length === 0
56
- }
57
- }