-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script types and a simple type guard (#27)
- Loading branch information
1 parent
ef38c23
commit 04e7407
Showing
7 changed files
with
73 additions
and
42 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
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,37 +1,2 @@ | ||
type ScriptStrategy = 'server' | 'client' | 'idle' | 'worker'; | ||
type ScriptLocation = 'head' | 'body'; | ||
type ScriptAction = 'append' | 'prepend'; | ||
export type SrcVal = { | ||
url: string; | ||
slugParam?: string; | ||
params?: Array<string>; | ||
}; | ||
|
||
export type AttributeVal = string | null | SrcVal | boolean | undefined; | ||
|
||
export type HtmlAttributes = { | ||
src?: SrcVal; | ||
[key: string]: AttributeVal; | ||
}; | ||
|
||
export interface Data { | ||
id: string; | ||
description: string; | ||
website?: string; | ||
html?: { | ||
element: string; | ||
attributes: HtmlAttributes; | ||
}; | ||
stylesheets?: Array<string>; | ||
scripts?: Array<{ | ||
url: string; | ||
params?: Array<string>; | ||
strategy: ScriptStrategy; | ||
location: ScriptLocation; | ||
action: ScriptAction; | ||
}>; | ||
} | ||
|
||
export interface Inputs { | ||
[key: string]: any; | ||
} | ||
export * from './type-declarations'; | ||
export * from './type-guards'; |
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,49 @@ | ||
type ScriptStrategy = 'server' | 'client' | 'idle' | 'worker'; | ||
type ScriptLocation = 'head' | 'body'; | ||
type ScriptAction = 'append' | 'prepend'; | ||
export type SrcVal = { | ||
url: string; | ||
slugParam?: string; | ||
params?: Array<string>; | ||
}; | ||
|
||
export type AttributeVal = string | null | SrcVal | boolean | undefined; | ||
|
||
export type HtmlAttributes = { | ||
src?: SrcVal; | ||
[key: string]: AttributeVal; | ||
}; | ||
|
||
type ScriptBase = { | ||
params?: Array<string>; | ||
strategy: ScriptStrategy; | ||
location: ScriptLocation; | ||
action: ScriptAction; | ||
}; | ||
|
||
export type ExternalScript = ScriptBase & { | ||
url: string; | ||
}; | ||
|
||
export type CodeBlock = ScriptBase & { | ||
code: string; | ||
}; | ||
|
||
export type Script = ExternalScript | CodeBlock; | ||
export type Scripts = Script[]; | ||
|
||
export interface Data { | ||
id: string; | ||
description: string; | ||
website?: string; | ||
html?: { | ||
element: string; | ||
attributes: HtmlAttributes; | ||
}; | ||
stylesheets?: Array<string>; | ||
scripts?: Scripts; | ||
} | ||
|
||
export interface Inputs { | ||
[key: string]: any; | ||
} |
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 @@ | ||
import { Script, ExternalScript } from '.'; | ||
|
||
export function isExternalScript(script: Script): script is ExternalScript { | ||
return (script as ExternalScript).url !== undefined; | ||
} |
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