Make possessive
Returns the possessive form of a given input string. If the input string ends with 's', it appends an apostrophe. Otherwise, it appends an apostrophe followed by 's'.
snippets/typescript/make-possessive.ts
/**
* Returns the possessive form of a given input string.
* If the input string ends with 's', it appends an apostrophe.
* Otherwise, it appends an apostrophe followed by 's'.
*
* @param input - The input string.
* @returns The possessive form of the input string.
*/
export const makePossessive = (input?: string) => {
if (!input) {
return "";
}
if (input.endsWith("s")) {
return `${input}'`;
}
return `${input}'s`;
};
Examples
snippets/typescript/make-possessive.example.ts
import { makePossessive } from "./make-possessive";
makePossessive("Lukas"); // Lukas'
makePossessive("Bobi"); // Bobi's
Tests
snippets/typescript/make-possessive.test.ts
import { describe } from "bun:test";
describe.todo("makePossessive", () => {});