Skip to content

Commit

Permalink
Merge pull request #50 from robertknight/js-package
Browse files Browse the repository at this point in the history
Add package.json and README.md file for npm package
  • Loading branch information
robertknight authored Apr 28, 2024
2 parents 63cf7e6 + 163c108 commit db19a6f
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build:

.PHONY: clean
clean:
rm -rf dist/*
rm -rf js/dist/*
rm -rf target/

.PHONY: check
Expand Down Expand Up @@ -38,8 +38,8 @@ test-e2e:
.PHONY: wasm
wasm:
RUSTFLAGS="-C target-feature=+simd128" cargo build --release --target wasm32-unknown-unknown --package ocrs
wasm-bindgen target/wasm32-unknown-unknown/release/ocrs.wasm --out-dir dist/ --target web --reference-types --weak-refs
tools/optimize-wasm.sh dist/ocrs_bg.wasm
wasm-bindgen target/wasm32-unknown-unknown/release/ocrs.wasm --out-dir js/dist/ --target web --reference-types --weak-refs
tools/optimize-wasm.sh js/dist/ocrs_bg.wasm

.PHONY: wasm-all
wasm-all: wasm wasm-nosimd
9 changes: 9 additions & 0 deletions js/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Ocrs

Ocrs is a library for extracting text from images.

This is an alpha WebAssembly build of the library for use in Node, the browser
and other WebAssembly runtimes.

See the [Ocrs GitHub repository](https://github.com/robertknight/ocrs) for JS
examples and updates.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";

import { readFile } from "fs/promises";

import { program } from "commander";
Expand Down Expand Up @@ -84,10 +87,13 @@ program
.option("-j, --json", "Output JSON")
.action(
async (detectionModelPath, recognitionModelPath, imagePath, options) => {
const scriptDir = dirname(fileURLToPath(import.meta.url));
const wasmPath = `${scriptDir}/../../dist/ocrs_bg.wasm`;

// Concurrently load the OCR library, text detection and recognition models,
// and input image.
const [_, detectionModel, recognitionModel, image] = await Promise.all([
readFile("dist/ocrs_bg.wasm").then(initOcrLib),
readFile(wasmPath).then(initOcrLib),
readFile(detectionModelPath).then((data) => new Uint8Array(data)),
readFile(recognitionModelPath).then((data) => new Uint8Array(data)),
loadImage(imagePath),
Expand Down
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "ocrs",
"version": "0.1.0",
"description": "Ocrs is a library for extracting text from images",
"type": "module",
"main": "dist/ocrs.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"files": ["dist/**"],
"keywords": ["OCR"],
"author": "Robert Knight <[email protected]>",
"license": "MIT"
}

0 comments on commit db19a6f

Please sign in to comment.