@scalar/core 0.4.3 → 0.4.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @scalar/core
2
2
 
3
+ ## 0.4.5
4
+
5
+ ## 0.4.4
6
+
7
+ ### Patch Changes
8
+
9
+ - [#8466](https://github.com/scalar/scalar/pull/8466): chore: new build pipeline
10
+
3
11
  ## 0.4.3
4
12
 
5
13
  ### Patch Changes
@@ -1,42 +1,59 @@
1
+ /**
2
+ * Helper function to add consistent indentation to multiline strings
3
+ * @param str The string to indent
4
+ * @param spaces Number of spaces for each level
5
+ * @param initialIndent Whether to indent the first line
6
+ */
1
7
  const addIndent = (str, spaces = 2, initialIndent = false) => {
2
- const indent = " ".repeat(spaces);
3
- const lines = str.split("\n");
4
- return lines.map((line, index) => {
5
- if (index === 0 && !initialIndent) {
6
- return line;
7
- }
8
- return `${indent}${line}`;
9
- }).join("\n");
8
+ const indent = ' '.repeat(spaces);
9
+ const lines = str.split('\n');
10
+ return lines
11
+ .map((line, index) => {
12
+ if (index === 0 && !initialIndent) {
13
+ return line;
14
+ }
15
+ return `${indent}${line}`;
16
+ })
17
+ .join('\n');
10
18
  };
19
+ /**
20
+ * Generate the style tag with custom theme if needed
21
+ */
11
22
  const getStyles = (configuration, customTheme) => {
12
- const styles = [];
13
- if (configuration.customCss) {
14
- styles.push("/* Custom CSS */");
15
- styles.push(configuration.customCss);
16
- }
17
- if (!configuration.theme && customTheme) {
18
- styles.push("/* Custom Theme */");
19
- styles.push(customTheme);
20
- }
21
- if (styles.length === 0) {
22
- return "";
23
- }
24
- return `
23
+ const styles = [];
24
+ if (configuration.customCss) {
25
+ styles.push('/* Custom CSS */');
26
+ styles.push(configuration.customCss);
27
+ }
28
+ if (!configuration.theme && customTheme) {
29
+ styles.push('/* Custom Theme */');
30
+ styles.push(customTheme);
31
+ }
32
+ if (styles.length === 0) {
33
+ return '';
34
+ }
35
+ return `
25
36
  <style type="text/css">
26
- ${addIndent(styles.join("\n\n"), 6)}
37
+ ${addIndent(styles.join('\n\n'), 6)}
27
38
  </style>`;
28
39
  };
29
- const getHtmlDocument = (givenConfiguration, customTheme = "") => {
30
- const { cdn, pageTitle, customCss, theme, ...rest } = givenConfiguration;
31
- const configuration = getConfiguration({
32
- ...rest,
33
- ...theme ? { theme } : {},
34
- customCss
35
- });
36
- const content = `<!doctype html>
40
+ /**
41
+ * The HTML document to render the Scalar API reference.
42
+ *
43
+ * We must check the passed in configuration and not the configuration for the theme as the configuration will have it
44
+ * defaulted to 'default'
45
+ */
46
+ export const getHtmlDocument = (givenConfiguration, customTheme = '') => {
47
+ const { cdn, pageTitle, customCss, theme, ...rest } = givenConfiguration;
48
+ const configuration = getConfiguration({
49
+ ...rest,
50
+ ...(theme ? { theme } : {}),
51
+ customCss,
52
+ });
53
+ const content = `<!doctype html>
37
54
  <html>
38
55
  <head>
39
- <title>${pageTitle ?? "Scalar API Reference"}</title>
56
+ <title>${pageTitle ?? 'Scalar API Reference'}</title>
40
57
  <meta charset="utf-8" />
41
58
  <meta
42
59
  name="viewport"
@@ -46,51 +63,63 @@ const getHtmlDocument = (givenConfiguration, customTheme = "") => {
46
63
  <div id="app"></div>${getScriptTags(configuration, cdn)}
47
64
  </body>
48
65
  </html>`;
49
- return content;
66
+ return content;
50
67
  };
68
+ /**
69
+ * Helper function to serialize arrays that may contain functions
70
+ */
51
71
  const serializeArrayWithFunctions = (arr) => {
52
- return `[${arr.map((item) => typeof item === "function" ? item.toString() : JSON.stringify(item)).join(", ")}]`;
72
+ return `[${arr.map((item) => (typeof item === 'function' ? item.toString() : JSON.stringify(item))).join(', ')}]`;
53
73
  };
54
- function getScriptTags(configuration, cdn) {
55
- const restConfig = { ...configuration };
56
- const functionProps = [];
57
- for (const [key, value] of Object.entries(configuration)) {
58
- if (typeof value === "function") {
59
- functionProps.push(`"${key}": ${value.toString()}`);
60
- delete restConfig[key];
61
- } else if (Array.isArray(value) && value.some((item) => typeof item === "function")) {
62
- functionProps.push(`"${key}": ${serializeArrayWithFunctions(value)}`);
63
- delete restConfig[key];
74
+ /**
75
+ * The script tags to load the @scalar/api-reference package from the CDN.
76
+ */
77
+ export function getScriptTags(configuration, cdn) {
78
+ const restConfig = { ...configuration };
79
+ const functionProps = [];
80
+ for (const [key, value] of Object.entries(configuration)) {
81
+ if (typeof value === 'function') {
82
+ functionProps.push(`"${key}": ${value.toString()}`);
83
+ delete restConfig[key];
84
+ }
85
+ else if (Array.isArray(value) && value.some((item) => typeof item === 'function')) {
86
+ // Handle arrays that contain functions (like plugins)
87
+ functionProps.push(`"${key}": ${serializeArrayWithFunctions(value)}`);
88
+ delete restConfig[key];
89
+ }
64
90
  }
65
- }
66
- const configString = JSON.stringify(restConfig, null, 2).split("\n").map((line, index) => index === 0 ? line : " " + line).join("\n").replace(/\s*}$/, "");
67
- const functionPropsString = functionProps.length ? `,
68
- ${functionProps.join(",\n ")}
69
- }` : "}";
70
- return `
91
+ // Stringify the rest of the configuration
92
+ const configString = JSON.stringify(restConfig, null, 2)
93
+ .split('\n')
94
+ .map((line, index) => (index === 0 ? line : ' ' + line))
95
+ .join('\n')
96
+ .replace(/\s*}$/, ''); // Remove the closing brace and any whitespace before it
97
+ const functionPropsString = functionProps.length ? `,\n ${functionProps.join(',\n ')}\n }` : '}';
98
+ return `
71
99
  <!-- Load the Script -->
72
- <script src="${cdn ?? "https://cdn.jsdelivr.net/npm/@scalar/api-reference"}"><\/script>
100
+ <script src="${cdn ?? 'https://cdn.jsdelivr.net/npm/@scalar/api-reference'}"></script>
73
101
 
74
102
  <!-- Initialize the Scalar API Reference -->
75
103
  <script type="text/javascript">
76
104
  Scalar.createApiReference('#app', ${configString}${functionPropsString})
77
- <\/script>`;
105
+ </script>`;
78
106
  }
79
- const getConfiguration = (givenConfiguration) => {
80
- const configuration = {
81
- ...givenConfiguration
82
- };
83
- if (typeof configuration.content === "function") {
84
- configuration.content = configuration.content();
85
- }
86
- if (configuration.content && configuration.url) {
87
- delete configuration.content;
88
- }
89
- return configuration;
90
- };
91
- export {
92
- getConfiguration,
93
- getHtmlDocument,
94
- getScriptTags
107
+ /**
108
+ * The configuration to pass to the @scalar/api-reference package.
109
+ */
110
+ export const getConfiguration = (givenConfiguration) => {
111
+ // Clone the given configuration
112
+ const configuration = {
113
+ ...givenConfiguration,
114
+ };
115
+ // Execute content if it's a function
116
+ if (typeof configuration.content === 'function') {
117
+ configuration.content = configuration.content();
118
+ }
119
+ // Only remove content if url is provided
120
+ if (configuration.content && configuration.url) {
121
+ delete configuration.content;
122
+ }
123
+ // Just return regular JSON string, no HTML escaping needed
124
+ return configuration;
95
125
  };
96
- //# sourceMappingURL=html-rendering.js.map
@@ -1,11 +1 @@
1
- import {
2
- getConfiguration,
3
- getHtmlDocument,
4
- getScriptTags
5
- } from "./html-rendering.js";
6
- export {
7
- getConfiguration,
8
- getHtmlDocument,
9
- getScriptTags
10
- };
11
- //# sourceMappingURL=index.js.map
1
+ export { getConfiguration, getHtmlDocument, getScriptTags, } from './html-rendering.js';
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "directory": "packages/core"
12
12
  },
13
13
  "keywords": [],
14
- "version": "0.4.3",
14
+ "version": "0.4.5",
15
15
  "engines": {
16
16
  "node": ">=22"
17
17
  },
@@ -28,18 +28,14 @@
28
28
  "CHANGELOG.md"
29
29
  ],
30
30
  "dependencies": {
31
- "@scalar/types": "0.7.3"
31
+ "@scalar/types": "0.7.5"
32
32
  },
33
33
  "devDependencies": {
34
- "vite": "^7.3.1",
35
- "@scalar/build-tooling": "0.5.0"
34
+ "vite": "8.0.0"
36
35
  },
37
36
  "scripts": {
38
- "build": "scalar-build-esbuild",
39
- "lint:check": "scalar-lint-check",
40
- "lint:fix": "scalar-lint-fix",
37
+ "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
41
38
  "test": "vitest",
42
- "types:build": "scalar-types-build",
43
- "types:check": "scalar-types-check"
39
+ "types:check": "tsc --noEmit"
44
40
  }
45
41
  }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/libs/html-rendering/html-rendering.ts"],
4
- "sourcesContent": ["import type { ApiReferenceConfigurationWithSource, HtmlRenderingConfiguration } from '@scalar/types/api-reference'\n\n// Re-export the type for convenience\nexport type { HtmlRenderingConfiguration }\n\n/**\n * Helper function to add consistent indentation to multiline strings\n * @param str The string to indent\n * @param spaces Number of spaces for each level\n * @param initialIndent Whether to indent the first line\n */\nconst addIndent = (str: string, spaces: number = 2, initialIndent: boolean = false): string => {\n const indent = ' '.repeat(spaces)\n const lines = str.split('\\n')\n return lines\n .map((line, index) => {\n if (index === 0 && !initialIndent) {\n return line\n }\n return `${indent}${line}`\n })\n .join('\\n')\n}\n\n/**\n * Generate the style tag with custom theme if needed\n */\nconst getStyles = (configuration: Partial<HtmlRenderingConfiguration>, customTheme: string): string => {\n const styles: string[] = []\n\n if (configuration.customCss) {\n styles.push('/* Custom CSS */')\n styles.push(configuration.customCss)\n }\n\n if (!configuration.theme && customTheme) {\n styles.push('/* Custom Theme */')\n styles.push(customTheme)\n }\n\n if (styles.length === 0) {\n return ''\n }\n\n return `\n <style type=\"text/css\">\n ${addIndent(styles.join('\\n\\n'), 6)}\n </style>`\n}\n\n/**\n * The HTML document to render the Scalar API reference.\n *\n * We must check the passed in configuration and not the configuration for the theme as the configuration will have it\n * defaulted to 'default'\n */\nexport const getHtmlDocument = (givenConfiguration: Partial<HtmlRenderingConfiguration>, customTheme = '') => {\n const { cdn, pageTitle, customCss, theme, ...rest } = givenConfiguration\n\n const configuration = getConfiguration({\n ...rest,\n ...(theme ? { theme } : {}),\n customCss,\n })\n\n const content = `<!doctype html>\n<html>\n <head>\n <title>${pageTitle ?? 'Scalar API Reference'}</title>\n <meta charset=\"utf-8\" />\n <meta\n name=\"viewport\"\n content=\"width=device-width, initial-scale=1\" />${getStyles(configuration, customTheme)}\n </head>\n <body>\n <div id=\"app\"></div>${getScriptTags(configuration, cdn)}\n </body>\n</html>`\n\n return content\n}\n\n/**\n * Helper function to serialize arrays that may contain functions\n */\nconst serializeArrayWithFunctions = (arr: unknown[]): string => {\n return `[${arr.map((item) => (typeof item === 'function' ? item.toString() : JSON.stringify(item))).join(', ')}]`\n}\n\n/**\n * The script tags to load the @scalar/api-reference package from the CDN.\n */\nexport function getScriptTags(configuration: Partial<ApiReferenceConfigurationWithSource>, cdn?: string) {\n const restConfig = { ...configuration }\n\n const functionProps: string[] = []\n\n for (const [key, value] of Object.entries(configuration) as [keyof typeof configuration, unknown][]) {\n if (typeof value === 'function') {\n functionProps.push(`\"${key}\": ${value.toString()}`)\n delete restConfig[key]\n } else if (Array.isArray(value) && value.some((item) => typeof item === 'function')) {\n // Handle arrays that contain functions (like plugins)\n functionProps.push(`\"${key}\": ${serializeArrayWithFunctions(value)}`)\n delete restConfig[key]\n }\n }\n\n // Stringify the rest of the configuration\n const configString = JSON.stringify(restConfig, null, 2)\n .split('\\n')\n .map((line, index) => (index === 0 ? line : ' ' + line))\n .join('\\n')\n .replace(/\\s*}$/, '') // Remove the closing brace and any whitespace before it\n\n const functionPropsString = functionProps.length ? `,\\n ${functionProps.join(',\\n ')}\\n }` : '}'\n\n return `\n <!-- Load the Script -->\n <script src=\"${cdn ?? 'https://cdn.jsdelivr.net/npm/@scalar/api-reference'}\"></script>\n\n <!-- Initialize the Scalar API Reference -->\n <script type=\"text/javascript\">\n Scalar.createApiReference('#app', ${configString}${functionPropsString})\n </script>`\n}\n\n/**\n * The configuration to pass to the @scalar/api-reference package.\n */\nexport const getConfiguration = (\n givenConfiguration: Partial<ApiReferenceConfigurationWithSource>,\n): Partial<ApiReferenceConfigurationWithSource> => {\n // Clone the given configuration\n const configuration = {\n ...givenConfiguration,\n }\n\n // Execute content if it's a function\n if (typeof configuration.content === 'function') {\n configuration.content = configuration.content()\n }\n\n // Only remove content if url is provided\n if (configuration.content && configuration.url) {\n delete configuration.content\n }\n\n //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 -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/libs/html-rendering/index.ts"],
4
- "sourcesContent": ["export {\n type HtmlRenderingConfiguration,\n getConfiguration,\n getHtmlDocument,\n getScriptTags,\n} from './html-rendering'\n"],
5
- "mappings": "AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;",
6
- "names": []
7
- }