mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-25 16:02:11 +00:00
c7f6ff14af
- Fixed 'occured' -> 'occurred' (10 instances) - Fixed 'commited' -> 'committed' (2 instances) Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
53 lines
1.1 KiB
TypeScript
53 lines
1.1 KiB
TypeScript
import { Parser } from '@json2csv/plainjs'
|
|
|
|
export function isLink(value: string) {
|
|
return value?.startsWith('http://') || value?.startsWith('https://')
|
|
}
|
|
|
|
export function isEmail(value: string) {
|
|
return value?.includes('@')
|
|
}
|
|
|
|
export function computeStructuredObjectsAndHeaders(objects: Array<Record<string, any>>): [
|
|
string[],
|
|
{
|
|
_id: number
|
|
rowData: Record<string, any>
|
|
}[]
|
|
] {
|
|
if (Array.isArray(objects)) {
|
|
let nextId = 1
|
|
|
|
let hds: string[] = []
|
|
let objs = objects.map((obj) => {
|
|
let rowData = obj && typeof obj == 'object' ? obj : {}
|
|
if (Array.isArray(rowData)) {
|
|
rowData = Object.fromEntries(rowData.map((x, i) => ['col' + i, x]))
|
|
}
|
|
let ks = Object.keys(rowData)
|
|
ks.forEach((x) => {
|
|
if (!hds.includes(x)) {
|
|
hds.push(x)
|
|
}
|
|
})
|
|
return {
|
|
_id: nextId++,
|
|
rowData
|
|
}
|
|
})
|
|
return [hds, objs]
|
|
} else {
|
|
return [[], []]
|
|
}
|
|
}
|
|
|
|
export function convertJsonToCsv(arr: Array<Record<string, any>>): string {
|
|
try {
|
|
const parser = new Parser({})
|
|
const csv = parser.parse(arr)
|
|
return csv
|
|
} catch (err) {
|
|
throw new Error('An error occurred when generating CSV:' + err)
|
|
}
|
|
}
|