forked from Expensify/react-native-onyx
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Expensify#474 from blazejkustra/ts/remaining-files
Migrate remaining files to TS
- Loading branch information
Showing
8 changed files
with
63 additions
and
169 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,31 @@ | ||
type LogData = { | ||
message: string; | ||
level: 'alert' | 'info'; | ||
}; | ||
type LoggerCallback = (data: LogData) => void; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
let logger: LoggerCallback = () => {}; | ||
|
||
/** | ||
* Register the logging callback | ||
*/ | ||
function registerLogger(callback: LoggerCallback) { | ||
logger = callback; | ||
} | ||
|
||
/** | ||
* Send an alert message to the logger | ||
*/ | ||
function logAlert(message: string) { | ||
logger({message: `[Onyx] ${message}`, level: 'alert'}); | ||
} | ||
|
||
/** | ||
* Send an info message to the logger | ||
*/ | ||
function logInfo(message: string) { | ||
logger({message: `[Onyx] ${message}`, level: 'info'}); | ||
} | ||
|
||
export {registerLogger, logInfo, logAlert}; |
This file was deleted.
Oops, something went wrong.
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,24 @@ | ||
/** | ||
* Returns true if the haystack begins with the needle | ||
* | ||
* @param haystack The full string to be searched | ||
* @param needle The case-sensitive string to search for | ||
* @return Returns true if the haystack starts with the needle. | ||
*/ | ||
function startsWith(haystack: string, needle: string) { | ||
return typeof haystack === 'string' && typeof needle === 'string' && haystack.startsWith(needle); | ||
} | ||
|
||
/** | ||
* Checks if parameter is a string or function. | ||
* If it is a string, then we will just return it. | ||
* If it is a function, then we will call it with | ||
* any additional arguments and return the result. | ||
*/ | ||
function result(parameter: string): string; | ||
function result<TFunction extends (...a: TArgs) => unknown, TArgs extends unknown[]>(parameter: TFunction, ...args: TArgs): ReturnType<TFunction>; | ||
function result<TFunction extends (...a: TArgs) => unknown, TArgs extends unknown[]>(parameter: TFunction, ...args: TArgs): ReturnType<TFunction> | string { | ||
return typeof parameter === 'function' ? (parameter(...args) as ReturnType<TFunction>) : parameter; | ||
} | ||
|
||
export {startsWith, result}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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