npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

qiao-file

v4.5.5

Published

nodejs file tool

Downloads

763

Readme

qiao-file

npm version npm downloads

nodejs 下文件相关封装

  1. Node.js-开发实践:高性能 FS
  2. Node.js-开发实践:使用健壮的 FS

install

安装

npm i qiao-file

use

使用

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

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

api

extname

获取文件的后缀

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

isExists

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

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

isDir

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

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

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);

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);

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);