-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add function to create a valid config object
- Loading branch information
1 parent
57343c8
commit 141ba00
Showing
4 changed files
with
78 additions
and
0 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,29 @@ | ||
/** @format */ | ||
|
||
import { VayConfig } from '../types'; | ||
|
||
const defaultConfig: VayConfig = { | ||
targetAttribute: 'vay', | ||
targetElement: document.documentElement, | ||
ignoreAttributes: false, | ||
removeAttributesOnRender: false, | ||
quiet: true, | ||
}; | ||
|
||
/** | ||
* @description | ||
* Method used to create a valid Vay configuration object. Mostly used to enable autocomplete in modern IDEs. | ||
* | ||
* @param { Partial<VayConfig> } [props] - optional object containing properties to override the default | ||
* configuration properties of the config object. | ||
* @returns { VayConfig } a valid Vay configuration object. | ||
*/ | ||
|
||
export const defineConfig = (props: Partial<VayConfig> = {}): VayConfig => { | ||
return { | ||
// default configuration properties | ||
...defaultConfig, | ||
// merge user supplied configuration properties | ||
...props, | ||
}; | ||
}; |
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 +1,3 @@ | ||
/** @format */ | ||
|
||
export { defineConfig } from './defineConfig'; |
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,45 @@ | ||
/** @format */ | ||
|
||
/** | ||
* @description | ||
* Object used to configure a Vay instance. | ||
*/ | ||
|
||
export type VayConfig = { | ||
/** | ||
* @type { string } | ||
* @description | ||
* The attribute tag used to mark an element for translation by the static translation method. | ||
* The default tag used is 'vay'. | ||
*/ | ||
targetAttribute: string; | ||
/** | ||
* @type { Element } | ||
* @description | ||
* The targetElement is the element that acts as root for the static translation. All children | ||
* of the element will be checked for translation tags. By default, `document.documentElement` is | ||
* used as root. | ||
*/ | ||
targetElement: Element; | ||
/** | ||
* @type { boolean } | ||
* @description | ||
* A boolean indicating if `vay-*` attribute tags should be ignored. By default, this value is | ||
* `false`. | ||
*/ | ||
ignoreAttributes: boolean; | ||
/** | ||
* @type { boolean } | ||
* @description | ||
* A boolean indicating if all vay-attributes should be removed after translation. By default, | ||
* this value is `false`. | ||
*/ | ||
removeAttributesOnRender: boolean; | ||
/** | ||
* @type { boolean } | ||
* @description | ||
* A boolean indicating if warnings should be suppressed. Is true by default, but can be set to false | ||
* to enable debugging messages in the console. | ||
*/ | ||
quiet: boolean; | ||
}; |
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 +1,3 @@ | ||
/** @format */ | ||
|
||
export type { VayConfig } from './VayConfig'; |