Skip to content

Commit 7e43c9c

Browse files
lower path param
1 parent f74289a commit 7e43c9c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/utils/util.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,48 @@ export const createJsVarName = (fileName: string): string => {
4141
return fileName;
4242
};
4343

44+
/**
45+
* Create a function that lowercases the first string parameter before passing it to the provided function
46+
* @param fn the function to pass the lowercased path to
47+
* @returns the result of the provided function
48+
*/
49+
const lowerPathParam = (fn: ((p: string) => boolean)) => (p: string) => fn(p.toLowerCase());
50+
4451
/**
4552
* Determine if a stringified file path is a TypeScript declaration file based on the extension at the end of the path.
4653
* @param p the path to evaluate
4754
* @returns `true` if the path ends in `.d.ts` (case-sensitive), `false` otherwise.
4855
*/
49-
export const isDtsFile = (p: string) => p.endsWith('.d.ts') || p.endsWith('.d.mts') || p.endsWith('.d.cts');
56+
export const isDtsFile = lowerPathParam((p) => p.endsWith('.d.ts') || p.endsWith('.d.mts') || p.endsWith('.d.cts'));
5057

5158
/**
5259
* Determine if a stringified file path is a TypeScript file based on the extension at the end of the path. This
5360
* function does _not_ consider type declaration files (`.d.ts` files) to be TypeScript files.
5461
* @param p the path to evaluate
5562
* @returns `true` if the path ends in `.ts` (case-sensitive) but does _not_ end in `.d.ts`, `false` otherwise.
5663
*/
57-
export const isTsFile = (p: string) => !isDtsFile(p) && (p.endsWith('.ts') || p.endsWith('.mts') || p.endsWith('.cts'));
64+
export const isTsFile = lowerPathParam((p: string) => !isDtsFile(p) && (p.endsWith('.ts') || p.endsWith('.mts') || p.endsWith('.cts')));
5865

5966
/**
6067
* Determine if a stringified file path is a TSX file based on the extension at the end of the path
6168
* @param p the path to evaluate
6269
* @returns `true` if the path ends in `.tsx` (case-sensitive), `false` otherwise.
6370
*/
64-
export const isTsxFile = (p: string) => p.endsWith('.tsx') || p.endsWith('.mtsx') || p.endsWith('.ctsx');
71+
export const isTsxFile = lowerPathParam((p: string) => p.endsWith('.tsx') || p.endsWith('.mtsx') || p.endsWith('.ctsx'));
6572

6673
/**
6774
* Determine if a stringified file path is a JSX file based on the extension at the end of the path
6875
* @param p the path to evaluate
6976
* @returns `true` if the path ends in `.jsx` (case-sensitive), `false` otherwise.
7077
*/
71-
export const isJsxFile = (p: string) => p.endsWith('.jsx') || p.endsWith('.mjsx') || p.endsWith('.cjsx');
78+
export const isJsxFile = lowerPathParam((p: string) => p.endsWith('.jsx') || p.endsWith('.mjsx') || p.endsWith('.cjsx'));
7279

7380
/**
7481
* Determine if a stringified file path is a JavaScript file based on the extension at the end of the path
7582
* @param p the path to evaluate
7683
* @returns `true` if the path ends in `.js` (case-sensitive), `false` otherwise.
7784
*/
78-
export const isJsFile = (p: string) => p.endsWith('.js') || p.endsWith('.mjs') || p.endsWith('.cjs');
85+
export const isJsFile = lowerPathParam((p: string) => p.endsWith('.js') || p.endsWith('.mjs') || p.endsWith('.cjs'));
7986

8087
/**
8188
* Generate the preamble to be placed atop the main file of the build

0 commit comments

Comments
 (0)