Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
fs-structure
Advanced tools
Create and delete files and folders in any structure using object syntax or JSON.
Create and delete files and folders in any structure using object syntax or JSON.
import { load, create, remove, flat, symlink } from "fs-structure";
const tree = {
// Flat style (path as key)
"README.md": "Write here README content.",
"src/index.js": "console.log('Hello');",
"src/helper/util.js": "...",
"src/helper/main.js": "...",
"some-link": symlink({ target: "/path/to/some" }), // Using helepr function.
"other-link": { $type: "Symlink", target: "/path/to/other" }, // Using object.
// Below files are added to "test" directory". Also paths can be used too.
test: {
"index.test.js": "...",
"helper/util.test.js": "...",
"helper/main.test.js": "...",
},
};
await create(tree, { cwd: "/path/to/project" });
const loadedTree = await load("/path/to/project");
await remove(tree, { cwd: "/path/to/project" });
const flatTree = flat(tree);
expect(flatTree).toEqual(loadedTree);
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.
.DS_Store
and Thumbs.db
. Change with load(path, { ignoreJunk: false })
flat()
function for easy comparison in tests.fs-structure
Ƭ Tree: ItemLike<Root>
Defined in: main.ts:17
▸ create(input
: Tree, options?
: CreateOptions): Promise<void>
Creates files and directories in file system using given tree.
await create({ a: 1, src: { b: 2, c: 2 } });
Name | Type | Default value | Description |
---|---|---|---|
input | Tree | - | is the file tree to create in file system. |
options | CreateOptions | ... | - |
Returns: Promise<void>
Defined in: main.ts:119
▸ flat(input
: Tree, __namedParameters?
: { cwd?
: string ; includeDirs?
: boolean }): Tree
Converts given tree to a flat structure. May be used to compare two file tree easily.
const tree = {
a: "1"
src: {
b: "2",
c: "3",
},
};
const flatObject = flat(tree); // { a: 1, "src/b": 2, "src/c": 2 }
Name | Type | Default value | Description |
---|---|---|---|
input | Tree | - | is the input tree. |
__namedParameters | { cwd? : string ; includeDirs? : boolean } | ... | - |
Returns: Tree
flat object for file system.
Defined in: main.ts:155
▸ load(path
: string, __namedParameters?
: { ignoreJunk?
: boolean ; includeDirs?
: boolean }): Promise<Tree>
Loads file tree from file system and makes it flat.
Name | Type | Default value | Description |
---|---|---|---|
path | string | - | is the path to load file tree from. |
__namedParameters | { ignoreJunk? : boolean ; includeDirs? : boolean } | ... | - |
Returns: Promise<Tree>
file tree.
Defined in: main.ts:103
▸ remove(input
: Tree, options?
: RemoveOptions): Promise<void>
Removes files and directories from file system using given tree. Also deletes empty directories.
await remove({ a: 1, src: { b: 2, c: 2 } });
Name | Type | Default value | Description |
---|---|---|---|
input | Tree | - | is the file tree to remove from file system. |
options | RemoveOptions | ... | - |
Returns: Promise<void>
Defined in: main.ts:133
▸ symlink(options
: PlainItemOptions<Symlink>): PlainItem<Symlink>
Generates a symlink to be used in file tree.
await create({
"src/index.js": "console.log('a')";
"node_modules": symlink({ target: "./node_modules.nosync" });
})
Name | Type | Description |
---|---|---|
options | PlainItemOptions<Symlink> | are the options. |
Returns: PlainItem<Symlink>
object to create a symlink.
Defined in: main.ts:170
▸ tempDir(): Promise<string>
Creates a random named directory in OS temporary directory.
let TEMPDIR: string;
beforeAll(async () => {
TEMPDIR = await tempDir();
});
Returns: Promise<string>
Defined in: main.ts:184
FAQs
Create and delete files and folders in any structure using object syntax or JSON.
We found that fs-structure demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.