Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

qiao-file

Package Overview
Dependencies
Maintainers
1
Versions
71
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 0.1.8 to 0.1.9

3

__tests__/lstree.js

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

var test = function(){
var fileTree = q.lstree('/Users/vincent/Data/projects/qiao/qiao-monorepo/packages/qiao-file/', 'node_modules');
console.log(fileTree);
var fileTree = q.lstree('/Users/vincent/Data/projects/qiao/qiao-monorepo/packages/qiao-file/', ['node_modules', 'is-']);
console.log(JSON.stringify(fileTree));

@@ -10,0 +9,0 @@ };

@@ -51,7 +51,8 @@ 'use strict';

* @param {*} fileTree
* @param {*} ignores
*/
const getFileTree = (fpath, fileTreeChildrens, ignore) => {
const getFileTree = (fpath, fileTree, ignores) => {
fs.readdirSync(fpath).forEach(function(name){
const rpath = fpath + name;
if(rpath.indexOf(ignore) > -1) return;
if(isFileTreeIgnore(rpath, ignores)) return;

@@ -61,9 +62,9 @@ const stat = fs.statSync(rpath);

let info = {};
info.path = rpath + '/';
info.name = '';
info.path = fpath;
info.name = name;
info.children = [];
fileTreeChildrens.push(info);
fileTree.push(info);
getFileTree(info.path, info.children);
getFileTree(rpath + '/', info.children, ignores);
}else {

@@ -74,3 +75,3 @@ let info = {};

fileTreeChildrens.push(info);
fileTree.push(info);
}

@@ -94,2 +95,14 @@ });

// is file tree ignore
const isFileTreeIgnore = (rpath, ignores) => {
if(!rpath || !ignores || !ignores.length) return;
let ignore = false;
for(let i=0; i<ignores.length; i++){
if(rpath.indexOf(ignores[i]) > -1) ignore = true;
}
return ignore;
};
/**

@@ -168,14 +181,10 @@ * cp

* @param {*} dir must end with /
* @param {*} ignore
* @param {*} ignores
* @returns
*/
const lstree = (dir, ignore) => {
let root = {};
root.path = dir;
root.name = '';
root.children = [];
getFileTree(dir, root.children, ignore);
const lstree = (dir, ignores) => {
let fileTree = [];
getFileTree(dir, fileTree, ignores);
return root;
return fileTree;
};

@@ -182,0 +191,0 @@

{
"name": "qiao-file",
"version": "0.1.8",
"version": "0.1.9",
"description": "nodejs file tool",

@@ -24,3 +24,3 @@ "author": "uikoo9 <uikoo9@qq.com>",

},
"gitHead": "36c092e9ae9de0d0d7e784de1ea613733d579615"
"gitHead": "d22efdf394f777c74006b60e6e24acae464d0f64"
}

@@ -66,4 +66,3 @@ # qiao-file

var test = function(){
var fileTree = q.lstree('./', 'node_modules');
console.log(fileTree);
var fileTree = q.lstree('./', ['node_modules']);
console.log(JSON.stringify(fileTree));

@@ -141,2 +140,5 @@ };

## version
### 0.1.3.20220420
1. lstree path name
### 0.1.2.20220419

@@ -143,0 +145,0 @@ 1. es6

@@ -31,14 +31,10 @@ 'use strict';

* @param {*} dir must end with /
* @param {*} ignore
* @param {*} ignores
* @returns
*/
export const lstree = (dir, ignore) => {
let root = {};
root.path = dir;
root.name = '';
root.children = [];
getFileTree(dir, root.children, ignore);
export const lstree = (dir, ignores) => {
let fileTree = [];
getFileTree(dir, fileTree, ignores);
return root;
return fileTree;
};

@@ -45,0 +41,0 @@

@@ -41,7 +41,8 @@ 'use strict';

* @param {*} fileTree
* @param {*} ignores
*/
export const getFileTree = (fpath, fileTreeChildrens, ignore) => {
export const getFileTree = (fpath, fileTree, ignores) => {
fs.readdirSync(fpath).forEach(function(name){
const rpath = fpath + name;
if(rpath.indexOf(ignore) > -1) return;
if(isFileTreeIgnore(rpath, ignores)) return;

@@ -51,9 +52,9 @@ const stat = fs.statSync(rpath);

let info = {};
info.path = rpath + '/';
info.name = '';
info.path = fpath;
info.name = name;
info.children = [];
fileTreeChildrens.push(info);
fileTree.push(info);
getFileTree(info.path, info.children);
getFileTree(rpath + '/', info.children, ignores);
}else{

@@ -64,3 +65,3 @@ let info = {};

fileTreeChildrens.push(info);
fileTree.push(info);
}

@@ -82,2 +83,14 @@ });

}
};
// is file tree ignore
const isFileTreeIgnore = (rpath, ignores) => {
if(!rpath || !ignores || !ignores.length) return;
let ignore = false;
for(let i=0; i<ignores.length; i++){
if(rpath.indexOf(ignores[i]) > -1) ignore = true;
}
return ignore;
};
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