Skip to content

Commit

Permalink
Optimize Object Property Conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairzx81 committed Apr 24, 2024
1 parent 2a2b5d9 commit 94924b7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/value/convert/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import type { TUndefined } from '../../type/undefined/index'
// ------------------------------------------------------------------
// ValueGuard
// ------------------------------------------------------------------
import { IsArray, IsObject, IsDate, IsUndefined, IsString, IsNumber, IsBoolean, IsBigInt, IsSymbol } from '../guard/index'
import { IsArray, IsObject, IsDate, IsUndefined, IsString, IsNumber, IsBoolean, IsBigInt, IsSymbol, HasPropertyKey } from '../guard/index'
// ------------------------------------------------------------------
// Conversions
// ------------------------------------------------------------------
Expand Down Expand Up @@ -194,11 +194,11 @@ function FromNumber(schema: TNumber, references: TSchema[], value: any): unknown
function FromObject(schema: TObject, references: TSchema[], value: any): unknown {
const isConvertable = IsObject(value)
if(!isConvertable) return value
return Object.getOwnPropertyNames(schema.properties).reduce((value, key) => {
return !IsUndefined(value[key])
? ({ ...value, [key]: Visit(schema.properties[key], references, value[key]) })
: ({ ...value })
}, value)
for(const key of Object.keys(value)) {
if(!HasPropertyKey(schema.properties, key)) continue
value[key] = Visit(schema.properties[key], references, value[key])
}
return value
}
function FromRecord(schema: TRecord, references: TSchema[], value: any): unknown {
const propertyKey = Object.getOwnPropertyNames(schema.patternProperties)[0]
Expand Down

0 comments on commit 94924b7

Please sign in to comment.