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

@lxf2513/mkdir-recursive

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lxf2513/mkdir-recursive - npm Package Compare versions

Comparing version
1.1.0
to
1.2.0
+6
-108
dist/index.cjs
'use strict';
const fs = require('node:fs');
const nodePath = require('node:path');
const mkdirSyncRecursive = require('mkdir-sync-recursive');
const mkdirAsyncRecursive = require('mkdir-async-recursive');
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
const nodePath__default = /*#__PURE__*/_interopDefaultCompat(nodePath);
const mkdirSyncRecursive__default = /*#__PURE__*/_interopDefaultCompat(mkdirSyncRecursive);
const mkdirAsyncRecursive__default = /*#__PURE__*/_interopDefaultCompat(mkdirAsyncRecursive);
const validateUint32 = (value, name) => {
if (typeof value !== "number") {
throw new Error(`${name}: ${value} is not number`);
}
if (!Number.isInteger(value)) {
throw new Error(`${name}: ${value} is not an integer`);
}
const min = 0;
const max = 4294967295;
if (value < min || value > max) {
throw new Error(`${name}: ${value} must >= ${min} && <= ${max}`);
}
};
function parseFileMode(value, name, def) {
value ?? (value = def);
if (typeof value === "string") {
if (!/^[0-7]+$/.test(value)) {
throw new Error(`${name}: ${value} is invalid`);
}
value = Number.parseInt(value, 8);
}
validateUint32(value, name);
return value;
}
const isArray = Array.isArray;
function mkdirp(path, options) {
let mode = 511;
if (typeof options === "number" || typeof options === "string") {
mode = parseFileMode(options, "mode");
} else if (options?.mode) {
mode = parseFileMode(options.mode, "options.mode");
}
const sep = path.includes("/") ? "/" : nodePath__default.sep;
const dirs = path.split(sep);
let dirPath = "";
const result = [];
for (const dir of dirs) {
dirPath += `${dir}${sep}`;
mkdir(dirPath, mode);
}
function mkdir(path2, mode2) {
if (!fs__default.existsSync(dirPath)) {
try {
fs__default.mkdirSync(path2, mode2);
result.push(path2);
return true;
} catch (error) {
console.error(error);
return false;
}
}
return void 0;
}
return result.length ? nodePath__default.resolve(result[0]) : void 0;
}
function mkdirSyncRecursive(path, options) {
let mpath;
if (typeof path === "string") {
mpath = mkdirp(path, options);
} else {
mpath = [];
for (const p of path) {
mpath.push(mkdirp(p, options));
}
}
return isArray(mpath) ? mpath.some((m) => !!m) ? mpath : void 0 : mpath;
}
async function mkdirAsyncRecursive(path, options) {
let mode = 511;
if (typeof options === "number" || typeof options === "string") {
mode = parseFileMode(options, "mode");
} else if (options) {
if (options.mode !== void 0) {
mode = parseFileMode(options.mode, "options.mode");
}
}
const sep = path.includes("/") ? "/" : nodePath__default.sep;
const dirs = path.split(sep);
let dirPath = "";
const result = [];
for (const dir of dirs) {
dirPath += `${dir}${sep}`;
await mkdir(dirPath, mode);
}
async function mkdir(path2, mode2) {
if (!fs__default.existsSync(dirPath)) {
try {
fs__default.mkdirSync(path2, mode2);
result.push(path2);
return await Promise.resolve(true);
} catch (error) {
console.error(error);
return await Promise.resolve(false);
}
}
return await Promise.resolve(void 0);
}
return await Promise.resolve(
result.length ? nodePath__default.resolve(result[0]) : void 0
);
}
exports.mkdirAsyncRecursive = mkdirAsyncRecursive;
exports.mkdirSyncRecursive = mkdirSyncRecursive;
exports.mkdirSyncRecursive = mkdirSyncRecursive__default;
exports.mkdirAsyncRecursive = mkdirAsyncRecursive__default;

@@ -1,12 +0,2 @@

import { MakeDirectoryOptions } from 'node:fs';
type MakeDirectoryRecursiveOptions = Omit<
MakeDirectoryOptions,
'recursive'
>;
declare function mkdirSyncRecursive(path: string | string[], options?: string | number | MakeDirectoryRecursiveOptions): string | (string | undefined)[] | undefined;
declare function mkdirAsyncRecursive(path: string, options?: string | number | MakeDirectoryRecursiveOptions): Promise<string | undefined>;
export { mkdirAsyncRecursive, mkdirSyncRecursive };
export { default as mkdirSyncRecursive } from 'mkdir-sync-recursive';
export { default as mkdirAsyncRecursive } from 'mkdir-async-recursive';

@@ -1,12 +0,2 @@

import { MakeDirectoryOptions } from 'node:fs';
type MakeDirectoryRecursiveOptions = Omit<
MakeDirectoryOptions,
'recursive'
>;
declare function mkdirSyncRecursive(path: string | string[], options?: string | number | MakeDirectoryRecursiveOptions): string | (string | undefined)[] | undefined;
declare function mkdirAsyncRecursive(path: string, options?: string | number | MakeDirectoryRecursiveOptions): Promise<string | undefined>;
export { mkdirAsyncRecursive, mkdirSyncRecursive };
export { default as mkdirSyncRecursive } from 'mkdir-sync-recursive';
export { default as mkdirAsyncRecursive } from 'mkdir-async-recursive';

@@ -1,12 +0,2 @@

import { MakeDirectoryOptions } from 'node:fs';
type MakeDirectoryRecursiveOptions = Omit<
MakeDirectoryOptions,
'recursive'
>;
declare function mkdirSyncRecursive(path: string | string[], options?: string | number | MakeDirectoryRecursiveOptions): string | (string | undefined)[] | undefined;
declare function mkdirAsyncRecursive(path: string, options?: string | number | MakeDirectoryRecursiveOptions): Promise<string | undefined>;
export { mkdirAsyncRecursive, mkdirSyncRecursive };
export { default as mkdirSyncRecursive } from 'mkdir-sync-recursive';
export { default as mkdirAsyncRecursive } from 'mkdir-async-recursive';

@@ -1,108 +0,2 @@

import fs from 'node:fs';
import nodePath from 'node:path';
const validateUint32 = (value, name) => {
if (typeof value !== "number") {
throw new Error(`${name}: ${value} is not number`);
}
if (!Number.isInteger(value)) {
throw new Error(`${name}: ${value} is not an integer`);
}
const min = 0;
const max = 4294967295;
if (value < min || value > max) {
throw new Error(`${name}: ${value} must >= ${min} && <= ${max}`);
}
};
function parseFileMode(value, name, def) {
value ?? (value = def);
if (typeof value === "string") {
if (!/^[0-7]+$/.test(value)) {
throw new Error(`${name}: ${value} is invalid`);
}
value = Number.parseInt(value, 8);
}
validateUint32(value, name);
return value;
}
const isArray = Array.isArray;
function mkdirp(path, options) {
let mode = 511;
if (typeof options === "number" || typeof options === "string") {
mode = parseFileMode(options, "mode");
} else if (options?.mode) {
mode = parseFileMode(options.mode, "options.mode");
}
const sep = path.includes("/") ? "/" : nodePath.sep;
const dirs = path.split(sep);
let dirPath = "";
const result = [];
for (const dir of dirs) {
dirPath += `${dir}${sep}`;
mkdir(dirPath, mode);
}
function mkdir(path2, mode2) {
if (!fs.existsSync(dirPath)) {
try {
fs.mkdirSync(path2, mode2);
result.push(path2);
return true;
} catch (error) {
console.error(error);
return false;
}
}
return void 0;
}
return result.length ? nodePath.resolve(result[0]) : void 0;
}
function mkdirSyncRecursive(path, options) {
let mpath;
if (typeof path === "string") {
mpath = mkdirp(path, options);
} else {
mpath = [];
for (const p of path) {
mpath.push(mkdirp(p, options));
}
}
return isArray(mpath) ? mpath.some((m) => !!m) ? mpath : void 0 : mpath;
}
async function mkdirAsyncRecursive(path, options) {
let mode = 511;
if (typeof options === "number" || typeof options === "string") {
mode = parseFileMode(options, "mode");
} else if (options) {
if (options.mode !== void 0) {
mode = parseFileMode(options.mode, "options.mode");
}
}
const sep = path.includes("/") ? "/" : nodePath.sep;
const dirs = path.split(sep);
let dirPath = "";
const result = [];
for (const dir of dirs) {
dirPath += `${dir}${sep}`;
await mkdir(dirPath, mode);
}
async function mkdir(path2, mode2) {
if (!fs.existsSync(dirPath)) {
try {
fs.mkdirSync(path2, mode2);
result.push(path2);
return await Promise.resolve(true);
} catch (error) {
console.error(error);
return await Promise.resolve(false);
}
}
return await Promise.resolve(void 0);
}
return await Promise.resolve(
result.length ? nodePath.resolve(result[0]) : void 0
);
}
export { mkdirAsyncRecursive, mkdirSyncRecursive };
export { default as mkdirSyncRecursive } from 'mkdir-sync-recursive';
export { default as mkdirAsyncRecursive } from 'mkdir-async-recursive';
+7
-3
{
"name": "@lxf2513/mkdir-recursive",
"version": "1.1.0",
"version": "1.2.0",
"description": "Recursively creates a directory. Returns undefined or the first directory path created.",

@@ -50,4 +50,4 @@ "type": "module",

"devDependencies": {
"@types/node": "^22.10.0",
"prettier": "^3.4.1",
"@types/node": "^22.10.1",
"prettier": "^3.4.2",
"typescript": "^5.7.2",

@@ -58,3 +58,7 @@ "unbuild": "^2.0.0"

"access": "public"
},
"dependencies": {
"mkdir-async-recursive": "^1.0.2",
"mkdir-sync-recursive": "^1.1.3"
}
}