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


TypeScript split.default函数代码示例

本文整理汇总了TypeScript中split.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了default函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: reject

    reader.on('open', () => {
      let shasum: crypto.Hash;
      if (shouldHash) {
        shasum = crypto.createHash('sha1');
      }

      let lines = 0;
      let error: Error | undefined;
      const byLine = reader!.pipe(split());
      byLine.on('error', (e: Error) => {
        error = e;
      });
      byLine.on('data', (d: string) => {
        if (shouldHash) {
          shasum.update(d);
        }
        lines++;
      });
      byLine.on('end', () => {
        if (error) {
          reject(error);
        } else {
          const hash = shouldHash ? shasum.digest('hex') : undefined;
          resolve({hash, lines});
        }
      });
    });
开发者ID:GoogleCloudPlatform,项目名称:cloud-debug-nodejs,代码行数:27,代码来源:scanner.ts

示例2: catch

        const logStreamInLogger = (
          stream: ReadableStream | null,
          loggerLevel: Level,
        ) => {
          if (!stream) return;
          stream.pipe(split()).on('data', (line: string) => {
            if (line.length === 0) return;
            if (line.startsWith('{') && line.endsWith('}')) {
              try {
                const json: object = JSON.parse(line);
                logger.log('', json, loggerLevel);
                return;
              } catch (err) {}
            }

            outputLogger.log(line, undefined, loggerLevel);
          });
        };
开发者ID:christophehurpeau,项目名称:springbokjs-daemon,代码行数:18,代码来源:index.ts

示例3: Promise

    return new Promise((resolve, reject) => {

        const script = path.join(__dirname, 'app.js');
        const app = spawn('node', [ script, configFile ]);
        const results: FetchFeedOut[] = [];
        const errors: FetchError[] = [];

        app.stdout.pipe(split()).on('data', (line: string) => {
            if (!line) {
                return;
            }
            const obj = JSON.parse(line);
            if (obj.type === 'error') {
                const error = obj.data as FetchError;
                errors.push(error);
                console.error(`Feed ${error.url}`);
                console.error(error.err);

            } else if (obj.type === 'feed') {
                const feed = obj.data as FetchFeedOut;
                debug(`Got feed ${feed.url}`);
                feed.items.forEach((article) => {
                    article.date = article.date === null ? null : new Date(article.date);
                });
                results.push(feed);
            }
        });

        app.stderr.on('data', (data: string | Buffer) => {
            process.stderr.write(data);
        });

        app.on('close', (code: number) => {
            if (code === 0) {
                const ret: FetchResult = { errors, feeds: results };
                resolve(ret);
            } else {
                reject(new Error('Fetching failed.'));
            }
        });

        const feedsToFetch = feeds.map(({url, uuid}) => ({url, uuid}));
        app.stdin.write(JSON.stringify(feedsToFetch) + '\n');
    });
开发者ID:rla,项目名称:feeds,代码行数:44,代码来源:index.ts

示例4: fetchAll

const debug = debugLogger('app:fetch');

const writeOutput = util.promisify(
    (msg: string, cb: (err: Error) => void) => process.stdout.write(msg, cb));

const promisedRequest = util.promisify(request);

// Sets up stdin for receiving data.

process.stdin.resume();
process.stdin.setEncoding('utf8');

// Wait for incoming request.

process.stdin.pipe(split()).on('data', (line) => {
    (async () => {
        try {
            const feeds = JSON.parse(line) as FetchFeedIn[];
            // Fetch all feeds and exit then.
            await fetchAll(feeds);
            process.exit(0);
        } catch (err) {
            process.stderr.write(err + '\n');
            process.exit(1);
        }
    })();
});

// This should be moved to the parsing package.
开发者ID:rla,项目名称:feeds,代码行数:29,代码来源:app.ts

示例5: createLineStream

function createLineStream(callback) {
  return split().on("data", callback);
}
开发者ID:Clever,项目名称:kayvee-js,代码行数:3,代码来源:middleware.ts


注:本文中的split.default函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。