UNPKG

@kotori-bot/tools

Version:
92 lines (91 loc) 3.04 kB
/** * @Package @kotori-bot/tools * @Version 1.5.2 * @Author Hotaru <me@hotaru.icu> * @Copyright 2024-2025 Hotaru. All rights reserved. * @License BAN-ZHINESE-USING * @Link https://github.com/kotorijs/kotori * @Date 17:26:22 */ "use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var function_exports = {}; __export(function_exports, { isClass: () => isClass, none: () => none, regExpExecAll: () => regExpExecAll, sleep: () => sleep, stringFormat: () => stringFormat, stringTemp: () => stringTemp }); module.exports = __toCommonJS(function_exports); function none(..._) { _.length.toString(); } function isClass(obj, strict = true) { if (typeof obj !== "function") return false; const str = obj.toString(); if (obj.prototype === void 0) return false; if (obj.prototype.constructor !== obj) return false; if (str.slice(0, 5) === "class") return true; if (Object.getOwnPropertyNames(obj.prototype).length >= 2) return true; if (/^function\s+\(|^function\s+anonymous\(/.test(str)) return false; if (strict && /^function\s+[A-Z]/.test(str)) return true; if (!/\b\(this\b|\bthis[.[]\b/.test(str)) return false; if (!strict || /classCallCheck\(this/.test(str)) return true; return /^function\sdefault_\d+\s*\(/.test(str); } function regExpExecAll(regExp, input) { if (!regExp.global) return regExp.exec(input); const arr = []; let res = regExp.exec(input); while (res) { arr.push(res); res = regExp.exec(input); } return arr.length === 0 ? null : arr; } function stringTemp(template, args) { const params = Object.assign(args, { break: "\n" }); let templateString = template; for (const param of Object.keys(params)) { if (typeof params[param] !== "string") params[param] = String(params[param]); templateString = templateString.replaceAll(`%${param}%`, params[param]); } return templateString; } function stringFormat(template, args) { let str = template; args.forEach((value, index) => { str = str.replaceAll(`{${index}}`, String(value)); }); return str; } function sleep(ms) { return new Promise((resolve) => setTimeout(() => resolve(ms), ms)); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { isClass, none, regExpExecAll, sleep, stringFormat, stringTemp });