-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
254 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,7 @@ | |
"type": "git", | ||
"url": "git+https://github.com/docenjs/docen.git" | ||
}, | ||
"keywords": [ | ||
"pandoc", | ||
"mammoth" | ||
], | ||
"keywords": ["pandoc", "mammoth"], | ||
"author": { | ||
"name": "Demo Macro", | ||
"email": "[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,7 @@ | |
"description": "Programmed implementation of csv format, powered by Demo Macro.", | ||
"main": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"files": ["dist"], | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.mjs", | ||
|
@@ -20,12 +18,7 @@ | |
"type": "git", | ||
"url": "git+https://github.com/docenjs/docen.git" | ||
}, | ||
"keywords": [ | ||
"pandoc", | ||
"papaparse", | ||
"csv", | ||
"json" | ||
], | ||
"keywords": ["pandoc", "papaparse", "csv", "json"], | ||
"author": { | ||
"name": "Demo Macro", | ||
"email": "[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,7 @@ | |
"description": "Programmatically and command-line implementation of document formatting, powered by Demo Macro.", | ||
"main": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"files": ["dist"], | ||
"bin": { | ||
"docen": "dist/cli.mjs" | ||
}, | ||
|
@@ -24,10 +22,7 @@ | |
"type": "git", | ||
"url": "git+https://github.com/docenjs/docen.git" | ||
}, | ||
"keywords": [ | ||
"pandoc", | ||
"mammoth" | ||
], | ||
"keywords": ["pandoc", "mammoth"], | ||
"author": { | ||
"name": "Demo Macro", | ||
"email": "[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,7 @@ | |
"description": "Programmed implementation of docx format, powered by Demo Macro.", | ||
"main": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"files": ["dist"], | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.mjs", | ||
|
@@ -20,10 +18,7 @@ | |
"type": "git", | ||
"url": "git+https://github.com/docenjs/docen.git" | ||
}, | ||
"keywords": [ | ||
"pandoc", | ||
"mammoth" | ||
], | ||
"keywords": ["pandoc", "mammoth"], | ||
"author": { | ||
"name": "Demo Macro", | ||
"email": "[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# @docen/image | ||
|
||
![npm version](https://img.shields.io/npm/v/@docen/image) | ||
![npm downloads](https://img.shields.io/npm/dw/@docen/image) | ||
![npm license](https://img.shields.io/npm/l/@docen/image) | ||
|
||
> Programmed implementation of image format, powered by Demo Macro. | ||
## Getting started | ||
|
||
```bash | ||
# npm | ||
$ npm install @docen/image | ||
|
||
# yarn | ||
$ yarn add @docen/image | ||
|
||
# pnpm | ||
$ pnpm add @docen/image | ||
``` | ||
|
||
## Usage | ||
|
||
```ts | ||
|
||
``` | ||
|
||
## License | ||
|
||
- [MIT](LICENSE) © [Demo Macro](https://imst.xyz/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { defineBuildConfig } from "unbuild"; | ||
|
||
export default defineBuildConfig({ | ||
declaration: true, | ||
entries: ["src/index"], | ||
rollup: { | ||
emitCJS: true, | ||
esbuild: { | ||
minify: true, | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "@docen/image", | ||
"version": "0.0.7-edge.3", | ||
"description": "Programmed implementation of image format, powered by Demo Macro.", | ||
"main": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"files": ["dist"], | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.cjs" | ||
} | ||
}, | ||
"scripts": { | ||
"prepack": "unbuild" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/docenjs/docen.git" | ||
}, | ||
"keywords": ["pandoc", "image"], | ||
"author": { | ||
"name": "Demo Macro", | ||
"email": "[email protected]", | ||
"url": "https://imst.xyz/" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/docenjs/docen/issues" | ||
}, | ||
"homepage": "https://github.com/docenjs/docen#readme", | ||
"dependencies": { | ||
"image-meta": "^0.2.0", | ||
"tesseract.js": "5.1.0", | ||
"undio": "0.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./ocr"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { imageMeta } from "image-meta"; | ||
import { createWorker } from "tesseract.js"; | ||
import { type DataType, toArrayBuffer, toUint8Array } from "undio"; | ||
|
||
export async function convertImageToText( | ||
source: DataType, | ||
options?: { | ||
// https://tesseract-ocr.github.io/tessdoc/Data-Files | ||
lang?: string | string[]; | ||
} | ||
) { | ||
const { type } = imageMeta(toUint8Array(source)); | ||
|
||
// bmp、jpg、png、pbm、webp | ||
const isImageType = | ||
type && ["bmp", "jpg", "png", "pbm", "webp"].includes(type); | ||
|
||
if (isImageType) { | ||
const worker = await createWorker(options?.lang); | ||
|
||
const { | ||
data: { text }, | ||
} = await worker.recognize(toArrayBuffer(source)); | ||
|
||
await worker.terminate(); | ||
|
||
return text; | ||
} | ||
|
||
throw new Error("Unsupported image type"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,7 @@ | |
"description": "Programmed implementation of jsonp format, powered by Demo Macro.", | ||
"main": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"files": ["dist"], | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.mjs", | ||
|
@@ -20,12 +18,7 @@ | |
"type": "git", | ||
"url": "git+https://github.com/docenjs/docen.git" | ||
}, | ||
"keywords": [ | ||
"pandoc", | ||
"jsonp", | ||
"csv", | ||
"json" | ||
], | ||
"keywords": ["pandoc", "jsonp", "csv", "json"], | ||
"author": { | ||
"name": "Demo Macro", | ||
"email": "[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,7 @@ | |
"description": "Programmed implementation of pdf format, powered by Demo Macro.", | ||
"main": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"files": ["dist"], | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.mjs", | ||
|
@@ -20,11 +18,7 @@ | |
"type": "git", | ||
"url": "git+https://github.com/docenjs/docen.git" | ||
}, | ||
"keywords": [ | ||
"pandoc", | ||
"unpdf", | ||
"pdf" | ||
], | ||
"keywords": ["pandoc", "unpdf", "pdf"], | ||
"author": { | ||
"name": "Demo Macro", | ||
"email": "[email protected]", | ||
|
Oops, something went wrong.