Skip to content

Commit fd6bd00

Browse files
authored
feat: Design tokens package (#7)
1 parent 83ea1f0 commit fd6bd00

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1601
-23
lines changed

.github/workflows/pr.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ jobs:
2929
node-version: '18.x'
3030
- run: pnpm i --frozen-lockfile
3131
- run: pnpm test:changed
32+
- name: Upload code coverage
33+
uses: actions/upload-artifact@v4
34+
with:
35+
name: code-coverage-report
36+
path: '**/html/**/*'
3237
format:
3338
name: Format checker
3439
runs-on: ubuntu-latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ yarn-error.log*
3636
# Misc
3737
.DS_Store
3838
*.pem
39+
html/

.prettierrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"singleQuote": true,
33
"tabWidth": 2,
4-
"semi": true
4+
"semi": true,
5+
"arrowParens": "avoid",
6+
"endOfLine": "lf"
57
}

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@
77
"lnf.aliases": {
88
"$/": "${workspaceRoot}/",
99
"$packages/": "${workspaceRoot}/packages/"
10+
},
11+
"[typescript]": {
12+
"editor.formatOnSave": true,
13+
"editor.defaultFormatter": "esbenp.prettier-vscode"
1014
}
1115
}

packages/arktype-utils/src/formData.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ export function formDataToObject(
3333
} else {
3434
if (pruneKeyNames && /\[.?\]/.test(key))
3535
key = key.replace(/\[.?\]/, '');
36-
ret[key] = all.map((v) =>
36+
37+
ret[key] = all.map(v =>
3738
typeof v === 'string' ? stringToJSValue(v) : v,
3839
);
3940
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
*
3+
* @description Modifies the base object the structure of the `str`
4+
* @param str
5+
* @param value
6+
* @param base
7+
* @returns
8+
*/
9+
export function strToObject<T>(
10+
str: string,
11+
value: T,
12+
base: object = {},
13+
): object {
14+
const ret = base;
15+
const parts = str.split('.');
16+
17+
while (parts.length > 0) {
18+
const key = parts.shift();
19+
if (!key) continue;
20+
}
21+
22+
return ret;
23+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { strToObject } from './strToObject.js';
3+
4+
describe('strToObjects', () => {
5+
it('does a thing', () => {
6+
const a = strToObject('a[4]', 3);
7+
expect(a.a[4]).toBe(3);
8+
expect(a.a).toHaveLength(5);
9+
expect(a.a.slice(0, 3).every(f => f === undefined)).toBeTruthy();
10+
expect(1).toBe(1);
11+
12+
const b = strToObject('b[]', 7);
13+
expect(b.b).toHaveLength(1);
14+
expect(b.b[0]).toBe(7);
15+
16+
expect(strToObject('a', 3)).toStrictEqual({
17+
a: 3,
18+
});
19+
// const a = strToObject('a.b', 3);
20+
// expect(a).toStrictEqual({
21+
// a: {
22+
// b: 3
23+
// }
24+
// });
25+
// const b = strToObject('a[]', 3);
26+
27+
// expect(b).toStrictEqual({
28+
// a: [3],
29+
// });
30+
31+
// const c = strToObject('a.b.c[]', 4);
32+
33+
// expect(c).toStrictEqual({
34+
// a: {
35+
// b: {
36+
// c: [4],
37+
// },
38+
// },
39+
// });
40+
41+
// expect(strToObject('a', 3, { b: 7 })).toStrictEqual({
42+
// a: 3,
43+
// b: 7,
44+
// });
45+
});
46+
47+
// expect(strToObject('a[].b[]', 7)).toStrictEqual({
48+
// a: [
49+
// { b: [7] }
50+
// ]
51+
// });
52+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { makeConfig } from './src/types.js';
2+
3+
export default makeConfig({
4+
tokens: {
5+
red: {
6+
100: 'lightred',
7+
500: 'red',
8+
900: 'darkred',
9+
},
10+
blue: {
11+
100: 'lightblue',
12+
500: 'blue',
13+
900: 'darkblue',
14+
},
15+
16+
primary: '!blue.900',
17+
secondary: '!red.100',
18+
},
19+
variants: {
20+
'prefer-color-scheme: dark': {
21+
something: 'red',
22+
primary: '!blue.100',
23+
},
24+
},
25+
});

0 commit comments

Comments
 (0)