diff options
| author | ST-DDT <[email protected]> | 2023-11-14 17:11:26 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-11-14 16:11:26 +0000 |
| commit | 7e3c92e802614ae5e9f621d9e679dfd6f6d63cf1 (patch) | |
| tree | bb6813a857c0c42ba1049be5035fce7f45b99c46 /src/modules/color | |
| parent | 36fc517d17591c8ea1d5135d9a93c7591e3d1f74 (diff) | |
| download | faker-7e3c92e802614ae5e9f621d9e679dfd6f6d63cf1.tar.xz faker-7e3c92e802614ae5e9f621d9e679dfd6f6d63cf1.zip | |
infra: enable strictNullChecks in tsconfig (#2435)
Diffstat (limited to 'src/modules/color')
| -rw-r--r-- | src/modules/color/index.ts | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/src/modules/color/index.ts b/src/modules/color/index.ts index 5962ef71..57b906a3 100644 --- a/src/modules/color/index.ts +++ b/src/modules/color/index.ts @@ -47,17 +47,19 @@ export type Casing = 'lower' | 'upper' | 'mixed'; * * @param hexColor Hex color string to be formatted. * @param options Options object. - * @param options.prefix Prefix of the generated hex color. Defaults to `'0x'`. - * @param options.casing Letter type case of the generated hex color. Defaults to `'mixed'`. + * @param options.prefix Prefix of the generated hex color. + * @param options.casing Letter type case of the generated hex color. */ function formatHexColor( hexColor: string, - options?: { - prefix?: string; - casing?: Casing; + options: { + prefix: string; + casing: Casing; } ): string { - switch (options?.casing) { + const { prefix, casing } = options; + + switch (casing) { case 'upper': hexColor = hexColor.toUpperCase(); break; @@ -68,8 +70,8 @@ function formatHexColor( // Do nothing } - if (options?.prefix) { - hexColor = options.prefix + hexColor; + if (prefix) { + hexColor = prefix + hexColor; } return hexColor; @@ -360,19 +362,20 @@ export class ColorModule extends ModuleBase { */ includeAlpha?: boolean; }): string | number[]; - rgb(options?: { - prefix?: string; - casing?: Casing; - format?: 'hex' | ColorFormat; - includeAlpha?: boolean; - }): string | number[] { + rgb( + options: { + prefix?: string; + casing?: Casing; + format?: 'hex' | ColorFormat; + includeAlpha?: boolean; + } = {} + ): string | number[] { const { format = 'hex', includeAlpha = false, prefix = '#', casing = 'lower', - } = options || {}; - options = { format, includeAlpha, prefix, casing }; + } = options; let color: string | number[]; let cssFunction: CssFunctionType = 'rgb'; if (format === 'hex') { @@ -380,7 +383,7 @@ export class ColorModule extends ModuleBase { length: includeAlpha ? 8 : 6, prefix: '', }); - color = formatHexColor(color, options); + color = formatHexColor(color, { prefix, casing }); return color; } |
