Environment API
isBrowser Runtime
Checks for browser window and document capabilities.
Signature
ts
export function isBrowser(): boolean;Example
ts
import { isBrowser } from "@fast-china/utils";
const result = isBrowser();Input
This method has no input parameters.
Returns
| Value | Type | Description |
|---|---|---|
result | boolean | true when both exist; does not inspect DOM content. |
isWebWorker Runtime
Checks for a worker-like runtime that is not a Window.
Signature
ts
export function isWebWorker(): boolean;Example
ts
import { isWebWorker } from "@fast-china/utils";
const result = isWebWorker();Input
This method has no input parameters.
Returns
| Value | Type | Description |
|---|---|---|
result | boolean | true when importScripts exists and the runtime is not a browser Window. |
isNode Runtime
Checks for the Node.js version marker.
Signature
ts
export function isNode(): boolean;Example
ts
import { isNode } from "@fast-china/utils";
const result = isNode();Input
This method has no input parameters.
Returns
| Value | Type | Description |
|---|---|---|
result | boolean | true when process.versions.node is a string. |
isUniApp Runtime
Checks for the uni-app uni runtime object.
Signature
ts
export function isUniApp(): boolean;Example
ts
import { isUniApp } from "@fast-china/utils";
const result = isUniApp();Input
This method has no input parameters.
Returns
| Value | Type | Description |
|---|---|---|
result | boolean | true when the uni identifier or compatible global property exists; calls no platform APIs. |
hasWebCrypto Capability
Checks for Web Crypto capabilities required by this library's full cryptography API.
Signature
ts
export function hasWebCrypto(): boolean;Example
ts
import { hasWebCrypto } from "@fast-china/utils";
const result = hasWebCrypto();Input
This method has no input parameters.
Returns
| Value | Type | Description |
|---|---|---|
result | boolean | true when all required Web Crypto methods are available. |
detectRuntime Runtime
Returns the primary runtime environment.
Signature
ts
export function detectRuntime(): RuntimeKind;Example
ts
import { detectRuntime } from "@fast-china/utils";
const result = detectRuntime();Input
This method has no input parameters.
Returns
| Value | Type | Description |
|---|---|---|
result | RuntimeKind | browser, worker, node, or unknown when unidentified. |
isMobileUserAgent Mobile
Heuristically identifies phones from the User-Agent.
Signature
ts
export function isMobileUserAgent(userAgent: string = currentUserAgent()): boolean;Example
ts
import { isMobileUserAgent } from "@fast-china/utils";
const result = isMobileUserAgent("Mozilla/5.0 (iPhone; Mobile)");Input
| Input | Type | Required / default | Description |
|---|---|---|---|
userAgent | string | Optional; defaults to currentUserAgent() | Reads navigator.userAgent by default; uses an empty string when unavailable. |
Returns
| Value | Type | Description |
|---|---|---|
result | boolean | true when phone characteristics match. |
isTabletUserAgent Mobile
Heuristically identifies tablets using User-Agent and touch-point count.
Signature
ts
export function isTabletUserAgent(userAgent: string = currentUserAgent(), maxTouchPoints: number = currentTouchPoints()): boolean;Example
ts
import { isTabletUserAgent } from "@fast-china/utils";
const result = isTabletUserAgent("Mozilla/5.0 (iPad)", 5);Input
| Input | Type | Required / default | Description |
|---|---|---|---|
userAgent | string | Optional; defaults to currentUserAgent() | Current User-Agent by default. |
maxTouchPoints | number | Optional; defaults to currentTouchPoints() | Identifies iPadOS with a desktop User-Agent; defaults to the current touch-point count. |
Returns
| Value | Type | Description |
|---|---|---|
result | boolean | true when tablet characteristics match. |
