Skip to content

Commit c346568

Browse files
committed
export wiki helpers
1 parent 8862cfc commit c346568

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from "./lib/check-wiki-validity";
44
export * from "./lib/twitter-api-client";
55
export * from "./data/constants";
66
export * from "./schema";
7+
export * from "./lib/wiki-helpers";

src/lib/check-wiki-validity.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,7 @@ import {
99
WHITELISTED_LINK_NAMES,
1010
} from "../data/constants";
1111
import { CommonMetaIds, MediaSource, MediaType, type Wiki } from "../schema";
12-
13-
/**
14-
* Counts the number of words in a given string.
15-
* @param text - The input string to count words from.
16-
* @returns The number of words in the string.
17-
*/
18-
export const countWords = (text: string) =>
19-
text.split(" ").filter((word) => word !== "").length;
20-
21-
/**
22-
* Checks if a given string is a valid URL.
23-
* @param urlString - The string to check.
24-
* @returns True if the string is a valid URL, false otherwise.
25-
*/
26-
export const isValidUrl = (urlString: string) => {
27-
try {
28-
return Boolean(new URL(urlString));
29-
} catch (_e) {
30-
return false;
31-
}
32-
};
12+
import { countWords, isValidUrl } from "./wiki-helpers";
3313

3414
/**
3515
* Checks if all content links in the given text are verified.

src/lib/wiki-helpers.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,27 @@ import {
2222
// Text and content helpers
2323
// ===============================
2424

25+
/**
26+
* Counts the number of words in a given string.
27+
* @param text - The input string to count words from.
28+
* @returns The number of words in the string.
29+
*/
2530
export function countWords(text: string): number {
2631
return text.split(" ").filter((word) => word !== "").length;
2732
}
2833

29-
export function isValidUrl(urlString: string): boolean {
34+
/**
35+
* Checks if a given string is a valid URL.
36+
* @param urlString - The string to check.
37+
* @returns True if the string is a valid URL, false otherwise.
38+
*/
39+
export const isValidUrl = (urlString: string) => {
3040
try {
3141
return Boolean(new URL(urlString));
3242
} catch (_e) {
3343
return false;
3444
}
35-
}
45+
};
3646

3747
export function containsOnlyVerifiedLinks(content: string): boolean {
3848
const markdownLinks = content.match(/\[(.*?)\]\((.*?)\)/g);

0 commit comments

Comments
 (0)