omg this is getting out of hand

This commit is contained in:
jelveh
2025-05-21 19:40:50 -07:00
parent f765180c1b
commit b703b60977
2 changed files with 25 additions and 4 deletions
-1
View File
@@ -1 +0,0 @@
import puter from './index.js';
+25 -3
View File
@@ -529,12 +529,34 @@ export default window.puter = (function() {
container = document.getElementById("--puter-printbox");
}
// Copy args to avoid modifying the original array
let processedArgs = [...args];
// Check if the last argument is an options object
const options = typeof args[args.length - 1] === 'object' && args[args.length - 1] !== null ? args.pop() : { newline: false };
const lastArg = processedArgs.length > 0 ? processedArgs[processedArgs.length - 1] : null;
let options = { newline: false };
if (lastArg && typeof lastArg === 'object' && lastArg !== null &&
!Array.isArray(lastArg) &&
Object.getPrototypeOf(lastArg) === Object.prototype &&
typeof lastArg.toString === 'undefined') {
options = processedArgs.pop();
}
// Process each argument
for(let arg of args) {
container.innerText += arg;
for(let arg of processedArgs) {
// If arg has custom toString, use it
if (arg && typeof arg === 'object' && typeof arg.toString === 'function') {
const stringValue = arg.toString();
if (typeof stringValue === 'string') {
container.innerText += stringValue;
} else {
container.innerText += String(arg);
}
} else {
container.innerText += arg;
}
if (options.newline) {
container.innerText += '\n';
}