Skip to content

Commit 3553c22

Browse files
committed
🎉 feat: handle property name with dot
1 parent e08a504 commit 3553c22

File tree

5 files changed

+32
-20
lines changed

5 files changed

+32
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.2.1 - 22 Aug 2025
2+
Bug fix:
3+
- handle property name with dot
4+
15
# 0.2.0 - 21 Aug 2025
26
Feature:
37
- add `createMirrorCode` to generate mirror code from schema

example/index.ts

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,20 @@ import createMirror, { createMirrorCode } from '../src/index'
33

44
import { TypeCompiler } from '@sinclair/typebox/compiler'
55

6-
const shape = t.Recursive((This) =>
7-
t.Object({
8-
type: t.String(),
9-
data: t.Union([t.Nullable(This), t.Array(This)])
10-
})
11-
)
6+
const shape = t.Object({
7+
'character.name': t.String()
8+
})
129

1310
const value = {
14-
type: 'yea',
15-
data: {
16-
type: 'ok',
17-
data: [
18-
{
19-
type: 'cool',
20-
data: null
21-
}
22-
]
23-
}
11+
'character.name': 'SaltyAom'
2412
} satisfies typeof shape.static
2513

26-
const mirror = createMirror(shape, {
14+
const mirror = createMirrorCode(shape, {
2715
TypeCompiler,
2816
sanitize: (a) => a
2917
})
3018

31-
// console.log(mirror.toString())
19+
console.log(mirror)
3220

3321
// console.dir(mirror(value), {
3422
// depth: null

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "exact-mirror",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "Mirror exact value to TypeBox/OpenAPI model",
55
"license": "MIT",
66
"scripts": {

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const Kind = Symbol.for('TypeBox.Kind')
66
const Hint = Symbol.for('TypeBox.Hint')
77

88
const isSpecialProperty = (name: string) =>
9-
/(\ |-|\t|\n)/.test(name) || !isNaN(+name[0])
9+
/(\ |-|\t|\n|\.)/.test(name) || !isNaN(+name[0])
1010

1111
const joinProperty = (v1: string, v2: string | number, isOptional = false) => {
1212
if (typeof v2 === 'number') return `${v1}[${v2}]`

test/index.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,24 @@ describe('Core', () => {
286286

287287
isEqual(shape, value)
288288
})
289+
290+
it('handle name with hyphen or dot', () => {
291+
const shape = t.Object({
292+
'a.b': t.String(),
293+
'a-b': t.String()
294+
})
295+
296+
const value = {
297+
'a.b': 'one',
298+
// @ts-ignore
299+
'a-b': 'b'
300+
} satisfies typeof shape.static
301+
302+
const expected = {
303+
'a.b': 'one',
304+
'a-b': 'b'
305+
} satisfies typeof shape.static
306+
307+
isEqual(shape, value, expected)
308+
})
289309
})

0 commit comments

Comments
 (0)