Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helper function for partial names #4

Merged
merged 1 commit into from
Oct 17, 2023
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Transcend Inc.",
"name": "@transcend-io/handlebars-utils",
"description": "Utility functions for handlebars templating with Transcend - available in node and client side.",
"version": "1.0.1",
"version": "1.1.0",
"homepage": "https://github.com/transcend-io/handlebars-utils",
"repository": {
"type": "git",
Expand Down
21 changes: 21 additions & 0 deletions src/createHandlebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@ import { cases } from './change-case';
// TODO: https://transcend.height.app/T-30349 - de-duplicate this with cli and node-util
export { Handlebars };

/**
* Given a file name, return the desirable name for a handlebars extension
* The extension is in camel case without the file suffix, and all slashes
* and spaces get removed
*
* @param fileName - Filename
* @param extension - File extension
* @returns Partial name
*/
export function getPartialNameFromFileName(
fileName: string,
extension = 'hbs',
): string {
return cases.camelCase(
Copy link
Member

@dipack95 dipack95 Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: You could use path.extname(filename) to find the extension and then use it in the function here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

many times the file is like test.js.hbs - and i want it to result in testJs

fileName
.slice(0, fileName.length - `.${extension}`.length)
.split('/')
.pop(),
);
}

/**
* Input for creating a handlebars instance
*/
Expand Down
Loading