Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/purple-shoes-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@everipedia/iq-utils": patch
---

expose wiki helpers
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
22 changes: 1 addition & 21 deletions src/lib/check-wiki-validity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 12 additions & 2 deletions src/lib/wiki-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down