core/normalizers/readme.normalizer.ts
core/normalizers/readme.normalizer.ts is a file in Bane's Lab Content. 28 lines of code and 7 definitions.
import {
ANCHOR_MARK,
ANCHOR_SPACE,
LETTERS_AND_DIGITS,
REPOSITORY_PAGES,
SENTENCE_STOP,
SPACE,
} from "#configuration/constants/readme.constants";
import { METHODOLOGY_PAGE } from "@banes-lab/web/core/ids/page.ids.ts";
import { WORD_SEPARATOR } from "#configuration/constants/chapter.constants";
export const isRepositoryPage = function isRepositoryPage(page: string): boolean {
return REPOSITORY_PAGES.includes(page);
};
export const pageFolderOf = function pageFolderOf(page: string, label: string): string {
return page === METHODOLOGY_PAGE ? "" : label.toLowerCase().split(SPACE).join(WORD_SEPARATOR);
};
export const anchorOf = function anchorOf(title: string): string {
let out = "";
for (const char of title.toLowerCase()) {
const kept = LETTERS_AND_DIGITS.includes(char) || char === ANCHOR_SPACE;
out += kept ? char : (char === SPACE ? ANCHOR_SPACE : "");
}
return ANCHOR_MARK + out;
};
export const firstSentenceOf = function firstSentenceOf(text: string): string {
const stop = text.indexOf(SENTENCE_STOP);
return stop === -1 ? text : text.slice(0, stop + SENTENCE_STOP.trimEnd().length);
};