how do I add something to the deps.ts file that isn't in curly braces?

I have
import formatRelative from "https://deno.land/x/date_fns@v2.22.1/formatRelative/index.ts";
import formatRelative from "https://deno.land/x/date_fns@v2.22.1/formatRelative/index.ts";
directly in source file and it works properly. I'd like to move it to my deps.ts file but I can't figure out how to do it.
22 Replies
dan.the.discloser
This works for me:
import formatRelative from "https://deno.land/x/date_fns@v2.22.1/formatRelative/index.ts";

export { formatRelative };
import formatRelative from "https://deno.land/x/date_fns@v2.22.1/formatRelative/index.ts";

export { formatRelative };
Is there a better way to do this?
javi
javi3y ago
You can do something like:
// deps.ts
export { default as formatRelative } from "https://deno.land/x/date_fns@v2.22.1/formatRelative/index.ts"

// main.ts
import { formRelative } from "./deps.ts" // default import, you can change the name
// deps.ts
export { default as formatRelative } from "https://deno.land/x/date_fns@v2.22.1/formatRelative/index.ts"

// main.ts
import { formRelative } from "./deps.ts" // default import, you can change the name
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
javi
javi3y ago
In the repl it returns
Module { default: [Function <name>] }
Module { default: [Function <name>] }
Since it’s a default export I think you don’t need it, but I’m not sure I’ll check
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
javi
javi3y ago
Yup you’re right, since we are getting the default and exporting it under a named export, so we need the braces in the main file 👍🏻
dan.the.discloser
how will it work differently than expected?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
dan.the.discloser
This is what I am running and seems to be giving me correct answers. deps.ts
import formatRelative from "https://deno.land/x/date_fns@v2.22.1/formatRelative/index.ts";

export { formatRelative };
import formatRelative from "https://deno.land/x/date_fns@v2.22.1/formatRelative/index.ts";

export { formatRelative };
my_display_in_html.ts
import { formatRelative } from "./port.ts";

...

function htmlize(o: Original): string {
const tim =
// o._id.getTimestamp().toDateString()
formatRelative(o._id.getTimestamp(), new Date());
return `<h3>${tim}</h3>
<div>${o.raw.replaceAll("\n", "<br/>")}</div>`;
}
import { formatRelative } from "./port.ts";

...

function htmlize(o: Original): string {
const tim =
// o._id.getTimestamp().toDateString()
formatRelative(o._id.getTimestamp(), new Date());
return `<h3>${tim}</h3>
<div>${o.raw.replaceAll("\n", "<br/>")}</div>`;
}
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
dan.the.discloser
You are right deps.ts
export { default as formatRelative } from "https://deno.land/x/date_fns@v2.22.1/formatRelative/index.ts";
export { default as formatRelative } from "https://deno.land/x/date_fns@v2.22.1/formatRelative/index.ts";
also works
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
dan.the.discloser
Thank you Is there some version of this that will work with my FindCursor problem? I want to get the FindCursor type from the mongo package and I don't see how to do it
javi
javi3y ago
If you’re using mongodb my personal recommendation is to ditch the packages and to use the mongodb atlas data api. It’s extremely easy and you can use native fetch
dan.the.discloser
thank you. is that one of these https://deno.land/x/atlas_sdk@v1.0.3 https://deno.land/x/atlas_sdk3@v0.3.1 which should I be using? ?? will they work with local installations of mongodb ??
javi
javi3y ago
My bad, you didn’t specify that you had a local installation so I assumed you were using atlas. You’ll need the package you were using for the local installation
dan.the.discloser
If I stick to Altas, which of those two packages would I want to use? I don't understand the version numbering?
javi
javi3y ago
It goes from left to right. In this case 1.0.3 is newer than 0.3.1, so use the newer one
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
javi
javi3y ago
Oh lol I didn’t see the 3, just get the one that suits you the most
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
dan.the.discloser
thank you