site-config-stack 3.2.4 → 3.2.7

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "site-config-stack",
3
3
  "type": "module",
4
- "version": "3.2.4",
4
+ "version": "3.2.7",
5
5
  "description": "Shared site configuration utilities.",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",
package/dist/index.cjs DELETED
@@ -1,110 +0,0 @@
1
- 'use strict';
2
-
3
- const ufo = require('ufo');
4
- const vue = require('vue');
5
-
6
- function normalizeSiteConfig(config) {
7
- if (typeof config.indexable !== "undefined")
8
- config.indexable = String(config.indexable) !== "false";
9
- if (typeof config.trailingSlash !== "undefined" && !config.trailingSlash)
10
- config.trailingSlash = String(config.trailingSlash) !== "false";
11
- if (config.url && !ufo.hasProtocol(String(config.url), { acceptRelative: true, strict: false }))
12
- config.url = ufo.withHttps(String(config.url));
13
- const keys = Object.keys(config).sort((a, b) => a.localeCompare(b));
14
- const newConfig = {};
15
- for (const k of keys)
16
- newConfig[k] = config[k];
17
- return newConfig;
18
- }
19
- function validateSiteConfigStack(stack) {
20
- const resolved = normalizeSiteConfig(stack.get({
21
- // we need the context
22
- debug: true
23
- }));
24
- const errors = [];
25
- if (resolved.url) {
26
- const val = resolved.url;
27
- const context = resolved._context?.url || "unknown";
28
- const url = ufo.parseURL(val);
29
- const { hostname } = ufo.parseHost(url.host);
30
- if (!url.host)
31
- errors.push(`url "${val}" from ${context} is not absolute`);
32
- else if (url.pathname && url.pathname !== "/")
33
- errors.push(`url "${val}" from ${context} should not contain a path`);
34
- else if (url.hash)
35
- errors.push(`url "${val}" from ${context} should not contain a hash`);
36
- else if (Object.keys(ufo.getQuery(val)).length > 0)
37
- errors.push(`url "${val}" from ${context} should not contain a query`);
38
- else if (hostname === "localhost" && resolved.env !== "development")
39
- errors.push(`url "${val}" from ${context} should not be localhost`);
40
- }
41
- return errors;
42
- }
43
- function createSiteConfigStack(options) {
44
- const debug = options?.debug || false;
45
- const stack = [];
46
- function push(input) {
47
- if (!input || typeof input !== "object" || Object.keys(input).length === 0) {
48
- return () => {
49
- };
50
- }
51
- if (!input._context && debug) {
52
- let lastFunctionName = new Error("tmp").stack?.split("\n")[2]?.split(" ")[5];
53
- if (lastFunctionName?.includes("/"))
54
- lastFunctionName = "anonymous";
55
- input._context = lastFunctionName;
56
- }
57
- const entry = {};
58
- for (const k in input) {
59
- const val = input[k];
60
- if (typeof val !== "undefined" && val !== "")
61
- entry[k] = val;
62
- }
63
- let idx;
64
- if (Object.keys(entry).filter((k) => !k.startsWith("_")).length > 0)
65
- idx = stack.push(entry);
66
- return () => {
67
- if (typeof idx !== "undefined") {
68
- stack.splice(idx - 1, 1);
69
- }
70
- };
71
- }
72
- function get(options2) {
73
- const siteConfig = {};
74
- if (options2?.debug)
75
- siteConfig._context = {};
76
- siteConfig._priority = {};
77
- for (const o in stack.sort((a, b) => (a._priority || 0) - (b._priority || 0))) {
78
- for (const k in stack[o]) {
79
- const key = k;
80
- const val = options2?.resolveRefs ? vue.toValue(stack[o][k]) : stack[o][k];
81
- if (!k.startsWith("_") && typeof val !== "undefined" && val !== "") {
82
- siteConfig[k] = val;
83
- if (typeof stack[o]._priority !== "undefined" && stack[o]._priority !== -1) {
84
- siteConfig._priority[key] = stack[o]._priority;
85
- }
86
- if (options2?.debug)
87
- siteConfig._context[key] = stack[o]._context?.[key] || stack[o]._context || "anonymous";
88
- }
89
- }
90
- }
91
- return options2?.skipNormalize ? siteConfig : normalizeSiteConfig(siteConfig);
92
- }
93
- return {
94
- stack,
95
- push,
96
- get
97
- };
98
- }
99
-
100
- function envSiteConfig(env) {
101
- return Object.fromEntries(Object.entries(env).filter(([k]) => k.startsWith("NUXT_SITE_") || k.startsWith("NUXT_PUBLIC_SITE_")).map(([k, v]) => [
102
- k.replace(/^NUXT_(PUBLIC_)?SITE_/, "").split("_").map((s, i) => i === 0 ? s.toLowerCase() : s[0]?.toUpperCase() + s.slice(1).toLowerCase()).join(""),
103
- v
104
- ]));
105
- }
106
-
107
- exports.createSiteConfigStack = createSiteConfigStack;
108
- exports.envSiteConfig = envSiteConfig;
109
- exports.normalizeSiteConfig = normalizeSiteConfig;
110
- exports.validateSiteConfigStack = validateSiteConfigStack;
package/dist/index.d.cts DELETED
@@ -1,81 +0,0 @@
1
- import { ComputedRef, Ref } from 'vue';
2
-
3
- interface SiteConfigResolved {
4
- /**
5
- * The canonical Site URL.
6
- *
7
- * - Build / Prerender: Inferred from CI environment (Netlify, Vercel)
8
- * - SSR: Inferred from request headers
9
- * - SPA: Inferred from `window.location`
10
- *
11
- * Used by: nuxt-simple-sitemap, nuxt-simple-robots, nuxt-schema-org, nuxt-og-image, etc.
12
- */
13
- url?: string;
14
- /**
15
- * The name of the site.
16
- *
17
- * - Build / Prerender: Inferred from CI environment (Netlify) or `package.json`
18
- * - SSR:
19
- *
20
- * Used by: nuxt-schema-org, nuxt-seo-kit
21
- */
22
- name?: string;
23
- /**
24
- * Whether the site is indexable by search engines.
25
- *
26
- * Allows you to opt-out productions environment from being indexed.
27
- */
28
- indexable?: boolean;
29
- /**
30
- * The environment of the site. Comparable to `process.env.NODE_ENV`.
31
- */
32
- env?: 'production' | 'staging' | 'development' | 'preview' | 'uat' | string;
33
- /**
34
- * Whether the site uses trailing slash.
35
- */
36
- trailingSlash?: boolean;
37
- /**
38
- * The mapping of the context of each site config value being set.
39
- */
40
- _context?: Record<string, string>;
41
- /**
42
- * Support any keys as site config.
43
- */
44
- [key: string]: any;
45
- }
46
- /**
47
- * @deprecated use SiteConfigResolved
48
- */
49
- type SiteConfig = SiteConfigResolved;
50
- type MaybeComputedRef<T> = T | (() => T) | ComputedRef<T> | Ref<T>;
51
- type MaybeComputedRefEntries<T> = {
52
- [key in keyof T]?: MaybeComputedRef<T[key]>;
53
- };
54
- type SiteConfigInput = Omit<MaybeComputedRefEntries<Partial<SiteConfigResolved>>, '_context' | 'indexable'> & {
55
- _context?: string;
56
- _priority?: number;
57
- indexable?: MaybeComputedRef<string | boolean>;
58
- };
59
- interface GetSiteConfigOptions {
60
- debug?: boolean;
61
- skipNormalize?: boolean;
62
- resolveRefs?: boolean;
63
- }
64
- interface SiteConfigStack {
65
- stack: Partial<SiteConfigInput>[];
66
- push: (config: SiteConfigInput) => () => void;
67
- get: (options?: GetSiteConfigOptions) => SiteConfigResolved;
68
- }
69
-
70
- declare function normalizeSiteConfig(config: SiteConfigResolved): SiteConfigResolved;
71
- declare function validateSiteConfigStack(stack: SiteConfigStack): string[];
72
- declare function createSiteConfigStack(options?: {
73
- debug: boolean;
74
- }): SiteConfigStack;
75
-
76
- declare function envSiteConfig(env: Record<string, any>): {
77
- [k: string]: any;
78
- };
79
-
80
- export { createSiteConfigStack, envSiteConfig, normalizeSiteConfig, validateSiteConfigStack };
81
- export type { GetSiteConfigOptions, MaybeComputedRef, MaybeComputedRefEntries, SiteConfig, SiteConfigInput, SiteConfigResolved, SiteConfigStack };
package/dist/index.d.mts DELETED
@@ -1,81 +0,0 @@
1
- import { ComputedRef, Ref } from 'vue';
2
-
3
- interface SiteConfigResolved {
4
- /**
5
- * The canonical Site URL.
6
- *
7
- * - Build / Prerender: Inferred from CI environment (Netlify, Vercel)
8
- * - SSR: Inferred from request headers
9
- * - SPA: Inferred from `window.location`
10
- *
11
- * Used by: nuxt-simple-sitemap, nuxt-simple-robots, nuxt-schema-org, nuxt-og-image, etc.
12
- */
13
- url?: string;
14
- /**
15
- * The name of the site.
16
- *
17
- * - Build / Prerender: Inferred from CI environment (Netlify) or `package.json`
18
- * - SSR:
19
- *
20
- * Used by: nuxt-schema-org, nuxt-seo-kit
21
- */
22
- name?: string;
23
- /**
24
- * Whether the site is indexable by search engines.
25
- *
26
- * Allows you to opt-out productions environment from being indexed.
27
- */
28
- indexable?: boolean;
29
- /**
30
- * The environment of the site. Comparable to `process.env.NODE_ENV`.
31
- */
32
- env?: 'production' | 'staging' | 'development' | 'preview' | 'uat' | string;
33
- /**
34
- * Whether the site uses trailing slash.
35
- */
36
- trailingSlash?: boolean;
37
- /**
38
- * The mapping of the context of each site config value being set.
39
- */
40
- _context?: Record<string, string>;
41
- /**
42
- * Support any keys as site config.
43
- */
44
- [key: string]: any;
45
- }
46
- /**
47
- * @deprecated use SiteConfigResolved
48
- */
49
- type SiteConfig = SiteConfigResolved;
50
- type MaybeComputedRef<T> = T | (() => T) | ComputedRef<T> | Ref<T>;
51
- type MaybeComputedRefEntries<T> = {
52
- [key in keyof T]?: MaybeComputedRef<T[key]>;
53
- };
54
- type SiteConfigInput = Omit<MaybeComputedRefEntries<Partial<SiteConfigResolved>>, '_context' | 'indexable'> & {
55
- _context?: string;
56
- _priority?: number;
57
- indexable?: MaybeComputedRef<string | boolean>;
58
- };
59
- interface GetSiteConfigOptions {
60
- debug?: boolean;
61
- skipNormalize?: boolean;
62
- resolveRefs?: boolean;
63
- }
64
- interface SiteConfigStack {
65
- stack: Partial<SiteConfigInput>[];
66
- push: (config: SiteConfigInput) => () => void;
67
- get: (options?: GetSiteConfigOptions) => SiteConfigResolved;
68
- }
69
-
70
- declare function normalizeSiteConfig(config: SiteConfigResolved): SiteConfigResolved;
71
- declare function validateSiteConfigStack(stack: SiteConfigStack): string[];
72
- declare function createSiteConfigStack(options?: {
73
- debug: boolean;
74
- }): SiteConfigStack;
75
-
76
- declare function envSiteConfig(env: Record<string, any>): {
77
- [k: string]: any;
78
- };
79
-
80
- export { createSiteConfigStack, envSiteConfig, normalizeSiteConfig, validateSiteConfigStack };
81
- export type { GetSiteConfigOptions, MaybeComputedRef, MaybeComputedRefEntries, SiteConfig, SiteConfigInput, SiteConfigResolved, SiteConfigStack };
package/dist/index.d.ts DELETED
@@ -1,81 +0,0 @@
1
- import { ComputedRef, Ref } from 'vue';
2
-
3
- interface SiteConfigResolved {
4
- /**
5
- * The canonical Site URL.
6
- *
7
- * - Build / Prerender: Inferred from CI environment (Netlify, Vercel)
8
- * - SSR: Inferred from request headers
9
- * - SPA: Inferred from `window.location`
10
- *
11
- * Used by: nuxt-simple-sitemap, nuxt-simple-robots, nuxt-schema-org, nuxt-og-image, etc.
12
- */
13
- url?: string;
14
- /**
15
- * The name of the site.
16
- *
17
- * - Build / Prerender: Inferred from CI environment (Netlify) or `package.json`
18
- * - SSR:
19
- *
20
- * Used by: nuxt-schema-org, nuxt-seo-kit
21
- */
22
- name?: string;
23
- /**
24
- * Whether the site is indexable by search engines.
25
- *
26
- * Allows you to opt-out productions environment from being indexed.
27
- */
28
- indexable?: boolean;
29
- /**
30
- * The environment of the site. Comparable to `process.env.NODE_ENV`.
31
- */
32
- env?: 'production' | 'staging' | 'development' | 'preview' | 'uat' | string;
33
- /**
34
- * Whether the site uses trailing slash.
35
- */
36
- trailingSlash?: boolean;
37
- /**
38
- * The mapping of the context of each site config value being set.
39
- */
40
- _context?: Record<string, string>;
41
- /**
42
- * Support any keys as site config.
43
- */
44
- [key: string]: any;
45
- }
46
- /**
47
- * @deprecated use SiteConfigResolved
48
- */
49
- type SiteConfig = SiteConfigResolved;
50
- type MaybeComputedRef<T> = T | (() => T) | ComputedRef<T> | Ref<T>;
51
- type MaybeComputedRefEntries<T> = {
52
- [key in keyof T]?: MaybeComputedRef<T[key]>;
53
- };
54
- type SiteConfigInput = Omit<MaybeComputedRefEntries<Partial<SiteConfigResolved>>, '_context' | 'indexable'> & {
55
- _context?: string;
56
- _priority?: number;
57
- indexable?: MaybeComputedRef<string | boolean>;
58
- };
59
- interface GetSiteConfigOptions {
60
- debug?: boolean;
61
- skipNormalize?: boolean;
62
- resolveRefs?: boolean;
63
- }
64
- interface SiteConfigStack {
65
- stack: Partial<SiteConfigInput>[];
66
- push: (config: SiteConfigInput) => () => void;
67
- get: (options?: GetSiteConfigOptions) => SiteConfigResolved;
68
- }
69
-
70
- declare function normalizeSiteConfig(config: SiteConfigResolved): SiteConfigResolved;
71
- declare function validateSiteConfigStack(stack: SiteConfigStack): string[];
72
- declare function createSiteConfigStack(options?: {
73
- debug: boolean;
74
- }): SiteConfigStack;
75
-
76
- declare function envSiteConfig(env: Record<string, any>): {
77
- [k: string]: any;
78
- };
79
-
80
- export { createSiteConfigStack, envSiteConfig, normalizeSiteConfig, validateSiteConfigStack };
81
- export type { GetSiteConfigOptions, MaybeComputedRef, MaybeComputedRefEntries, SiteConfig, SiteConfigInput, SiteConfigResolved, SiteConfigStack };
package/dist/index.mjs DELETED
@@ -1,105 +0,0 @@
1
- import { hasProtocol, withHttps, parseURL, parseHost, getQuery } from 'ufo';
2
- import { toValue } from 'vue';
3
-
4
- function normalizeSiteConfig(config) {
5
- if (typeof config.indexable !== "undefined")
6
- config.indexable = String(config.indexable) !== "false";
7
- if (typeof config.trailingSlash !== "undefined" && !config.trailingSlash)
8
- config.trailingSlash = String(config.trailingSlash) !== "false";
9
- if (config.url && !hasProtocol(String(config.url), { acceptRelative: true, strict: false }))
10
- config.url = withHttps(String(config.url));
11
- const keys = Object.keys(config).sort((a, b) => a.localeCompare(b));
12
- const newConfig = {};
13
- for (const k of keys)
14
- newConfig[k] = config[k];
15
- return newConfig;
16
- }
17
- function validateSiteConfigStack(stack) {
18
- const resolved = normalizeSiteConfig(stack.get({
19
- // we need the context
20
- debug: true
21
- }));
22
- const errors = [];
23
- if (resolved.url) {
24
- const val = resolved.url;
25
- const context = resolved._context?.url || "unknown";
26
- const url = parseURL(val);
27
- const { hostname } = parseHost(url.host);
28
- if (!url.host)
29
- errors.push(`url "${val}" from ${context} is not absolute`);
30
- else if (url.pathname && url.pathname !== "/")
31
- errors.push(`url "${val}" from ${context} should not contain a path`);
32
- else if (url.hash)
33
- errors.push(`url "${val}" from ${context} should not contain a hash`);
34
- else if (Object.keys(getQuery(val)).length > 0)
35
- errors.push(`url "${val}" from ${context} should not contain a query`);
36
- else if (hostname === "localhost" && resolved.env !== "development")
37
- errors.push(`url "${val}" from ${context} should not be localhost`);
38
- }
39
- return errors;
40
- }
41
- function createSiteConfigStack(options) {
42
- const debug = options?.debug || false;
43
- const stack = [];
44
- function push(input) {
45
- if (!input || typeof input !== "object" || Object.keys(input).length === 0) {
46
- return () => {
47
- };
48
- }
49
- if (!input._context && debug) {
50
- let lastFunctionName = new Error("tmp").stack?.split("\n")[2]?.split(" ")[5];
51
- if (lastFunctionName?.includes("/"))
52
- lastFunctionName = "anonymous";
53
- input._context = lastFunctionName;
54
- }
55
- const entry = {};
56
- for (const k in input) {
57
- const val = input[k];
58
- if (typeof val !== "undefined" && val !== "")
59
- entry[k] = val;
60
- }
61
- let idx;
62
- if (Object.keys(entry).filter((k) => !k.startsWith("_")).length > 0)
63
- idx = stack.push(entry);
64
- return () => {
65
- if (typeof idx !== "undefined") {
66
- stack.splice(idx - 1, 1);
67
- }
68
- };
69
- }
70
- function get(options2) {
71
- const siteConfig = {};
72
- if (options2?.debug)
73
- siteConfig._context = {};
74
- siteConfig._priority = {};
75
- for (const o in stack.sort((a, b) => (a._priority || 0) - (b._priority || 0))) {
76
- for (const k in stack[o]) {
77
- const key = k;
78
- const val = options2?.resolveRefs ? toValue(stack[o][k]) : stack[o][k];
79
- if (!k.startsWith("_") && typeof val !== "undefined" && val !== "") {
80
- siteConfig[k] = val;
81
- if (typeof stack[o]._priority !== "undefined" && stack[o]._priority !== -1) {
82
- siteConfig._priority[key] = stack[o]._priority;
83
- }
84
- if (options2?.debug)
85
- siteConfig._context[key] = stack[o]._context?.[key] || stack[o]._context || "anonymous";
86
- }
87
- }
88
- }
89
- return options2?.skipNormalize ? siteConfig : normalizeSiteConfig(siteConfig);
90
- }
91
- return {
92
- stack,
93
- push,
94
- get
95
- };
96
- }
97
-
98
- function envSiteConfig(env) {
99
- return Object.fromEntries(Object.entries(env).filter(([k]) => k.startsWith("NUXT_SITE_") || k.startsWith("NUXT_PUBLIC_SITE_")).map(([k, v]) => [
100
- k.replace(/^NUXT_(PUBLIC_)?SITE_/, "").split("_").map((s, i) => i === 0 ? s.toLowerCase() : s[0]?.toUpperCase() + s.slice(1).toLowerCase()).join(""),
101
- v
102
- ]));
103
- }
104
-
105
- export { createSiteConfigStack, envSiteConfig, normalizeSiteConfig, validateSiteConfigStack };
package/dist/urls.cjs DELETED
@@ -1,150 +0,0 @@
1
- 'use strict';
2
-
3
- const ufo = require('ufo');
4
-
5
- function resolveSitePath(pathOrUrl, options) {
6
- let path = pathOrUrl;
7
- if (ufo.hasProtocol(pathOrUrl, { strict: false, acceptRelative: true })) {
8
- const parsed = ufo.parseURL(pathOrUrl);
9
- path = parsed.pathname;
10
- }
11
- const base = ufo.withLeadingSlash(options.base || "/");
12
- if (base !== "/" && path.startsWith(base)) {
13
- path = path.slice(base.length);
14
- }
15
- let origin = ufo.withoutTrailingSlash(options.absolute ? options.siteUrl : "");
16
- if (base !== "/" && origin.endsWith(base)) {
17
- origin = origin.slice(0, origin.indexOf(base));
18
- }
19
- const baseWithOrigin = options.withBase ? ufo.withBase(base, origin || "/") : origin;
20
- const resolvedUrl = ufo.withBase(path, baseWithOrigin);
21
- return path === "/" && !options.withBase ? ufo.withTrailingSlash(resolvedUrl) : fixSlashes(options.trailingSlash, resolvedUrl);
22
- }
23
- const fileExtensions = [
24
- // Images
25
- "jpg",
26
- "jpeg",
27
- "png",
28
- "gif",
29
- "bmp",
30
- "webp",
31
- "svg",
32
- "ico",
33
- // Documents
34
- "pdf",
35
- "doc",
36
- "docx",
37
- "xls",
38
- "xlsx",
39
- "ppt",
40
- "pptx",
41
- "txt",
42
- "md",
43
- "markdown",
44
- // Archives
45
- "zip",
46
- "rar",
47
- "7z",
48
- "tar",
49
- "gz",
50
- // Audio
51
- "mp3",
52
- "wav",
53
- "flac",
54
- "ogg",
55
- "opus",
56
- "m4a",
57
- "aac",
58
- "midi",
59
- "mid",
60
- // Video
61
- "mp4",
62
- "avi",
63
- "mkv",
64
- "mov",
65
- "wmv",
66
- "flv",
67
- "webm",
68
- // Web
69
- "html",
70
- "css",
71
- "js",
72
- "json",
73
- "xml",
74
- "tsx",
75
- "jsx",
76
- "ts",
77
- "vue",
78
- "svelte",
79
- "xsl",
80
- "rss",
81
- "atom",
82
- // Programming
83
- "php",
84
- "py",
85
- "rb",
86
- "java",
87
- "c",
88
- "cpp",
89
- "h",
90
- "go",
91
- // Data formats
92
- "csv",
93
- "tsv",
94
- "sql",
95
- "yaml",
96
- "yml",
97
- // Fonts
98
- "woff",
99
- "woff2",
100
- "ttf",
101
- "otf",
102
- "eot",
103
- // Executables/Binaries
104
- "exe",
105
- "msi",
106
- "apk",
107
- "ipa",
108
- "dmg",
109
- "iso",
110
- "bin",
111
- // Scripts/Config
112
- "bat",
113
- "cmd",
114
- "sh",
115
- "env",
116
- "htaccess",
117
- "conf",
118
- "toml",
119
- "ini",
120
- // Package formats
121
- "deb",
122
- "rpm",
123
- "jar",
124
- "war",
125
- // E-books
126
- "epub",
127
- "mobi",
128
- // Common temporary/backup files
129
- "log",
130
- "tmp",
131
- "bak",
132
- "old",
133
- "sav"
134
- ];
135
- function isPathFile(path) {
136
- const lastSegment = path.split("/").pop();
137
- const ext = (lastSegment || path).match(/\.[0-9a-z]+$/i)?.[0];
138
- return ext && fileExtensions.includes(ext.replace(".", ""));
139
- }
140
- function fixSlashes(trailingSlash, pathOrUrl) {
141
- const $url = ufo.parseURL(pathOrUrl);
142
- if (isPathFile($url.pathname))
143
- return pathOrUrl;
144
- const fixedPath = trailingSlash ? ufo.withTrailingSlash($url.pathname) : ufo.withoutTrailingSlash($url.pathname);
145
- return `${$url.protocol ? `${$url.protocol}//` : ""}${$url.host || ""}${fixedPath}${$url.search || ""}${$url.hash || ""}`;
146
- }
147
-
148
- exports.fixSlashes = fixSlashes;
149
- exports.isPathFile = isPathFile;
150
- exports.resolveSitePath = resolveSitePath;
package/dist/urls.d.cts DELETED
@@ -1,11 +0,0 @@
1
- declare function resolveSitePath(pathOrUrl: string, options: {
2
- siteUrl: string;
3
- trailingSlash?: boolean;
4
- base?: string;
5
- absolute?: boolean;
6
- withBase?: boolean;
7
- }): string;
8
- declare function isPathFile(path: string): boolean | "" | undefined;
9
- declare function fixSlashes(trailingSlash: boolean | undefined, pathOrUrl: string): string;
10
-
11
- export { fixSlashes, isPathFile, resolveSitePath };
package/dist/urls.d.mts DELETED
@@ -1,11 +0,0 @@
1
- declare function resolveSitePath(pathOrUrl: string, options: {
2
- siteUrl: string;
3
- trailingSlash?: boolean;
4
- base?: string;
5
- absolute?: boolean;
6
- withBase?: boolean;
7
- }): string;
8
- declare function isPathFile(path: string): boolean | "" | undefined;
9
- declare function fixSlashes(trailingSlash: boolean | undefined, pathOrUrl: string): string;
10
-
11
- export { fixSlashes, isPathFile, resolveSitePath };
package/dist/urls.d.ts DELETED
@@ -1,11 +0,0 @@
1
- declare function resolveSitePath(pathOrUrl: string, options: {
2
- siteUrl: string;
3
- trailingSlash?: boolean;
4
- base?: string;
5
- absolute?: boolean;
6
- withBase?: boolean;
7
- }): string;
8
- declare function isPathFile(path: string): boolean | "" | undefined;
9
- declare function fixSlashes(trailingSlash: boolean | undefined, pathOrUrl: string): string;
10
-
11
- export { fixSlashes, isPathFile, resolveSitePath };
package/dist/urls.mjs DELETED
@@ -1,146 +0,0 @@
1
- import { hasProtocol, parseURL, withLeadingSlash, withoutTrailingSlash, withBase, withTrailingSlash } from 'ufo';
2
-
3
- function resolveSitePath(pathOrUrl, options) {
4
- let path = pathOrUrl;
5
- if (hasProtocol(pathOrUrl, { strict: false, acceptRelative: true })) {
6
- const parsed = parseURL(pathOrUrl);
7
- path = parsed.pathname;
8
- }
9
- const base = withLeadingSlash(options.base || "/");
10
- if (base !== "/" && path.startsWith(base)) {
11
- path = path.slice(base.length);
12
- }
13
- let origin = withoutTrailingSlash(options.absolute ? options.siteUrl : "");
14
- if (base !== "/" && origin.endsWith(base)) {
15
- origin = origin.slice(0, origin.indexOf(base));
16
- }
17
- const baseWithOrigin = options.withBase ? withBase(base, origin || "/") : origin;
18
- const resolvedUrl = withBase(path, baseWithOrigin);
19
- return path === "/" && !options.withBase ? withTrailingSlash(resolvedUrl) : fixSlashes(options.trailingSlash, resolvedUrl);
20
- }
21
- const fileExtensions = [
22
- // Images
23
- "jpg",
24
- "jpeg",
25
- "png",
26
- "gif",
27
- "bmp",
28
- "webp",
29
- "svg",
30
- "ico",
31
- // Documents
32
- "pdf",
33
- "doc",
34
- "docx",
35
- "xls",
36
- "xlsx",
37
- "ppt",
38
- "pptx",
39
- "txt",
40
- "md",
41
- "markdown",
42
- // Archives
43
- "zip",
44
- "rar",
45
- "7z",
46
- "tar",
47
- "gz",
48
- // Audio
49
- "mp3",
50
- "wav",
51
- "flac",
52
- "ogg",
53
- "opus",
54
- "m4a",
55
- "aac",
56
- "midi",
57
- "mid",
58
- // Video
59
- "mp4",
60
- "avi",
61
- "mkv",
62
- "mov",
63
- "wmv",
64
- "flv",
65
- "webm",
66
- // Web
67
- "html",
68
- "css",
69
- "js",
70
- "json",
71
- "xml",
72
- "tsx",
73
- "jsx",
74
- "ts",
75
- "vue",
76
- "svelte",
77
- "xsl",
78
- "rss",
79
- "atom",
80
- // Programming
81
- "php",
82
- "py",
83
- "rb",
84
- "java",
85
- "c",
86
- "cpp",
87
- "h",
88
- "go",
89
- // Data formats
90
- "csv",
91
- "tsv",
92
- "sql",
93
- "yaml",
94
- "yml",
95
- // Fonts
96
- "woff",
97
- "woff2",
98
- "ttf",
99
- "otf",
100
- "eot",
101
- // Executables/Binaries
102
- "exe",
103
- "msi",
104
- "apk",
105
- "ipa",
106
- "dmg",
107
- "iso",
108
- "bin",
109
- // Scripts/Config
110
- "bat",
111
- "cmd",
112
- "sh",
113
- "env",
114
- "htaccess",
115
- "conf",
116
- "toml",
117
- "ini",
118
- // Package formats
119
- "deb",
120
- "rpm",
121
- "jar",
122
- "war",
123
- // E-books
124
- "epub",
125
- "mobi",
126
- // Common temporary/backup files
127
- "log",
128
- "tmp",
129
- "bak",
130
- "old",
131
- "sav"
132
- ];
133
- function isPathFile(path) {
134
- const lastSegment = path.split("/").pop();
135
- const ext = (lastSegment || path).match(/\.[0-9a-z]+$/i)?.[0];
136
- return ext && fileExtensions.includes(ext.replace(".", ""));
137
- }
138
- function fixSlashes(trailingSlash, pathOrUrl) {
139
- const $url = parseURL(pathOrUrl);
140
- if (isPathFile($url.pathname))
141
- return pathOrUrl;
142
- const fixedPath = trailingSlash ? withTrailingSlash($url.pathname) : withoutTrailingSlash($url.pathname);
143
- return `${$url.protocol ? `${$url.protocol}//` : ""}${$url.host || ""}${fixedPath}${$url.search || ""}${$url.hash || ""}`;
144
- }
145
-
146
- export { fixSlashes, isPathFile, resolveSitePath };