Skip to content

Instantly share code, notes, and snippets.

@scarf005
Created September 11, 2023 23:12
Show Gist options
  • Save scarf005/cb820319d6e6d76a216dcb5bc7348f0d to your computer and use it in GitHub Desktop.
Save scarf005/cb820319d6e6d76a216dcb5bc7348f0d to your computer and use it in GitHub Desktop.
rename all files to be snake_case
import { walk } from "https://deno.land/std@0.201.0/fs/walk.ts"
import { join } from "https://deno.land/std@0.201.0/path/join.ts"
import { parse } from "https://deno.land/std@0.201.0/path/parse.ts"
import { asynciter } from "https://deno.land/x/asynciter@0.0.18/mod.ts"
import { snakeCase } from "https://deno.land/x/case@2.1.1/mod.ts"
if (import.meta.main) {
// walk all markdown files in doc/src/content, and rename filenames to snake_case
await asynciter(walk("doc/src/content", { exts: ["md"], includeDirs: false }))
.map(({ path }) => ({ path, ...parse(path) }))
.concurrentUnorderedMap(({ path, dir, name, ext }) => {
const newPath = join(dir, snakeCase(name) + ext)
console.log(`${path} -> ${newPath}`)
return Deno.rename(path, newPath)
})
.collect()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment