Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
feat: Add file name sanitizer to the fs module
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed Mar 18, 2020
1 parent 0ffd1fb commit c53838c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import which from 'which';
import glob from 'glob';
import crypto from 'crypto';
import klaw from 'klaw';
import sanitize from 'sanitize-filename';
import { pluralize } from './util';
import log from './logger';
import Timer from './timing';
Expand Down Expand Up @@ -50,6 +51,7 @@ let fs = {
mv: B.promisify(mv),
which: B.promisify(which),
glob: B.promisify(glob),
sanitizeName: sanitize,
async hash (filePath, algorithm = 'sha1') {
return await new B((resolve, reject) => {
const fileHash = crypto.createHash(algorithm);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"request": "^2.83.0",
"request-promise": "^4.2.2",
"rimraf": "^3.0.0",
"sanitize-filename": "^1.6.1",
"semver": "^7.0.0",
"shell-quote": "^1.7.2",
"source-map-support": "^0.5.5",
Expand Down
5 changes: 5 additions & 0 deletions test/fs-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ describe('fs', function () {
await fs.rimraf(newPath);
(await fs.exists(newPath)).should.be.false;
});
it('sanitizeName', function () {
fs.sanitizeName(':file?.txt', {
replacement: '-',
}).should.eql('-file-.txt');
});
it('rimrafSync', async function () {
let newPath = path.resolve(await tempDir.openDir(), 'fs-specs.js');
await fs.copyFile(existingPath, newPath);
Expand Down

0 comments on commit c53838c

Please sign in to comment.