@navita/adapter 0.0.2 → 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/index.d.ts +26 -0
- package/package.json +3 -11
- package/.turbo/turbo-build.log +0 -5
- package/.turbo/turbo-test.log +0 -19
- package/src/index.ts +0 -58
- package/tests/src/index.test.ts +0 -57
- /package/{dist/index.cjs → index.cjs} +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/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { StyleRule, GlobalStyleRule, CSSKeyframes, FontFaceRule } from '@navita/types';
|
|
2
|
+
|
|
3
|
+
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
|
+
declare const setAdapter: (newAdapter: Adapter) => void;
|
|
12
|
+
declare function generateIdentifier(value: unknown): string;
|
|
13
|
+
declare function addCss(css: StyleRule): string;
|
|
14
|
+
declare function addStaticCss(selector: string, css: GlobalStyleRule): void;
|
|
15
|
+
declare function addKeyframe(keyframe: CSSKeyframes): string;
|
|
16
|
+
declare function addFontFace(fontFace: FontFaceRule | FontFaceRule[]): string;
|
|
17
|
+
declare function collectResult<T>(input: {
|
|
18
|
+
filePath: string;
|
|
19
|
+
index: number;
|
|
20
|
+
result: () => T;
|
|
21
|
+
identifier?: string;
|
|
22
|
+
line: number;
|
|
23
|
+
column: number;
|
|
24
|
+
}): T;
|
|
25
|
+
|
|
26
|
+
export { Adapter, addCss, addFontFace, addKeyframe, addStaticCss, collectResult, generateIdentifier, setAdapter };
|
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.2"
|
|
12
|
-
},
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "build",
|
|
15
|
-
"dev": "build --dev",
|
|
16
|
-
"test": "jest"
|
|
17
9
|
}
|
|
18
10
|
}
|
package/.turbo/turbo-build.log
DELETED
package/.turbo/turbo-test.log
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @navita/adapter@0.0.1 test /Users/zn4rk/Projects/compass-style/packages/adapter
|
|
3
|
-
> jest
|
|
4
|
-
|
|
5
|
-
jest-haste-map: Haste module naming collision: @navita/adapter
|
|
6
|
-
The following files share their name; please adjust your hasteImpl:
|
|
7
|
-
* <rootDir>/package.json
|
|
8
|
-
* <rootDir>/dist/package.json
|
|
9
|
-
|
|
10
|
-
[0m[7m[1m[32m PASS [39m[22m[27m[0m [0m[7m[37m packages/adapter [39m[27m[0m [2mtests/src/[22m[1mindex.test.ts[22m
|
|
11
|
-
adapter
|
|
12
|
-
[32m✓[39m [2mshould return undefined without adapter (1 ms)[22m
|
|
13
|
-
[32m✓[39m [2mshould set adapter[22m
|
|
14
|
-
|
|
15
|
-
[1mTest Suites: [22m[1m[32m1 passed[39m[22m, 1 total
|
|
16
|
-
[1mTests: [22m[1m[32m2 passed[39m[22m, 2 total
|
|
17
|
-
[1mSnapshots: [22m0 total
|
|
18
|
-
[1mTime:[22m 1.139 s, estimated 2 s
|
|
19
|
-
[2mRan all test suites[22m[2m.[22m
|
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
|