Skip to content

Commit 9ed1e8d

Browse files
Helper function for partial names (#4)
1 parent ea7b701 commit 9ed1e8d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "Transcend Inc.",
33
"name": "@transcend-io/handlebars-utils",
44
"description": "Utility functions for handlebars templating with Transcend - available in node and client side.",
5-
"version": "1.0.1",
5+
"version": "1.1.0",
66
"homepage": "https://github.com/transcend-io/handlebars-utils",
77
"repository": {
88
"type": "git",

src/createHandlebars.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ import { cases } from './change-case';
77
// TODO: https://transcend.height.app/T-30349 - de-duplicate this with cli and node-util
88
export { Handlebars };
99

10+
/**
11+
* Given a file name, return the desirable name for a handlebars extension
12+
* The extension is in camel case without the file suffix, and all slashes
13+
* and spaces get removed
14+
*
15+
* @param fileName - Filename
16+
* @param extension - File extension
17+
* @returns Partial name
18+
*/
19+
export function getPartialNameFromFileName(
20+
fileName: string,
21+
extension = 'hbs',
22+
): string {
23+
return cases.camelCase(
24+
fileName
25+
.slice(0, fileName.length - `.${extension}`.length)
26+
.split('/')
27+
.pop(),
28+
);
29+
}
30+
1031
/**
1132
* Input for creating a handlebars instance
1233
*/

0 commit comments

Comments
 (0)