@navita/adapter 0.0.0-main-20230917201540 → 0.0.4
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/LICENSE.md +21 -0
- package/package.json +3 -11
- package/.turbo/turbo-build.log +0 -5
- package/CHANGELOG.md +0 -7
- package/dist/package.json +0 -10
- package/src/index.ts +0 -58
- package/tests/src/index.test.ts +0 -57
- /package/{dist/index.cjs → index.cjs} +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Alexander Liljengård
|
|
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/package.json
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navita/adapter",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": {
|
|
6
|
-
"types": "./
|
|
7
|
-
"default": "./
|
|
6
|
+
"types": "./index.d.ts",
|
|
7
|
+
"default": "./index.cjs"
|
|
8
8
|
}
|
|
9
|
-
},
|
|
10
|
-
"devDependencies": {
|
|
11
|
-
"@navita/types": "0.0.0-main-20230917201540"
|
|
12
|
-
},
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "build",
|
|
15
|
-
"dev": "build --dev",
|
|
16
|
-
"test": "jest"
|
|
17
9
|
}
|
|
18
10
|
}
|
package/.turbo/turbo-build.log
DELETED
package/CHANGELOG.md
DELETED
package/dist/package.json
DELETED
package/src/index.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { CSSKeyframes, GlobalStyleRule, StyleRule, FontFaceRule } from "@navita/types";
|
|
2
|
-
|
|
3
|
-
export type Adapter = {
|
|
4
|
-
generateIdentifier: typeof generateIdentifier,
|
|
5
|
-
addCss: typeof addCss,
|
|
6
|
-
addStaticCss: typeof addStaticCss,
|
|
7
|
-
addKeyframe: typeof addKeyframe,
|
|
8
|
-
addFontFace: typeof addFontFace,
|
|
9
|
-
collectResult?: typeof collectResult;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
let adapter: Adapter | undefined = undefined;
|
|
13
|
-
|
|
14
|
-
function getAdapter() {
|
|
15
|
-
if (!adapter) {
|
|
16
|
-
throw new Error(
|
|
17
|
-
'Could not find an adapter. Please ensure you have added a bundler integration:\n' +
|
|
18
|
-
'https://navita.style/#bundler-integration',
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return adapter;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const setAdapter = (newAdapter: Adapter) => {
|
|
26
|
-
adapter = newAdapter;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function generateIdentifier(value: unknown): string {
|
|
30
|
-
return getAdapter().generateIdentifier(value) as string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function addCss(css: StyleRule): string {
|
|
34
|
-
return getAdapter().addCss(css);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function addStaticCss(selector: string, css: GlobalStyleRule): void {
|
|
38
|
-
return getAdapter().addStaticCss(selector, css);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function addKeyframe(keyframe: CSSKeyframes): string {
|
|
42
|
-
return getAdapter().addKeyframe(keyframe) as string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function addFontFace(fontFace: FontFaceRule | FontFaceRule[]): string {
|
|
46
|
-
return getAdapter().addFontFace(fontFace) as string;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function collectResult<T>(input: {
|
|
50
|
-
filePath: string,
|
|
51
|
-
index: number,
|
|
52
|
-
result: () => T,
|
|
53
|
-
identifier?: string,
|
|
54
|
-
line: number,
|
|
55
|
-
column: number,
|
|
56
|
-
}): T {
|
|
57
|
-
return getAdapter().collectResult?.(input) as T;
|
|
58
|
-
}
|
package/tests/src/index.test.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { Adapter } from "../../src";
|
|
2
|
-
import {
|
|
3
|
-
collectResult,
|
|
4
|
-
generateIdentifier,
|
|
5
|
-
setAdapter,
|
|
6
|
-
addCss,
|
|
7
|
-
addFontFace,
|
|
8
|
-
addKeyframe,
|
|
9
|
-
addStaticCss
|
|
10
|
-
} from "../../src";
|
|
11
|
-
|
|
12
|
-
describe('adapter', () => {
|
|
13
|
-
it('should throw error without adapter', () => {
|
|
14
|
-
expect(() => generateIdentifier('something')).toThrowError();
|
|
15
|
-
expect(() => addCss({})).toThrowError();
|
|
16
|
-
// noinspection JSVoidFunctionReturnValueUsed
|
|
17
|
-
expect(() => addStaticCss('selector', {})).toThrowError();
|
|
18
|
-
expect(() => addKeyframe({})).toThrowError();
|
|
19
|
-
expect(() => addFontFace({
|
|
20
|
-
src: '',
|
|
21
|
-
})).toThrowError();
|
|
22
|
-
expect(() => collectResult({
|
|
23
|
-
index: 0,
|
|
24
|
-
column: 0,
|
|
25
|
-
line: 0,
|
|
26
|
-
filePath: "",
|
|
27
|
-
result: () => undefined
|
|
28
|
-
})).toThrowError();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('should set adapter', () => {
|
|
32
|
-
setAdapter({
|
|
33
|
-
generateIdentifier: () => 'something',
|
|
34
|
-
addCss: () => 'something',
|
|
35
|
-
addStaticCss: () => 'something',
|
|
36
|
-
addKeyframe: () => 'something',
|
|
37
|
-
addFontFace: () => 'something',
|
|
38
|
-
collectResult: () => 'something',
|
|
39
|
-
} as unknown as Adapter);
|
|
40
|
-
|
|
41
|
-
expect(generateIdentifier('anything')).toBe('something');
|
|
42
|
-
expect(addCss({})).toBe('something');
|
|
43
|
-
// noinspection JSVoidFunctionReturnValueUsed
|
|
44
|
-
expect(addStaticCss('selector', {})).toBe('something');
|
|
45
|
-
expect(addKeyframe({})).toBe('something');
|
|
46
|
-
expect(addFontFace({
|
|
47
|
-
src: '',
|
|
48
|
-
})).toBe('something');
|
|
49
|
-
expect(collectResult({
|
|
50
|
-
index: 0,
|
|
51
|
-
column: 0,
|
|
52
|
-
line: 0,
|
|
53
|
-
filePath: "",
|
|
54
|
-
result: () => undefined,
|
|
55
|
-
})).toBe('something');
|
|
56
|
-
});
|
|
57
|
-
});
|
|
File without changes
|
|
File without changes
|