本文整理匯總了TypeScript中csv-parse.default方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript csv-parse.default方法的具體用法?TypeScript csv-parse.default怎麽用?TypeScript csv-parse.default使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類csv-parse
的用法示例。
在下文中一共展示了csv-parse.default方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: read
static read(src: string, arg1: any, arg2?: any) {
let readOptions: ReadOptions;
let cb: ResultCb<any[]>;
if (arg2 === undefined) {
readOptions = {};
cb = arg1;
} else {
readOptions = arg1;
cb = arg2;
}
const delimiter = readOptions.delimiter || this.getDefaultDelimiter(src);
const parseOptions = this.getParseOptions(delimiter);
createReadStream(src).pipe(parse(parseOptions, cb));
}
示例2: Error
export async function* readRows(file: string) {
const parser = csvParse(csvOptions);
const stream = fs.createReadStream(file, 'utf8');
let isDone = false;
let dataCallback;
const mkBarrier = () => new Promise<void>((resolve, reject) => {
dataCallback = resolve;
});
// TODO(danvk): use a deque
const rows: (RowResult|Promise<void>)[] = [mkBarrier()];
parser.on('readable', () => {
let row;
while (row = parser.read()) {
rows.push({type: 'row', value: row});
}
const oldCb = dataCallback;
rows.push(mkBarrier());
oldCb();
});
parser.on('error', error => {
rows.push({type: 'error', error});
parser.pause();
dataCallback();
});
parser.on('finish', () => {
rows.push({type: 'done'});
dataCallback();
});
stream.pipe(parser);
while (rows.length) {
const row = rows.shift();
if (isPromise(row)) {
await row;
} else {
if (row.type === 'row') {
yield row.value;
} else if (row.type === 'error') {
throw new Error(row.error);
} else if (row.type === 'done') {
break;
}
}
}
}
示例3: BeaconSlot
let parser = parse({delimiter: ",", columns: true}, function(err, data){
return Promise.map<BeaconRow, any>(data, function(b) {
return new BeaconSlot({
id: b.bid,
lat: b.lat,
long: b.lng,
edge: b.edge,
floor: b.floor,
start_node: b.start,
end_node: b.end,
deployment_id: 6,
}).save(null, {method: "insert"})
.then(function(slot) {
return new Beacon({
id: b.bid,
minor_id: b.minor,
slot: slot.id,
deployment_id: 6,
}).save(null, {method: "insert"})
.then(function(beacon) {
return slot.save({beacon_id: beacon.id}, {method: "update"});
});
}).then(() => process.exit())
.catch(err => {
console.log(err);
process.exit(1);
});
});
});
示例4: parse
static parse(content: string, delimiter: string, cb: ResultCb<any[]>) {
const parseOptions = this.getParseOptions(delimiter);
parse(content, parseOptions, cb);
}
示例5: createReadStream
static createReadStream(src: string, readOptions: ReadOptions = {}): NodeJS.ReadableStream {
const delimiter = readOptions.delimiter || this.getDefaultDelimiter(src);
const parseOptions = this.getParseOptions(delimiter);
return createReadStream(src).pipe(parse(parseOptions));
}