Skip to content

Commit

Permalink
feat: add case helper
Browse files Browse the repository at this point in the history
  • Loading branch information
nishantwrp committed Nov 2, 2023
1 parent 9e56eb7 commit 72a3f39
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/helpers/case.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { HandlebarsHelper, HelperConstructorBlock } from "./helper";

export const caseHelper: HelperConstructorBlock = ctx => {

Check warning on line 3 in src/helpers/case.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

'ctx' is defined but never used
return new HandlebarsHelper("case", (type, rawV1): string => {
const v1 = new String(rawV1);

switch (type) {
case "upper":
return v1.toUpperCase();
case "lower":
return v1.toLowerCase();
default:
throw new Error(`Invalid case type used with case: ${type}`);
}
});
};
2 changes: 2 additions & 0 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { mathHelper } from "./math";
import { conditionHelper } from "./condition";
import { repeatHelper } from "./repeat";
import { advancedDatetimeHelper } from "./advanced_datetime";
import { caseHelper } from "./case";

export class HelperFactory {
private static helpers: HelperConstructorBlock[] = [
Expand All @@ -17,6 +18,7 @@ export class HelperFactory {
conditionHelper,
repeatHelper,
advancedDatetimeHelper,
caseHelper,
];

static registerHelpers(dateAndTimeUtils: DateAndTimeUtils): void {
Expand Down

0 comments on commit 72a3f39

Please sign in to comment.