本文整理汇总了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});
}
});
});
示例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);
});
};
示例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');
});
示例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.
示例5: createLineStream
function createLineStream(callback) {
return split().on("data", callback);
}