e621-sdk
Version:
从E621抓取帖子。支持搜索、引用、随机。
47 lines (46 loc) • 1.84 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.progressBar = exports.count = exports.createForm = exports.assignRecursive = void 0;
const chalk_template_1 = __importDefault(require("chalk-template"));
function assignRecursive(target, ...sources) {
const result = Object(target);
for (const nextSource of sources) {
if (nextSource != null) {
for (const nextKey in nextSource) {
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
const nextVal = nextSource[nextKey];
if (typeof nextVal === "object" && nextVal !== null && !Array.isArray(nextVal)) {
result[nextKey] = assignRecursive(Object.prototype.hasOwnProperty.call(result, nextKey) ? result[nextKey] : {}, nextVal);
}
else {
result[nextKey] = nextVal;
}
}
}
}
}
return result;
}
exports.assignRecursive = assignRecursive;
function createForm(data) {
const result = new FormData();
Object.keys(data).forEach(key => result.append(key, String(data[key])));
return result;
}
exports.createForm = createForm;
function count(c) {
return {
per(t) {
return t / c;
}
};
}
exports.count = count;
function progressBar(percent, length = 10) {
const filled = Math.floor(percent * length);
return (0, chalk_template_1.default) `<{bold ${"#".repeat(filled)}}${".".repeat(length - filled)} {bold.yellow ${(percent * 100).toFixed(2)}%}>`;
}
exports.progressBar = progressBar;