From 954adfd1e80ab2852ceb4eac363d9d83ccd60bb3 Mon Sep 17 00:00:00 2001 From: michaelfarrell76 Date: Tue, 17 Oct 2023 14:04:19 -0700 Subject: [PATCH] Helper function for partial names --- package.json | 2 +- src/createHandlebars.ts | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 24e358b..eb88545 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/createHandlebars.ts b/src/createHandlebars.ts index 0410d70..96ff1a5 100644 --- a/src/createHandlebars.ts +++ b/src/createHandlebars.ts @@ -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( + fileName + .slice(0, fileName.length - `.${extension}`.length) + .split('/') + .pop(), + ); +} + /** * Input for creating a handlebars instance */