Skip to content

Commit

Permalink
fix: Reverted callable module to self-executable (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanMad authored Jul 4, 2021
1 parent dbfbbd7 commit be67540
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Config files
*.config.*
.tsconfig.*

# Git
.gitignore
Expand Down
4 changes: 1 addition & 3 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import onTheCase from './index';

global.String.prototype.toCamelCase = () => 'foo';
global.String.prototype.toKebabCase = () => 'bar';
global.String.prototype.toPascalCase = () => 'baz';
global.String.prototype.toSnakeCase = () => 'qui';
global.String.prototype.toTitleCase = () => 'thud';

onTheCase();
import './index';

describe('On The Case', () => {
it('Respects pre-existing toCamelCase prop on the String object', () => {
Expand Down
24 changes: 10 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@ const funcs: Record<string, () => string> = {
toTitleCase,
};

const onTheCase = (): void => {
Object.keys(funcs).map((func: string) => {
if (func in String.prototype) {
if (process.env.NODE_ENV !== 'test') {
console.error(
`On The Case:\n${func} could not be written to JavaScript\'s String object because a function with this name already exists.`,
);
}
} else {
String.prototype[func] = funcs[func];
Object.keys(funcs).map((func: string) => {
if (func in String.prototype) {
if (process.env.NODE_ENV !== 'test') {
console.error(
`On The Case:\n${func} could not be written to JavaScript\'s String object because a function with this name already exists.`,
);
}
});
};

export { onTheCase as default };
} else {
String.prototype[func] = funcs[func];
}
});

0 comments on commit be67540

Please sign in to comment.