Skip to content

Commit 62b167b

Browse files
committed
feat(core): add useBrowserOnly
1 parent b643027 commit 62b167b

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

packages/core/src/platform.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { inject, PLATFORM_ID } from '@angular/core';
2+
3+
export const useBrowserOnly =
4+
(platform = inject(PLATFORM_ID)) =>
5+
<T>(fn: () => T): T | null => {
6+
if (platform !== 'browser') return null;
7+
return fn();
8+
};

packages/core/src/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './exception';
22
export * from './injection';
3+
export * from './platform';
34
export * from './provide';
45
export { $type, ContainedTypeOf, TypeContainer } from 'type-container';

0 commit comments

Comments
 (0)