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 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);