Socket
Socket
Sign inDemoInstall

make-empty-dir

Package Overview
Dependencies
13
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 2.1.0

8

index.d.ts

@@ -0,3 +1,7 @@

declare function makeEmptyDir (dir: string, opts?: { recursive?: boolean }): Promise<'created' | 'emptied'>
declare namespace makeEmptyDir {
function sync(dir: string, opts?: { recursive?: boolean }): 'created' | 'emptied'
}
export = makeEmptyDir
declare function makeEmptyDir (dir: string, opts?: { recursive?: boolean }): Promise<'created' | 'emptied'>
'use strict'
const fs = require('fs').promises
const fs = require('fs')
const path = require('path')

@@ -8,6 +8,6 @@ const rimraf = require('@zkochan/rimraf')

if (opts && opts.recursive) {
await fs.mkdir(path.dirname(dir), { recursive: true })
await fs.promises.mkdir(path.dirname(dir), { recursive: true })
}
try {
await fs.mkdir(dir)
await fs.promises.mkdir(dir)
return 'created'

@@ -24,3 +24,3 @@ } catch (err) {

async function removeContentsOfDir (dir) {
const items = await fs.readdir(dir)
const items = await fs.promises.readdir(dir)
for (const item of items) {

@@ -30,1 +30,24 @@ await rimraf(path.join(dir, item))

}
module.exports.sync = function makeEmptyDirSync (dir, opts) {
if (opts && opts.recursive) {
fs.mkdirSync(path.dirname(dir), { recursive: true })
}
try {
fs.mkdirSync(dir)
return 'created'
} catch (err) {
if (err.code === 'EEXIST') {
removeContentsOfDirSync(dir)
return 'emptied'
}
throw err
}
}
function removeContentsOfDirSync (dir) {
const items = fs.readdirSync(dir)
for (const item of items) {
rimraf.sync(path.join(dir, item))
}
}
{
"name": "make-empty-dir",
"version": "2.0.0",
"version": "2.1.0",
"description": "Ensures that a directory is empty",

@@ -10,9 +10,6 @@ "main": "index.js",

],
"scripts": {
"test": "node test"
},
"engines": {
"node": ">=12.10"
},
"repository": "https://github.com/zkochan/packages/tree/master/make-empty-dir",
"repository": "https://github.com/zkochan/packages/tree/main/make-empty-dir",
"keywords": [

@@ -30,10 +27,13 @@ "directory",

"license": "MIT",
"homepage": "https://github.com/zkochan/packages/tree/master/make-empty-dir#readme",
"homepage": "https://github.com/zkochan/packages/tree/main/make-empty-dir#readme",
"devDependencies": {
"tape": "^5.1.1",
"tempy": "^1.0.0"
"tape": "^5.3.2",
"tempy": "^1.0.1"
},
"dependencies": {
"@zkochan/rimraf": "^2.1.0"
"@zkochan/rimraf": "^2.1.3"
},
"scripts": {
"test": "node test"
}
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc