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

ndef.js

v1.0.0

Published

用于生成和解析 NFC NDEF 消息的 Node.js 库

Readme

NFC-NDEF 库

一个用于生成和解析 NFC NDEF (NFC Data Exchange Format) 消息的 Node.js 库。该库支持创建各种类型的 NDEF 记录,包括 URI 记录、文本记录、安卓应用记录和自定义记录。

安装

npm install nfc-ndef

功能特点

  • 创建 NDEF 消息并添加多种类型的记录
  • 支持 URI 记录(网址、电话号码、邮件等)
  • 支持多语言文本记录
  • 支持安卓应用记录(AAR)
  • 支持自定义记录类型
  • 将 NDEF 消息编码为十六进制字符串
  • 解析十六进制格式的 NDEF 消息

使用示例

创建 NDEF 消息

const NDEF = require('nfc-ndef');

// 创建一个新的 NDEF 消息实例
const ndefMessage = new NDEF();

// 添加一个 URI 记录(网址)
ndefMessage.addUriRecord('https://www.example.com');

// 添加一个文本记录
ndefMessage.addTextRecord('Hello, NFC World!', 'en');

// 添加一个安卓应用记录(用于启动应用)
ndefMessage.addAndroidAppRecord('com.example.myapp');

// 添加一个自定义记录
ndefMessage.addCustomRecord('custom.type', 'Custom payload data');

// 生成 NDEF 消息(十六进制格式)
const hexMessage = ndefMessage.generateMessage();
console.log('NDEF 消息:', hexMessage);

解析 NDEF 消息

const NDEF = require('nfc-ndef');

// 十六进制格式的 NDEF 消息
const hexMessage = '91020A5402656E48656C6C6F2C204E464320576F726C6421';

// 解析 NDEF 消息
const parsedNdef = NDEF.parseMessage(hexMessage);

// 获取解析后的记录内容
const records = parsedNdef.getRecordContents();
console.log('解析的记录:', records);

API 文档

构造函数

const ndefMessage = new NDEF();

创建一个新的 NDEF 消息实例。

添加记录方法

addUriRecord(uri)

添加一个 URI 记录。

  • 参数:
    • uri {string} - URI 字符串(如 https://example.com, tel:123456789 等)
  • 返回值: {NDEF} - 当前实例,支持链式调用

addTextRecord(text, language)

添加一个文本记录。

  • 参数:
    • text {string} - 文本内容
    • language {string} - 语言代码,默认为 "en"
  • 返回值: {NDEF} - 当前实例,支持链式调用

addAndroidAppRecord(packageName)

添加一个安卓应用记录(AAR)。

  • 参数:
    • packageName {string} - 安卓应用包名
  • 返回值: {NDEF} - 当前实例,支持链式调用

addCustomRecord(type, payload, tnf)

添加一个自定义记录类型。

  • 参数:
    • type {string} - 记录类型
    • payload {string|Buffer} - 记录载荷
    • tnf {number} - 记录 TNF 值,默认为 0x04(外部类型)
  • 返回值: {NDEF} - 当前实例,支持链式调用

消息操作方法

generateMessage()

生成完整的 NDEF 消息。

  • 返回值: {string} - NDEF 消息的十六进制字符串表示

clear()

清除所有记录。

  • 返回值: {NDEF} - 当前实例,支持链式调用

静态方法

NDEF.parseMessage(hexString)

从十六进制字符串解析 NDEF 消息。

  • 参数:
    • hexString {string} - NDEF 消息的十六进制字符串
  • 返回值: {NDEF} - 包含解析记录的 NDEF 实例

getRecordContents()

获取解析后的记录内容。

  • 返回值: {Array} - 包含解析后记录内容的数组

许可证

ISC