site-config-stack 3.0.6 → 3.1.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/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Harlan Wilton
3
+ Copyright (c) 2023-Present - Harlan Wilton
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
6
 
package/dist/index.cjs CHANGED
@@ -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
@@ -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.6",
4
+ "version": "3.1.0",
5
5
  "description": "Shared site configuration utilities.",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",
@@ -45,7 +45,7 @@
45
45
  "ufo": "^1.5.4"
46
46
  },
47
47
  "devDependencies": {
48
- "vue": "^3.5.12"
48
+ "vue": "^3.5.13"
49
49
  },
50
50
  "scripts": {
51
51
  "lint": "eslint . --fix",