feat: create isNumberFrom1To100 function

This commit is contained in:
P. Reis 2024-07-19 13:19:04 -03:00
parent 8c19c5ba09
commit dcec2ecdd0

View file

@ -1,6 +1,6 @@
import { NostrEvent, NSchema as n } from '@nostrify/nostrify'; import { NostrEvent, NSchema as n } from '@nostrify/nostrify';
import { nip19 } from 'nostr-tools'; import { nip19 } from 'nostr-tools';
import { z } from 'zod'; import { boolean, z } from 'zod';
/** Get the current time in Nostr format. */ /** Get the current time in Nostr format. */
const nostrNow = (): number => Math.floor(Date.now() / 1000); const nostrNow = (): number => Math.floor(Date.now() / 1000);
@ -93,12 +93,17 @@ function isURL(value: unknown): boolean {
return z.string().url().safeParse(value).success; return z.string().url().safeParse(value).success;
} }
function isNumberFrom1To100(value: unknown): boolean {
return z.coerce.number().int().gte(1).lte(100).safeParse(value).success;
}
export { export {
bech32ToPubkey, bech32ToPubkey,
dedupeEvents, dedupeEvents,
eventAge, eventAge,
findTag, findTag,
isNostrId, isNostrId,
isNumberFrom1To100,
isURL, isURL,
type Nip05, type Nip05,
nostrDate, nostrDate,