Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Release

# Publishing is gated on pushing a version tag (e.g. v0.2.1), NOT on merging to
# main. Merge freely; main accumulates unreleased changes. When you're ready to
# ship, run `npm version patch|minor|major` and `git push --follow-tags`.
on:
push:
tags:
- 'v*'

jobs:
publish:
name: Publish to npm
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # required for OIDC Trusted Publishing + provenance
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
cache: npm
registry-url: 'https://registry.npmjs.org'

# Trusted Publishing (OIDC) requires npm >= 11.5.1; the bundled npm may be older.
- run: npm install -g npm@latest

- run: npm ci

- name: Verify tag matches package.json version
run: |
PKG_VERSION="v$(node -p "require('./package.json').version")"
if [ "$PKG_VERSION" != "$GITHUB_REF_NAME" ]; then
echo "::error::Tag $GITHUB_REF_NAME does not match package.json version $PKG_VERSION"
exit 1
fi

- run: npm run lint
- run: npm run test
- run: npm run build

# No NODE_AUTH_TOKEN: auth is via OIDC Trusted Publishing (configured on
# npmjs.com). npm mints a short-lived token from the id-token permission
# and generates provenance automatically.
- name: Publish
run: npm publish
9 changes: 0 additions & 9 deletions .npmignore

This file was deleted.

32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Changelog

All notable changes to this project are documented here.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- iOS: return UTF-16 offsets from `NSDataDetector` instead of grapheme-cluster
distances, so `start`/`end` align with JavaScript string indices and Android's
ML Kit char offsets. Previously mismatched on text containing emoji, accented,
or non-BMP characters.
- Android: read the library version from `package.json` instead of a hardcoded
value, so `build.gradle` can no longer drift from the published version.

### Changed

- Ship an explicit `files` allowlist in `package.json` and drop the stale
`.npmignore`; development config (ESLint, Prettier, EditorConfig, CONTRIBUTING)
is no longer included in the published tarball.
- README hero image now uses an absolute URL so it renders on npmjs.com.

## [0.2.0]

- Initial public release: cross-platform text data detection using
`NSDataDetector` on iOS and ML Kit Entity Extraction on Android.

[Unreleased]: https://github.com/pablogdcr/react-native-data-detector/compare/v0.2.0...HEAD
[0.2.0]: https://github.com/pablogdcr/react-native-data-detector/releases/tag/v0.2.0
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Cross-platform text data detection for React Native. Uses **NSDataDetector** on iOS and **ML Kit Entity Extraction** on Android to detect phone numbers, URLs, emails, dates, and addresses — returning structured results to JavaScript.

<p align="center">
<img src="data-detector.png" alt="Data Detector Example" width="500" />
<img src="https://raw.githubusercontent.com/pablogdcr/react-native-data-detector/main/data-detector.png" alt="Data Detector Example" width="500" />
</p>

## Features
Expand Down
6 changes: 5 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
apply plugin: 'com.android.library'
apply plugin: 'org.jetbrains.kotlin.android'

import groovy.json.JsonSlurper

def packageJson = new JsonSlurper().parseText(file('../package.json').text)

group = 'expo.modules.datadetector'
version = '0.1.0'
version = packageJson.version

android {
namespace 'expo.modules.datadetector'
Expand Down
5 changes: 3 additions & 2 deletions ios/ReactNativeDataDetectorModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ public class ReactNativeDataDetectorModule: Module {
continue
}

let start = text.distance(from: text.startIndex, to: matchRange.lowerBound)
let end = text.distance(from: text.startIndex, to: matchRange.upperBound)
// Return UTF-16 offsets so indices align with JavaScript strings (and Android's ML Kit char offsets).
let start = match.range.location
let end = match.range.location + match.range.length

results.append([
"type": type,
Expand Down
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
"type": "commonjs",
"main": "build/index.js",
"types": "build/index.d.ts",
"files": [
"src",
"build",
"android",
"ios",
"expo-module.config.json",
"README.md",
"LICENSE"
],
"scripts": {
"build": "expo-module build",
"clean": "expo-module clean",
Expand Down
Loading