D
Deno

help

Hoping for a clean way to get an array of filenames in directory

QQuantum1/28/2024
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?
ARAyo Reis1/28/2024
You could turn the iterable into an array with Array.from and then map it, if memory is not a concern.
ABAltair 680b1/29/2024
let files = [];
for await (const entry of Deno.readDirSync(Deno.cwd())) {
if (entry.isFile) files.push(entry.name);
}
let files = [];
for await (const entry of Deno.readDirSync(Deno.cwd())) {
if (entry.isFile) files.push(entry.name);
}
Dduncanmak1/29/2024
GitHub
GitHub - tc39/proposal-iterator-helpers: Methods for working with i...
Methods for working with iterators in ECMAScript. Contribute to tc39/proposal-iterator-helpers development by creating an account on GitHub.
npm
es-iterator-helpers
An ESnext spec-compliant iterator helpers shim/polyfill/replacement that works as far down as ES3.. Latest version: 1.0.15, last published: 4 months ago. Start using es-iterator-helpers in your project by running npm i es-iterator-helpers. There are 75 other projects in the npm registry using es-iterator-helpers.
Jjavi1/29/2024
You can use <Array>.fromAsync
const result = (await Array.fromAsync(Deno.readDir(Deno.cwd()))).filter(({ isFile }) => isFile);
const result = (await Array.fromAsync(Deno.readDir(Deno.cwd()))).filter(({ isFile }) => isFile);
Or go over the board with fp-ts, which is way more readable
import { task, function as func } from "npm:fp-ts"

const result = await func.pipe(
Deno.cwd(),
Deno.readDir,
Array.fromAsync,
task.of,
task.map((files) => files.filter(({ isFile }) => isFile)),
(fn) => fn()
)
import { task, function as func } from "npm:fp-ts"

const result = await func.pipe(
Deno.cwd(),
Deno.readDir,
Array.fromAsync,
task.of,
task.map((files) => files.filter(({ isFile }) => isFile)),
(fn) => fn()
)
LLeokuma1/29/2024
import { walkSync } from "https://deno.land/std@0.213.0/fs/walk.ts"

const files = walkSync('.', {maxDepth: 1})
import { walkSync } from "https://deno.land/std@0.213.0/fs/walk.ts"

const files = walkSync('.', {maxDepth: 1})
https://deno.land/std@0.213.0/fs/mod.ts?s=WalkOptions
QQuantum1/30/2024
Thanks everyone! Also, walk is awesome. 🙂

Looking for more? Join the community!

Recommended Posts
Support for auto-accessorsI'm playing around with Decorators, it seems like with `"experimentalDecorators": false`, there's a Rust sdk register_actity_typeHey, I am using the core_sdk in rust. I registered an activity, which should be able to consume follIs there a feature allowing custom "Allow?" CLI inputs?For example, if you `deno run` some program that reads from the file system, you're prompted `Deno r"deno compile --no-terminal" is not workingI'm trying to compile a very simple file named main.ts ```ts await Deno.writeTextFile('test.txt', 'HUsing fresh inside an existing deno folderI have an existing deno project with deno.jsonc at the root and would like to add a web app as a subRemove Dependencies from `deno.lock` fileHello, Somewhere in the code, I did `import postgres from npm:postgres`. This import is the writtenGood scripts/tools to automate conversion of Node.js based projects to Deno?I'm wondering if there are commendations for tools like this? (I found something like this, but it VS Code Extension API development with Deno as a runtime?I'm dipping my toes into [VS Code extension development](https://code.visualstudio.com/api/get-startImporting submodulesHi, I am working for the first time with deno in my supabase edge functions. I am trying to import aVariable references causing lint errors across cells in Deno+JupyterIf you define a variable in one cell and then try to reference it in another cell, you get a "CannotVSCode starting Deno even if enabled=falseII use VSCode in a large project (with several JS packages, none of which use Deno), and after instalUnable to build crate with deno_runtime 0.139.0 or 0.140.0, due to version numbering in deno_astThe two most recently released versions of the deno_runtime crate cannot build at all, due to its buwalk() include only last directory...Hey, I'm currently trying to write a replacer for file names, file content and folder names. My goalHow to link local NPM package with DenoI have a package which has a couple of peer dependencies, which I want to link locally and patch. Wh