()
| 59 | }; |
| 60 | |
| 61 | const generate = function () { |
| 62 | let options; |
| 63 | let callback; |
| 64 | if (arguments.length === 2) { |
| 65 | options = arguments[0]; |
| 66 | callback = arguments[1]; |
| 67 | } else if (arguments.length === 1) { |
| 68 | if (typeof arguments[0] === "function") { |
| 69 | options = {}; |
| 70 | callback = arguments[0]; |
| 71 | } else { |
| 72 | options = arguments[0]; |
| 73 | } |
| 74 | } else if (arguments.length === 0) { |
| 75 | options = {}; |
| 76 | } |
| 77 | const generator = new Generator(options); |
| 78 | if (callback) { |
| 79 | const data = []; |
| 80 | generator.on("readable", function () { |
| 81 | let d; |
| 82 | while ((d = generator.read()) !== null) { |
| 83 | data.push(d); |
| 84 | } |
| 85 | }); |
| 86 | generator.on("error", callback); |
| 87 | generator.on("end", function () { |
| 88 | if (generator.options.objectMode) { |
| 89 | callback(null, data); |
| 90 | } else { |
| 91 | if (generator.options.encoding) { |
| 92 | callback(null, data.join("")); |
| 93 | } else { |
| 94 | callback(null, Buffer.concat(data)); |
| 95 | } |
| 96 | } |
| 97 | }); |
| 98 | } |
| 99 | return generator; |
| 100 | }; |
| 101 | |
| 102 | export { generate, Generator }; |
nothing calls this directly
no test coverage detected