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

iver-file

v1.0.1

Published

日常涉及到文件的一些处理

Downloads

6

Readme

iver-file

关联到文件操作的一些小手段

Install

npm install --save iver-file

Method

  • GetFilesPathByDirs - 得到当前调用文件的目录下的所有文件 GetFilesPathByDirs(dirs : string[]) : string[] 入参为目录数组,返回路径数组。
  • AppendInfoObjToFile - 向文件内追加信息,一般用于记录日志信息,具体看使用示例。
  • FileToArr - 将AppendInfoObjToFile记录的文本日志变成对象数组,具体看使用示例。
  • MergeFileToArr - FileToArr方法的扩展,具体看使用示例。

Usage

示例演示了调用GetFilesPathByDirs方法,得到当前调用文件的目录下的所有文件

const { GetFilesPathByDirs } = require("iver-file");
const path = require("path");
const filesPath = GetFilesPathByDirs([
  path.join(__dirname, "./"),
  //多个目录
  //...
]);

一般用于记录日志信息,下面演示,如何向文件内追加信息,以及追加之后,如何获取追加内容

const { AppendInfoObjToFile, FileToArr, MergeFileToArr } = require("./index");
const path = require("path")
const fs = require("fs");

//为了演示FileToArr方法,重新定义了目录位置
const filePath = path.join(__dirname, "./a/b/c.txt");

//文件默认存储在当前调用方法文件的目录下。
AppendInfoObjToFile({
  //要追加到文件的信息-必填
  infoObj: { result: true, msg: "操作成功", date: Date() },
  //目录名-选填
  // dirName: "log",
  //文件名-选填
  // fileName: "操作日志",
  //文件路径-选填-重新定义目录位置,如果该参数启用“dirName”,“fileName”参数将失效
  filePath

})
//继续记录日志
AppendInfoObjToFile({
  infoObj: { result: false, msg: "操作失败",date: Date() },
  filePath
})
//...

//将日志文件变成对象数组
const arr = FileToArr(filePath)
console.log(arr);

//FileToArr方法的扩展,通过文件夹名,返回合并以后目录下的所有日志文件
const dirArr = MergeFileToArr(path.dirname(filePath))
console.log(dirArr)