mirror of
https://github.com/nocodb/nocodb.git
synced 2026-04-29 17:17:16 +00:00
32 lines
761 B
TypeScript
32 lines
761 B
TypeScript
import { UITypes } from 'nocodb-sdk'
|
|
|
|
export default
|
|
function convertCellData(args: { from: UITypes; to: UITypes; value: any }) {
|
|
const { from, to, value } = args
|
|
if (from === to) {
|
|
return value
|
|
}
|
|
|
|
switch (to) {
|
|
case UITypes.Number:
|
|
return Number(value)
|
|
case UITypes.Checkbox:
|
|
return Boolean(value)
|
|
case UITypes.Date:
|
|
return new Date(value)
|
|
case UITypes.Attachment:
|
|
try {
|
|
return typeof value === 'string' ? JSON.parse(value) : value
|
|
} catch (e) {
|
|
return []
|
|
}
|
|
case UITypes.LinkToAnotherRecord:
|
|
case UITypes.Lookup:
|
|
case UITypes.Rollup:
|
|
case UITypes.Formula:
|
|
throw new Error(`Unsupported conversion from ${from} to ${to}`)
|
|
default:
|
|
return value
|
|
}
|
|
}
|