Quantum
Quantum
DDeno
Created by Quantum on 1/28/2024 in #help
Hoping for a clean way to get an array of filenames in directory
Trying to do something like this:
const files = Deno.readDirSync(Deno.cwd()).map(x => x.name);
const files = Deno.readDirSync(Deno.cwd()).map(x => x.name);
But I get this: Property 'map' does not exist on type 'Iterable<DirEntry>'. Is a for loop the only way?
7 replies
DDeno
Created by Quantum on 12/18/2023 in #help
How to get the path to the compiled binary?
import.meta.url and Deno.mainModule are used to get the current script, but after a binary is created, those get frozen to the script at the time that the compile was performed. Moving the binary somewhere else gives you the same (now wrong) result when import.meta.url or Deno.mainModule get called.
11 replies
DDeno
Created by Quantum on 11/14/2023 in #help
How do I make the crypto.subtle.digest algo flexible?
This is a learning moment, bear with me. 😅 I can hard code an algo for the digest like this:
const algo = "SHA-256";
const d = new Uint8Array(
await crypto.subtle.digest(
algo, new TextEncoder().encode("test")
)
);
const algo = "SHA-256";
const d = new Uint8Array(
await crypto.subtle.digest(
algo, new TextEncoder().encode("test")
)
);
But if I want to make the algo flexible, it forces me to make it a DigestAlgorithm and it cannot be a string shown here:
async function digest(algo: string): Promise<Uint8Array> {
return new Uint8Array(
await crypto.subtle.digest(
algo, new TextEncoder().encode("test")
)
);
}
async function digest(algo: string): Promise<Uint8Array> {
return new Uint8Array(
await crypto.subtle.digest(
algo, new TextEncoder().encode("test")
)
);
}
I reviewed what that is in the source: https://github.com/denoland/deno_std/blob/main/crypto/_wasm/mod.ts I see this: export type DigestAlgorithm = typeof digestAlgorithms[number]; (I don't quite see what is going on here and am interested.) Bottom line is, when I make algo:string a algo:DigestAlgorithm in the digest function param list, it stops complaining, but I need to have some calling code somewhere be a flexible string (or maybe an enum if necessary) that somehow translates to a DigestAlgorithm for this to work. I've been struggling with this. Any ideas?
26 replies
DDeno
Created by Quantum on 11/12/2023 in #help
Is there a built-in parser for the string that Deno.inspect produces?
I found out in another thread that Deno.inspect(myObj) produces a visually gorgeous string representation of objects and can represent internal data structures that JSON.stringify fails to represent. (Thank you @cknight for helping me with that!) My next question is, does Deno happen to have the analog of JSON.parse for what gets output by Deno.inspect? Can we take the Deno.inspect output and turn it back into what would become a clone of the original object? (To be clear: I am not asking if JSON.parse will do this. I am asking if there is a nifty Deno function that does it.)
4 replies
DDeno
Created by Quantum on 11/12/2023 in #help
How to get the nice Deno console.log format into a string?
When I do a console.log on an instantiated class object, I get a beautiful format in the terminal, thanks to Deno. How would I get that same nice Deno format into a string? When I do obj.toString(), I just get the standard Javascript [object Object].
6 replies