You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

qiao-file

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

qiao-file

nodejs file tool

2.1.2
Source
npmnpm
Version published
Weekly downloads
199
-13.1%
Maintainers
1
Weekly downloads
 
Created
Source

qiao-file

npm version npm downloads

nodejs 下文件相关封装

install

安装

npm i qiao-file

use

使用

// cjs
const { isExists } = require('qiao-file');

// mjs
import { isExists } from 'qiao-file';

cmd

复制,移动,删除文件或文件夹

cp

复制文件或文件夹

  • src
    • 类型: string
    • 说明: 文件或文件夹地址
  • dest
    • 类型: string
    • 说明: 目标文件或文件夹地址,如果 dest 存在,默认会覆盖
  • return
    • 类型: boolean
    • 说明: 结果
    • true: 成功
const res = await cp(src, dest);

mv

移动文件或文件夹

  • src
    • 类型: string
    • 说明: 文件或文件夹地址
  • dest
    • 类型: string
    • 说明: 目标文件或文件夹地址,如果 dest 存在,默认会覆盖
  • return
    • 类型: boolean
    • 说明: 结果
    • true: 成功
const res = await mv(src, dest);

rm

删除文件或文件夹

  • path
    • 类型: string
    • 说明: 文件或文件夹地址
  • return
    • 类型: boolean
    • 说明: 结果
    • true: 成功
const res = await rm(path);

dir

文件夹相关操作

mkdir

创建文件夹

  • dirpath
    • 类型: string
    • 说明: 文件夹地址
  • return
    • 类型: boolean
    • 说明: 结果
    • true: 成功
const res = await mkdir(dirpath);

readdir

读取文件夹内容

  • dirpath
    • 类型: string
    • 说明: 文件夹地址
  • return
    • 类型: string[]
    • 说明: dirpath 下的文件或文件夹路径
    • ['path', ...]
      
const res = await readdir(dirpath);

lsdir

列出文件夹下所有的文件和文件夹路径

  • dirpath
    • 类型: string
    • 说明: 文件夹地址
  • return
    • 类型: object
    • 说明: dirpath 下的文件或文件夹路径
    • {
        files: [
          {
            name: 'index.js',
            path: '/path/to/index.js',
          },
          ...
        ],
        folders: [
          {
            name: '1',
            path: '/path/to/1',
          },
          ...
        ],
      }
      
const res = await lsdir(dirpath);

lstree

列出文件夹下所有的文件和文件夹信息,以树的方式

  • dirpath

    • 类型: string
    • 说明: 文件夹地址
  • ignores

    • 类型: string[]
    • 说明:需要过滤的路径
  • return

    • 类型: object[]
    • 说明: dirpath 下的文件和文件夹信息,以树的方式
    • [
        {
          children: [],
          name: 'filename',
          path: '',
        },
      ];
      
const dirpath = 'xx';
const ignores = ['node_modules', 'is-'];
const res = await lstree(dirpath, ignores);

file

文件相关操作

extname

获取文件的后缀

  • filePath
    • 类型: string
    • 说明: 文件地址
  • return
    • 类型: string
    • 说明: 文件后缀,例如.js
const res = extname(filePath);

readFile

读取文件内容

  • filePath
    • 类型: string
    • 说明: 文件地址
  • return
    • 类型: string
    • 说明: 文件内容
const res = await readFile(filePath);

readFileLineByLine

按行读取文件

  • filePath
    • 类型: string
    • 说明: 文件地址
  • onLine
    • 类型: function
    • 说明: 每行的回调函数
  • onClose
    • 类型: function
    • 说明: 整个文件读取完毕的回调函数
readFileLineByLine(filePath, onLine, onClose);

writeFile

写文件

  • filePath
    • 类型: string
    • 说明: 文件地址
  • content
    • 类型: string
    • 说明: 文件内容
  • return
    • 类型: boolean
    • 说明: 结果
    • true: 成功
const res = await writeFile(filePath, content);

is

文件相关判断

isDir

判断文件路径是否为文件夹

  • fpath
    • 类型: string
    • 说明: 文件或者文件夹地址
  • return
    • 类型: boolean
    • 说明: 结果
    • true: 是文件夹
const res = await isDir(fpath);

isExists

判断文件或者文件夹是否存在

  • fpath
    • 类型: string
    • 说明: 文件或者文件夹地址
  • return
    • 类型: boolean
    • 说明: 结果
    • true: 存在
const res = await isExists(fpath);

version

0.1.7.20230404

  • add ava
  • readDir --> readdir

0.1.6.20230307

  • 2.0.0

0.1.5.20221008

  • 1.0.0

0.1.4.20220707

  • write file from lines
  • read file line by line
  • read file line by line sync

0.1.3.20220420

  • lstree path name
  • mv
  • write file

0.1.2.20220419

  • es6
  • add lstree
  • read file

0.1.1.20220417

  • add lerna

0.1.0.20220317

  • add cp

0.0.9.20191204

  • add funding

0.0.8.20191011

  • exports.fs
  • exports.path

0.0.7.20190122

  • modify md

0.0.6.20190117

  • extname to lower case
  • add lsdir
  • add rm

0.0.5.20190107

  • nodejs file tool

0.0.4.20181127

  • modify method name
  • add .js

0.0.3.20181122

  • npm audit

0.0.2.20181017

  • isExists
  • extname
  • mkdir
  • getAllFiles

0.0.1.20181016

  • init

Keywords

fs

FAQs

Package last updated on 07 Apr 2023

Did you know?

Socket

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.

Install

Related posts