From c346568b4bedea25c4b89c51ff6ee024a176089d Mon Sep 17 00:00:00 2001 From: yomzy2223 Date: Tue, 13 May 2025 15:07:44 +0100 Subject: [PATCH 1/2] export wiki helpers --- src/index.ts | 1 + src/lib/check-wiki-validity.ts | 22 +--------------------- src/lib/wiki-helpers.ts | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/index.ts b/src/index.ts index 0756a9a..c0f72cb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,3 +4,4 @@ export * from "./lib/check-wiki-validity"; export * from "./lib/twitter-api-client"; export * from "./data/constants"; export * from "./schema"; +export * from "./lib/wiki-helpers"; diff --git a/src/lib/check-wiki-validity.ts b/src/lib/check-wiki-validity.ts index d0048dc..417eae8 100644 --- a/src/lib/check-wiki-validity.ts +++ b/src/lib/check-wiki-validity.ts @@ -9,27 +9,7 @@ import { WHITELISTED_LINK_NAMES, } from "../data/constants"; import { CommonMetaIds, MediaSource, MediaType, type Wiki } from "../schema"; - -/** - * Counts the number of words in a given string. - * @param text - The input string to count words from. - * @returns The number of words in the string. - */ -export const countWords = (text: string) => - text.split(" ").filter((word) => word !== "").length; - -/** - * Checks if a given string is a valid URL. - * @param urlString - The string to check. - * @returns True if the string is a valid URL, false otherwise. - */ -export const isValidUrl = (urlString: string) => { - try { - return Boolean(new URL(urlString)); - } catch (_e) { - return false; - } -}; +import { countWords, isValidUrl } from "./wiki-helpers"; /** * Checks if all content links in the given text are verified. diff --git a/src/lib/wiki-helpers.ts b/src/lib/wiki-helpers.ts index 769fd65..38fa70a 100644 --- a/src/lib/wiki-helpers.ts +++ b/src/lib/wiki-helpers.ts @@ -22,17 +22,27 @@ import { // Text and content helpers // =============================== +/** + * Counts the number of words in a given string. + * @param text - The input string to count words from. + * @returns The number of words in the string. + */ export function countWords(text: string): number { return text.split(" ").filter((word) => word !== "").length; } -export function isValidUrl(urlString: string): boolean { +/** + * Checks if a given string is a valid URL. + * @param urlString - The string to check. + * @returns True if the string is a valid URL, false otherwise. + */ +export const isValidUrl = (urlString: string) => { try { return Boolean(new URL(urlString)); } catch (_e) { return false; } -} +}; export function containsOnlyVerifiedLinks(content: string): boolean { const markdownLinks = content.match(/\[(.*?)\]\((.*?)\)/g); From e74fc70a6223372163daddc0fedb7b96e971b205 Mon Sep 17 00:00:00 2001 From: yomzy2223 Date: Tue, 13 May 2025 15:29:02 +0100 Subject: [PATCH 2/2] add changeset --- .changeset/purple-shoes-teach.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/purple-shoes-teach.md diff --git a/.changeset/purple-shoes-teach.md b/.changeset/purple-shoes-teach.md new file mode 100644 index 0000000..e59cc6a --- /dev/null +++ b/.changeset/purple-shoes-teach.md @@ -0,0 +1,5 @@ +--- +"@everipedia/iq-utils": patch +--- + +expose wiki helpers