Skip to main content
This release is 18 versions behind 5.0.12 — the latest version of @lost-c3/lib. Jump to latest

Lost for easy making Construct 3 Addons.

This package works with DenoIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
35%
Published
4 months ago (3.3.2)
export function findClassesInheritingFrom(fileContent: string, parentClass: string) { // Динамическое регулярное выражение для поиска классов const classRegex = new RegExp(`class\\s+(\\w+)\\s+extends\\s+${parentClass.replace('.', '\\.')}\\s*{`, 'g'); const matches = []; let match; while ((match = classRegex.exec(fileContent)) !== null) { matches.push(match[1]); // Имя класса находится в первой группе } return matches[0]; } export function dedent(strings: TemplateStringsArray, ...values: any[]) { const fullString = strings.reduce((result, str, i) => result + str + (values[i] || ""), ""); const lines = fullString.split("\n"); // Убираем пустые строки и минимальные отступы const minIndent = lines.filter(line => line.trim()).reduce((min, line) => { const indent = line.match(/^(\s*)/)?.[0]?.length ?? 0; return Math.min(min, indent); }, Infinity); return lines.map(line => line.slice(minIndent)).join("\n").trim(); } export async function isFileExists(path: string): Promise<boolean> { try { const dirStat = await Deno.stat(path); if ( dirStat && dirStat.isFile ) { return true; } else { return false; } } catch (_e) { return false; } } export async function isDirectoryExists(path: string): Promise<boolean> { try { const dirStat = await Deno.stat(path); if ( dirStat && dirStat.isDirectory ) { return true; } else { return false; } } catch (_e) { return false; } } export function serializeObjectWithFunctions(obj: any): string { let str = '{\n'; for (const key in obj) { // deno-lint-ignore no-prototype-builtins if (obj.hasOwnProperty(key)) { const value = obj[key]; if (typeof value === 'function') { // Преобразование функции в строку str += ` ${key}: function ${value.toString().replace(/^function\s*\w*\s*/, '')},\n`; } else { str += ` ${key}: ${JSON.stringify(value, null, 2)},\n`; } } } str = str.replace(/,\n$/, '\n'); // Удаляем последнюю запятую str += '}'; return str; }