@scalar/core 0.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/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # @scalar/core
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - bab7990: init :)
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [bab7990]
12
+ - Updated dependencies [2c621d4]
13
+ - @scalar/types@0.0.39
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present Scalar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Scalar Core
2
+
3
+ [![Version](https://img.shields.io/npm/v/%40scalar/core)](https://www.npmjs.com/package/@scalar/core)
4
+ [![Downloads](https://img.shields.io/npm/dm/%40scalar/core)](https://www.npmjs.com/package/@scalar/core)
5
+ [![License](https://img.shields.io/npm/l/%40scalar%2Fcore)](https://www.npmjs.com/package/@scalar/core)
6
+ [![Discord](https://img.shields.io/discord/1135330207960678410?style=flat&color=5865F2)](https://discord.gg/scalar)
7
+
8
+ Shared libraries for our packages, specifically [@scalar/api-reference](https://npmjs.com/@scalar/api-reference) and [@scalar/api-client](https://www.npmjs.com/package/@scalar/api-client).
9
+
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install @scalar/core
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```ts
20
+ import { getHtmlDocument } from '@scalar/core/lib/html-rendering'
21
+
22
+ const html = getHtmlDocument({
23
+ spec: {
24
+ url: 'https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.json',
25
+ },
26
+ })
27
+ ```
28
+
29
+ ## Community
30
+
31
+ We are API nerds. You too? Let’s chat on Discord: <https://discord.gg/scalar>
32
+
33
+ ## License
34
+
35
+ The source code in this repository is licensed under [MIT](https://github.com/scalar/scalar/blob/main/LICENSE).
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,22 @@
1
+ import { type ApiReferenceConfiguration, type HtmlRenderingConfiguration } from '@scalar/types/api-reference';
2
+ export type { HtmlRenderingConfiguration };
3
+ /**
4
+ * The HTML document to render the Scalar API reference.
5
+ *
6
+ * We must check the passed in configuration and not the parsedConfig for the theme as the parsedConfig will have it
7
+ * defaulted to 'default'
8
+ */
9
+ export declare const getHtmlDocument: (configuration: Partial<HtmlRenderingConfiguration>, customTheme?: string) => string;
10
+ /**
11
+ * The script tags to load the @scalar/api-reference package from the CDN.
12
+ */
13
+ export declare function getScriptTags(configuration: ApiReferenceConfiguration, cdn: string): string;
14
+ /**
15
+ * The configuration to pass to the @scalar/api-reference package.
16
+ */
17
+ export declare const getConfiguration: (givenConfiguration: ApiReferenceConfiguration) => string;
18
+ /**
19
+ * The content to pass to the @scalar/api-reference package as the <script> tag content.
20
+ */
21
+ export declare const getScriptTagContent: (configuration: ApiReferenceConfiguration) => string;
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/libs/html-rendering/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,EAGhC,MAAM,6BAA6B,CAAA;AAGpC,YAAY,EAAE,0BAA0B,EAAE,CAAA;AAE1C;;;;;GAKG;AACH,eAAO,MAAM,eAAe,kBAAmB,OAAO,CAAC,0BAA0B,CAAC,iCAwBjF,CAAA;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,aAAa,EAAE,yBAAyB,EAAE,GAAG,EAAE,MAAM,UAQlF;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,uBAAwB,yBAAyB,WAa7E,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB,kBAAmB,yBAAyB,WAKpE,CAAA"}
@@ -0,0 +1,69 @@
1
+ import { htmlRenderingConfigurationSchema, apiReferenceConfigurationSchema } from '@scalar/types/api-reference';
2
+
3
+ /**
4
+ * The HTML document to render the Scalar API reference.
5
+ *
6
+ * We must check the passed in configuration and not the parsedConfig for the theme as the parsedConfig will have it
7
+ * defaulted to 'default'
8
+ */
9
+ const getHtmlDocument = (configuration, customTheme = '') => {
10
+ const { cdn, pageTitle, ...rest } = configuration;
11
+ const parsedHtmlOptions = htmlRenderingConfigurationSchema.parse({ cdn, pageTitle, customTheme });
12
+ const parsedConfig = apiReferenceConfigurationSchema.parse(rest);
13
+ return `
14
+ <!DOCTYPE html>
15
+ <html>
16
+ <head>
17
+ <title>${parsedHtmlOptions.pageTitle}</title>
18
+ <meta charset="utf-8" />
19
+ <meta
20
+ name="viewport"
21
+ content="width=device-width, initial-scale=1" />
22
+ <style>
23
+ ${configuration.theme ? '' : customTheme}
24
+ </style>
25
+ </head>
26
+ <body>
27
+ ${getScriptTags(parsedConfig, parsedHtmlOptions.cdn)}
28
+ </body>
29
+ </html>
30
+ `;
31
+ };
32
+ /**
33
+ * The script tags to load the @scalar/api-reference package from the CDN.
34
+ */
35
+ function getScriptTags(configuration, cdn) {
36
+ return `
37
+ <script
38
+ id="api-reference"
39
+ type="application/json"
40
+ data-configuration="${getConfiguration(configuration)}">${getScriptTagContent(configuration)}</script>
41
+ <script src="${cdn}"></script>
42
+ `;
43
+ }
44
+ /**
45
+ * The configuration to pass to the @scalar/api-reference package.
46
+ */
47
+ const getConfiguration = (givenConfiguration) => {
48
+ // Clone before mutating
49
+ const configuration = {
50
+ ...givenConfiguration,
51
+ };
52
+ if (!configuration.spec?.url) {
53
+ delete configuration.spec;
54
+ }
55
+ else if (configuration.spec?.content) {
56
+ delete configuration.spec?.content;
57
+ }
58
+ return JSON.stringify(configuration).split('"').join('&quot;');
59
+ };
60
+ /**
61
+ * The content to pass to the @scalar/api-reference package as the <script> tag content.
62
+ */
63
+ const getScriptTagContent = (configuration) => configuration.spec?.content
64
+ ? typeof configuration.spec?.content === 'function'
65
+ ? JSON.stringify(configuration.spec?.content())
66
+ : JSON.stringify(configuration.spec?.content)
67
+ : '';
68
+
69
+ export { getConfiguration, getHtmlDocument, getScriptTagContent, getScriptTags };
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@scalar/core",
3
+ "description": "Shared libraries for our packages",
4
+ "license": "MIT",
5
+ "author": "Scalar (https://github.com/scalar)",
6
+ "homepage": "https://github.com/scalar/scalar",
7
+ "bugs": "https://github.com/scalar/scalar/issues/new/choose",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/scalar/scalar.git",
11
+ "directory": "packages/core"
12
+ },
13
+ "keywords": [],
14
+ "version": "0.1.0",
15
+ "engines": {
16
+ "node": ">=18"
17
+ },
18
+ "type": "module",
19
+ "main": "dist/index.js",
20
+ "exports": {
21
+ ".": {
22
+ "import": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "default": "./dist/index.js"
25
+ },
26
+ "./libs/html-rendering": {
27
+ "import": "./dist/libs/html-rendering/index.js",
28
+ "types": "./dist/libs/html-rendering/index.d.ts",
29
+ "default": "./dist/libs/html-rendering/index.js"
30
+ }
31
+ },
32
+ "files": [
33
+ "dist",
34
+ "CHANGELOG.md"
35
+ ],
36
+ "module": "dist/index.js",
37
+ "dependencies": {
38
+ "@scalar/types": "0.0.39"
39
+ },
40
+ "devDependencies": {
41
+ "vite": "^5.4.10",
42
+ "@scalar/build-tooling": "0.1.16"
43
+ },
44
+ "scripts": {
45
+ "build": "scalar-build-rollup",
46
+ "lint:check": "scalar-lint-check",
47
+ "lint:fix": "scalar-lint-fix",
48
+ "test": "vitest",
49
+ "types:build": "scalar-types-build",
50
+ "types:check": "scalar-types-check"
51
+ }
52
+ }