This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef6b6e0
commit 8cdaaf0
Showing
3 changed files
with
35 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { NodePath } from '@babel/core' | ||
import type { CallExpression, ImportDeclaration } from '@babel/types' | ||
import type RegexString from './regex-string.type' | ||
|
||
/** | ||
* @file Type Definitions - TrextMatch | ||
* @module trext/types/TrextMatch | ||
*/ | ||
|
||
/** | ||
* The matched substring when [replacing a file extension][1], or when used | ||
* within `Trextel`, a custom Babel plugin, a type of {@link NodePath} object: | ||
* | ||
* - `NodePath<CallExpression>`; see {@link CallExpression} | ||
* - `NodePath<ImportDeclaration>`; see {@link ImportDeclaration} | ||
* | ||
* [1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_function_as_a_parameter | ||
*/ | ||
type TrextMatch = RegexString | NodePath<CallExpression | ImportDeclaration> | ||
|
||
export default TrextMatch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,32 @@ | ||
import type { NodePath } from '@babel/core' | ||
import type { CallExpression, ImportDeclaration } from '@babel/types' | ||
import type FileExtension from './file-extension.type' | ||
import type RegexString from './regex-string.type' | ||
import type TrextMatch from './trext-match.type' | ||
|
||
/** | ||
* @file Type Definitions - TrextToFn | ||
* @module trext/types/TrextToFn | ||
*/ | ||
|
||
/** | ||
* [Function that returns a file extension][1]. | ||
* Function that returns a file extension. | ||
* | ||
* When used in `Trext.plugin`, a custom Babel plugin, the only argument passed | ||
* will be one of the following {@link NodePath} types: | ||
* The exact number of arguments passed depends on the context in which the | ||
* function was invoked, and then on if the first argument is a `RegExp` object. | ||
* | ||
* - `NodePath<CallExpression>`; see {@link CallExpression} | ||
* - `NodePath<ImportDeclaration>`; see {@link ImportDeclaration} | ||
* See [Specifying a function as a parameter][1] from MDN documentation for | ||
* arguments passed when using `String.prototype.replace`. | ||
* | ||
* When used within `Trextel`, our custom Babel plugin, the only argument passed | ||
* will be a type of {@link NodePath} object: | ||
* | ||
* - `NodePath<CallExpression>` | ||
* - `NodePath<ImportDeclaration>` | ||
* | ||
* @template T - File extension name(s) | ||
* | ||
* [1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_function_as_a_parameter | ||
*/ | ||
type TrextToFn<T extends string = string> = { | ||
( | ||
match: RegexString | NodePath<CallExpression | ImportDeclaration>, | ||
...args: any[] | ||
): FileExtension<T> | ||
(match: TrextMatch, ...args: any[]): FileExtension<T> | ||
} | ||
|
||
export default TrextToFn |