-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notices): notices lib, refactor, use for "yahooSurvey" (#783)
- Loading branch information
Showing
4 changed files
with
53 additions
and
11 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
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,46 @@ | ||
import options from "./options.js"; | ||
const logger = options.logger || console; | ||
|
||
type Notice = { | ||
id: string; | ||
text: string; | ||
level?: keyof typeof logger; | ||
onceOnly?: boolean; | ||
suppress?: boolean; | ||
}; | ||
|
||
const notices = { | ||
yahooSurvey: { | ||
id: "yahooSurvey", | ||
text: | ||
"Please consider completing the survey at https://bit.ly/yahoo-finance-api-feedback " + | ||
"if you haven't already; for more info see " + | ||
"https://github.com/gadicc/node-yahoo-finance2/issues/764#issuecomment-2056623851.", | ||
onceOnly: true, | ||
} as Notice, | ||
}; | ||
|
||
export function showNotice(id: keyof typeof notices) { | ||
const n = notices[id]; | ||
if (!n) throw new Error(`Unknown notice id: ${id}`); | ||
|
||
if (n.suppress) return; | ||
if (n.onceOnly) n.suppress = true; | ||
|
||
const text = | ||
n.text + | ||
// (n.onceOnly ? " (only shown once)" : "") + | ||
" You can supress this message in future with `yahooFinance.supressNotices(['" + | ||
id + | ||
"'])`."; | ||
const level = n.level || "info"; | ||
logger[level](text); | ||
} | ||
|
||
export function suppressNotices(noticeIds: (keyof typeof notices)[]) { | ||
noticeIds.forEach((id) => { | ||
const n = notices[id]; | ||
if (!n) logger.error(`Unknown notice id: ${id}`); | ||
n.suppress = true; | ||
}); | ||
} |
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