Son CV dans un terminal web en Javascript!
https://terminal-cv.gregandev.fr
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
2 years ago
|
// @flow strict-local
|
||
|
|
||
|
import type {JSONObject} from '@parcel/types';
|
||
|
|
||
|
import logger from '@parcel/logger';
|
||
|
import {Transform} from 'stream';
|
||
|
|
||
|
// Transforms chunks of json strings to parsed objects.
|
||
|
// Pair with split2 to parse stream of newline-delimited text.
|
||
|
export default class JSONParseStream extends Transform {
|
||
|
constructor(options: mixed) {
|
||
|
super({...options, objectMode: true});
|
||
|
}
|
||
|
|
||
|
// $FlowFixMe We are in object mode, so we emit objects, not strings
|
||
|
_transform(
|
||
|
chunk: Buffer | string,
|
||
|
encoding: string,
|
||
|
callback: (err: ?Error, parsed: ?JSONObject) => mixed,
|
||
|
) {
|
||
|
try {
|
||
|
let parsed;
|
||
|
try {
|
||
|
parsed = JSON.parse(chunk.toString());
|
||
|
} catch (e) {
|
||
|
// Be permissive and ignoreJSON parse errors in case there was
|
||
|
// a non-JSON line in the package manager's stdout.
|
||
|
logger.verbose({
|
||
|
message: 'Ignored invalid JSON message: ' + chunk.toString(),
|
||
|
origin: '@parcel/package-manager',
|
||
|
});
|
||
|
return;
|
||
|
}
|
||
|
callback(null, parsed);
|
||
|
} catch (err) {
|
||
|
callback(err);
|
||
|
}
|
||
|
}
|
||
|
}
|