// JS++ // Created by Samuel Lord (NodeMixaholic/Sparksammy) // Now Maintained by Sneed Group // Licensed under Samuel Public License with <3 class JSPlusPlus { static General = class { static Helpers = class { sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } isToxic(sentences) { // Load the model. Users optionally pass in a threshold and an array of // labels to include. const gen = new JSPlusPlus.General gen.require("https://cdn.jsdelivr.net/npm/@tensorflow/tfjs") gen.require("https://cdn.jsdelivr.net/npm/@tensorflow-models/toxicity") let threshold = 0.9; let toxic = false toxicity.load(threshold).then(model => { model.classify(sentences).then(predictions => { predictions.forEach(classified => { if (classified.label == "toxicity") { toxic = classified.results.match } }); }); }); return toxic } async asyncSleep(ms) { await new Promise(r => setTimeout(r, ms)); } consoleUseWarner(warning) { try { console.log(`%cSTOP!%c ${warning}`, "font-size: 42px; color: white; background-color: red;", "font-size: 20px; color: white; background-color: red;") } catch { console.warn(`STOP! ${warning}`) } } // Constructor Helpers BEGIN enableJSConstructorHelpers() { Date.prototype.toUSADateString = function() { let day = this.getDate().toString().padStart(2, '0'); let month = (this.getMonth() + 1).toString().padStart(2, '0'); let year = this.getFullYear(); return `${day}/${month}/${year}`; }; Date.prototype.toISODateString = function() { let year = this.getFullYear(); let month = (this.getMonth() + 1).toString().padStart(2, '0'); let day = this.getDate().toString().padStart(2, '0'); return `${year}-${month}-${day}`; }; Object.merge = function(target, source) { for (let key in source) { if (source.hasOwnProperty(key)) { target[key] = source[key]; } } return target; }; Function.prototype.once = function() { let called = false; const func = this; return function(...args) { if (!called) { called = true; return func.apply(this, args); } }; }; String.prototype.capitalize = function() { return this.charAt(0).toUpperCase() + this.slice(1); }; Array.prototype.last = function() { return this[this.length - 1]; }; Array.prototype.unique = function() { return [...new Set(this)]; }; Array.prototype.remove = function(element) { const index = this.indexOf(element); if (index !== -1) { this.splice(index, 1); } return this; }; String.prototype.reverse = function() { return this.split('').reverse().join(''); }; Function.prototype.debounce = function(wait) { let timeout; const func = this; return function(...args) { clearTimeout(timeout); timeout = setTimeout(() => func.apply(this, args), wait); }; }; Date.prototype.addDays = function(days) { let date = new Date(this.valueOf()); date.setDate(date.getDate() + days); return date; }; Array.prototype.flatten = function() { return this.reduce((flat, toFlatten) => { return flat.concat(Array.isArray(toFlatten) ? toFlatten.flatten() : toFlatten); }, []); }; String.prototype.camelCase = function() { return this.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function(match, index) { return index === 0 ? match.toLowerCase() : match.toUpperCase(); }).replace(/\s+/g, ''); }; Number.prototype.toCurrency = function(locale = 'en-US', currency = 'USD') { return this.toLocaleString(locale, { style: 'currency', currency }); }; Object.isEmpty = function(obj) { return Object.keys(obj).length === 0 && obj.constructor === Object; }; Array.prototype.chunk = function(size) { let result = []; for (let i = 0; i < this.length; i += size) { result.push(this.slice(i, i + size)); } return result; }; Array.prototype.first = function() { return this[0]; }; String.prototype.contains = function(substring) { return this.indexOf(substring) !== -1; }; Object.assignDeep = function(target, ...sources) { sources.forEach(source => { for (let key in source) { if (source[key] instanceof Object) { if (!target[key]) { target[key] = {}; } Object.assignDeep(target[key], source[key]); } else { target[key] = source[key]; } } }); return target; }; Array.prototype.shuffle = function() { for (let i = this.length - 1; i > 0; i--) { let j = Math.floor(Math.random() * (i + 1)); [this[i], this[j]] = [this[j], this[i]]; } return this; }; String.prototype.isPalindrome = function() { let normalized = this.replace(/[\W_]/g, '').toLowerCase(); return normalized === normalized.split('').reverse().join(''); }; Number.prototype.isPrime = function() { if (this <= 1) return false; for (let i = 2, sqrt = Math.sqrt(this); i <= sqrt; i++) { if (this % i === 0) return false; } return true; }; Array.prototype.compact = function() { return this.filter(Boolean); }; Array.prototype.pluck = function(property) { return this.map(item => item[property]); }; String.prototype.toKebabCase = function() { return this.replace(/([a-z])([A-Z])/g, '$1-$2') .replace(/[\s_]+/g, '-') .toLowerCase(); }; Function.prototype.memoize = function() { const cache = {}; const func = this; return function(...args) { const key = JSON.stringify(args); if (!cache[key]) { cache[key] = func.apply(this, args); } return cache[key]; }; }; Object.invert = function(obj) { let inverted = {}; for (let key in obj) { if (obj.hasOwnProperty(key)) { inverted[obj[key]] = key; } } return inverted; }; Date.prototype.toTimeString = function() { let hours = this.getHours().toString().padStart(2, '0'); let minutes = this.getMinutes().toString().padStart(2, '0'); let seconds = this.getSeconds().toString().padStart(2, '0'); return `${hours}:${minutes}:${seconds}`; }; String.prototype.truncate = function(length) { return this.length > length ? this.slice(0, length) + '...' : this; }; Number.prototype.toOrdinal = function() { const suffixes = ["th", "st", "nd", "rd"]; const v = this % 100; return this + (suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0]); }; Array.prototype.sum = function() { return this.reduce((total, num) => total + num, 0); }; String.prototype.isUpperCase = function() { return this.valueOf() === this.toUpperCase(); }; Function.prototype.delay = function(ms) { setTimeout(this, ms); }; Object.keysAmount = function(obj) { return Object.keys(obj).length; }; Date.prototype.isWeekend = function() { const day = this.getDay(); return day === 0 || day === 6; }; Array.prototype.average = function() { return this.sum() / this.length; }; String.prototype.isLowerCase = function() { return this.valueOf() === this.toLowerCase(); }; console.log("Javascript Extras Enabled!") } // Constructor Helpers END } static Debug = class { tryCatch(funcTry, funcCatch) { try { funcTry } catch { funcCatch } } } //Eval alternative //Example: exec("alert('Hello, world!')") exec(jsCode) { let js = jsCode.toString(); Function(js)() } readInternetText(url) { try { var request = new XMLHttpRequest(); // Create a new XMLHttpRequest object request.open('GET', url, false); // Open the request with synchronous mode request.send(null); // Send the request with no additional data if (request.status === 200) { // Check if the request was successful return request.responseText; // Return the response text } else { return 'Error: ' + request.status; // Return an error message if the request failed } } catch { try { let http = require('http'); let body = "" let request = http.get(url, function (res) { var data = ''; res.on('data', function (chunk) { data += chunk; }); res.on('end', function () { body = data.toString() }); }); request.on('error', function (e) { body = e.message }); request.end(); return body; } catch { return "Unknown error fetching URL! :'(" } } } require(jsURI) { let gen = new JSPlusPlus.General let req = gen.readInternetText(jsURI); gen.exec(req); } } static HTMLFrontend = class { // Get element by ID getElementById(elementID) { return document.getElementById(elementID) } //Convert markdown to HTML and back markdownToHTML(markdown) { // Replace headers (h1, h2, h3) with corresponding HTML tags markdown = markdown.replace(/^# (.*$)/gim, '

$1

'); markdown = markdown.replace(/^## (.*$)/gim, '

$1

'); markdown = markdown.replace(/^### (.*$)/gim, '

$1

'); // Replace bold and italic text with corresponding HTML tags markdown = markdown.replace(/\*\*(.*)\*\*/gim, '$1'); markdown = markdown.replace(/\*(.*)\*/gim, '$1'); // Replace unordered list items with HTML list tags markdown = markdown.replace(/\* (.*?)(\n|$)/gim, '
  • $1
  • '); // Replace inline code with HTML tag markdown = markdown.replace(/`(.*?)`/gim, '$1'); // Replace blockquotes with HTML
    tag markdown = markdown.replace(/^\s*> (.*)$/gim, '
    $1
    '); // Replace horizontal rules with HTML
    tag markdown = markdown.replace(/^\s*[-*_]{3,}\s*$/gim, '
    '); // Replace line breaks with HTML
    tag markdown = markdown.replace(/\n$/gim, '
    '); // Replace images with HTML tag markdown = markdown.replace(/!\[(.*?)\]\((.*?)\)/gim, '$1'); // Replace links with HTML tag markdown = markdown.replace(/\[(.*?)\]\((.*?)\)/gim, '$1'); markdown = markdown.replaceAll("
        ", "") markdown = markdown.replaceAll("
    ", "") return markdown; } htmlToMarkdown(html) { // Replace headers (h1, h2, h3) with corresponding Markdown tags html = html.replace(/

    (.*?)<\/h1>/gim, '# $1'); html = html.replace(/

    (.*?)<\/h2>/gim, '## $1'); html = html.replace(/

    (.*?)<\/h3>/gim, '### $1'); // Replace bold and italic text with corresponding Markdown tags html = html.replace(/(.*?)<\/b>/gim, '**$1**'); html = html.replace(/(.*?)<\/i>/gim, '*$1*'); // Replace unordered list items with Markdown list tags html = html.replace(/