🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@lxf2513/node-mv

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lxf2513/node-mv - npm Package Compare versions

Comparing version
1.1.0
to
1.2.0
+111
dist/shared/node-mv.BeuPSJ9l.mjs
import { existsSync, statSync, renameSync } from 'node:fs';
import { mkdirpSync } from 'makedirp';
import { cpr } from 'node-cpr';
import { rmrfSync } from 'node-rmrf';
import { sep, resolve } from 'node:path';
const name = "nodemv";
const errorLog = (str) => {
console.log("\x1B[31m%s\x1B[0m", str);
};
function isPathExist(path) {
try {
return existsSync(path);
} catch {
return false;
}
}
function isFile(path) {
try {
const stat = statSync(resolve(path));
return stat.isFile();
} catch {
return false;
}
}
function isDirectory(path) {
try {
const stat = statSync(resolve(path));
return stat.isDirectory();
} catch {
return false;
}
}
function isExistedInDest(source, dest) {
if (isDirectory(dest) && isPathExist(`${dest}${sep}${source}`)) {
return true;
}
return false;
}
function errorMsg(source, dest, mkdirp) {
if (typeof source === "string" || source.length === 1) {
const sourcePath = typeof source === "string" ? source : source[0];
if (!isPathExist(sourcePath)) {
errorLog(
`${name}: cannot stat '${sourcePath}': No such file or directory`
);
return false;
} else if (isDirectory(sourcePath) && !isDirectory(dest) && isFile(dest)) {
errorLog(
`${name}: cannot overwrite non-directory '${dest}' with directory '${sourcePath}'`
);
return false;
} else if (isDirectory(sourcePath) && isDirectory(dest) && sourcePath === dest) {
errorLog(
`${name}: cannot move '${sourcePath}' to a subdirectory of itself, '${dest}/${sourcePath}'`
);
return false;
} else if (!isPathExist(sourcePath) && true) {
errorLog(
`${name}: cannot move '${sourcePath}' to '${dest}': No such file or directory`
);
return false;
}
return true;
} else {
if (!isDirectory(dest) && true) {
errorLog(`${name}: target '${dest}' is not a directory`);
return false;
} else {
source.forEach((s) => {
errorMsg(s, dest);
});
return true;
}
}
}
function moveFile(source, dest) {
try {
renameSync(source, dest);
} catch (error) {
const err = error;
if (err?.code === "EPERM" || err?.code === "EISDIR" || err?.code === "EXDEV") {
cpr(source, dest);
rmrfSync(source);
}
}
}
function mv(source, dest, options) {
const { clobber = true, mkdirp } = options;
const exist = isPathExist(dest);
const isStr = typeof source === "string";
const isArray = Array.isArray(source);
if (isArray && source.length > 1 && !exist && mkdirp || isStr && !exist) {
mkdirpSync(dest);
}
if (!errorMsg(source, dest)) {
return;
}
if (!exist || clobber || !clobber && (isStr && !isExistedInDest(source, dest) || isArray && source.length === 1 && !isExistedInDest(source[0], dest))) {
if (isStr) {
moveFile(source, dest);
} else {
source.forEach((s) => {
moveFile(s, dest);
});
}
}
}
export { errorLog as e, mv as m, name as n };
'use strict';
const node_fs = require('node:fs');
const makedirp = require('makedirp');
const nodeCpr = require('node-cpr');
const nodeRmrf = require('node-rmrf');
const node_path = require('node:path');
const name = "nodemv";
const errorLog = (str) => {
console.log("\x1B[31m%s\x1B[0m", str);
};
function isPathExist(path) {
try {
return node_fs.existsSync(path);
} catch {
return false;
}
}
function isFile(path) {
try {
const stat = node_fs.statSync(node_path.resolve(path));
return stat.isFile();
} catch {
return false;
}
}
function isDirectory(path) {
try {
const stat = node_fs.statSync(node_path.resolve(path));
return stat.isDirectory();
} catch {
return false;
}
}
function isExistedInDest(source, dest) {
if (isDirectory(dest) && isPathExist(`${dest}${node_path.sep}${source}`)) {
return true;
}
return false;
}
function errorMsg(source, dest, mkdirp) {
if (typeof source === "string" || source.length === 1) {
const sourcePath = typeof source === "string" ? source : source[0];
if (!isPathExist(sourcePath)) {
errorLog(
`${name}: cannot stat '${sourcePath}': No such file or directory`
);
return false;
} else if (isDirectory(sourcePath) && !isDirectory(dest) && isFile(dest)) {
errorLog(
`${name}: cannot overwrite non-directory '${dest}' with directory '${sourcePath}'`
);
return false;
} else if (isDirectory(sourcePath) && isDirectory(dest) && sourcePath === dest) {
errorLog(
`${name}: cannot move '${sourcePath}' to a subdirectory of itself, '${dest}/${sourcePath}'`
);
return false;
} else if (!isPathExist(sourcePath) && true) {
errorLog(
`${name}: cannot move '${sourcePath}' to '${dest}': No such file or directory`
);
return false;
}
return true;
} else {
if (!isDirectory(dest) && true) {
errorLog(`${name}: target '${dest}' is not a directory`);
return false;
} else {
source.forEach((s) => {
errorMsg(s, dest);
});
return true;
}
}
}
function moveFile(source, dest) {
try {
node_fs.renameSync(source, dest);
} catch (error) {
const err = error;
if (err?.code === "EPERM" || err?.code === "EISDIR" || err?.code === "EXDEV") {
nodeCpr.cpr(source, dest);
nodeRmrf.rmrfSync(source);
}
}
}
function mv(source, dest, options) {
const { clobber = true, mkdirp } = options;
const exist = isPathExist(dest);
const isStr = typeof source === "string";
const isArray = Array.isArray(source);
if (isArray && source.length > 1 && !exist && mkdirp || isStr && !exist) {
makedirp.mkdirpSync(dest);
}
if (!errorMsg(source, dest)) {
return;
}
if (!exist || clobber || !clobber && (isStr && !isExistedInDest(source, dest) || isArray && source.length === 1 && !isExistedInDest(source[0], dest))) {
if (isStr) {
moveFile(source, dest);
} else {
source.forEach((s) => {
moveFile(s, dest);
});
}
}
}
exports.errorLog = errorLog;
exports.mv = mv;
exports.name = name;
+2
-2

@@ -5,3 +5,3 @@ #!/usr/bin/env node

const readline = require('readline');
const index = require('./shared/node-mv.5714bdb0.cjs');
const index = require('./shared/node-mv.BJ49bY0J.cjs');
require('node:fs');

@@ -13,3 +13,3 @@ require('makedirp');

const version = "1.1.0";
const version = "1.2.0";

@@ -16,0 +16,0 @@ const helpInfo = () => {

export { }
export { }
export { }
#!/usr/bin/env node
import { createInterface } from 'readline';
import { e as errorLog, n as name, m as mv } from './shared/node-mv.52ddd0ae.mjs';
import { e as errorLog, n as name, m as mv } from './shared/node-mv.BeuPSJ9l.mjs';
import 'node:fs';

@@ -10,3 +10,3 @@ import 'makedirp';

const version = "1.1.0";
const version = "1.2.0";

@@ -13,0 +13,0 @@ const helpInfo = () => {

@@ -7,3 +7,3 @@ 'use strict';

require('node-rmrf');
const index = require('./shared/node-mv.5714bdb0.cjs');
const index = require('./shared/node-mv.BJ49bY0J.cjs');
require('node:path');

@@ -10,0 +10,0 @@

@@ -5,3 +5,3 @@ import 'node:fs';

import 'node-rmrf';
export { m as mv } from './shared/node-mv.52ddd0ae.mjs';
export { m as mv } from './shared/node-mv.BeuPSJ9l.mjs';
import 'node:path';
{
"name": "@lxf2513/node-mv",
"version": "1.1.0",
"version": "1.2.0",
"description": "The 'mv' command implementation for nodejs.It will create all the necessary directories and destination file which not exist.",

@@ -53,11 +53,11 @@ "type": "module",

"devDependencies": {
"@types/node": "^22.10.0",
"prettier": "^3.4.1",
"typescript": "^5.7.2",
"unbuild": "^2.0.0"
"@types/node": "^22.10.7",
"prettier": "^3.4.2",
"typescript": "^5.7.3",
"unbuild": "^3.3.1"
},
"dependencies": {
"makedirp": "^1.1.2",
"node-cpr": "^1.2.4",
"node-rmrf": "^1.0.7"
"makedirp": "^1.2.0",
"node-cpr": "^1.3.0",
"node-rmrf": "^1.1.1"
},

@@ -64,0 +64,0 @@ "publishConfig": {

import { existsSync, statSync, renameSync } from 'node:fs';
import { mkdirpSync } from 'makedirp';
import { cpr } from 'node-cpr';
import { rmrfSync } from 'node-rmrf';
import { sep, resolve } from 'node:path';
const name = "nodemv";
const errorLog = (str) => {
console.log("\x1B[31m%s\x1B[0m", str);
};
function isPathExist(path) {
try {
return existsSync(path);
} catch {
return false;
}
}
function isFile(path) {
try {
const stat = statSync(resolve(path));
return stat.isFile();
} catch {
return false;
}
}
function isDirectory(path) {
try {
const stat = statSync(resolve(path));
return stat.isDirectory();
} catch {
return false;
}
}
function isExistedInDest(source, dest) {
if (isDirectory(dest) && isPathExist(`${dest}${sep}${source}`)) {
return true;
}
return false;
}
function errorMsg(source, dest, mkdirp) {
if (typeof source === "string" || source.length === 1) {
const sourcePath = typeof source === "string" ? source : source[0];
if (!isPathExist(sourcePath)) {
errorLog(
`${name}: cannot stat '${sourcePath}': No such file or directory`
);
return false;
} else if (isDirectory(sourcePath) && !isDirectory(dest) && isFile(dest)) {
errorLog(
`${name}: cannot overwrite non-directory '${dest}' with directory '${sourcePath}'`
);
return false;
} else if (isDirectory(sourcePath) && isDirectory(dest) && sourcePath === dest) {
errorLog(
`${name}: cannot move '${sourcePath}' to a subdirectory of itself, '${dest}/${sourcePath}'`
);
return false;
} else if (!isPathExist(sourcePath) && !mkdirp) {
errorLog(
`${name}: cannot move '${sourcePath}' to '${dest}': No such file or directory`
);
return false;
}
return true;
} else {
if (!isDirectory(dest) && !mkdirp) {
errorLog(`${name}: target '${dest}' is not a directory`);
return false;
} else {
source.forEach((s) => {
errorMsg(s, dest);
});
return true;
}
}
}
function moveFile(source, dest) {
try {
renameSync(source, dest);
} catch (error) {
const err = error;
if (err?.code === "EPERM" || err?.code === "EISDIR" || err?.code === "EXDEV") {
cpr(source, dest);
rmrfSync(source);
}
}
}
function mv(source, dest, options) {
const { clobber = true, mkdirp } = options;
const exist = isPathExist(dest);
const isStr = typeof source === "string";
const isArray = Array.isArray(source);
if (isArray && source.length > 1 && !exist && mkdirp || isStr && !exist) {
mkdirpSync(dest);
}
if (!errorMsg(source, dest)) {
return;
}
if (!exist || clobber || !clobber && (isStr && !isExistedInDest(source, dest) || isArray && source.length === 1 && !isExistedInDest(source[0], dest))) {
if (isStr) {
moveFile(source, dest);
} else {
source.forEach((s) => {
moveFile(s, dest);
});
}
}
}
export { errorLog as e, mv as m, name as n };
'use strict';
const node_fs = require('node:fs');
const makedirp = require('makedirp');
const nodeCpr = require('node-cpr');
const nodeRmrf = require('node-rmrf');
const node_path = require('node:path');
const name = "nodemv";
const errorLog = (str) => {
console.log("\x1B[31m%s\x1B[0m", str);
};
function isPathExist(path) {
try {
return node_fs.existsSync(path);
} catch {
return false;
}
}
function isFile(path) {
try {
const stat = node_fs.statSync(node_path.resolve(path));
return stat.isFile();
} catch {
return false;
}
}
function isDirectory(path) {
try {
const stat = node_fs.statSync(node_path.resolve(path));
return stat.isDirectory();
} catch {
return false;
}
}
function isExistedInDest(source, dest) {
if (isDirectory(dest) && isPathExist(`${dest}${node_path.sep}${source}`)) {
return true;
}
return false;
}
function errorMsg(source, dest, mkdirp) {
if (typeof source === "string" || source.length === 1) {
const sourcePath = typeof source === "string" ? source : source[0];
if (!isPathExist(sourcePath)) {
errorLog(
`${name}: cannot stat '${sourcePath}': No such file or directory`
);
return false;
} else if (isDirectory(sourcePath) && !isDirectory(dest) && isFile(dest)) {
errorLog(
`${name}: cannot overwrite non-directory '${dest}' with directory '${sourcePath}'`
);
return false;
} else if (isDirectory(sourcePath) && isDirectory(dest) && sourcePath === dest) {
errorLog(
`${name}: cannot move '${sourcePath}' to a subdirectory of itself, '${dest}/${sourcePath}'`
);
return false;
} else if (!isPathExist(sourcePath) && !mkdirp) {
errorLog(
`${name}: cannot move '${sourcePath}' to '${dest}': No such file or directory`
);
return false;
}
return true;
} else {
if (!isDirectory(dest) && !mkdirp) {
errorLog(`${name}: target '${dest}' is not a directory`);
return false;
} else {
source.forEach((s) => {
errorMsg(s, dest);
});
return true;
}
}
}
function moveFile(source, dest) {
try {
node_fs.renameSync(source, dest);
} catch (error) {
const err = error;
if (err?.code === "EPERM" || err?.code === "EISDIR" || err?.code === "EXDEV") {
nodeCpr.cpr(source, dest);
nodeRmrf.rmrfSync(source);
}
}
}
function mv(source, dest, options) {
const { clobber = true, mkdirp } = options;
const exist = isPathExist(dest);
const isStr = typeof source === "string";
const isArray = Array.isArray(source);
if (isArray && source.length > 1 && !exist && mkdirp || isStr && !exist) {
makedirp.mkdirpSync(dest);
}
if (!errorMsg(source, dest)) {
return;
}
if (!exist || clobber || !clobber && (isStr && !isExistedInDest(source, dest) || isArray && source.length === 1 && !isExistedInDest(source[0], dest))) {
if (isStr) {
moveFile(source, dest);
} else {
source.forEach((s) => {
moveFile(s, dest);
});
}
}
}
exports.errorLog = errorLog;
exports.mv = mv;
exports.name = name;