{"id":17999564,"url":"https://github.com/ozum/fs-structure","last_synced_at":"2025-04-04T07:15:04.189Z","repository":{"id":57242367,"uuid":"329073760","full_name":"ozum/fs-structure","owner":"ozum","description":"Create and delete files and folders in any structure using object syntax or JSON.","archived":false,"fork":false,"pushed_at":"2021-01-26T11:11:45.000Z","size":297,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-10T13:04:47.225Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/ozum.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}},"created_at":"2021-01-12T18:16:49.000Z","updated_at":"2021-01-26T11:10:19.000Z","dependencies_parsed_at":"2022-09-09T04:00:23.091Z","dependency_job_id":null,"html_url":"https://github.com/ozum/fs-structure","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ozum%2Ffs-structure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ozum%2Ffs-structure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ozum%2Ffs-structure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ozum%2Ffs-structure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ozum","download_url":"https://codeload.github.com/ozum/fs-structure/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247135147,"owners_count":20889421,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-10-29T22:13:43.033Z","updated_at":"2025-04-04T07:15:04.171Z","avatar_url":"https://github.com/ozum.png","language":"TypeScript","readme":"# fs-structure\n\nCreate and delete files and folders in any structure using object syntax or JSON.\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n- [Installation](#installation)\n- [Synopsis](#synopsis)\n- [Details](#details)\n- [fs-structure](#fs-structure)\n  - [Table of contents](#table-of-contents)\n    - [Type aliases](#type-aliases)\n    - [Functions](#functions)\n  - [Type aliases](#type-aliases-1)\n    - [Tree](#tree)\n  - [Functions](#functions-1)\n    - [create](#create)\n    - [flat](#flat)\n    - [load](#load)\n    - [remove](#remove)\n    - [symlink](#symlink)\n    - [tempDir](#tempdir)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n# Installation\n\n# Synopsis\n\n```ts\nimport { load, create, remove, flat, symlink } from \"fs-structure\";\n```\n\n```ts\nconst tree = {\n  // Flat style (path as key)\n  \"README.md\": \"Write here README content.\",\n  \"src/index.js\": \"console.log('Hello');\",\n  \"src/helper/util.js\": \"...\",\n  \"src/helper/main.js\": \"...\",\n  \"some-link\": symlink({ target: \"/path/to/some\" }), // Using helepr function.\n  \"other-link\": { $type: \"Symlink\", target: \"/path/to/other\" }, // Using object.\n\n  // Below files are added to \"test\" directory\". Also paths can be used too.\n  test: {\n    \"index.test.js\": \"...\",\n    \"helper/util.test.js\": \"...\",\n    \"helper/main.test.js\": \"...\",\n  },\n};\n```\n\n```ts\nawait create(tree, { cwd: \"/path/to/project\" });\n\nconst loadedTree = await load(\"/path/to/project\");\n\nawait remove(tree, { cwd: \"/path/to/project\" });\n\nconst flatTree = flat(tree);\n```\n\n```ts\nexpect(flatTree).toEqual(loadedTree);\n```\n\n# Details\n\n`fs-structure` is a basic module to make it easier to create and delete file and folder structure. Structre can be defined as JS object or loaded from JSON.\n\n- Ignores system files such as `.DS_Store` and `Thumbs.db`. Change with `load(path, { ignoreJunk: false })`\n- Deletes empty directories. Change with `remove(tree, { rmUp: undefined });\n- Loads tree from file system.\n- Provides `flat()` function for easy comparison in tests.\n\n\u003c!-- usage --\u003e\n\n\u003c!-- commands --\u003e\n\n\u003ca name=\"readmemd\"\u003e\u003c/a\u003e\n\nfs-structure\n\n# fs-structure\n\n## Table of contents\n\n### Type aliases\n\n- [Tree](#tree)\n\n### Functions\n\n- [create](#create)\n- [flat](#flat)\n- [load](#load)\n- [remove](#remove)\n- [symlink](#symlink)\n- [tempDir](#tempdir)\n\n## Type aliases\n\n### Tree\n\nƬ **Tree**: _ItemLike_\u003cRoot\\\u003e\n\nDefined in: [main.ts:17](https://github.com/ozum/fs-structure/blob/efe12fd/src/main.ts#L17)\n\n## Functions\n\n### create\n\n▸ **create**(`input`: [_Tree_](#tree), `options?`: CreateOptions): _Promise_\u003c_void_\\\u003e\n\nCreates files and directories in file system using given tree.\n\n#### Example\n\n```typescript\nawait create({ a: 1, src: { b: 2, c: 2 } });\n```\n\n#### Parameters:\n\n| Name      | Type            | Default value | Description                                |\n| --------- | --------------- | ------------- | ------------------------------------------ |\n| `input`   | [_Tree_](#tree) | -             | is the file tree to create in file system. |\n| `options` | CreateOptions   | ...           | -                                          |\n\n**Returns:** _Promise_\u003c_void_\\\u003e\n\nDefined in: [main.ts:119](https://github.com/ozum/fs-structure/blob/efe12fd/src/main.ts#L119)\n\n---\n\n### flat\n\n▸ **flat**(`input`: [_Tree_](#tree), `__namedParameters?`: { `cwd?`: _string_ ; `includeDirs?`: _boolean_ }): [_Tree_](#tree)\n\nConverts given tree to a flat structure. May be used to compare two file tree easily.\n\n#### Example\n\n```typescript\nconst tree = {\n  a: \"1\"\n  src: {\n    b: \"2\",\n    c: \"3\",\n  },\n};\n\nconst flatObject = flat(tree); // { a: 1, \"src/b\": 2, \"src/c\": 2 }\n```\n\n#### Parameters:\n\n| Name                | Type                                             | Default value | Description        |\n| ------------------- | ------------------------------------------------ | ------------- | ------------------ |\n| `input`             | [_Tree_](#tree)                                  | -             | is the input tree. |\n| `__namedParameters` | { `cwd?`: _string_ ; `includeDirs?`: _boolean_ } | ...           | -                  |\n\n**Returns:** [_Tree_](#tree)\n\nflat object for file system.\n\nDefined in: [main.ts:155](https://github.com/ozum/fs-structure/blob/efe12fd/src/main.ts#L155)\n\n---\n\n### load\n\n▸ **load**(`path`: _string_, `__namedParameters?`: { `ignoreJunk?`: _boolean_ ; `includeDirs?`: _boolean_ }): _Promise_\u003c[_Tree_](#tree)\\\u003e\n\nLoads file tree from file system and makes it flat.\n\n#### Parameters:\n\n| Name                | Type                                                     | Default value | Description                         |\n| ------------------- | -------------------------------------------------------- | ------------- | ----------------------------------- |\n| `path`              | _string_                                                 | -             | is the path to load file tree from. |\n| `__namedParameters` | { `ignoreJunk?`: _boolean_ ; `includeDirs?`: _boolean_ } | ...           | -                                   |\n\n**Returns:** _Promise_\u003c[_Tree_](#tree)\\\u003e\n\nfile tree.\n\nDefined in: [main.ts:103](https://github.com/ozum/fs-structure/blob/efe12fd/src/main.ts#L103)\n\n---\n\n### remove\n\n▸ **remove**(`input`: [_Tree_](#tree), `options?`: RemoveOptions): _Promise_\u003c_void_\\\u003e\n\nRemoves files and directories from file system using given tree. Also deletes empty directories.\n\n#### Example\n\n```typescript\nawait remove({ a: 1, src: { b: 2, c: 2 } });\n```\n\n#### Parameters:\n\n| Name      | Type            | Default value | Description                                  |\n| --------- | --------------- | ------------- | -------------------------------------------- |\n| `input`   | [_Tree_](#tree) | -             | is the file tree to remove from file system. |\n| `options` | RemoveOptions   | ...           | -                                            |\n\n**Returns:** _Promise_\u003c_void_\\\u003e\n\nDefined in: [main.ts:133](https://github.com/ozum/fs-structure/blob/efe12fd/src/main.ts#L133)\n\n---\n\n### symlink\n\n▸ **symlink**(`options`: _PlainItemOptions_\u003cSymlink\\\u003e): _PlainItem_\u003cSymlink\\\u003e\n\nGenerates a symlink to be used in file tree.\n\n#### Example\n\n```typescript\nawait create({\n  \"src/index.js\": \"console.log('a')\";\n  \"node_modules\": symlink({ target: \"./node_modules.nosync\" });\n})\n```\n\n#### Parameters:\n\n| Name      | Type                         | Description      |\n| --------- | ---------------------------- | ---------------- |\n| `options` | _PlainItemOptions_\u003cSymlink\\\u003e | are the options. |\n\n**Returns:** _PlainItem_\u003cSymlink\\\u003e\n\nobject to create a symlink.\n\nDefined in: [main.ts:170](https://github.com/ozum/fs-structure/blob/efe12fd/src/main.ts#L170)\n\n---\n\n### tempDir\n\n▸ **tempDir**(): _Promise_\u003c_string_\\\u003e\n\nCreates a random named directory in OS temporary directory.\n\n#### Example\n\n```typescript\nlet TEMPDIR: string;\n\nbeforeAll(async () =\u003e {\n  TEMPDIR = await tempDir();\n});\n```\n\n**Returns:** _Promise_\u003c_string_\\\u003e\n\nDefined in: [main.ts:184](https://github.com/ozum/fs-structure/blob/efe12fd/src/main.ts#L184)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fozum%2Ffs-structure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fozum%2Ffs-structure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fozum%2Ffs-structure/lists"}