UNPKG

@stryke/prisma-trpc-generator

Version:

A fork of the prisma-trpc-generator code to work in ESM with Prisma v6.

34 lines (32 loc) 1.41 kB
import { ACRONYMS } from "./acronyms.mjs"; import { ARTICLES } from "./articles.mjs"; import { CONJUNCTIONS } from "./conjunctions.mjs"; import { PREPOSITIONS } from "./prepositions.mjs"; import { SPECIAL_CASES } from "./special-cases.mjs"; //#region ../string-format/src/format-special-cases.ts /** * Handle special words in a title. * * @see https://apastyle.apa.org/style-grammar-guidelines/capitalization/title-case * * @param value - The word to handle * @param index - The index of the word in the title * @param words - The full title as an array of words * @returns The formatted word */ function formatSpecialCases(value, index, words, options) { const lowercaseStr = value.toLowerCase(); const uppercaseStr = value.toUpperCase(); for (const special of SPECIAL_CASES) if (special.toLowerCase() === lowercaseStr) return special; if (ACRONYMS[uppercaseStr]) return options?.useDescriptions !== false ? ACRONYMS[uppercaseStr].description : ACRONYMS[uppercaseStr].display || uppercaseStr; if (index === 0) return value; if (index === words.length - 1) return value; if (value.length >= 4) return value; if (PREPOSITIONS.includes(lowercaseStr)) return lowercaseStr; if (CONJUNCTIONS.includes(lowercaseStr)) return lowercaseStr; if (ARTICLES.includes(lowercaseStr)) return lowercaseStr; return value; } //#endregion export { formatSpecialCases }; //# sourceMappingURL=format-special-cases.mjs.map