Skip to content

Commit a5a04a5

Browse files
committed
🎉 feat: improve array operation
1 parent 2ee87b3 commit a5a04a5

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 0.1.7
1+
# 0.1.7 - 25 Apr 2025
22
Improvement:
33
- improve array operation
44

example/index.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import { t } from 'elysia'
22
import { createAccelerator } from '../src/index'
33

4-
const shape = t.Object({
5-
name: t.String({
6-
// trusted: true
4+
const shape = t.Array(
5+
t.Object({
6+
name: t.String()
77
})
8-
})
8+
)
99

10-
const string = `hi awd`
11-
12-
const value = {
13-
name: string
14-
} satisfies typeof shape.static
10+
const value = [
11+
{
12+
name: 'a'
13+
},
14+
{
15+
name: 'b'
16+
}
17+
] satisfies typeof shape.static
1518

1619
const mirror = createAccelerator(shape)
1720

18-
console.log(JSON.parse(mirror(value)))
21+
console.log((mirror(value)))

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-accelerator",
3-
"version": "0.1.6",
3+
"version": "0.1.7",
44
"description": "Speed up JSON stringification by providing OpenAPI/TypeBox model",
55
"license": "MIT",
66
"scripts": {

src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,7 @@ const accelerate = (
355355
const name = joinProperty(property, key)
356356
const hasShortName =
357357
schema.properties[key].type === 'object' &&
358-
!name.startsWith('ar') &&
359-
Object.keys(schema.properties).length > 5
358+
!name.startsWith('ar')
360359

361360
const i = instruction.properties.length
362361
if (hasShortName) instruction.properties.push(name)
@@ -529,6 +528,8 @@ export const createAccelerator = <T extends TAnySchema>(
529528
definitions
530529
})
531530

531+
console.log(f)
532+
532533
return Function('v', f) as any
533534
}
534535

0 commit comments

Comments
 (0)