npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

expo-barcode-recognizer

v0.1.0

Published

A barcode recognizer based on Google ML Kit

Readme

expo-barcode-recognizer

  • 简介 (ZH): 基于 Google ML Kit 的本地二维码/条形码识别器,提供一个简单的方法从本地图片中识别条码信息,完全离线运行。
  • Overview (EN): A lightweight on-device barcode/QR recognizer powered by Google ML Kit. It exposes a single method to recognize barcodes from an image.

特性

  • 本地识别: 依赖 Google ML Kit,离线运行,低延迟。
  • 跨平台: iOS 与 Android 支持。
  • 简单 API: 一个方法完成识别,支持常见条码格式与详细结构化结果。

安装

npx expo install expo-barcode-recognizer

如果你在裸工作流或需要原生构建:

  • 使用 Expo Dev Client 或运行预构建:
npx expo prebuild

提示:如果你搭配 expo-image-picker 选择图片,请参考它的文档配置相册/相机权限。

快速开始

以下示例基于 example/App.tsx,演示从相册选择图片并识别:

import ExpoBarcodeRecognizer, { ExpoBarcodeRecognizeResult } from "expo-barcode-recognizer";
import { launchImageLibraryAsync } from "expo-image-picker";

async function pickAndRecognize() {
  const image = await launchImageLibraryAsync({
    mediaTypes: "images",
    allowsEditing: false,
    selectionLimit: 1,
    quality: 1,
  });

  if (!image.canceled) {
    const results: ExpoBarcodeRecognizeResult[] = await ExpoBarcodeRecognizer.recognizeCodeFromImageAsync({
      base64OrImageUri: image.assets[0].uri,
      // 可选:formats, orientation(iOS), rotationDegrees(Android)
    });

    console.log(results);
  }
}

API 参考

recognizeCodeFromImageAsync(options)

从图片中识别条码/二维码。

type RecognizeOptions = {
  base64OrImageUri: string;            // 必填,本地图片 URI 或 base64
  orientation?: InputImageOrientation; // 可选,仅 iOS
  formats?: BarcodeFormat[];           // 可选,限定识别格式
  rotationDegrees?: number;            // 可选,仅 Android,旋转角度
};

function recognizeCodeFromImageAsync(
  options: RecognizeOptions
): Promise<ExpoBarcodeRecognizeResult[]>;

返回值 ExpoBarcodeRecognizeResult[](节选字段):

interface ExpoBarcodeRecognizeResult {
  rawValue?: string;                 // 条码原始内容
  format: BarcodeFormat;             // 条码格式
  valueType: ExpoBarcodeValueType;   // 值类型(文本、URL、WiFi、联系人等)
  frame?: { x: number; y: number; width: number; height: number };
  cornerPoints?: { x: number; y: number }[];
  // 根据 valueType 可能包含:email, phone, sms, url, wifi, geoPoint,
  // contactInfo, calendarEvent, driverLicense 等结构化信息
}

开发与示例

仓库包含一个可运行的示例应用:example/

  • 进入示例并启动开发:
cd example
npm install
npm run start

注意事项

MLKit会造成安装包增大。比如,在安卓上,大小增加约 2.4 MB。更多信息可以在这里看。 iOS的GoogleMLKit/BarcodeScanning(iOS基于此)不支持arm架构的模拟器,如果你希望在iOS模拟器上运行,请运行在Rosetta模拟器上,或者使用真机。

许可

MIT