can-write-to-dir
Advanced tools
Comparing version 1.0.1 to 1.1.0
# can-write-to-dir | ||
## 1.1.0 | ||
### Minor Changes | ||
- bba9985: graceful-fs and mz removed from dependencies. | ||
## 1.0.0 | ||
### Major Changes | ||
- 48d36f2: Project created. |
36
index.js
'use strict' | ||
const gracefulFs = require('graceful-fs') | ||
const defaultFS = require('fs') | ||
const pathTemp = require('path-temp') | ||
module.exports = (dir, customFs) => { | ||
const fs = customFs || gracefulFs | ||
return new Promise((resolve, reject) => { | ||
const tempFile = pathTemp(dir) | ||
fs.writeFile(tempFile, '', 'utf8', err => { | ||
if (!err) { | ||
fs.unlink(tempFile, () => {}) | ||
resolve(true) | ||
return | ||
} | ||
if (err.code === 'EACCES' || err.code === 'EPERM' || err.code === 'EROFS') { | ||
resolve(false) | ||
return | ||
} | ||
reject(err) | ||
}) | ||
}) | ||
module.exports = async (dir, customFS) => { | ||
const fs = customFS || defaultFS | ||
const tempFile = pathTemp(dir) | ||
try { | ||
await fs.promises.writeFile(tempFile, '', 'utf8') | ||
fs.promises.unlink(tempFile).catch(() => {}) | ||
return true | ||
} catch (err) { | ||
if (err.code === 'EACCES' || err.code === 'EPERM' || err.code === 'EROFS') { | ||
return false | ||
} | ||
throw err | ||
} | ||
} | ||
module.exports.sync = (dir, customFs) => { | ||
const fs = customFs || gracefulFs | ||
module.exports.sync = (dir, customFS) => { | ||
const fs = customFS || defaultFS | ||
const tempFile = pathTemp(dir) | ||
@@ -27,0 +23,0 @@ try { |
{ | ||
"name": "can-write-to-dir", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Returns true if the current process has permission to write to the specified directory", | ||
@@ -28,3 +28,2 @@ "main": "index.js", | ||
"dependencies": { | ||
"graceful-fs": "^4.2.4", | ||
"path-temp": "^2.0.0" | ||
@@ -34,5 +33,5 @@ }, | ||
"package-preview": "3.0.0", | ||
"standard": "^16.0.1", | ||
"tape": "^5.0.1" | ||
"standard": "^16.0.3", | ||
"tape": "^5.1.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
3801
36
2
- Removedgraceful-fs@^4.2.4
- Removedgraceful-fs@4.2.11(transitive)