@ankhorage/permissions

中文文档
0.3.13发布于 2026/11/05MITTypeScriptES Module构建来源已验证近 30 天下载 1万

Cross-platform permission registry and runtime helpers for Expo, React Native, and React Native Web apps, with unified request/check APIs for camera, media, location, notifications, microphone, and other web/native capabilities.

原始使用文档
文档目录6 节
  1. Usage
  2. CLI
  3. Basic permissions
  4. Generated documentation
  5. Public API
  6. Utilities

PERMISSIONS

license: MIT npm: v0.3.13 runtime: bun typescript: strict eslint: checked prettier: checked build: checked tests: checked paradox: canonical

Cross-platform permission registry and runtime helpers for Expo, React Native, and React Native Web apps, with unified request/check APIs for camera, media, location, notifications, microphone, and other web/native capabilities.

Usage

CLI

Ankhorage packages expose their command-line interface through ankh. Use ankh --help to discover available package commands, or run a package command with --help for package-specific usage.

# Install the Ankhorage CLI
bun add --global @ankhorage/ankh

# Show usage information for permissions
ankh permissions --help

Basic permissions

Basic permissions runtime example.

Create a permission client, provide it at the app root, and use usePermission to read, refresh, and request a normalized permission state.

export default function BasicPermissionsExample() {
  return (
    <PermissionsProvider client={permissionClient}>
      <CameraPermissionExample />
    </PermissionsProvider>
  );
}

This package contains 1 additional example. See the generated documentation for the complete set.

Generated documentation

Public API

Utilities

createFakePermissionClient
createFakePermissionClient(options?: FakePermissionClientOptions) => FakePermissionClient

Creates a deterministic in-memory client for tests and examples.

Fake clients make permission flows testable without native devices, browser prompts, simulators, or network access.

Module: src/testing/index.ts Source: src/testing/index.ts:61:1 Related symbols: FakePermissionClient, FakePermissionClientOptions

createPermissionClient
createPermissionClient() => PermissionClient

Creates a permission client backed by Expo SDK modules.

Denials that Expo cannot request again are normalized to blocked. Limited media-library access and provisional or ephemeral iOS notification access are normalized to usable limited states, where granted remains true. The client requires expo-linking for settings recovery and rejects with a stable error when the operating-system settings page cannot be opened.

Expo modules are loaded only when a client operation uses them. The package root and Expo manifest metadata remain free of native module imports.

Module: src/expo/client.ts Source: src/expo/client.ts:38:1 Related symbols: PermissionClient

createPermissionManager
createPermissionManager(client: PermissionClient) => PermissionManager

Creates a permission manager from a runtime-specific client.

The manager validates permission names and normalizes client results. Native app configuration remains a separate build-time concern.

Module: src/manager/createPermissionManager.ts Source: src/manager/createPermissionManager.ts:21:1 Related symbols: PermissionClient, PermissionManager

createWebPermissionClient
createWebPermissionClient(options?: WebPermissionClientOptions) => PermissionClient

Creates a browser permission client using guarded structural globals.

Unsupported web APIs resolve to status: 'unavailable'. The adapter does not import DOM types and does not assume it is running in a browser.

Module: src/web/index.ts Source: src/web/index.ts:80:1 Related symbols: PermissionClient, WebPermissionClientOptions

Permission

Common runtime permissions supported by the registry.

The registry is intentionally platform-neutral. Adapters translate each permission into whatever a browser, React Native app, Expo app, or test environment can actually check or request.

Module: src/registry/permissions.ts Source: src/registry/permissions.ts:9:1

PermissionsProvider
PermissionsProvider({
  children,
  client,
  manager,
}: PermissionsProviderProps) => ReactNode

Provides a permission manager to React hooks.

React helpers are framework-neutral. They depend on React only and do not import browser, Expo, or React Native permission APIs.

Related types: PermissionsProviderProps

Props
PropTypeRequiredDefaultDescription
childrenReactNode | undefinedno—
clientPermissionClient | undefinedno—
managerPermissionManager | undefinedno—

版本与发布记录

@ankhorage/permissions 共发布 81 个版本,首次发布于 2026/06/09;过去 12 个月发布了 81 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.3.13latest2026/11/051 天前
0.3.122026/10/297 天前
0.3.112026/10/297 天前
0.3.102026/10/2610 天前
0.3.92026/10/2413 天前
0.3.82026/10/2214 天前

关于 @ankhorage/permissions 的常见问题

@ankhorage/permissions 是什么?

Cross-platform permission registry and runtime helpers for Expo, React Native, and React Native Web apps, with unified request/check APIs for camera, media, location, notifications, microphone, and other web/native capabilities.

如何安装 @ankhorage/permissions?

在项目目录运行 npm install @ankhorage/permissions,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18.2.0 || >=19.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@ankhorage/permissions 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ankhorage/permissions 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@ankhorage/permissions 可以商用吗?

@ankhorage/permissions 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ankhorage/permissions 的下载量有多少?

根据 npm 官方下载统计,@ankhorage/permissions 在 2026/10/06 – 2026/11/04 这 30 天内被下载 10,043 次,日均约 335 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ankhorage/permissions 还在维护吗?

最新版本 0.3.13 发布于 2026/11/05(1 天前);至今共发布 81 个版本,其中过去 12 个月发布了 81 个;首次发布于 2026/06/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。