当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript csv-parse.default方法代码示例

本文整理汇总了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));
 }
开发者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.default方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。