-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): allow creation of static imports from a transform function
Export createDefaultImport and createNamedImport functions to create static imports from within a transform function.
- Loading branch information
Showing
8 changed files
with
280 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@content-collections/core": minor | ||
--- | ||
|
||
Allow creation of static imports from a transform function |
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,28 @@ | ||
const importSymbol = Symbol("import"); | ||
|
||
export type Import<T> = { | ||
[importSymbol]: true; | ||
path: string; | ||
name?: string; | ||
}; | ||
|
||
export type GetTypeOfImport<T> = T extends Import<infer U> ? U : never; | ||
|
||
export function isImport(value: any): value is Import<any> { | ||
return value && value[importSymbol]; | ||
} | ||
|
||
export function createDefaultImport<T>(path: string): Import<T> { | ||
return { | ||
[importSymbol]: true, | ||
path, | ||
}; | ||
} | ||
|
||
export function createNamedImport<T>(name: string, path: string): Import<T> { | ||
return { | ||
[importSymbol]: true, | ||
path, | ||
name, | ||
}; | ||
} |
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
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
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