# void-fs **Repository Path**: void-js/void-fs ## Basic Information - **Project Name**: void-fs - **Description**: 简易的 fs 工具 - **Primary Language**: TypeScript - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-11-30 - **Last Updated**: 2024-10-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # void-fs 简易的fs工具集 [![NPM Version](https://img.shields.io/npm/v/void-fs?style=flat-square)](https://www.npmjs.com/package/void-fs) [![NPM Downloads](https://img.shields.io/npm/dm/void-fs?style=flat-square)](https://www.npmjs.com/package/void-fs) [![NPM License](https://img.shields.io/npm/l/void-fs?style=flat-square)](https://www.npmjs.com/package/void-fs) ## 复制目录 ```ts import { copy } from 'void-fs' /** * 复制目录 */ copy( // 拷贝源目录 'src', // 拷贝目标目录 'dest', { // 目录 root cwd: process.cwd(), // 拷贝目标目录 root,未设置使用 cwd destCwd: process.cwd(), } ) /** * fast-glob 复制目录 */ copy( // 拷贝源目录 ['src', '!src/index.ts'], // 拷贝目标目录 'dest', { // 目录 root cwd: process.cwd(), // 拷贝目标目录 root,未设置使用 cwd destCwd: process.cwd(), } ) ``` ## 删除 ```ts /** * 删除目录 */ del( // 目标目录 'src', { // 目录 root cwd: process.cwd(), } ) /** * 删除文件 */ del( // 目标目录 'src/index.ts', { // 目录 root cwd: process.cwd(), } ) /** * fast-glob 删除 */ del( // 目标目录 ['src', '!src/index.ts'], { // 目录 root cwd: process.cwd(), } ) ``` ## 路径文件/目录是否存在 ```ts const has = await exists( // 目标目录 'src/index.ts', { // 目录 root cwd: process.cwd(), } ) // true // false ``` ## 文件/目录创建 ```ts /** * 创建目录 * 上级目录不存在则创建 */ makeDir( // 目标目录 'src', { // 目录 root cwd: process.cwd(), } ) /** * 创建文件 * 上级目录不存在则创建 */ makeFile( // 目标目录 'src/index.ts', { // 目录 root cwd: process.cwd(), } ) ``` ## 文件读取 ```ts /** * 将文件读取为字符串 */ readFile( // 目标目录 'src/index.ts', { // 目录 root cwd: process.cwd(), } ) /** * 读取json文件为json object */ readJSON( // 目标目录 'src/index.json', { // 目录 root cwd: process.cwd(), } ) ``` ## 文件写入 ```ts /** * 文件写入 */ writeFile( // 目标目录 'src/index.ts', 'export const foo = ""', { // 目录 root cwd: process.cwd(), } ) /** * 文件写入 * prettier ts 格式化 */ writeTS( // 目标目录 'src/index.ts', // 文件数据 'export const foo = ""', { // 目录 root cwd: process.cwd(), } ) /** * 文件写入 * prettier json 格式化 */ writeJSON( // 目标目录 'src/index.json', // json数据 { foo: 'bar' }, { // 目录 root cwd: process.cwd(), } ) /** * 文件写入 * prettier css/less/scss 格式化 */ writeCSS( // 目标目录 'src/index.ts', // 文件数据 '.foo{color:#fff;}', { // 目录 root cwd: process.cwd(), } ) ``` ## License [MIT License](./LICENSE)