177177177
177177177
DDeno
Created by 177177177 on 3/9/2024 in #help
Make an image cropper that crops from data uri
How to make an image cropper that crops to the given dimensions
6 replies
DDeno
Created by 177177177 on 12/10/2023 in #help
How to override type definitions provided by a third party module
@Deno AI Helper How do I override type definitions provided by a third party module
8 replies
DDeno
Created by 177177177 on 12/7/2023 in #help
Can you make a fresh route detect, if it is being requested by `deno run`
Can you make a fresh route detect, if it is being requested by deno run like deno run https://localhost:3000/api/test doing deno run https://localhost:3000/api/test on the fresh route gives me this error
>> deno run http://localhost:3000/api/test

error: The module's source code could not be parsed: Expected ';', '}' or <eof> at http://localhost:3000/api/test:1:11

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport...
>> deno run http://localhost:3000/api/test

error: The module's source code could not be parsed: Expected ';', '}' or <eof> at http://localhost:3000/api/test:1:11

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport...
8 replies
DDeno
Created by 177177177 on 12/3/2023 in #help
Relative path in WebSocket
Why does relative path in WebSocket not work?
6 replies
DDeno
Created by 177177177 on 12/2/2023 in #help
ReadableStream passed to an island component argument becomes an empty object
I am passing ReadableStream to an island component argument becomes an empty object
16 replies
DDeno
Created by 177177177 on 12/2/2023 in #help
Signal value not updating from inside of `for await of` loop inside of an IIFE
// routes/connect.tsx
import type { FunctionComponent } from 'preact'
import type { PageProps } from '$fresh/server.ts'

const api_version = 10

export default ((props) => {
const message = useSignal('Connecting')

;(async () => {
const wss = new WebSocketStream(`${
(await (
await fetch(`https://discord.com/api/v${api_version}/gateway`)
).json()).url
}/?v=${api_version}&encoding=json`)
const { readable } = await wss.opened

for await (const msg of readable) {
message.value = msg // not updating message.value

console.log(msg) // this works
}
})()

message.value = 'updated outside of the IIFE' // this works too

return (
<div class='max-w-screen-md mx-auto flex flex-col items-center justify-center'>
<div class='flex gap-8 py-6'>
<button>{message}</button>
</div>
</div>
)
}) satisfies <FunctionComponent<PageProps>>
// routes/connect.tsx
import type { FunctionComponent } from 'preact'
import type { PageProps } from '$fresh/server.ts'

const api_version = 10

export default ((props) => {
const message = useSignal('Connecting')

;(async () => {
const wss = new WebSocketStream(`${
(await (
await fetch(`https://discord.com/api/v${api_version}/gateway`)
).json()).url
}/?v=${api_version}&encoding=json`)
const { readable } = await wss.opened

for await (const msg of readable) {
message.value = msg // not updating message.value

console.log(msg) // this works
}
})()

message.value = 'updated outside of the IIFE' // this works too

return (
<div class='max-w-screen-md mx-auto flex flex-col items-center justify-center'>
<div class='flex gap-8 py-6'>
<button>{message}</button>
</div>
</div>
)
}) satisfies <FunctionComponent<PageProps>>
I'm using an IIFE here because otherwise the for await of loop will block the code and page keeps loading till WebSocketStream connection ends, so I did that. But why does setting message.value = msg not update the button text, it is stuck at the initial Connecting text. But when I set message.value = 'updated outside of the IIFE' then it works fine, the value is updating as expected. The console.log(msg) inside the IIFE's for await of loop also works and logs the msg to the console, but still message.value = msg doesn't. Why ??
11 replies
DDeno
Created by 177177177 on 12/1/2023 in #help
How to enable "WebSocketStream" using deno.json file
I want to enable "WebSocketStream" using deno.json's "unstable" array option.
2 replies
DDeno
Created by 177177177 on 11/30/2023 in #help
How to monkey patch an installed third party deno module.
Is it possible to monkey patch an installed third party deno module?? I want to overwrite a function from a third party module that I'm using so the function logic gets updated everywhere.
3 replies
DDeno
Created by 177177177 on 5/18/2023 in #help
Error when using readline.question()
I get this error with the following code
import process from 'node:process'
import readline from 'node:readline'

let intf = readline.createInterface({
input: process.stdin,
output: process.stdout
});

intf.question('Enter name :', name => console.log(name))
import process from 'node:process'
import readline from 'node:readline'

let intf = readline.createInterface({
input: process.stdin,
output: process.stdout
});

intf.question('Enter name :', name => console.log(name))
error: Uncaught ReferenceError: process is not defined
intf.question('Enter name :', name => console.log(name))
^
at Interface.prompt (ext:deno_node/internal/readline/interface.mjs:377:26)
at Interface.[kQuestion] (ext:deno_node/internal/readline/interface.mjs:395:12)
at Interface.question (ext:deno_node/_readline.mjs:144:20)
at file:///C:/my_project_path/main.ts:39:7
at ext:deno_node/_fs/_fs_readFile.ts:29:25
at eventLoopTick (ext:core/01_core.js:181:11)
NativeCommandExitException: Program "deno.exe" ended with non-zero exit code: 1.
error: Uncaught ReferenceError: process is not defined
intf.question('Enter name :', name => console.log(name))
^
at Interface.prompt (ext:deno_node/internal/readline/interface.mjs:377:26)
at Interface.[kQuestion] (ext:deno_node/internal/readline/interface.mjs:395:12)
at Interface.question (ext:deno_node/_readline.mjs:144:20)
at file:///C:/my_project_path/main.ts:39:7
at ext:deno_node/_fs/_fs_readFile.ts:29:25
at eventLoopTick (ext:core/01_core.js:181:11)
NativeCommandExitException: Program "deno.exe" ended with non-zero exit code: 1.
5 replies
DDeno
Created by 177177177 on 1/29/2023 in #help
Deno fmt conflicting with Deno lint, when using IIFE
// before formating
((): void => { /* code */ })()
// before formating
((): void => { /* code */ })()
after formating with deno fmt, it adds an extra semicolon before the IIFE, but deno lint says Unnecessary semicolon. Remove the extra (and unnecessary) semi-colon deno-lint(no-extra-semi)
// after formatting
;((): void => { /* code */ })()
^// deno-lint(no-extra-semi)
// after formatting
;((): void => { /* code */ })()
^// deno-lint(no-extra-semi)
6 replies
DDeno
Created by 177177177 on 11/14/2022 in #help
About performance
if a function takes only one paramater and i pass unnecessary additional parameters would it affect the performance of just the function part of the code?
function echo(sentence) {
console.log(sentence)
}

echo('hello')

echo('hello', 'bye', 'okay')
function echo(sentence) {
console.log(sentence)
}

echo('hello')

echo('hello', 'bye', 'okay')
this is what im caonfused abt i have a object, every value is a function that takes the same parameter payload except only one value that takes an additional second parameter args i want to know which way from these two would perform better
const handler = {
READY: (payload, args) => {},
GUILD_CREATE: (payload) => {},
MESSAGE_CREATE: (payload) => {}.
// ...about 30 more
}


// should i do this
handler[eventName](payload, args)

// or this
if (eventName === 'READY') handler[eventName](payload, args)
else handler[eventName](payload)
const handler = {
READY: (payload, args) => {},
GUILD_CREATE: (payload) => {},
MESSAGE_CREATE: (payload) => {}.
// ...about 30 more
}


// should i do this
handler[eventName](payload, args)

// or this
if (eventName === 'READY') handler[eventName](payload, args)
else handler[eventName](payload)
7 replies
DDeno
Created by 177177177 on 11/13/2022 in #help
How to stop reading from a ReadableStream?
let user

for await (const data of readable) {
if (data.user.id === 'user-id') {
user = data

break
}
}

console.log(user)
let user

for await (const data of readable) {
if (data.user.id === 'user-id') {
user = data

break
}
}

console.log(user)
the break stops the for loop, but it doesnt exit? because it only logs the user after the readable stream is completed. i dont want to wait for the stream to complete/end, i want to get user immidiately after break is called. here readable is ReadableStream
2 replies
DDeno
Created by 177177177 on 11/12/2022 in #help
Deno.inspect, how to log class instances with getters
im trying to log a class instance that has getters in it, with Deno.inspect
Deno.inspect(client, {
colors: true,
getters: true
})
Deno.inspect(client, {
colors: true,
getters: true
})
and it logs [Circular *1], why?
10 replies
DDeno
Created by 177177177 on 10/13/2022 in #help
weird interface
how can a class implement this interface
interface I {
(): void
type: string
}
interface I {
(): void
type: string
}
or a const i accidently did this
const a = () => {}

a.type = 'ok'
const a = () => {}

a.type = 'ok'
and it changed a's type to { (): void; type: string }
2 replies
DDeno
Created by 177177177 on 10/7/2022 in #help
type a whole directory to make sure each file in the directory exports a default module of a type.
Can you type a whole directory to make sure that every file in the directory is exporting a default module of a certain type im making a library, and it reads a directory named commands in the users current working directory, each file in the commands directory should export a default object of type Command currently my library checks if the file is exporting a default module before going further, but i was wondering if typescript could do that since its about exporting the correct type
1 replies
DDeno
Created by 177177177 on 10/6/2022 in #help
extract generic type of generic class
how to get typeof generic type in generic class
class GenericClass<T> {}
class GenericClass<T> {}
i want to extract type T i am using a library, it exports a generic class, but doesnt export the generic type that the generic class takes, and i want to extend the generic class, like this
export class MyGenericClass<T extends GenericClassTypeArgument<GenericClass>> extends GenericClass<T> {}
export class MyGenericClass<T extends GenericClassTypeArgument<GenericClass>> extends GenericClass<T> {}
another example,
class ExtendedClient<T> extends Client<T> {}
class ExtendedClient<T> extends Client<T> {}
i want the generic type of ExtendedClient be the same as the generic type of Client. but i dont have access to generic type of Client, so thats why i want to extract it. so i can do
class ExtendedClient<T extends GenericTypeOf<Client>> extends Client<T> {}
class ExtendedClient<T extends GenericTypeOf<Client>> extends Client<T> {}
4 replies
DDeno
Created by 177177177 on 10/4/2022 in #help
sub sub domain on deno.dev
Is it possible to create a sub sub domain with deno.dev, example, invite.my-bot.deno.dev, support.my-bot.deno.dev, discord.my-bot.deno.dev ?
4 replies
DDeno
Created by 177177177 on 9/22/2022 in #help
i need a regex that matches, from a double quote to a double quote and has two fullstop between it.
i need a regex that matches, from a " to a " and has two . between it for example, "fjhhdjkdj.s28e7d.podk"
4 replies