Socket
Socket
Sign inDemoInstall

hotfile

Package Overview
Dependencies
0
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.7 to 0.2.8

69

index.js

@@ -15,11 +15,11 @@ const fs = require('fs')

this.isDirectory ? this.children = [] : this.ext = ext
if(options.stat) this.stat = stat
if (options.stat) this.stat = stat
}
static mkdirSync(path, options = { recursive: true }){
static mkdirSync(path, options = { recursive: true }) {
let flag = true
try{
try {
fs.mkdirSync(path, options)
}catch(e){
flag = false
} catch (e) {
flag = false
}

@@ -29,8 +29,8 @@ return flag

static existsSync(path){
static existsSync(path) {
let flag = true
try{
fs.accessSync(path, fs.constants.F_OK)
}catch(e){
flag = false
try {
fs.accessSync(path, fs.constants.F_OK)
} catch (e) {
flag = false
}

@@ -40,3 +40,3 @@ return flag

static async exists(path){
static async exists(path) {
try {

@@ -46,9 +46,9 @@ await fs.promises.access(path, fs.constants.F_OK)

} catch (err) {
if(err.message.includes('no such file or directory')) return false
if (err.message.includes('no such file or directory')) return false
}
}
static async mkdir(path, options = {}){
static async mkdir(path, options = {}) {
const { recursive, force } = options
if(!force && await this.exists(path)) return false
if (!force && await this.exists(path)) return false
try {

@@ -64,3 +64,2 @@ await fs.promises.mkdir(path, { recursive })

async loadChildren(options = {}, currentDepth) {
this.children = []
typeof currentDepth === 'number' ? currentDepth++ : currentDepth = 1

@@ -70,4 +69,4 @@ const items = await fs.promises.readdir(this.path)

const path = resolve(this.path, items[i])
const hotfile = new Hotfile(path, options.options ? options.options: {})
if(typeof options.filter === 'function' && !(await options.filter(hotfile) || hotfile.isDirectory)) continue
const hotfile = new Hotfile(path, options.options ? options.options : {})
if (typeof options.filter === 'function' && !(await options.filter(hotfile) || hotfile.isDirectory)) continue
if (typeof options.cb === 'function') await options.cb(hotfile)

@@ -84,3 +83,21 @@ this.children.push(hotfile)

async createChildDirectory(directoryName){
loadChildrenSync(options = {}, currentDepth) {
typeof currentDepth === 'number' ? currentDepth++ : currentDepth = 1
const items = fs.readdirSync(this.path)
for (let i = 0; i < items.length; i++) {
const path = resolve(this.path, items[i])
const hotfile = new Hotfile(path, options.options ? options.options : {})
if (typeof options.filter === 'function' && !(options.filter(hotfile) || hotfile.isDirectory)) continue
if (typeof options.cb === 'function') options.cb(hotfile)
this.children.push(hotfile)
if (hotfile.isDirectory) {
if ((typeof options.depth === 'number') && !(options.depth >= currentDepth)) continue
hotfile.loadChildrenSync(options, currentDepth)
}
}
return this
}
async createChildDirectory(directoryName) {
const newPath = resolve(this.path, directoryName)

@@ -93,3 +110,3 @@ await Hotfile.mkdir(newPath)

async delete(){
async delete() {
await fs.promises.unlink(this.path)

@@ -99,3 +116,3 @@ return null

updatePath(newPath){
updatePath(newPath) {
this.path = newPath

@@ -107,3 +124,3 @@ const { name, base } = parse(newPath)

async rename(newbase){
async rename(newbase) {
const oldPath = this.path

@@ -116,7 +133,7 @@ const newPath = this.path.replace(this.base, newbase)

async moveTo(destinationPath){
const hotfolder = destinationPath instanceof Hotfile
? destinationPath
: new Hotfile(destinationPath)
if(!hotfolder.isDirectory) throw(new Error("destination must be a folder, file provided"))
async moveTo(destinationPath) {
const hotfolder = destinationPath instanceof Hotfile
? destinationPath
: new Hotfile(destinationPath)
if (!hotfolder.isDirectory) throw (new Error("destination must be a folder, file provided"))
const oldPath = this.path

@@ -123,0 +140,0 @@ const newPath = resolve(hotfolder.path, this.base)

{
"name": "hotfile",
"version": "0.2.7",
"version": "0.2.8",
"description": "Hotfile makes working with folders and files in node-js easy and clear.",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc