{"id":25509367,"url":"https://github.com/javarome/fileutil","last_synced_at":"2026-02-25T19:31:02.900Z","repository":{"id":243510830,"uuid":"812241517","full_name":"Javarome/fileutil","owner":"Javarome","description":"File utility functions","archived":false,"fork":false,"pushed_at":"2025-02-28T15:53:36.000Z","size":64,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-26T21:53:45.007Z","etag":null,"topics":["directory","encoding-decoding","file","find","utilities-library"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Javarome.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-08T10:37:22.000Z","updated_at":"2025-02-28T15:53:40.000Z","dependencies_parsed_at":"2024-06-09T14:04:08.712Z","dependency_job_id":"a6e3b426-1c29-4539-a6e8-685be09c0f0e","html_url":"https://github.com/Javarome/fileutil","commit_stats":null,"previous_names":["javarome/fileutil"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Javarome/fileutil","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Javarome%2Ffileutil","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Javarome%2Ffileutil/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Javarome%2Ffileutil/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Javarome%2Ffileutil/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Javarome","download_url":"https://codeload.github.com/Javarome/fileutil/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Javarome%2Ffileutil/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29836174,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-25T19:08:47.527Z","status":"ssl_error","status_checked_at":"2026-02-25T18:59:04.705Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["directory","encoding-decoding","file","find","utilities-library"],"created_at":"2025-02-19T08:56:03.707Z","updated_at":"2026-02-25T19:31:02.884Z","avatar_url":"https://github.com/Javarome.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fileutil\nFile utilities.\n\n## Data types\n\n### FileContents\nRepresents a file with contents, either instantiated programmatically:\n```js\nnew FileContents()\n```\nor from the file system\n```js\nFileContents.read(\"path/someFile.xxx\")\n```\n```mermaid\nclassDiagram\n    class FileContents {\n        name: string\n        lastModified: Date\n        contents: string\n        encoding: BufferEncoding\n        write(): Promise\u003cvoid\u003e\n        read(fileName, declaredEncoding)$: FileContents\n        readOrNew(fileName, declaredEncoding)$: FileContents\n        getLang(filePath)$: FileContentsLang\n        getContents(fileName, declaredEncoding)$\n    }\n    class FileContentsLang {\n        lang: string | undefined\n        variants: string[]\n    }\n    FileContents --\u003e FileContentsLang: lang\n```\n\n- `static read(fileName, declaredEncoding)` creates FileContents from a file path.\n- `static readOrNew(fileName, declaredEncoding)` reads a file or instantiate a brand new SsgFile if it doesn't exist.\n- `static getLang(filePath): SsgFileLang` guesses a file language and its language file variants in the same directory.\n- `static getContents(fileName, declaredEncoding)` gets the text contents of a file, and how it is encoded.\n- `write()` writes the file contents according to its encoding.\n\n`FileContentsLang` represents a file language and the detected file variants.\n\nAn `HtmlFileContents` is available from [ssg-api](https://github.com/Javarome/ssg-api/blob/main/src/file/HtmlFileContents.test.ts).\n\n## Functions\n\n- `toBufferEncoding (encoding)` ccnverts encoding names to Node's buffer encoding names.\n- `detectEncoding (filePath)` detects the encoding of some file contents.\n- `detectContentsEncoding (buffer)` detects the encoding of some contents.\n- `ensureDirectoryOf (filePath)` checks if a directory exists and, if not, creates it.\n- `writeFile (filePath, contents, encoding)` writes a file. If the file directory doesn't exit, it is created.\n- `subDirs (fromDir): Promise\u003cDirent[]` gets a list of subdirectories.\n- `subDirsNames (fromDir): Promise\u003cstring[]\u003e` gets a list of subdirectories' names.\n- `findDirs (fromDirs, excludedDirs): Promise\u003cstring[]\u003e` finds directories under a set of dirs.\n- `findDirsContaining (fileName, exclude?): Promise\u003cstring[]\u003e` finds directories containing a file (but other).\n- `findSubDirs (ofDir, excludedDirs = []): Promise\u003cstring[]\u003e` finds subdirectories of a dir.\n- `copy (toDir, sourcePatterns, options): Promise\u003cstring[]\u003e` copies files to a destination directory.\n- `copyFiles (sourceFiles, toDir) {): string[]` copies multiple files to a directory.\n- `copyFile (sourceFilePath, destDir): string` copies a file to a directory.\n\n## Import\nFor instance:\n```js\nimport { FileContents, copy } from \"@javarome/fileutil\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjavarome%2Ffileutil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjavarome%2Ffileutil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjavarome%2Ffileutil/lists"}