-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create createAppOptions function and separate the code to utils.ts file
- Loading branch information
1 parent
7bcd3ca
commit c70f6eb
Showing
2 changed files
with
35 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Color from "color" | ||
import { OptionsType, AppOptionsType } from "./types" | ||
|
||
const defaultOptions = { | ||
fontSize: 30, | ||
color: "rgba(255, 255, 255, 1)", | ||
bgColor: "rgba(0, 0, 0, 1)", | ||
wordCounts: { min: 5, max: 20 }, | ||
rainSpeed: { min: 1, max: 3 }, | ||
switchInterval: { min: 500, max: 1500 }, | ||
} | ||
|
||
export function createAppOptions(options: OptionsType): AppOptionsType { | ||
return { | ||
fontSize: options.fontSize || defaultOptions.fontSize, | ||
color: new Color(options.color || defaultOptions.color).rgb().string(), | ||
bgColor: new Color(options.bgColor || defaultOptions.bgColor) | ||
.rgb() | ||
.string(), | ||
bgFade: new Color(options.bgColor || defaultOptions.bgColor) | ||
.alpha(0.2) | ||
.rgb() | ||
.string(), | ||
firstWordColor: new Color( | ||
options.firstWordColor || options.color || defaultOptions.color | ||
) | ||
.rgb() | ||
.string(), | ||
wordCounts: options.wordCounts || defaultOptions.wordCounts, | ||
rainSpeed: options.rainSpeed || defaultOptions.rainSpeed, | ||
switchInterval: options.switchInterval || defaultOptions.switchInterval, | ||
} | ||
} |