本文整理汇总了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));
}