Skip to content

Commit fba6603

Browse files
author
Al Manning
committed
improve cap first letter
1 parent af32b45 commit fba6603

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/publish/confluence/confluence-helper.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ export const FILE_FINDER: RegExp = /(?<=href=\')(.*)(?=\.qmd)/;
3434
const IMAGE_FINDER: RegExp =
3535
/(?<=ri:attachment ri:filename=["\'])[^"\']+?\.(?:jpe?g|png|gif|m4a|mp3|txt)(?=["\'])/g;
3636

37-
const capitalizeFirstLetter = (value: string): string => {
37+
export const capitalizeFirstLetter = (value: string = ""): string => {
38+
if (!value || value.length === 0) {
39+
return "";
40+
}
3841
return value[0].toUpperCase() + value.slice(1);
3942
};
4043

tests/unit/confluence.test.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
buildFileToMetaTable,
1212
buildPublishRecordForContent,
1313
buildSpaceChanges,
14+
capitalizeFirstLetter,
1415
confluenceParentFromString,
1516
FILE_FINDER,
1617
filterFilesForUpdate,
@@ -58,7 +59,7 @@ import {
5859
Space,
5960
} from "../../src/publish/confluence/api/types.ts";
6061

61-
const RUN_ALL_TESTS = true;
62+
const RUN_ALL_TESTS = false;
6263
const FOCUS_TEST = false;
6364

6465
const xtest = (
@@ -3211,6 +3212,25 @@ const runUpdateImagePathsForContentBody = () => {
32113212
});
32123213
};
32133214

3215+
const runCapFirstLetter = () => {
3216+
const suiteLabel = (label: string) => `CapFirstLetter_${label}`;
3217+
test(suiteLabel("basic"), async () => {
3218+
assertEquals("A", capitalizeFirstLetter("a"));
3219+
});
3220+
3221+
test(suiteLabel("basic_space"), async () => {
3222+
assertEquals("A b", capitalizeFirstLetter("a b"));
3223+
});
3224+
3225+
test(suiteLabel("empty"), async () => {
3226+
assertEquals("", capitalizeFirstLetter(""));
3227+
});
3228+
3229+
test(suiteLabel("empty2"), async () => {
3230+
assertEquals("", capitalizeFirstLetter());
3231+
});
3232+
};
3233+
32143234
if (RUN_ALL_TESTS) {
32153235
runGeneralTests();
32163236
runFilterFilesForUpdate();
@@ -3229,6 +3249,7 @@ if (RUN_ALL_TESTS) {
32293249
runFindAttachments();
32303250
runGetAttachmentsDirectory();
32313251
runUpdateImagePathsForContentBody();
3252+
runCapFirstLetter();
32323253
} else {
3233-
runGetAttachmentsDirectory();
3254+
runCapFirstLetter();
32343255
}

0 commit comments

Comments
 (0)