tar-compress-cli
Advanced tools
Comparing version 0.2.2 to 0.2.3
@@ -42,3 +42,3 @@ "use strict"; | ||
} | ||
const sourceFiles = await (0, index_1.getExistFiles)(Array.isArray(argv.source) ? argv.source : String(argv.source)); | ||
const sourceFiles = await (0, index_1.getExistFiles)((0, index_1.arrayUnique)(argv.source)); | ||
if ((0, index_1.isEmptyValue)(sourceFiles)) { | ||
@@ -45,0 +45,0 @@ throw new Error('No such file or directory.'); |
@@ -51,5 +51,3 @@ "use strict"; | ||
} | ||
const extractFiles = Array.isArray(argv.extractFile) | ||
? argv.extractFile | ||
: []; | ||
const extractFiles = (0, index_1.arrayUnique)(argv.extractFile); | ||
let targetDirectory; | ||
@@ -56,0 +54,0 @@ if ((0, index_1.isEmptyValue)(String(argv.target))) { |
@@ -11,3 +11,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getExistFiles = exports.getFileName = exports.isEmptyValue = exports.getDataType = void 0; | ||
exports.getExistFiles = exports.getFileName = exports.arrayUnique = exports.isEmptyValue = exports.getDataType = void 0; | ||
const fs_extra_1 = __importDefault(require("fs-extra")); | ||
@@ -32,2 +32,7 @@ const getDataType = (value) => Object.prototype.toString.call(value).slice(8, -1); | ||
exports.isEmptyValue = isEmptyValue; | ||
const arrayUnique = (array) => { | ||
const arr = Array.isArray(array) ? array : []; | ||
return Array.from(new Set(arr)); | ||
}; | ||
exports.arrayUnique = arrayUnique; | ||
const getFileName = (filePath, dirPath) => { | ||
@@ -39,3 +44,3 @@ const fileName = filePath.slice(dirPath.length + 1); | ||
const getExistFiles = async (files) => { | ||
const fileArray = Array.isArray(files) ? files : [files]; | ||
const fileArray = (Array.isArray(files) ? files : [files]).filter((item) => !isEmptyValue(item)); | ||
const handleFileArray = await Promise.all(fileArray.map(async (item) => { | ||
@@ -42,0 +47,0 @@ const result = await fs_extra_1.default.pathExists(item); |
@@ -0,1 +1,9 @@ | ||
## [0.2.3](https://github.com/VicSolWang/tar-compress-cli/compare/v0.2.2...v0.2.3) (2022-01-04) | ||
### Bug Fixes | ||
* add arrayUnique function ([d93f564](https://github.com/VicSolWang/tar-compress-cli/commit/d93f564f3fbf2e9830760cc08a26afc7fc4ecac6)) | ||
* modify test ([bf1b404](https://github.com/VicSolWang/tar-compress-cli/commit/bf1b404b3fe8d71a933eb4b59dfd2e03b4286a3f)) | ||
## [0.2.2](https://github.com/VicSolWang/tar-compress-cli/compare/v0.2.1...v0.2.2) (2022-01-03) | ||
@@ -2,0 +10,0 @@ |
{ | ||
"name": "tar-compress-cli", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Use tar to pack and unpack file", | ||
@@ -5,0 +5,0 @@ "bin": { |
@@ -11,3 +11,8 @@ /** | ||
import { CommandModule } from 'yargs'; | ||
import { isEmptyValue, getFileName, getExistFiles } from '../utils/index'; | ||
import { | ||
isEmptyValue, | ||
arrayUnique, | ||
getFileName, | ||
getExistFiles, | ||
} from '../utils/index'; | ||
@@ -45,3 +50,3 @@ const commandName: string = getFileName(__filename, __dirname); | ||
const sourceFiles: string[] = await getExistFiles( | ||
Array.isArray(argv.source) ? argv.source : String(argv.source), | ||
arrayUnique(argv.source), | ||
); | ||
@@ -48,0 +53,0 @@ if (isEmptyValue(sourceFiles)) { |
@@ -11,3 +11,8 @@ /** | ||
import { CommandModule } from 'yargs'; | ||
import { isEmptyValue, getFileName, getExistFiles } from '../utils/index'; | ||
import { | ||
isEmptyValue, | ||
arrayUnique, | ||
getFileName, | ||
getExistFiles, | ||
} from '../utils/index'; | ||
@@ -58,5 +63,3 @@ const commandName: string = getFileName(__filename, __dirname); | ||
} | ||
const extractFiles: string[] = Array.isArray(argv.extractFile) | ||
? argv.extractFile | ||
: []; | ||
const extractFiles: string[] = arrayUnique(argv.extractFile); | ||
let targetDirectory: string; | ||
@@ -63,0 +66,0 @@ if (isEmptyValue(String(argv.target))) { |
@@ -28,2 +28,7 @@ /** | ||
const arrayUnique = (array: unknown): Array<any> => { | ||
const arr: Array<any> = Array.isArray(array) ? array : []; | ||
return Array.from(new Set(arr)); | ||
}; | ||
const getFileName = (filePath: string, dirPath: string): string => { | ||
@@ -35,3 +40,5 @@ const fileName = filePath.slice(dirPath.length + 1); | ||
const getExistFiles = async (files: string | string[]): Promise<string[]> => { | ||
const fileArray: string[] = Array.isArray(files) ? files : [files]; | ||
const fileArray: string[] = (Array.isArray(files) ? files : [files]).filter( | ||
(item) => !isEmptyValue(item), | ||
); | ||
const handleFileArray: string[] = await Promise.all( | ||
@@ -46,2 +53,2 @@ fileArray.map(async (item) => { | ||
export { getDataType, isEmptyValue, getFileName, getExistFiles }; | ||
export { getDataType, isEmptyValue, arrayUnique, getFileName, getExistFiles }; |
@@ -11,2 +11,3 @@ /** | ||
isEmptyValue, | ||
arrayUnique, | ||
getFileName, | ||
@@ -29,2 +30,9 @@ getExistFiles, | ||
test('Test the function named "arrayUnique".', (t) => { | ||
const array1 = arrayUnique('abc'); | ||
t.true(Array.isArray(array1) && array1.length === 0); | ||
const array2 = arrayUnique(['abc', 'abc']); | ||
t.true(Array.isArray(array2) && array2.length === 1); | ||
}); | ||
test('Test the function named "getFileName".', (t) => { | ||
@@ -31,0 +39,0 @@ t.is(getFileName(__filename, __dirname), 'utils'); |
@@ -8,4 +8,5 @@ /** | ||
declare const isEmptyValue: (value: any) => boolean; | ||
declare const arrayUnique: (array: unknown) => Array<any>; | ||
declare const getFileName: (filePath: string, dirPath: string) => string; | ||
declare const getExistFiles: (files: string | string[]) => Promise<string[]>; | ||
export { getDataType, isEmptyValue, getFileName, getExistFiles }; | ||
export { getDataType, isEmptyValue, arrayUnique, getFileName, getExistFiles }; |
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
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
26528
30
586