sflow
Version:
sflow is a powerful and highly-extensible library designed for processing and manipulating streams of data effortlessly. Inspired by the functional programming paradigm, it provides a rich set of utilities for transforming streams, including chunking, fil
45 lines (39 loc) • 1.32 kB
text/typescript
import { lines } from "./lines";
import { sflow } from "./sf";
it("split string stream into lines stream", async () => {
expect(
await sflow("a,b,c\n1,2,3\n\nd,s,f".split(""))
.through(lines({ EOL: "NONE" }))
.toArray(),
).toEqual(["a,b,c", "1,2,3", "", "d,s,f"]);
expect(
await sflow("a,b,c\n1,2,3\n\nd,s,f")
.through(lines({ EOL: "NONE" }))
.toArray(),
).toEqual(["a,b,c", "1,2,3", "", "d,s,f"]);
expect(
await sflow(["a,b,c\n1,", "2,3\n\nd,s,f"]).lines({ EOL: "NONE" }).toArray(),
).toEqual(["a,b,c", "1,2,3", "", "d,s,f"]);
});
it("Change EOL", async () => {
expect(
await sflow("a,b,c\n1,2,3\n\nd,s,f".split(""))
.through(lines({ EOL: "LF" }))
.toArray(),
).toEqual(["a,b,c\n", "1,2,3\n", "\n", "d,s,f\n"]);
expect(
await sflow("a,b,c\n1,2,3\n\nd,s,f".split(""))
.through(lines({ EOL: "CRLF" }))
.toArray(),
).toEqual(["a,b,c\r\n", "1,2,3\r\n", "\r\n", "d,s,f\r\n"]);
expect(
await sflow("a,b,c\n1,2,3\n\r\nd,s,f".split(""))
.through(lines({ EOL: "KEEP" }))
.toArray(),
).toEqual(["a,b,c\n", "1,2,3\n", "\r\n", "d,s,f"]);
expect(
await sflow("a,b,c\n1,2,3\n\r\nd,s,f\n".split(""))
.through(lines({ EOL: "KEEP" }))
.toArray(),
).toEqual(["a,b,c\n", "1,2,3\n", "\r\n", "d,s,f\n"]);
});