site-config-stack 3.0.7 → 3.1.1

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
@@ -8,8 +8,8 @@ function normalizeSiteConfig(config) {
8
8
  config.indexable = String(config.indexable) !== "false";
9
9
  if (typeof config.trailingSlash !== "undefined" && !config.trailingSlash)
10
10
  config.trailingSlash = String(config.trailingSlash) !== "false";
11
- if (config.url && !ufo.hasProtocol(config.url, { acceptRelative: true, strict: false }))
12
- config.url = ufo.withHttps(config.url);
11
+ if (config.url && !ufo.hasProtocol(String(config.url), { acceptRelative: true, strict: false }))
12
+ config.url = ufo.withHttps(String(config.url));
13
13
  const keys = Object.keys(config).sort((a, b) => a.localeCompare(b));
14
14
  const newConfig = {};
15
15
  for (const k of keys)
@@ -43,8 +43,10 @@ function createSiteConfigStack(options) {
43
43
  const debug = options?.debug || false;
44
44
  const stack = [];
45
45
  function push(input) {
46
- if (!input || typeof input !== "object" || Object.keys(input).length === 0)
47
- return;
46
+ if (!input || typeof input !== "object" || Object.keys(input).length === 0) {
47
+ return () => {
48
+ };
49
+ }
48
50
  if (!input._context && debug) {
49
51
  let lastFunctionName = new Error("tmp").stack?.split("\n")[2].split(" ")[5];
50
52
  if (lastFunctionName?.includes("/"))
@@ -57,19 +59,29 @@ function createSiteConfigStack(options) {
57
59
  if (typeof val !== "undefined" && val !== "")
58
60
  entry[k] = val;
59
61
  }
62
+ let idx;
60
63
  if (Object.keys(entry).filter((k) => !k.startsWith("_")).length > 0)
61
- stack.push(entry);
64
+ idx = stack.push(entry);
65
+ return () => {
66
+ if (typeof idx !== "undefined") {
67
+ stack.splice(idx - 1, 1);
68
+ }
69
+ };
62
70
  }
63
71
  function get(options2) {
64
72
  const siteConfig = {};
65
73
  if (options2?.debug)
66
74
  siteConfig._context = {};
75
+ siteConfig._priority = {};
67
76
  for (const o in stack.sort((a, b) => (a._priority || 0) - (b._priority || 0))) {
68
77
  for (const k in stack[o]) {
69
78
  const key = k;
70
79
  const val = options2?.resolveRefs ? vue.toValue(stack[o][k]) : stack[o][k];
71
80
  if (!k.startsWith("_") && typeof val !== "undefined") {
72
81
  siteConfig[k] = val;
82
+ if (typeof stack[o]._priority !== "undefined" && stack[o]._priority !== -1) {
83
+ siteConfig._priority[key] = stack[o]._priority;
84
+ }
73
85
  if (options2?.debug)
74
86
  siteConfig._context[key] = stack[o]._context?.[key] || stack[o]._context || "anonymous";
75
87
  }
package/dist/index.d.cts CHANGED
@@ -63,7 +63,7 @@ interface GetSiteConfigOptions {
63
63
  }
64
64
  interface SiteConfigStack {
65
65
  stack: Partial<SiteConfigInput>[];
66
- push: (config: SiteConfigInput) => void;
66
+ push: (config: SiteConfigInput) => () => void;
67
67
  get: (options?: GetSiteConfigOptions) => SiteConfigResolved;
68
68
  }
69
69
 
package/dist/index.d.mts CHANGED
@@ -63,7 +63,7 @@ interface GetSiteConfigOptions {
63
63
  }
64
64
  interface SiteConfigStack {
65
65
  stack: Partial<SiteConfigInput>[];
66
- push: (config: SiteConfigInput) => void;
66
+ push: (config: SiteConfigInput) => () => void;
67
67
  get: (options?: GetSiteConfigOptions) => SiteConfigResolved;
68
68
  }
69
69
 
package/dist/index.d.ts CHANGED
@@ -63,7 +63,7 @@ interface GetSiteConfigOptions {
63
63
  }
64
64
  interface SiteConfigStack {
65
65
  stack: Partial<SiteConfigInput>[];
66
- push: (config: SiteConfigInput) => void;
66
+ push: (config: SiteConfigInput) => () => void;
67
67
  get: (options?: GetSiteConfigOptions) => SiteConfigResolved;
68
68
  }
69
69
 
package/dist/index.mjs CHANGED
@@ -6,8 +6,8 @@ function normalizeSiteConfig(config) {
6
6
  config.indexable = String(config.indexable) !== "false";
7
7
  if (typeof config.trailingSlash !== "undefined" && !config.trailingSlash)
8
8
  config.trailingSlash = String(config.trailingSlash) !== "false";
9
- if (config.url && !hasProtocol(config.url, { acceptRelative: true, strict: false }))
10
- config.url = withHttps(config.url);
9
+ if (config.url && !hasProtocol(String(config.url), { acceptRelative: true, strict: false }))
10
+ config.url = withHttps(String(config.url));
11
11
  const keys = Object.keys(config).sort((a, b) => a.localeCompare(b));
12
12
  const newConfig = {};
13
13
  for (const k of keys)
@@ -41,8 +41,10 @@ function createSiteConfigStack(options) {
41
41
  const debug = options?.debug || false;
42
42
  const stack = [];
43
43
  function push(input) {
44
- if (!input || typeof input !== "object" || Object.keys(input).length === 0)
45
- return;
44
+ if (!input || typeof input !== "object" || Object.keys(input).length === 0) {
45
+ return () => {
46
+ };
47
+ }
46
48
  if (!input._context && debug) {
47
49
  let lastFunctionName = new Error("tmp").stack?.split("\n")[2].split(" ")[5];
48
50
  if (lastFunctionName?.includes("/"))
@@ -55,19 +57,29 @@ function createSiteConfigStack(options) {
55
57
  if (typeof val !== "undefined" && val !== "")
56
58
  entry[k] = val;
57
59
  }
60
+ let idx;
58
61
  if (Object.keys(entry).filter((k) => !k.startsWith("_")).length > 0)
59
- stack.push(entry);
62
+ idx = stack.push(entry);
63
+ return () => {
64
+ if (typeof idx !== "undefined") {
65
+ stack.splice(idx - 1, 1);
66
+ }
67
+ };
60
68
  }
61
69
  function get(options2) {
62
70
  const siteConfig = {};
63
71
  if (options2?.debug)
64
72
  siteConfig._context = {};
73
+ siteConfig._priority = {};
65
74
  for (const o in stack.sort((a, b) => (a._priority || 0) - (b._priority || 0))) {
66
75
  for (const k in stack[o]) {
67
76
  const key = k;
68
77
  const val = options2?.resolveRefs ? toValue(stack[o][k]) : stack[o][k];
69
78
  if (!k.startsWith("_") && typeof val !== "undefined") {
70
79
  siteConfig[k] = val;
80
+ if (typeof stack[o]._priority !== "undefined" && stack[o]._priority !== -1) {
81
+ siteConfig._priority[key] = stack[o]._priority;
82
+ }
71
83
  if (options2?.debug)
72
84
  siteConfig._context[key] = stack[o]._context?.[key] || stack[o]._context || "anonymous";
73
85
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "site-config-stack",
3
3
  "type": "module",
4
- "version": "3.0.7",
4
+ "version": "3.1.1",
5
5
  "description": "Shared site configuration utilities.",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",