Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { camelCase } from './transformations/camelCase';
import { capitalizeWords } from './transformations/capitalizeWords';

declare global {
interface String {
camelCase(): string; // 👈 match the existing function name
capitalizeWords(): string;
}
}

String.prototype.camelCase = function () {
return camelCase(this.toString());
};
String.prototype.capitalizeWords = function () {
return capitalizeWords(this.toString());
};
export {};
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { formatting } from './formatting';
import { transformations } from './transformations';
import { validations } from './validations';

//importing the extension to ensure String prototype is extended
import './extension';

export default {
analyzing,
formatting,
Expand Down
18 changes: 18 additions & 0 deletions src/tests/extension.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import test from "node:test";
import assert from "node:assert/strict";
import "../extension";

test("should convert to camelCase", () => {
const result = "hello world".camelCase();
assert.equal(result, "helloWorld");
});

test("should capitalize words", () => {
const result = "hello world".capitalizeWords();
assert.equal(result, "Hello World");
});

test("should chain methods (camelCase + capitalizeWords)", () => {
const result = "string example".camelCase().capitalizeWords();
assert.equal(result, "StringExample");
});