Files
NativeScript/packages/core/utils/platform-check.ts
farfromrefuge 40b2a6a6db chore: use __ANDROID__ and __IOS__ throughout (#10446)
Standardizes usage for more macro style removal during bundling for target platforms.
[skip ci]
2023-11-25 08:34:25 -08:00

27 lines
685 B
TypeScript

/**
* @internal Util used for exporting opposing platform utils and warning the user if they are trying to access them.
*/
export function platformCheck(parent?: string) {
if (__DEV__) {
return new Proxy(
{},
{
get(_, prop) {
const propPretty = [parent, prop.toString()].join('.');
const hintPlatformCheck = __ANDROID__ ? '__IOS__' : '__ANDROID__';
// prettier-ignore
const errorMsg = [
`Trying to access "${propPretty}" without checking platform first.`,
`Hint: Use "${hintPlatformCheck}" to check platform before accessing "${propPretty}".`
].join('\n');
throw new Error(errorMsg);
},
}
);
}
return undefined;
}