44 lines
1,001 B
JavaScript
44 lines
1,001 B
JavaScript
![]() |
function serializeListValue(value) {
|
||
|
const hash = {};
|
||
|
push(value);
|
||
|
return Object.keys(hash).join(" ");
|
||
|
function push(item) {
|
||
|
if (item && typeof item.forEach === "function")
|
||
|
item.forEach(push);
|
||
|
else if (item === Object(item))
|
||
|
Object.keys(item).forEach((name) => {
|
||
|
if (item[name])
|
||
|
push(name);
|
||
|
});
|
||
|
else {
|
||
|
item = item === false || item == null ? "" : String(item).trim();
|
||
|
if (item) {
|
||
|
item.split(/\s+/).forEach((name) => {
|
||
|
hash[name] = true;
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
function isPromise(value) {
|
||
|
return !!value && typeof value === "object" && typeof value.then === "function";
|
||
|
}
|
||
|
async function* streamAsyncIterator(stream) {
|
||
|
const reader = stream.getReader();
|
||
|
try {
|
||
|
while (true) {
|
||
|
const { done, value } = await reader.read();
|
||
|
if (done)
|
||
|
return;
|
||
|
yield value;
|
||
|
}
|
||
|
} finally {
|
||
|
reader.releaseLock();
|
||
|
}
|
||
|
}
|
||
|
export {
|
||
|
isPromise,
|
||
|
serializeListValue,
|
||
|
streamAsyncIterator
|
||
|
};
|