當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript csv-parse類代碼示例

本文整理匯總了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;未經允許,請勿轉載。