Prevent cyclical import of Time module
This commit is contained in:
parent
028ff27c49
commit
4e68e3868f
|
@ -1,5 +1,5 @@
|
||||||
import { TTLCache, z } from '@/deps.ts';
|
import { TTLCache, z } from '@/deps.ts';
|
||||||
import { Time } from '@/utils.ts';
|
import { Time } from '@/utils/time.ts';
|
||||||
|
|
||||||
const nip05Cache = new TTLCache<string, Promise<string | null>>({ ttl: Time.hours(1), max: 5000 });
|
const nip05Cache = new TTLCache<string, Promise<string | null>>({ ttl: Time.hours(1), max: 5000 });
|
||||||
|
|
||||||
|
|
14
src/utils.ts
14
src/utils.ts
|
@ -106,17 +106,6 @@ function eventAge(event: Event): number {
|
||||||
return new Date().getTime() - nostrDate(event.created_at).getTime();
|
return new Date().getTime() - nostrDate(event.created_at).getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
const Time = {
|
|
||||||
milliseconds: (ms: number) => ms,
|
|
||||||
seconds: (s: number) => s * 1000,
|
|
||||||
minutes: (m: number) => m * Time.seconds(60),
|
|
||||||
hours: (h: number) => h * Time.minutes(60),
|
|
||||||
days: (d: number) => d * Time.hours(24),
|
|
||||||
weeks: (w: number) => w * Time.days(7),
|
|
||||||
months: (m: number) => m * Time.days(30),
|
|
||||||
years: (y: number) => y * Time.days(365),
|
|
||||||
};
|
|
||||||
|
|
||||||
function findTag(tags: string[][], name: string): string[] | undefined {
|
function findTag(tags: string[][], name: string): string[] | undefined {
|
||||||
return tags.find((tag) => tag[0] === name);
|
return tags.find((tag) => tag[0] === name);
|
||||||
}
|
}
|
||||||
|
@ -150,5 +139,6 @@ export {
|
||||||
parseBody,
|
parseBody,
|
||||||
parseNip05,
|
parseNip05,
|
||||||
sha256,
|
sha256,
|
||||||
Time,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export { Time } from './utils/time.ts';
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
const Time = {
|
||||||
|
milliseconds: (ms: number) => ms,
|
||||||
|
seconds: (s: number) => s * 1000,
|
||||||
|
minutes: (m: number) => m * Time.seconds(60),
|
||||||
|
hours: (h: number) => h * Time.minutes(60),
|
||||||
|
days: (d: number) => d * Time.hours(24),
|
||||||
|
weeks: (w: number) => w * Time.days(7),
|
||||||
|
months: (m: number) => m * Time.days(30),
|
||||||
|
years: (y: number) => y * Time.days(365),
|
||||||
|
};
|
||||||
|
|
||||||
|
export { Time };
|
Loading…
Reference in New Issue