本文整理汇总了TypeScript中csv-parse类的典型用法代码示例。如果您正苦于以下问题:TypeScript csv-parse类的具体用法?TypeScript csv-parse怎么用?TypeScript csv-parse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了csv-parse类的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));
}
开发者ID:DrDanRyan,项目名称:csv-translator,代码行数:14,代码来源:index.ts
示例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;
}
}
}
}
开发者ID:danvk,项目名称:localturk,代码行数:47,代码来源:csv.ts
示例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);
});
});
});
开发者ID:CMUBigLab,项目名称:cmuNodeFbot,代码行数:29,代码来源:import_beacon_csv.ts
示例4: parse
static parse(content: string, delimiter: string, cb: ResultCb<any[]>) {
const parseOptions = this.getParseOptions(delimiter);
parse(content, parseOptions, cb);
}
开发者ID:DrDanRyan,项目名称:csv-translator,代码行数:4,代码来源:index.ts
示例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));
}
开发者ID:DrDanRyan,项目名称:csv-translator,代码行数:5,代码来源:index.ts
注:本文中的csv-parse类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论