Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
feat(typescript): FileExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
unicornware committed Oct 9, 2021
1 parent 189490e commit 98f8e5b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/interfaces/trext-options.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { TransformOptions } from '@babel/core'
import type { FileExtension } from '@trext/types'

/**
* @file Interfaces - TrextOptions
Expand All @@ -7,12 +8,15 @@ import type { TransformOptions } from '@babel/core'

/**
* Options to configure file extension and import statement transformations.
*
* @template F - Old file extension name(s)
* @template T - New file extension name(s)
*/
interface TrextOptions {
interface TrextOptions<F extends string = string, T extends string = string> {
/**
* File extension to transform.
*/
from: string
from: F

/**
* File extension search pattern.
Expand All @@ -31,12 +35,12 @@ interface TrextOptions {
/**
* New file extension or [function that returns new file extension][1].
*
* If the value is a string and doesn't start with a period (`.`), one will be
* prepended to coerce the value into a valid file extension.
* If the value is a string, a period (`.`) will be prepended to coerce the
* value into a valid file extension.
*
* [1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_function_as_a_parameter
*/
to: string | ((match: string, ...args: any[]) => string)
to: FileExtension<T> | ((match: string, ...args: any[]) => FileExtension<T>)
}

export default TrextOptions
13 changes: 13 additions & 0 deletions src/types/file-extension.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @file Type Definitions - FileExtension
* @module trext/types/FileExtension
*/

/**
* String representing a file extension.
*
* @template T - File extension name(s)
*/
type FileExtension<T extends string = string> = `.${T}`

export default FileExtension
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
* @module trext/types
*/

export type { default as FileExtension } from './file-extension.type'
export type { default as TrextDefaults } from './trext-defaults.type'

0 comments on commit 98f8e5b

Please sign in to comment.