本文整理匯總了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);
}