Skip to content

Commit

Permalink
feat: add function to create a valid config object
Browse files Browse the repository at this point in the history
  • Loading branch information
IamSebastianDev committed Apr 15, 2023
1 parent 57343c8 commit 141ba00
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/lib/defineConfig.ts
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,
};
};
2 changes: 2 additions & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/** @format */

export { defineConfig } from './defineConfig';
45 changes: 45 additions & 0 deletions src/types/VayConfig.d.ts
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;
};
2 changes: 2 additions & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/** @format */

export type { VayConfig } from './VayConfig';

0 comments on commit 141ba00

Please sign in to comment.