mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-21 05:40:29 +08:00
122 lines
3.7 KiB
JavaScript
122 lines
3.7 KiB
JavaScript
'use strict';Object.defineProperty(exports,Symbol.toStringTag,{value:'Module'});const misc=require('../../_virtual/misc.cjs'),require$$0=require('node:path'),require$$1=require('node:fs'),require$$2=require('node:fs/promises');var hasRequiredMisc;
|
|
|
|
function requireMisc () {
|
|
if (hasRequiredMisc) return misc.__exports;
|
|
hasRequiredMisc = 1;
|
|
(function (exports) {
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
function _export(target, all) {
|
|
for(var name in all)Object.defineProperty(target, name, {
|
|
enumerable: true,
|
|
get: all[name]
|
|
});
|
|
}
|
|
_export(exports, {
|
|
fastIpVersion: function() {
|
|
return fastIpVersion;
|
|
},
|
|
fastStringCompare: function() {
|
|
return fastStringCompare;
|
|
},
|
|
isDirectoryEmptySync: function() {
|
|
return isDirectoryEmptySync;
|
|
},
|
|
mkdirp: function() {
|
|
return mkdirp;
|
|
},
|
|
notSupported: function() {
|
|
return notSupported;
|
|
},
|
|
removeFiles: function() {
|
|
return removeFiles;
|
|
},
|
|
withBannerArray: function() {
|
|
return withBannerArray;
|
|
},
|
|
withIdentityContent: function() {
|
|
return withIdentityContent;
|
|
},
|
|
writeFile: function() {
|
|
return writeFile;
|
|
}
|
|
});
|
|
const _nodepath = require$$0;
|
|
const _nodefs = /*#__PURE__*/ _interop_require_default(require$$1);
|
|
const _promises = /*#__PURE__*/ _interop_require_default(require$$2);
|
|
function _interop_require_default(obj) {
|
|
return obj && obj.__esModule ? obj : {
|
|
default: obj
|
|
};
|
|
}
|
|
function fastStringCompare(a, b) {
|
|
const lenA = a.length;
|
|
const lenB = b.length;
|
|
const minLen = lenA < lenB ? lenA : lenB;
|
|
for(let i = 0; i < minLen; ++i){
|
|
const ca = a.charCodeAt(i);
|
|
const cb = b.charCodeAt(i);
|
|
if (ca > cb) return 1;
|
|
if (ca < cb) return -1;
|
|
}
|
|
if (lenA === lenB) {
|
|
return 0;
|
|
}
|
|
return lenA > lenB ? 1 : -1;
|
|
}
|
|
function mkdirp(dir) {
|
|
if (_nodefs.default.existsSync(dir)) {
|
|
return;
|
|
}
|
|
return _promises.default.mkdir(dir, {
|
|
recursive: true
|
|
});
|
|
}
|
|
const writeFile = async (destination, input, dir = (0, _nodepath.dirname)(destination))=>{
|
|
const p = mkdirp(dir);
|
|
if (p) {
|
|
await p;
|
|
}
|
|
return _promises.default.writeFile(destination, input, {
|
|
encoding: 'utf-8'
|
|
});
|
|
};
|
|
const removeFiles = async (files)=>Promise.all(files.map((file)=>_promises.default.rm(file, {
|
|
force: true
|
|
})));
|
|
function withBannerArray(title, description, date, content) {
|
|
return [
|
|
'#########################################',
|
|
`# ${title}`,
|
|
`# Last Updated: ${date.toISOString()}`,
|
|
`# Size: ${content.length}`,
|
|
...description.map((line)=>line ? `# ${line}` : '#'),
|
|
'#########################################',
|
|
...content,
|
|
'################## EOF ##################'
|
|
];
|
|
}
|
|
function notSupported(name) {
|
|
return (...args)=>{
|
|
console.error(`${name}: not supported.`, args);
|
|
throw new Error(`${name}: not implemented.`);
|
|
};
|
|
}
|
|
function withIdentityContent(title, description, date, content) {
|
|
return content;
|
|
}
|
|
function isDirectoryEmptySync(path) {
|
|
const directoryHandle = _nodefs.default.opendirSync(path);
|
|
try {
|
|
return directoryHandle.readSync() === null;
|
|
} finally{
|
|
directoryHandle.closeSync();
|
|
}
|
|
}
|
|
function fastIpVersion(ip) {
|
|
return ip.includes(':') ? 6 : ip.includes('.') ? 4 : 0;
|
|
}
|
|
} (misc.__exports));
|
|
return misc.__exports;
|
|
}exports.__require=requireMisc; |