A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://c2fo.github.io/fast-csv/docs/introduction/example below:

Quick Examples | Fast-CSV

import * as fs from 'fs';

import * as path from 'path';

import * as csv from 'fast-csv';

import { User } from './models/user';

interface UserCsvRow {

id: string;

first_name: string;

last_name: string;

address: string;

}

interface UserDetailsRow {

id: number;

firstName: string;

lastName: string;

address: string;

isVerified: boolean;

hasLoggedIn: boolean;

age: number;

}

fs.createReadStream(path.resolve(__dirname, 'assets', 'snake_case_users.csv'))

.pipe(csv.parse({ headers: true }))

.pipe(

csv.format<UserCsvRow, UserDetailsRow>({ headers: true }),

)

.transform((row, next): void => {

User.findById(+row.id, (err, user) => {

if (err) {

return next(err);

}

if (!user) {

return next(new Error(`Unable to find user for ${row.id}`);

}

return next(null, {

id: user.id,

firstName: row.first_name,

lastName: row.last_name,

address: row.address,

isVerified: user.isVerified,

hasLoggedIn: user.hasLoggedIn,

age: user.age,

});

});

})

.pipe(process.stdout)

.on('end', () => process.exit());


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4