Comparing version 0.0.1 to 0.1.0
26
index.js
@@ -1,5 +0,23 @@ | ||
export default async function aiDecode(data) { | ||
for (const item of data) { | ||
await item; | ||
} | ||
import AsyncIterable from "asynciterable"; | ||
import { TextDecoder } from "util"; | ||
export default function aiDecode(iterable, encoding = "utf8") { | ||
const decoder = new TextDecoder(encoding); | ||
const generator = iterable[Symbol.asyncIterator] || iterable[Symbol.iterator]; | ||
const iterator = generator.call(iterable); | ||
return new AsyncIterable(async (write, end) => { | ||
let item = {}; | ||
while (!item.done) { | ||
item = await iterator.next(); | ||
if (!item.done) { | ||
write(decoder.decode(item.value, { stream: true })); | ||
} | ||
} | ||
const lastChunk = decoder.decode(); | ||
if (lastChunk) { | ||
write(lastChunk); | ||
} | ||
end(); | ||
}); | ||
} |
{ | ||
"name": "ai-decode", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Decode a Buffer async iterable into a String async iterable.", | ||
@@ -44,2 +44,4 @@ "repository": "parro-it/ai-decode", | ||
"@std/esm": "^0.18.0", | ||
"ai-concat": "^1.3.0", | ||
"ai-node": "^0.1.1", | ||
"documentation": "^5.3.3", | ||
@@ -49,3 +51,7 @@ "linterjs": "^1.11.0", | ||
"tape-async": "^2.3.0" | ||
}, | ||
"dependencies": { | ||
"asynciterable": "^1.1.0", | ||
"prettier": "^1.8.2" | ||
} | ||
} |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
3862
21
0
2
7
+ Addedasynciterable@^1.1.0
+ Addedprettier@^1.8.2
+ Addedasynciterable@1.1.0(transitive)
+ Addedprettier@1.19.1(transitive)