site-config-stack 1.2.3 → 1.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/index.cjs CHANGED
@@ -2,18 +2,26 @@
2
2
 
3
3
  const ufo = require('ufo');
4
4
 
5
- function createSiteConfigStack() {
5
+ function createSiteConfigStack(options) {
6
+ const debug = options?.debug || false;
6
7
  const stack = [];
7
8
  function push(input) {
8
9
  if (!input || typeof input !== "object" || Object.keys(input).length === 0)
9
10
  return;
10
- if (!input._context) {
11
+ if (!input._context && debug) {
11
12
  let lastFunctionName = new Error("tmp").stack?.split("\n")[2].split(" ")[5];
12
13
  if (lastFunctionName?.includes("/"))
13
14
  lastFunctionName = "anonymous";
14
15
  input._context = lastFunctionName;
15
16
  }
16
- stack.push(input);
17
+ const entry = {};
18
+ for (const k in input) {
19
+ const val = input[k];
20
+ if (typeof val !== "undefined" && val !== "")
21
+ entry[k] = val;
22
+ }
23
+ if (Object.keys(entry).filter((k) => !k.startsWith("_")).length > 0)
24
+ stack.push(entry);
17
25
  }
18
26
  function get() {
19
27
  const siteConfig = {
@@ -23,7 +31,7 @@ function createSiteConfigStack() {
23
31
  for (const k in stack[o]) {
24
32
  const key = k;
25
33
  const val = stack[o][k];
26
- if (!k.startsWith("_") && typeof val !== "undefined" && val !== "") {
34
+ if (!k.startsWith("_")) {
27
35
  siteConfig[k] = val;
28
36
  siteConfig._context[key] = stack[o]._context?.[key] || stack[o]._context || "anonymous";
29
37
  }
@@ -45,7 +53,11 @@ function normalizeSiteConfig(config) {
45
53
  config.trailingSlash = String(config.trailingSlash) !== "false";
46
54
  if (config.url && !ufo.hasProtocol(config.url, { acceptRelative: true, strict: false }))
47
55
  config.url = ufo.withHttps(config.url);
48
- return config;
56
+ const keys = Object.keys(config).sort((a, b) => a.localeCompare(b));
57
+ const newConfig = {};
58
+ for (const k of keys)
59
+ newConfig[k] = config[k];
60
+ return newConfig;
49
61
  }
50
62
  function resolveSitePath(pathOrUrl, options) {
51
63
  let path = pathOrUrl;
@@ -53,7 +65,7 @@ function resolveSitePath(pathOrUrl, options) {
53
65
  const parsed = ufo.parseURL(pathOrUrl);
54
66
  path = parsed.pathname;
55
67
  }
56
- const base = ufo.withLeadingSlash(options.base);
68
+ const base = ufo.withLeadingSlash(options.base || "/");
57
69
  if (base !== "/" && path.startsWith(base)) {
58
70
  path = path.slice(base.length);
59
71
  }
package/dist/index.d.cts CHANGED
@@ -1,3 +1,5 @@
1
+ import { ComputedRef, Ref } from 'vue';
2
+
1
3
  interface SiteConfig {
2
4
  /**
3
5
  * The canonical Site URL.
@@ -68,10 +70,14 @@ interface SiteConfig {
68
70
  _context: Partial<Record<Exclude<keyof SiteConfig, '_meta'>, string>>;
69
71
  [key: (string & Record<never, never>)]: any;
70
72
  }
71
- type SiteConfigInput = Partial<Omit<SiteConfig, '_context' | 'indexable'>> & {
73
+ type MaybeComputedRef<T> = T | (() => T) | ComputedRef<T> | Ref<T>;
74
+ type MaybeComputedRefEntries<T> = {
75
+ [key in keyof T]?: MaybeComputedRef<T[key]>;
76
+ };
77
+ type SiteConfigInput = Omit<MaybeComputedRefEntries<Partial<SiteConfig>>, '_context' | 'indexable'> & {
72
78
  _context?: string;
73
79
  _priority?: number;
74
- indexable?: string | boolean;
80
+ indexable?: MaybeComputedRef<string | boolean>;
75
81
  };
76
82
  interface SiteConfigStack {
77
83
  stack: Partial<SiteConfigInput>[];
@@ -79,16 +85,18 @@ interface SiteConfigStack {
79
85
  get: () => SiteConfig;
80
86
  }
81
87
 
82
- declare function createSiteConfigStack(): SiteConfigStack;
88
+ declare function createSiteConfigStack(options?: {
89
+ debug: boolean;
90
+ }): SiteConfigStack;
83
91
 
84
92
  declare function normalizeSiteConfig(config: SiteConfig): SiteConfig;
85
93
  declare function resolveSitePath(pathOrUrl: string, options: {
86
94
  siteUrl: string;
87
95
  trailingSlash: boolean;
88
- base: string;
96
+ base?: string;
89
97
  absolute?: boolean;
90
98
  withBase?: boolean;
91
99
  }): string;
92
100
  declare function fixSlashes(trailingSlash: boolean, pathOrUrl: string): string;
93
101
 
94
- export { type SiteConfig, type SiteConfigInput, type SiteConfigStack, createSiteConfigStack, fixSlashes, normalizeSiteConfig, resolveSitePath };
102
+ export { type MaybeComputedRef, type MaybeComputedRefEntries, type SiteConfig, type SiteConfigInput, type SiteConfigStack, createSiteConfigStack, fixSlashes, normalizeSiteConfig, resolveSitePath };
package/dist/index.d.mts CHANGED
@@ -1,3 +1,5 @@
1
+ import { ComputedRef, Ref } from 'vue';
2
+
1
3
  interface SiteConfig {
2
4
  /**
3
5
  * The canonical Site URL.
@@ -68,10 +70,14 @@ interface SiteConfig {
68
70
  _context: Partial<Record<Exclude<keyof SiteConfig, '_meta'>, string>>;
69
71
  [key: (string & Record<never, never>)]: any;
70
72
  }
71
- type SiteConfigInput = Partial<Omit<SiteConfig, '_context' | 'indexable'>> & {
73
+ type MaybeComputedRef<T> = T | (() => T) | ComputedRef<T> | Ref<T>;
74
+ type MaybeComputedRefEntries<T> = {
75
+ [key in keyof T]?: MaybeComputedRef<T[key]>;
76
+ };
77
+ type SiteConfigInput = Omit<MaybeComputedRefEntries<Partial<SiteConfig>>, '_context' | 'indexable'> & {
72
78
  _context?: string;
73
79
  _priority?: number;
74
- indexable?: string | boolean;
80
+ indexable?: MaybeComputedRef<string | boolean>;
75
81
  };
76
82
  interface SiteConfigStack {
77
83
  stack: Partial<SiteConfigInput>[];
@@ -79,16 +85,18 @@ interface SiteConfigStack {
79
85
  get: () => SiteConfig;
80
86
  }
81
87
 
82
- declare function createSiteConfigStack(): SiteConfigStack;
88
+ declare function createSiteConfigStack(options?: {
89
+ debug: boolean;
90
+ }): SiteConfigStack;
83
91
 
84
92
  declare function normalizeSiteConfig(config: SiteConfig): SiteConfig;
85
93
  declare function resolveSitePath(pathOrUrl: string, options: {
86
94
  siteUrl: string;
87
95
  trailingSlash: boolean;
88
- base: string;
96
+ base?: string;
89
97
  absolute?: boolean;
90
98
  withBase?: boolean;
91
99
  }): string;
92
100
  declare function fixSlashes(trailingSlash: boolean, pathOrUrl: string): string;
93
101
 
94
- export { type SiteConfig, type SiteConfigInput, type SiteConfigStack, createSiteConfigStack, fixSlashes, normalizeSiteConfig, resolveSitePath };
102
+ export { type MaybeComputedRef, type MaybeComputedRefEntries, type SiteConfig, type SiteConfigInput, type SiteConfigStack, createSiteConfigStack, fixSlashes, normalizeSiteConfig, resolveSitePath };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { ComputedRef, Ref } from 'vue';
2
+
1
3
  interface SiteConfig {
2
4
  /**
3
5
  * The canonical Site URL.
@@ -68,10 +70,14 @@ interface SiteConfig {
68
70
  _context: Partial<Record<Exclude<keyof SiteConfig, '_meta'>, string>>;
69
71
  [key: (string & Record<never, never>)]: any;
70
72
  }
71
- type SiteConfigInput = Partial<Omit<SiteConfig, '_context' | 'indexable'>> & {
73
+ type MaybeComputedRef<T> = T | (() => T) | ComputedRef<T> | Ref<T>;
74
+ type MaybeComputedRefEntries<T> = {
75
+ [key in keyof T]?: MaybeComputedRef<T[key]>;
76
+ };
77
+ type SiteConfigInput = Omit<MaybeComputedRefEntries<Partial<SiteConfig>>, '_context' | 'indexable'> & {
72
78
  _context?: string;
73
79
  _priority?: number;
74
- indexable?: string | boolean;
80
+ indexable?: MaybeComputedRef<string | boolean>;
75
81
  };
76
82
  interface SiteConfigStack {
77
83
  stack: Partial<SiteConfigInput>[];
@@ -79,16 +85,18 @@ interface SiteConfigStack {
79
85
  get: () => SiteConfig;
80
86
  }
81
87
 
82
- declare function createSiteConfigStack(): SiteConfigStack;
88
+ declare function createSiteConfigStack(options?: {
89
+ debug: boolean;
90
+ }): SiteConfigStack;
83
91
 
84
92
  declare function normalizeSiteConfig(config: SiteConfig): SiteConfig;
85
93
  declare function resolveSitePath(pathOrUrl: string, options: {
86
94
  siteUrl: string;
87
95
  trailingSlash: boolean;
88
- base: string;
96
+ base?: string;
89
97
  absolute?: boolean;
90
98
  withBase?: boolean;
91
99
  }): string;
92
100
  declare function fixSlashes(trailingSlash: boolean, pathOrUrl: string): string;
93
101
 
94
- export { type SiteConfig, type SiteConfigInput, type SiteConfigStack, createSiteConfigStack, fixSlashes, normalizeSiteConfig, resolveSitePath };
102
+ export { type MaybeComputedRef, type MaybeComputedRefEntries, type SiteConfig, type SiteConfigInput, type SiteConfigStack, createSiteConfigStack, fixSlashes, normalizeSiteConfig, resolveSitePath };
package/dist/index.mjs CHANGED
@@ -1,17 +1,25 @@
1
1
  import { hasProtocol, withHttps, parseURL, withLeadingSlash, withBase, withTrailingSlash, withoutTrailingSlash } from 'ufo';
2
2
 
3
- function createSiteConfigStack() {
3
+ function createSiteConfigStack(options) {
4
+ const debug = options?.debug || false;
4
5
  const stack = [];
5
6
  function push(input) {
6
7
  if (!input || typeof input !== "object" || Object.keys(input).length === 0)
7
8
  return;
8
- if (!input._context) {
9
+ if (!input._context && debug) {
9
10
  let lastFunctionName = new Error("tmp").stack?.split("\n")[2].split(" ")[5];
10
11
  if (lastFunctionName?.includes("/"))
11
12
  lastFunctionName = "anonymous";
12
13
  input._context = lastFunctionName;
13
14
  }
14
- stack.push(input);
15
+ const entry = {};
16
+ for (const k in input) {
17
+ const val = input[k];
18
+ if (typeof val !== "undefined" && val !== "")
19
+ entry[k] = val;
20
+ }
21
+ if (Object.keys(entry).filter((k) => !k.startsWith("_")).length > 0)
22
+ stack.push(entry);
15
23
  }
16
24
  function get() {
17
25
  const siteConfig = {
@@ -21,7 +29,7 @@ function createSiteConfigStack() {
21
29
  for (const k in stack[o]) {
22
30
  const key = k;
23
31
  const val = stack[o][k];
24
- if (!k.startsWith("_") && typeof val !== "undefined" && val !== "") {
32
+ if (!k.startsWith("_")) {
25
33
  siteConfig[k] = val;
26
34
  siteConfig._context[key] = stack[o]._context?.[key] || stack[o]._context || "anonymous";
27
35
  }
@@ -43,7 +51,11 @@ function normalizeSiteConfig(config) {
43
51
  config.trailingSlash = String(config.trailingSlash) !== "false";
44
52
  if (config.url && !hasProtocol(config.url, { acceptRelative: true, strict: false }))
45
53
  config.url = withHttps(config.url);
46
- return config;
54
+ const keys = Object.keys(config).sort((a, b) => a.localeCompare(b));
55
+ const newConfig = {};
56
+ for (const k of keys)
57
+ newConfig[k] = config[k];
58
+ return newConfig;
47
59
  }
48
60
  function resolveSitePath(pathOrUrl, options) {
49
61
  let path = pathOrUrl;
@@ -51,7 +63,7 @@ function resolveSitePath(pathOrUrl, options) {
51
63
  const parsed = parseURL(pathOrUrl);
52
64
  path = parsed.pathname;
53
65
  }
54
- const base = withLeadingSlash(options.base);
66
+ const base = withLeadingSlash(options.base || "/");
55
67
  if (base !== "/" && path.startsWith(base)) {
56
68
  path = path.slice(base.length);
57
69
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "site-config-stack",
3
3
  "type": "module",
4
- "version": "1.2.3",
5
- "description": "Shared site configuration utilities.",
4
+ "version": "1.4.0",
5
+ "description": "Shared site configuration utilities.",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",
8
8
  "homepage": "https://github.com/harlan-zw/nuxt-site-config#readme",
@@ -26,8 +26,14 @@
26
26
  "files": [
27
27
  "dist"
28
28
  ],
29
+ "peerDependencies": {
30
+ "vue": "^3"
31
+ },
29
32
  "dependencies": {
30
- "ufo": "^1.3.0"
33
+ "ufo": "^1.3.1"
34
+ },
35
+ "devDependencies": {
36
+ "vue": "^3.3.4"
31
37
  },
32
38
  "scripts": {
33
39
  "lint": "eslint . --fix",