New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

qiao-file

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

qiao-file - npm Package Compare versions

Comparing version 2.1.1 to 2.1.2

src/cp.js

129

index.js

@@ -6,3 +6,2 @@ 'use strict';

var Debug = require('debug');
var readline = require('readline');

@@ -30,3 +29,3 @@ function _interopNamespaceDefault(e) {

// fs
const debug = Debug('qiao-file');
const debug$6 = Debug('qiao-file');

@@ -43,3 +42,3 @@ /**

if (!srcExists) {
debug('/ cp / src not exists');
debug$6('/ cp / src not exists');
return;

@@ -49,7 +48,7 @@ }

await fsExtra.copy(src, dest);
debug('/ cp / success');
debug$6('/ cp / success');
return true;
} catch (e) {
debug('/ cp / fail');
debug$6('/ cp / fail');
console.log(e);

@@ -59,2 +58,5 @@ }

// fs
const debug$5 = Debug('qiao-file');
/**

@@ -69,3 +71,3 @@ * mv

if (!srcExists) {
debug('/ mv / src not exists');
debug$5('/ mv / src not exists');
return;

@@ -75,7 +77,7 @@ }

await fsExtra.move(oldPath, newPath, { overwrite: true });
debug('/ mv / success');
debug$5('/ mv / success');
return true;
} catch (e) {
debug('/ mv / fail');
debug$5('/ mv / fail');
console.log(e);

@@ -85,2 +87,5 @@ }

// fs
const debug$4 = Debug('qiao-file');
/**

@@ -94,4 +99,7 @@ * rm

await fsExtra.remove(fpath);
debug$4('/ rm / success');
return true;
} catch (e) {
debug$4('/ rm / fail');
console.log(e);

@@ -102,30 +110,5 @@ }

// fs
const debug$3 = Debug('qiao-file');
/**
* is exists
* @param {*} path
* @returns
*/
const isExists = async (path) => {
return await fsExtra.pathExists(path);
};
/**
* is dir
* @param {*} dir
* @returns
*/
const isDir = async (dir) => {
// check
const dirExists = await isExists(dir);
if (!dirExists) return;
// stat
const statRes = await fsExtra.stat(dir);
return statRes.isDirectory();
};
// path
/**
* mk dir

@@ -138,4 +121,7 @@ * @param {*} dir

await fsExtra.ensureDir(dir);
debug$3('/ mkdir / success');
return true;
} catch (e) {
debug$3('/ mkdir / fail');
console.log(e);

@@ -145,2 +131,4 @@ }

// fs
/**

@@ -159,3 +147,23 @@ * read dir

// fs
/**
* is dir
* @param {*} dir
* @returns
*/
const isDir = async (dir) => {
// check
const dirExists = await fsExtra.pathExists(dir);
if (!dirExists) return;
// stat
const statRes = await fsExtra.stat(dir);
return statRes.isDirectory();
};
// path
const debug$2 = Debug('qiao-file');
/**
* ls dir

@@ -180,2 +188,3 @@ * @param {*} dir

const dirs = await readdir(fpath);
debug$2('/ lsdir / getFoldersAndFiles / dirs', dirs);
if (!dirs) return;

@@ -188,2 +197,7 @@

const isDirRes = await isDir(realPath);
debug$2('/ lsdir / getFoldersAndFiles / dir', dir);
debug$2('/ lsdir / getFoldersAndFiles / realPath', realPath);
debug$2('/ lsdir / getFoldersAndFiles / isDirRes', isDirRes);
//
if (isDirRes) {

@@ -205,2 +219,4 @@ folders.push({

// path
/**

@@ -280,2 +296,5 @@ * ls tree

// fs
const debug$1 = Debug('qiao-file');
/**

@@ -289,2 +308,3 @@ * readFile

// check
debug$1('/ readFile / filePath', filePath);
if (!filePath) return;

@@ -296,5 +316,7 @@

options = options || opt;
debug$1('/ readFile / options', options);
return await fsExtra.readFile(filePath, options);
} catch (e) {
debug$1('/ readFile / fail');
console.log(e);

@@ -304,23 +326,5 @@ }

/**
* readFileLineByLine
* @param {*} filePath
* @param {*} onLine
* @param {*} onClose
*/
const readFileLineByLine = (filePath, onLine, onClose) => {
// rl
const rl = readline.createInterface({
input: fsExtra.createReadStream(filePath, { encoding: 'utf8' }),
});
// fs
const debug = Debug('qiao-file');
// on
rl.on('line', function (line) {
if (onLine) onLine(line);
});
rl.on('close', function () {
if (onClose) onClose();
});
};
/**

@@ -334,2 +338,3 @@ * writeFile

// check
debug('/ writeFile / filePath', filePath);
if (!filePath) return;

@@ -341,6 +346,8 @@

options = options || {};
debug('/ writeFile / options', options);
await fsExtra.outputFile(filePath, fileData, options);
return true;
} catch (e) {
debug('/ writeFile / fail');
console.log(e);

@@ -350,2 +357,13 @@ }

// fs
/**
* is exists
* @param {*} path
* @returns
*/
const isExists = async (path) => {
return await fsExtra.pathExists(path);
};
exports.fs = fsExtra__namespace;

@@ -362,5 +380,4 @@ exports.path = path__namespace;

exports.readFile = readFile;
exports.readFileLineByLine = readFileLineByLine;
exports.readdir = readdir;
exports.rm = rm;
exports.writeFile = writeFile;
{
"name": "qiao-file",
"version": "2.1.1",
"version": "2.1.2",
"description": "nodejs file tool",

@@ -52,3 +52,3 @@ "keywords": [

},
"gitHead": "e3a210c00dd4b2fd1642542ffa6656ee622b1f3c"
"gitHead": "913e26b327dd9f1742beeda2fc6fcd3ec91c7512"
}

@@ -164,2 +164,26 @@ ## qiao-file

- dirpath
- 类型: string
- 说明: 文件夹地址
- ignores
- 类型: string[]
- 说明:需要过滤的路径
- return
- 类型: object[]
- 说明: dirpath 下的文件和文件夹信息,以树的方式
- ```javascript
[
{
children: [],
name: 'filename',
path: '',
},
];
```
```
```
```javascript

@@ -179,2 +203,9 @@ const dirpath = 'xx';

- filePath
- 类型: string
- 说明: 文件地址
- return
- 类型: string
- 说明: 文件后缀,例如.js
```javascript

@@ -188,2 +219,9 @@ const res = extname(filePath);

- filePath
- 类型: string
- 说明: 文件地址
- return
- 类型: string
- 说明: 文件内容
```javascript

@@ -197,2 +235,12 @@ const res = await readFile(filePath);

- filePath
- 类型: string
- 说明: 文件地址
- onLine
- 类型: function
- 说明: 每行的回调函数
- onClose
- 类型: function
- 说明: 整个文件读取完毕的回调函数
```javascript

@@ -206,4 +254,15 @@ readFileLineByLine(filePath, onLine, onClose);

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

@@ -219,2 +278,10 @@

- fpath
- 类型: string
- 说明: 文件或者文件夹地址
- return
- 类型: boolean
- 说明: 结果
- true: 是文件夹
```javascript

@@ -228,2 +295,10 @@ const res = await isDir(fpath);

- fpath
- 类型: string
- 说明: 文件或者文件夹地址
- return
- 类型: boolean
- 说明: 结果
- true: 存在
```javascript

@@ -230,0 +305,0 @@ const res = await isExists(fpath);

@@ -5,6 +5,20 @@ // fs & path

// xx
export * from './cmd.js';
export * from './dir.js';
export * from './file.js';
export * from './is.js';
// cmd
export * from './cp.js';
export * from './mv.js';
export * from './rm.js';
// dir
export * from './mkdir.js';
export * from './readdir.js';
export * from './lsdir.js';
export * from './lstree.js';
// file
export * from './extname.js';
export * from './read-file.js';
export * from './write-file.js';
// is
export * from './is-dir.js';
export * from './is-exists.js';
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc