MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / platformCheck

Function platformCheck

packages/core/utils/platform-check.ts:4–26  ·  view source on GitHub ↗
(parent?: string)

Source from the content-addressed store, hash-verified

2 * @internal Util used for exporting opposing platform utils and warning the user if they are trying to access them.
3 */
4export function platformCheck(parent?: string) {
5 if (__DEV__) {
6 return new Proxy(
7 {},
8 {
9 get(_, prop) {
10 const propPretty = [parent, prop.toString()].join('.');
11 const hintPlatformCheck = __ANDROID__ ? '__IOS__' : '__ANDROID__';
12
13 // prettier-ignore
14 const errorMsg = [
15 `Trying to access "${propPretty}" without checking platform first.`,
16 `Hint: Use "${hintPlatformCheck}" to check platform before accessing "${propPretty}".`
17 ].join('\n');
18
19 throw new Error(errorMsg);
20 },
21 },
22 );
23 }
24
25 return undefined;
26}

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected