Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
devchenyan committed Jun 5, 2024
1 parent d4a5e51 commit d0e6363
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/neuron-wallet/src/models/chain/cell-dep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class CellDep {
this.depType = depType
}

public static fromObject({ outPoint, depType }: { outPoint: OutPoint; depType: DepType }): CellDep {
public static fromObject({ outPoint, depType }: { outPoint: OutPoint; depType: DepType | 'dep_group' }): CellDep {
const _depType = snakeToCamel(depType) as DepType
return new CellDep(OutPoint.fromObject(outPoint), _depType)
}
Expand Down
38 changes: 14 additions & 24 deletions packages/neuron-wallet/src/utils/deep-camelize-keys.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
export function snakeToCamel(key: string) {
if (!key) return ''

let keyArr = key.split('_')
for (let i = 0; i < keyArr.length; i++) {
if (i !== 0) {
keyArr[i] = keyArr[i][0].toUpperCase() + keyArr[i].substr(1)
}
}
return keyArr.join('')
export const snakeToCamel = (str: string): string => {
return str.replace(/([-_][a-z])/gi, c => c.toUpperCase().replace(/[-_]/g, ''))
}

type Json = Record<string, unknown>

export function deepCamelizeKeys(param: Json): Json {
Object.keys(param).map(key => {
let item = param[key]
if (item instanceof Object) {
deepCamelizeKeys(item as Json)
}
if (snakeToCamel(key) !== key) {
param[snakeToCamel(key)] = param[key]
delete param[key]
}
})
return param
export const deepCamelizeKeys = (item: unknown): unknown => {
if (Array.isArray(item)) {
return item.map((el: unknown) => deepCamelizeKeys(el))
} else if (typeof item === 'function' || item !== Object(item)) {
return item
}
return Object.fromEntries(
Object.entries(item as Record<string, unknown>).map(([key, value]: [string, unknown]) => [
key.replace(/([-_][a-z])/gi, c => c.toUpperCase().replace(/[-_]/g, '')),
deepCamelizeKeys(value),
])
)
}

export default { deepCamelizeKeys, snakeToCamel }

1 comment on commit d0e6363

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packaging for test is done in 9377482374

Please sign in to comment.