comic-book-dl
Version:
40 lines (39 loc) • 1 kB
JavaScript
import fs from 'node:fs';
export * from './log.js';
export * from './ua.js';
export function fixPathName(path) {
if (!path)
return '';
const dirNameReg = /[\\/:*?"<>|\n\r]/g;
return path.replace(dirNameReg, '_').replace(/\s/g, '');
}
export function existsMkdir(path) {
if (!fs.existsSync(path)) {
fs.mkdirSync(path, { recursive: true });
}
}
export function notEmpty(value) {
return value !== null && value !== undefined;
}
export function getUrlFileName(url) {
if (!url)
return '';
const urlObj = new URL(url);
return urlObj.pathname.split('/').at(-1);
}
export function toReversed(arr) {
const newArr = [];
arr.forEach(item => newArr.unshift(item));
return newArr;
}
export function sleep(seconds) {
return new Promise((resolve) => {
setTimeout(() => {
resolve(true);
}, seconds);
});
}
export function isHasHost(url) {
const reg = /^(http(s):\/\/)?.*\..*\//g;
return reg.test(url);
}