@scalar/import 0.3.23 → 0.3.25
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 +16 -0
- package/dist/get-configuration-attribute.test.js +33 -0
- package/dist/get-configuration-attribute.test.js.map +7 -0
- package/dist/get-content-of-script-tag.test.js +33 -0
- package/dist/get-content-of-script-tag.test.js.map +7 -0
- package/dist/index.js +5 -1
- package/dist/index.js.map +7 -0
- package/dist/resolve.js +208 -290
- package/dist/resolve.js.map +7 -0
- package/dist/resolve.test.js +1050 -0
- package/dist/resolve.test.js.map +7 -0
- package/package.json +6 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @scalar/import
|
|
2
2
|
|
|
3
|
+
## 0.3.25
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [cd6cf24]
|
|
8
|
+
- @scalar/oas-utils@0.2.142
|
|
9
|
+
|
|
10
|
+
## 0.3.24
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 8c7bad8: chore: move build tooling to esbuild
|
|
15
|
+
- Updated dependencies [8c7bad8]
|
|
16
|
+
- @scalar/openapi-parser@0.10.17
|
|
17
|
+
- @scalar/oas-utils@0.2.141
|
|
18
|
+
|
|
3
19
|
## 0.3.23
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { getConfigurationAttribute } from "./resolve.js";
|
|
3
|
+
describe("getConfigurationAttribute", () => {
|
|
4
|
+
it("returns the configuration attribute with double quotes", () => {
|
|
5
|
+
const html = `<script id="api-reference" data-configuration="{"spec":{"content":"foo"}}"><\/script>`;
|
|
6
|
+
const result = getConfigurationAttribute(html);
|
|
7
|
+
expect(result).toBe("{"spec":{"content":"foo"}}");
|
|
8
|
+
});
|
|
9
|
+
it("returns the configuration attribute with single quotes", () => {
|
|
10
|
+
const html = `<script id='api-reference' data-configuration='{"spec":{"content":"foo"}}'><\/script>`;
|
|
11
|
+
const result = getConfigurationAttribute(html);
|
|
12
|
+
expect(result).toBe("{"spec":{"content":"foo"}}");
|
|
13
|
+
});
|
|
14
|
+
it("returns undefined if no configuration attribute is present", () => {
|
|
15
|
+
const html = `<script id="api-reference"><\/script>`;
|
|
16
|
+
const result = getConfigurationAttribute(html);
|
|
17
|
+
expect(result).toBeUndefined();
|
|
18
|
+
});
|
|
19
|
+
it("returns undefined for non-matching script tags", () => {
|
|
20
|
+
const html = `<script data-other-attribute="value" data-configuration="{"spec":{"content":"foo"}}"><\/script>`;
|
|
21
|
+
const result = getConfigurationAttribute(html);
|
|
22
|
+
expect(result).toBeUndefined();
|
|
23
|
+
});
|
|
24
|
+
it("handles multiple script tags and returns the first match", () => {
|
|
25
|
+
const html = `
|
|
26
|
+
<script id="api-reference" data-configuration="{"spec":{"content":"first"}}"><\/script>
|
|
27
|
+
<script id="api-reference" data-configuration="{"spec":{"content":"second"}}"><\/script>
|
|
28
|
+
`;
|
|
29
|
+
const result = getConfigurationAttribute(html);
|
|
30
|
+
expect(result).toBe("{"spec":{"content":"first"}}");
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=get-configuration-attribute.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/get-configuration-attribute.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { getConfigurationAttribute } from './resolve'\n\ndescribe('getConfigurationAttribute', () => {\n it('returns the configuration attribute with double quotes', () => {\n const html = `<script id=\"api-reference\" data-configuration=\"{"spec":{"content":"foo"}}\"></script>`\n const result = getConfigurationAttribute(html)\n expect(result).toBe('{"spec":{"content":"foo"}}')\n })\n\n it('returns the configuration attribute with single quotes', () => {\n const html = `<script id='api-reference' data-configuration='{"spec":{"content":"foo"}}'></script>`\n const result = getConfigurationAttribute(html)\n expect(result).toBe('{"spec":{"content":"foo"}}')\n })\n\n it('returns undefined if no configuration attribute is present', () => {\n const html = `<script id=\"api-reference\"></script>`\n const result = getConfigurationAttribute(html)\n expect(result).toBeUndefined()\n })\n\n it('returns undefined for non-matching script tags', () => {\n const html = `<script data-other-attribute=\"value\" data-configuration=\"{"spec":{"content":"foo"}}\"></script>`\n const result = getConfigurationAttribute(html)\n expect(result).toBeUndefined()\n })\n\n it('handles multiple script tags and returns the first match', () => {\n const html = `\n <script id=\"api-reference\" data-configuration=\"{"spec":{"content":"first"}}\"></script>\n <script id=\"api-reference\" data-configuration=\"{"spec":{"content":"second"}}\"></script>\n `\n const result = getConfigurationAttribute(html)\n expect(result).toBe('{"spec":{"content":"first"}}')\n })\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,iCAAiC;AAE1C,SAAS,6BAA6B,MAAM;AAC1C,KAAG,0DAA0D,MAAM;AACjE,UAAM,OAAO;AACb,UAAM,SAAS,0BAA0B,IAAI;AAC7C,WAAO,MAAM,EAAE,KAAK,0DAA0D;AAAA,EAChF,CAAC;AAED,KAAG,0DAA0D,MAAM;AACjE,UAAM,OAAO;AACb,UAAM,SAAS,0BAA0B,IAAI;AAC7C,WAAO,MAAM,EAAE,KAAK,0DAA0D;AAAA,EAChF,CAAC;AAED,KAAG,8DAA8D,MAAM;AACrE,UAAM,OAAO;AACb,UAAM,SAAS,0BAA0B,IAAI;AAC7C,WAAO,MAAM,EAAE,cAAc;AAAA,EAC/B,CAAC;AAED,KAAG,kDAAkD,MAAM;AACzD,UAAM,OAAO;AACb,UAAM,SAAS,0BAA0B,IAAI;AAC7C,WAAO,MAAM,EAAE,cAAc;AAAA,EAC/B,CAAC;AAED,KAAG,4DAA4D,MAAM;AACnE,UAAM,OAAO;AAAA;AAAA;AAAA;AAIb,UAAM,SAAS,0BAA0B,IAAI;AAC7C,WAAO,MAAM,EAAE,KAAK,4DAA4D;AAAA,EAClF,CAAC;AACH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { getContentOfScriptTag } from "./resolve.js";
|
|
3
|
+
describe("getContentOfScriptTag", () => {
|
|
4
|
+
it("returns the content of the script tag", () => {
|
|
5
|
+
const html = '<script id="api-reference">console.log("Hello, world!");<\/script>';
|
|
6
|
+
expect(getContentOfScriptTag(html)).toBe('console.log("Hello, world!");');
|
|
7
|
+
});
|
|
8
|
+
it("works with single quotes", () => {
|
|
9
|
+
const html = `<script id='api-reference'>console.log("Hello, world!");<\/script>`;
|
|
10
|
+
expect(getContentOfScriptTag(html)).toBe('console.log("Hello, world!");');
|
|
11
|
+
});
|
|
12
|
+
it("ignores HTML characters inside the attributes", () => {
|
|
13
|
+
const html = `<!DOCTYPE html>
|
|
14
|
+
<html>
|
|
15
|
+
<head>
|
|
16
|
+
<title>Scalar API Reference</title>
|
|
17
|
+
<meta charset="utf-8" />
|
|
18
|
+
<meta
|
|
19
|
+
name="viewport"
|
|
20
|
+
content="width=device-width, initial-scale=1" />
|
|
21
|
+
<style>
|
|
22
|
+
null
|
|
23
|
+
</style>
|
|
24
|
+
</head>
|
|
25
|
+
<body>
|
|
26
|
+
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"><\/script>
|
|
27
|
+
<script id="api-reference" type="application/json" data-configuration="foo<br>bar">console.log("Hello, world!");<\/script>
|
|
28
|
+
</body>
|
|
29
|
+
</html>`;
|
|
30
|
+
expect(getContentOfScriptTag(html)).toBe('console.log("Hello, world!");');
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=get-content-of-script-tag.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/get-content-of-script-tag.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { getContentOfScriptTag } from './resolve'\n\ndescribe('getContentOfScriptTag', () => {\n it('returns the content of the script tag', () => {\n const html = '<script id=\"api-reference\">console.log(\"Hello, world!\");</script>'\n expect(getContentOfScriptTag(html)).toBe('console.log(\"Hello, world!\");')\n })\n\n it('works with single quotes', () => {\n const html = `<script id='api-reference'>console.log(\"Hello, world!\");</script>`\n expect(getContentOfScriptTag(html)).toBe('console.log(\"Hello, world!\");')\n })\n\n it('ignores HTML characters inside the attributes', () => {\n // HTML tags inside the attributes\n const html = `<!DOCTYPE html>\n <html>\n <head>\n <title>Scalar API Reference</title>\n <meta charset=\"utf-8\" />\n <meta\n name=\"viewport\"\n content=\"width=device-width, initial-scale=1\" />\n <style>\n null\n </style>\n </head>\n <body>\n <script src=\"https://cdn.jsdelivr.net/npm/@scalar/api-reference\"></script>\n <script id=\"api-reference\" type=\"application/json\" data-configuration=\"foo<br>bar\">console.log(\"Hello, world!\");</script>\n </body>\n </html>`\n\n expect(getContentOfScriptTag(html)).toBe('console.log(\"Hello, world!\");')\n })\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,6BAA6B;AAEtC,SAAS,yBAAyB,MAAM;AACtC,KAAG,yCAAyC,MAAM;AAChD,UAAM,OAAO;AACb,WAAO,sBAAsB,IAAI,CAAC,EAAE,KAAK,+BAA+B;AAAA,EAC1E,CAAC;AAED,KAAG,4BAA4B,MAAM;AACnC,UAAM,OAAO;AACb,WAAO,sBAAsB,IAAI,CAAC,EAAE,KAAK,+BAA+B;AAAA,EAC1E,CAAC;AAED,KAAG,iDAAiD,MAAM;AAExD,UAAM,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBb,WAAO,sBAAsB,IAAI,CAAC,EAAE,KAAK,+BAA+B;AAAA,EAC1E,CAAC;AACH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/index.js
CHANGED