Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 6x 6x 6x 6x 6x 5x 10x 1x 9x 10x 5x | import {ERRORS} from '@grnsft/if-core/utils';
import {ConfigParams} from '@grnsft/if-core/types';
import {STRINGS} from '../../../config';
import {Generator} from '../interfaces';
const {ConfigError} = ERRORS;
const {MISSING_CONFIG} = STRINGS;
export const CommonGenerator = (config: ConfigParams): Generator => {
/**
* Generates next value by copying the validated config.
* Validates the provided config is not null or empty.
* Returns a copy of the validated config, otherwise throws an ConfigError.
*/
const validateConfig = (config: object) => {
if (!config || Object.keys(config).length === 0) {
throw new ConfigError(MISSING_CONFIG);
}
return structuredClone(config);
};
/**
* Generates next value by copying the validated config.
*/
const next = (): Object => validateConfig(config);
return {
next,
};
};
|