Add special characters to text to print in color in the console (combined with console.log()).

Use template literals and special characters to add the appropriate color code to the string output.
For background colors, add a special character that resets the background color at the end of the string.

继续阅读 30秒学会 JavaScript 片段 – colorize

Checks if the given argument is a readable stream.

Check if the value is different from null, use typeof to check if the value is of type object and the pipe property is of type function.
Additionally check if the typeof the _read and _readableState properties are function and object respectively.

继续阅读 30秒学会 JavaScript 片段 – isReadableStream

Checks if the given argument is a duplex (readable and writable) stream.

Check if the value is different from null, use typeof to check if a value is of type object and the pipe property is of type function.
Additionally check if the typeof the _read, _write and _readableState, _writableState properties are function and object respectively.

继续阅读 30秒学会 JavaScript 片段 – isDuplexStream

Returns an array of lines from the specified file.

Use readFileSync function in fs node package to create a Buffer from a file.
convert buffer to string using toString(encoding) function.
creating an array from contents of file by spliting file content line by line (each \n).

继续阅读 30秒学会 JavaScript 片段 – readFileLines