mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-23 02:12:41 +00:00
migrate to typescript
This commit is contained in:
18
src/lib/serial/line-break-transformer.ts
Normal file
18
src/lib/serial/line-break-transformer.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export class LineBreakTransformer {
|
||||
private chunks = ""
|
||||
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
transform(chunk: string, controller: TransformStreamDefaultController) {
|
||||
this.chunks += chunk
|
||||
const lines = this.chunks.split("\r\n")
|
||||
this.chunks = lines.pop()!
|
||||
for (const line of lines) {
|
||||
controller.enqueue(line)
|
||||
}
|
||||
}
|
||||
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
flush(controller: TransformStreamDefaultController) {
|
||||
controller.enqueue(this.chunks)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user