kjelsrud.dev/node_modules/astro/dist/runtime/server/util.js

44 lines
1,001 B
JavaScript
Raw Normal View History

2023-07-19 21:31:30 +02:00
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
};