You are an expert at JavaScript and C#
. You must format indents using 2 spaces, and you must wrap strings using doublequotes " instead of '.
Let's think step by step.
| /////// download.js: SAVE data TO file (aka 'export/download')... | |
| //// const download_MIN=(d,f=`file-${+new Date}.txt`,t="octet-stream")=>{const h=URL.createObjectURL(new Blob([d].slice(void 0===d),{type:t})),s=null!==f;return Object.assign(document.createElement("a"),{href:h,[s&&"download"]:f,target:"_blank"}).click(),s&&URL.revokeObjectURL(h)}; | |
| const download = ( | |
| data | |
| , filename = `file-${+new Date}.txt` // null means download: filename OMITTED = DISPLAY data in browser | |
| , type = "octet-stream" // default is ~ "application/octet-binary" | |
| ) => { | |
| const href = URL.createObjectURL(new Blob( // https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob | |
| [data].slice(data === undefined) |
| //The following code is a reimplementation of the native Javascript method JSON.stringify | |
| //keep reading for the though process that lead to the solution | |
| var stringify = function(obj) { | |
| //checks if the input obj is a function statement or undefined | |
| if(typeof obj === 'undefined' || typeof obj === 'function') { | |
| return undefined; | |
| } | |
| //checks if the input obj is a string | |
| if(typeof obj === 'string') { |
| "use strict"; | |
| const { URL } = require("."); | |
| const inputs = [ | |
| "https://\u0000y", | |
| "https://x/\u0000y", | |
| "https://x/?\u0000y", | |
| "https://x/?#\u0000y" | |
| ]; |
| // contentsInNewWindow.js - F5-REFRESHABLE! - with TITLE! - (contents = '' or [], title, type = 'octet-stream', array-joining-delim = '\n\n') | |
| // const contentsInNewWindow=(c=[],T,t="octet-stream",d="\n\n")=>{const w=open(URL.createObjectURL(new Blob([[c].flat(1/0).join(d)],{type:"text"===t?t+"/plain;charset=utf-8":t})),"_blank");return w&&!w.closed&&(w.onload=()=>w.document.title=T),w}; | |
| const contentsInNewWindow = (contents = [], title, type = ["text", "octet-stream"][1], delim = "\n\n") => { | |
| const win = open( | |
| URL.createObjectURL( | |
| new Blob([ | |
| [contents].flat(1/0).join(delim) | |
| ], { | |
| // auto-UTF8 if type === 'text', to easily ensure visible emojis etc. |
| // randomWithSeed.js - use rnd() after rnd = createRandomWithSeed( seed [0+] = Date.now() ) - Math.random is less than 2x faster than this 'good enough' SEED-able version | |
| let createRandomWithSeed = seed => { | |
| seed = Math.abs(isNaN(seed) ? Date.now() : seed); | |
| return () => { | |
| seed = (seed * 9301 + 49297) % 233280; | |
| return seed / 233280; | |
| }; | |
| }; | |
| // R=s=>(s=Math.abs(isNaN(s)?Date.now():s),_=>(s=(9301*s+49297)%233280,s/233280)); |
| // dtString.js (dateArg, includeTime, defaultDate, defaultReturnValue) '1-2-2022 1:00' returns '02Jan2022 100am' or '02Jan2022' | |
| const assert=(...a)=>!a.reduce((b,c,d,e,f)=>(f=("function"==typeof c?!c():!c)&&[2>a.length?c:`<arg #${d+1}> ${a.map((a,b)=>`#${b+1} = [ ${a} ]`).join(" , ")}`],f&&console.assert(0,...b[b.push(f)-1]),b),a.length?[]:[a]).length; | |
| const assertMessage = (test, ...messageAndSubstitutions) => assert(test) || console.error(...messageAndSubstitutions) || false; | |
| console.clear(); | |
| // 183 chars: const dtString=(a,b,c,e,f=new Date(a),[,,,,g,h,,i]=(f=+f?f:new Date(c)).toLocaleString().toLowerCase().split(/\W/),[,j,k,d]=f.toString().split(" "))=>isNaN(f)?e:`${k}${j}${d}${b?` ${g}${h}${i}`:""}` | |
| const dtString = (dateArg, includeTime, defaultDate, defaultReturnValue, z = new Date(dateArg), [, , , , h, n, , ampm] = (z = +z ? z : new Date(defaultDate)).toLocaleString().toLowerCase().split(/\W/), [, m, d, y] = z.toString().split(" ")) => isNaN(z) ? defaultReturnValue : `${d}${m}${y}${includeTime ? ` |
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>ChatGPT Playground (starting up)</title> | |
| <style> | |
| .byline { | |
| font-family: Verdana; | |
| font-size: 80%; |
| // magic! | |
| function dom<Props extends Record<string, unknown>>( | |
| str: TemplateStringsArray, | |
| ...args: string[] | ((props: Props) => string)[] | |
| ) { | |
| const interleaved = args.flatMap((arg, index) => { | |
| return [arg, str[index + 1]]; | |
| }); | |
| return (props?: Props) => |
| // Date Object CheatSheet | |
| // The Date object is used to work with dates and times. | |
| // More: http://www.w3schools.com/jsref/jsref_obj_date.asp | |
| // 1. Instantiating a Date. | |
| var date = new Date(); | |
| var date = new Date(milliseconds); |