當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。