diff --git a/src/cli/files.cmd.ts b/src/cli/files.cmd.ts index d59174a..c995130 100644 --- a/src/cli/files.cmd.ts +++ b/src/cli/files.cmd.ts @@ -20,8 +20,8 @@ const listCmd = new Command('ls') }); logOutputList(cmd.format, files.map(v => ({ ...v, - size: Number(v.size), - dataId: Number(v.dataId) + size: v.size, + dataId: v.dataId }), { dataId: 'Data ID', name: 'Name', @@ -48,10 +48,10 @@ const viewCmd = new Command('view') return; } logOutputObject(cmd.format, { - dataId: Number(file.dataId), + dataId: file.dataId, name: file.name, type: file.type, - size: Number(file.size), + size: file.size, hash: file.hash, supportedCountries: file.supportedCountries, supportedLanguages: file.supportedLanguages, diff --git a/src/cli/output.ts b/src/cli/output.ts index 7970cec..7b64c5e 100644 --- a/src/cli/output.ts +++ b/src/cli/output.ts @@ -11,14 +11,16 @@ function mapOutputObject(obj: FormattableObject, mapping: FieldMapping): Formatt return Object.fromEntries(mappedEntries); } +function jsonReplacer(key: string, value: any): any { + if (typeof value === 'bigint') { + return Number(value); + } + return value; +} + export function logOutputList(format: FormatOption, items: T[], mapping: FieldMapping = {}): void { if (format === 'json') { - console.log(JSON.stringify(items, (_, v) => { - if (typeof v === 'bigint') { - return v.toString(); - } - return v; - }, 2)); + console.log(JSON.stringify(items, jsonReplacer, 2)); return; } const mappedItems = items.map(item => mapOutputObject(item, mapping)); @@ -27,7 +29,7 @@ export function logOutputList(format: FormatOption, export function logOutputObject(format: FormatOption, obj: T, mapping: FieldMapping = {}): void { if (format === 'json') { - console.log(JSON.stringify(obj, null, 2)); + console.log(JSON.stringify(obj, jsonReplacer, 2)); return; } console.log(mapOutputObject(obj, mapping));