site-config-stack 4.2.0 → 4.2.2

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
@@ -109,12 +109,23 @@ function createSiteConfigStack(options) {
109
109
  };
110
110
  }
111
111
 
112
- const NUXT_SITE_ENV_RE = /^NUXT_(PUBLIC_)?SITE_/;
112
+ const NUXT_SITE_PREFIX = "NUXT_SITE_";
113
+ const NUXT_PUBLIC_SITE_PREFIX = "NUXT_PUBLIC_SITE_";
113
114
  function envSiteConfig(env = {}) {
114
- return Object.fromEntries(Object.entries(env).filter(([k]) => k.startsWith("NUXT_SITE_") || k.startsWith("NUXT_PUBLIC_SITE_")).map(([k, v]) => [
115
- k.replace(NUXT_SITE_ENV_RE, "").split("_").map((s, i) => i === 0 ? s.toLowerCase() : s[0]?.toUpperCase() + s.slice(1).toLowerCase()).join(""),
116
- v
117
- ]));
115
+ const config = {};
116
+ for (const key of Object.keys(env)) {
117
+ const prefixLength = key.startsWith(NUXT_SITE_PREFIX) ? NUXT_SITE_PREFIX.length : key.startsWith(NUXT_PUBLIC_SITE_PREFIX) ? NUXT_PUBLIC_SITE_PREFIX.length : 0;
118
+ if (!prefixLength)
119
+ continue;
120
+ const segments = key.slice(prefixLength).split("_");
121
+ let configKey = segments[0].toLowerCase();
122
+ for (let i = 1; i < segments.length; i++) {
123
+ const segment = segments[i];
124
+ configKey += segment[0]?.toUpperCase() + segment.slice(1).toLowerCase();
125
+ }
126
+ config[configKey] = env[key];
127
+ }
128
+ return config;
118
129
  }
119
130
 
120
131
  exports.SiteConfigPriority = SiteConfigPriority;
package/dist/index.mjs CHANGED
@@ -107,12 +107,23 @@ function createSiteConfigStack(options) {
107
107
  };
108
108
  }
109
109
 
110
- const NUXT_SITE_ENV_RE = /^NUXT_(PUBLIC_)?SITE_/;
110
+ const NUXT_SITE_PREFIX = "NUXT_SITE_";
111
+ const NUXT_PUBLIC_SITE_PREFIX = "NUXT_PUBLIC_SITE_";
111
112
  function envSiteConfig(env = {}) {
112
- return Object.fromEntries(Object.entries(env).filter(([k]) => k.startsWith("NUXT_SITE_") || k.startsWith("NUXT_PUBLIC_SITE_")).map(([k, v]) => [
113
- k.replace(NUXT_SITE_ENV_RE, "").split("_").map((s, i) => i === 0 ? s.toLowerCase() : s[0]?.toUpperCase() + s.slice(1).toLowerCase()).join(""),
114
- v
115
- ]));
113
+ const config = {};
114
+ for (const key of Object.keys(env)) {
115
+ const prefixLength = key.startsWith(NUXT_SITE_PREFIX) ? NUXT_SITE_PREFIX.length : key.startsWith(NUXT_PUBLIC_SITE_PREFIX) ? NUXT_PUBLIC_SITE_PREFIX.length : 0;
116
+ if (!prefixLength)
117
+ continue;
118
+ const segments = key.slice(prefixLength).split("_");
119
+ let configKey = segments[0].toLowerCase();
120
+ for (let i = 1; i < segments.length; i++) {
121
+ const segment = segments[i];
122
+ configKey += segment[0]?.toUpperCase() + segment.slice(1).toLowerCase();
123
+ }
124
+ config[configKey] = env[key];
125
+ }
126
+ return config;
116
127
  }
117
128
 
118
129
  export { SiteConfigPriority, createSiteConfigStack, envSiteConfig, normalizeSiteConfig, validateSiteConfigStack };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "site-config-stack",
3
3
  "type": "module",
4
- "version": "4.2.0",
4
+ "version": "4.2.2",
5
5
  "description": "Shared site configuration utilities.",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",