@json-to-office/jto 0.8.2 → 0.8.3

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.js CHANGED
@@ -8,6 +8,10 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
8
8
  // src/format-adapter.ts
9
9
  import * as path from "path";
10
10
  import * as fs from "fs";
11
+ var UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
12
+ function safeThemeKey(name) {
13
+ return name && !UNSAFE_KEYS.has(name) ? name : "custom";
14
+ }
11
15
  function buildServicesFromEnv() {
12
16
  const serverUrl = process.env.HIGHCHARTS_SERVER_URL;
13
17
  const apiKey = process.env.HIGHCHARTS_API_KEY;
@@ -144,16 +148,20 @@ ${errors.map((e) => ` - ${e.path}: ${e.message}`).join("\n")}`
144
148
  Object.assign(customThemes, options.customThemes);
145
149
  }
146
150
  if (typeof options.theme === "object" && options.theme !== null) {
147
- customThemes.custom = options.theme;
151
+ customThemes[safeThemeKey(options.theme.name)] = options.theme;
148
152
  }
149
153
  if (options.themePath) {
150
154
  try {
155
+ let theme;
151
156
  if (options.themePath.endsWith(".json")) {
152
- customThemes.custom = await core.loadThemeFromFile(options.themePath);
157
+ theme = await core.loadThemeFromFile(options.themePath);
153
158
  } else {
154
159
  const themePath = path.resolve(process.cwd(), options.themePath);
155
160
  const themeModule = await import(themePath);
156
- customThemes.custom = themeModule.default || themeModule.theme;
161
+ theme = themeModule.default || themeModule.theme;
162
+ }
163
+ if (theme) {
164
+ customThemes[safeThemeKey(theme.name)] = theme;
157
165
  }
158
166
  } catch (error) {
159
167
  console.warn(
@@ -363,20 +371,24 @@ ${errors.map((e) => ` - ${e.path}: ${e.message}`).join("\n")}`
363
371
  Object.assign(customThemes, options.customThemes);
364
372
  }
365
373
  if (typeof options.theme === "object" && options.theme !== null) {
366
- customThemes.custom = options.theme;
374
+ customThemes[safeThemeKey(options.theme.name)] = options.theme;
367
375
  }
368
376
  if (options.themePath) {
369
377
  try {
378
+ let theme;
370
379
  if (options.themePath.endsWith(".json")) {
371
380
  const content = fs.readFileSync(
372
381
  path.resolve(process.cwd(), options.themePath),
373
382
  "utf-8"
374
383
  );
375
- customThemes.custom = JSON.parse(content);
384
+ theme = JSON.parse(content);
376
385
  } else {
377
386
  const themePath = path.resolve(process.cwd(), options.themePath);
378
387
  const themeModule = await import(themePath);
379
- customThemes.custom = themeModule.default || themeModule.theme;
388
+ theme = themeModule.default || themeModule.theme;
389
+ }
390
+ if (theme) {
391
+ customThemes[safeThemeKey(theme.name)] = theme;
380
392
  }
381
393
  } catch (error) {
382
394
  console.warn(