Skip to content

Commit 04e6b0d

Browse files
committed
Merge branch 'release/v0.26.2'
2 parents 985fda2 + dda6848 commit 04e6b0d

7 files changed

+156
-25
lines changed

package.json

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "zeed",
33
"type": "module",
4-
"version": "0.26.1",
4+
"version": "0.26.2",
55
"description": "🌱 Simple foundation library",
66
"author": {
77
"name": "Dirk Holtwick",
@@ -69,19 +69,19 @@
6969
"watch": "nr build -- --watch src"
7070
},
7171
"devDependencies": {
72-
"@antfu/eslint-config": "^3.8",
73-
"@antfu/ni": "^0.23.0",
74-
"@types/node": "^22.9.0",
75-
"@vitejs/plugin-vue": "^5.1.4",
76-
"@vitest/browser": "^2.1.4",
77-
"@vitest/coverage-v8": "^2.1.4",
72+
"@antfu/eslint-config": "^3.11",
73+
"@antfu/ni": "^0.23.1",
74+
"@types/node": "^22.10.1",
75+
"@vitejs/plugin-vue": "^5.2.1",
76+
"@vitest/browser": "^2.1.8",
77+
"@vitest/coverage-v8": "^2.1.8",
7878
"esbuild": "^0.24.0",
79-
"eslint": "^9",
80-
"playwright": "^1.48.2",
79+
"eslint": "^9.16.0",
80+
"playwright": "^1.49.0",
8181
"tsup": "^8.3.5",
82-
"typescript": "^5.6.3",
83-
"vite": "^5.4.10",
84-
"vitest": "^2.1.4"
82+
"typescript": "^5.7.2",
83+
"vite": "^6.0.2",
84+
"vitest": "^2.1.8"
8585
},
8686
"pnpm": {
8787
"overrides": {

src/browser/log/log-colors.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,23 @@ export function browserSupportsColors(): boolean {
3333
// @ts-expect-error xxx
3434
&& document.documentElement.style.WebkitAppearance)
3535
// Is firebug? http://stackoverflow.com/a/398120/376773
36-
|| (typeof window !== 'undefined'
37-
&& window.console
36+
|| (typeof window !== 'undefined'
37+
&& window.console
38+
// @ts-expect-error xxx
39+
&& (window.console.firebug
3840
// @ts-expect-error xxx
39-
&& (window.console.firebug
40-
// @ts-expect-error xxx
4141

42-
|| (window.console.exception && window.console.table)))
42+
|| (window.console.exception && window.console.table)))
4343
// Is firefox >= v31?
4444
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
45-
|| (typeof navigator !== 'undefined'
46-
&& navigator.userAgent
47-
&& navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)
48-
// eslint-disable-next-line regexp/no-legacy-features
49-
&& Number.parseInt(RegExp.$1, 10) >= 31)
45+
|| (typeof navigator !== 'undefined'
46+
&& navigator.userAgent
47+
&& navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)
48+
// eslint-disable-next-line regexp/no-legacy-features
49+
&& Number.parseInt(RegExp.$1, 10) >= 31)
5050
// Double check webkit in userAgent just in case we are in a worker
51-
|| (typeof navigator !== 'undefined'
52-
&& navigator.userAgent
53-
&& navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))
51+
|| (typeof navigator !== 'undefined'
52+
&& navigator.userAgent
53+
&& navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))
5454
)
5555
}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { Infer } from './schema'
2+
import { schemaExportSwiftStruct } from './export-swift'
3+
import { boolean, int, number, object, string } from './schema'
4+
5+
describe('swift.spec', () => {
6+
it('parse args', async () => {
7+
const schema = object({
8+
anInt: int().optional().default(0),
9+
aBool: boolean(),
10+
aNumber: number(),
11+
aString: string(),
12+
})
13+
14+
type t = Infer<typeof schema>
15+
expectTypeOf<t>().toMatchTypeOf<any>()
16+
17+
const r = schemaExportSwiftStruct(schema, 'Test')
18+
19+
expect(r).toMatchInlineSnapshot(`
20+
"struct Test {
21+
var anInt: Int? = 0
22+
var aBool: Bool
23+
var aNumber: Double
24+
var aString: String
25+
}"
26+
`)
27+
})
28+
})

src/common/schema/export-swift.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import type { Type } from './schema'
2+
import { assert } from '../assert'
3+
import { objectMap } from '../data/object'
4+
import { isSchemaObjectFlat } from './utils'
5+
6+
// declare module './schema' {
7+
// interface TypeProps {
8+
// argShort?: string
9+
// argDesc?: string
10+
// }
11+
// }
12+
13+
const mapSwiftType = {
14+
string: 'String',
15+
number: 'Double',
16+
int: 'Int',
17+
boolean: 'Bool',
18+
} as any
19+
20+
export function schemaExportSwiftStruct<T>(schema: Type<T>, name: string = 'Example'): string {
21+
assert(isSchemaObjectFlat(schema), 'schema should be a flat object')
22+
23+
const lines: string[] = [
24+
`struct ${name} {`,
25+
]
26+
27+
objectMap(schema._object!, (key, schema: Type<any>) => {
28+
let s = ` var ${key}: ${mapSwiftType[schema.type] ?? schema.type}`
29+
if (schema._optional === true)
30+
s += '?'
31+
if (schema._default != null)
32+
s += ` = ${schema._default}`
33+
lines.push(s)
34+
})
35+
36+
lines.push('}')
37+
38+
return lines.join('\n')
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { Infer } from './schema'
2+
import { schemaExportTypescriptInterface } from './export-typescript'
3+
import { boolean, int, number, object, string } from './schema'
4+
5+
describe('typescript.spec', () => {
6+
it('parse args', async () => {
7+
const schema = object({
8+
anInt: int().optional().default(0),
9+
aBool: boolean(),
10+
aNumber: number(),
11+
aString: string(),
12+
})
13+
14+
type t = Infer<typeof schema>
15+
expectTypeOf<t>().toMatchTypeOf<any>()
16+
17+
const r = schemaExportTypescriptInterface(schema, 'Test')
18+
19+
expect(r).toMatchInlineSnapshot(`
20+
"interface Test {
21+
anInt?: number
22+
aBool: boolean
23+
aNumber: number
24+
aString: string
25+
}"
26+
`)
27+
})
28+
})
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { Type } from './schema'
2+
import { assert } from '../assert'
3+
import { objectMap } from '../data/object'
4+
import { isSchemaObjectFlat } from './utils'
5+
6+
// declare module './schema' {
7+
// interface TypeProps {
8+
// argShort?: string
9+
// argDesc?: string
10+
// }
11+
// }
12+
13+
const mapTypescriptType = {
14+
int: 'number',
15+
} as any
16+
17+
export function schemaExportTypescriptInterface<T>(schema: Type<T>, name: string = 'Example'): string {
18+
assert(isSchemaObjectFlat(schema), 'schema should be a flat object')
19+
20+
const lines: string[] = [
21+
`interface ${name} {`,
22+
]
23+
24+
objectMap(schema._object!, (key, schema: Type<any>) => {
25+
const s = ` ${key}${schema._optional === true ? '?' : ''}: ${mapTypescriptType[schema.type] ?? schema.type}`
26+
// if (schema._default != null)
27+
// s += ` = ${schema._default}`
28+
lines.push(s)
29+
})
30+
31+
lines.push('}')
32+
33+
return lines.join('\n')
34+
}

src/common/schema/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export * from './args'
22
export * from './env'
3+
export * from './export-swift'
4+
export * from './export-typescript'
35
export * from './schema'
46
export * from './utils'

0 commit comments

Comments
 (0)