(options)
| 8 | import { Generator } from "./index.js"; |
| 9 | |
| 10 | const generate = function (options) { |
| 11 | if (typeof options === "string" && /\d+/.test(options)) { |
| 12 | options = parseInt(options); |
| 13 | } |
| 14 | if (Number.isInteger(options)) { |
| 15 | options = { length: options }; |
| 16 | } else if (typeof options !== "object" || options === null) { |
| 17 | throw Error("Invalid Argument: options must be an object or an integer"); |
| 18 | } |
| 19 | if (!Number.isInteger(options.length)) { |
| 20 | throw Error("Invalid Argument: length is not defined"); |
| 21 | } |
| 22 | const chunks = []; |
| 23 | let work = true; |
| 24 | const generator = new Generator(options); |
| 25 | generator.push = function (chunk) { |
| 26 | if (chunk === null) { |
| 27 | return (work = false); |
| 28 | } |
| 29 | chunks.push(chunk); |
| 30 | }; |
| 31 | while (work) { |
| 32 | generator.__read(options.highWaterMark); |
| 33 | } |
| 34 | if (!options.objectMode) { |
| 35 | return chunks.join(""); |
| 36 | } else { |
| 37 | return chunks; |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | export { generate }; |
no outgoing calls
no test coverage detected