Skip to content

Commit 5625c0d

Browse files
committedAug 23, 2017
first commit; scaffold for napi
0 parents  commit 5625c0d

12 files changed

+307
-0
lines changed
 

‎.babelrc

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"plugins": [
3+
"add-module-exports",
4+
"transform-es2015-modules-commonjs",
5+
"transform-class-properties",
6+
"transform-object-rest-spread",
7+
"transform-exponentiation-operator",
8+
"transform-async-to-generator",
9+
"syntax-trailing-function-commas",
10+
"transform-inline-environment-variables",
11+
[
12+
"transform-runtime", {
13+
"regenerator": true
14+
}
15+
]
16+
],
17+
18+
"parserOpts": {
19+
// Allow returns in the module
20+
"allowReturnOutsideFunction": true
21+
},
22+
23+
"env": {
24+
"development": {
25+
"sourceMaps": "inline"
26+
}
27+
}
28+
}

‎.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# top-most EditorConfig file
2+
root = true
3+
4+
# Unix-style newlines with a newline ending every file
5+
[*.{js,css,md}]
6+
end_of_line = lf
7+
insert_final_newline = true
8+
indent_style = space
9+
indent_size = 2

‎.gitignore

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# babel dist
2+
/lib
3+
4+
# Numerous always-ignore extensions
5+
*.bak
6+
*.patch
7+
*.diff
8+
*.err
9+
*.orig
10+
*.log
11+
*.rej
12+
*.swo
13+
*.swp
14+
*.zip
15+
*.vi
16+
*~
17+
*.sass-cache
18+
*.lock
19+
*.rdb
20+
*.db
21+
nohup.out
22+
.nyc_output
23+
coverage.lcov
24+
package-lock.json
25+
26+
# OS or Editor folders
27+
.DS_Store
28+
._*
29+
.cache
30+
.project
31+
.settings
32+
.tmproj
33+
*.esproj
34+
*.sublime-project
35+
*.sublime-workspace
36+
nbproject
37+
thumbs.db
38+
39+
# Folders to ignore
40+
.hg
41+
.svn
42+
.CVS
43+
.idea
44+
node_modules
45+
old/
46+
*-old/
47+
*-notrack/
48+
no-track/
49+
build/
50+
combo/
51+
reference/
52+
jscoverage_lib/
53+
temp/
54+
tmp/
55+
56+
# codecov.io
57+
coverage/

‎.npmignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/src
2+
.travis.yml
3+
.appveyor.yml
4+
.babelrc
5+
.editorconfig

‎.travis.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: node_js
2+
sudo: false
3+
node_js:
4+
- "6"
5+
- "8"
6+
after_success:
7+
- npm run report-cov

‎LICENSE-MIT

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright (c) 2013 kaelzhang <i@kael.me>, contributors
2+
http://kael.me/
3+
4+
Permission is hereby granted, free of charge, to any person obtaining
5+
a copy of this software and associated documentation files (the
6+
"Software"), to deal in the Software without restriction, including
7+
without limitation the rights to use, copy, modify, merge, publish,
8+
distribute, sublicense, and/or sell copies of the Software, and to
9+
permit persons to whom the Software is furnished to do so, subject to
10+
the following conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

‎README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[![Build Status](https://travis-ci.org/kaelzhang/napi-penteract.svg?branch=master)](https://travis-ci.org/kaelzhang/napi-penteract)
2+
[![Coverage](https://codecov.io/gh/kaelzhang/napi-penteract/branch/master/graph/badge.svg)](https://codecov.io/gh/kaelzhang/napi-penteract)
3+
<!-- optional appveyor tst
4+
[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/kaelzhang/napi-penteract?branch=master&svg=true)](https://ci.appveyor.com/project/kaelzhang/napi-penteract)
5+
-->
6+
<!-- optional npm version
7+
[![NPM version](https://badge.fury.io/js/napi-penteract.svg)](http://badge.fury.io/js/napi-penteract)
8+
-->
9+
<!-- optional npm downloads
10+
[![npm module downloads per month](http://img.shields.io/npm/dm/napi-penteract.svg)](https://www.npmjs.org/package/napi-penteract)
11+
-->
12+
<!-- optional dependency status
13+
[![Dependency Status](https://david-dm.org/kaelzhang/napi-penteract.svg)](https://david-dm.org/kaelzhang/napi-penteract)
14+
-->
15+
16+
# penteract
17+
18+
The tesseract wrapper using node.js N-API
19+
20+
## Install
21+
22+
```sh
23+
$ npm install penteract
24+
```
25+
26+
## Usage
27+
28+
```js
29+
const penteract = require('napi-penteract')
30+
```
31+
32+
## License
33+
34+
MIT

‎binding.gyp

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'penteract-native',
5+
'sources': [ 'src/penteract.cc' ],
6+
'include_dirs': ["<!@(node -p \"require('node-addon-api').include\")"],
7+
'dependencies': ["<!(node -p \"require('node-addon-api').gyp\")"],
8+
'cflags!': [ '-fno-exceptions' ],
9+
'cflags_cc!': [ '-fno-exceptions' ],
10+
'xcode_settings': {
11+
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
12+
'CLANG_CXX_LIBRARY': 'libc++',
13+
'MACOSX_DEPLOYMENT_TARGET': '10.7'
14+
},
15+
'msvs_settings': {
16+
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
17+
}
18+
}
19+
]
20+
}

‎package.json

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"main": "lib/binding.js",
3+
"devDependencies": {
4+
"ava": "^0.16.0",
5+
"babel-cli": "^6.16.0",
6+
"babel-plugin-add-module-exports": "^0.2.1",
7+
"babel-plugin-transform-async-to-generator": "^6.22.0",
8+
"babel-plugin-syntax-trailing-function-commas": "^6.13.0",
9+
"babel-plugin-transform-class-properties": "^6.16.0",
10+
"babel-plugin-transform-es2015-modules-commonjs": "^6.16.0",
11+
"babel-plugin-transform-exponentiation-operator": "^6.8.0",
12+
"babel-plugin-transform-inline-environment-variables": "^6.8.0",
13+
"babel-plugin-transform-object-rest-spread": "^6.16.0",
14+
"babel-plugin-transform-runtime": "^6.23.0",
15+
"babel-register": "^6.24.1",
16+
"nyc": "^11.1.0",
17+
"codecov": "^2.3.0"
18+
},
19+
"dependencies": {
20+
"babel-runtime": "^6.23.0",
21+
"node-addon-api": "^0.3.0"
22+
},
23+
"scripts": {
24+
"build": "BABEL_ENV=production babel src --out-dir lib",
25+
"test": "node --napi-modules ./test/test_binding.js",
26+
"// test": "nyc ava --verbose --timeout=10s",
27+
"prepublish": "npm run build",
28+
"report-cov": "nyc report --reporter=text-lcov > coverage.lcov && codecov"
29+
},
30+
"gypfile": true,
31+
"name": "penteract",
32+
"version": "1.0.0",
33+
"description": "The tesseract wrapper using node.js N-API",
34+
"repository": {
35+
"type": "git",
36+
"url": "git+https://github.com/kaelzhang/napi-penteract.git"
37+
},
38+
"keywords": [
39+
"tesseract",
40+
"ocr",
41+
"penteract",
42+
"n-api"
43+
],
44+
"author": "kael",
45+
"license": "MIT",
46+
"bugs": {
47+
"url": "https://github.com/kaelzhang/napi-penteract/issues"
48+
},
49+
"homepage": "https://github.com/kaelzhang/napi-penteract#readme"
50+
}

‎src/penteract.cc

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include "penteract.h"
2+
3+
using namespace Napi;
4+
5+
void Penteract::Initialize(Napi::Env& env, Object& target) {
6+
Napi::Function constructor = DefineClass(env, "Penteract", {
7+
InstanceMethod("greet", &Penteract::Greet)
8+
});
9+
10+
target.Set("Penteract", constructor);
11+
}
12+
13+
Napi::Value Penteract::Greet(const Napi::CallbackInfo& info) {
14+
if (!info[0].IsString())
15+
{
16+
throw Error::New(info.Env(), "You need to introduce yourself to greet");
17+
}
18+
19+
String name = info[0].As<String>();
20+
21+
printf("Hello %s\n", name.Utf8Value().c_str());
22+
printf("I am %s\n", this->_greeterName.Value().Utf8Value().c_str());
23+
24+
return this->_greeterName.Value();
25+
}
26+
27+
Penteract::Penteract(const Napi::CallbackInfo& info) {
28+
if (!info[0].IsString())
29+
{
30+
throw Error::New(info.Env(), "You must name me");
31+
}
32+
33+
this->_greeterName = Persistent(info[0].As<String>());
34+
}
35+
36+
void Init(Env env, Object exports, Object module) {
37+
Penteract::Initialize(env, exports);
38+
}
39+
40+
NODE_API_MODULE(addon, Init)

‎src/penteract.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#include <napi.h>
4+
5+
class Penteract : public Napi::ObjectWrap<Penteract>
6+
{
7+
public:
8+
static void Initialize(Napi::Env&, Napi::Object&);
9+
10+
Penteract(const Napi::CallbackInfo&);
11+
Napi::Value Greet(const Napi::CallbackInfo&);
12+
13+
private:
14+
Napi::Reference<Napi::String> _greeterName;
15+
};

‎test/test_binding.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const Penteract = require("../lib/binding.js");
2+
const assert = require("assert");
3+
4+
assert(Penteract, "The expected module is undefined");
5+
6+
function testBasic()
7+
{
8+
const instance = new Penteract("mr-yeoman");
9+
assert(instance.greet, "The expected method is not defined");
10+
assert.strictEqual(instance.greet("kermit"), "mr-yeoman", "Unexpected value returned");
11+
}
12+
13+
function testInvalidParams()
14+
{
15+
const instance = new Penteract();
16+
}
17+
18+
assert.doesNotThrow(testBasic, undefined, "testBasic threw an expection");
19+
assert.throws(testInvalidParams, undefined, "testInvalidParams didn't throw");
20+
21+
console.log("Tests passed- everything looks OK!");

0 commit comments

Comments
 (0)
Please sign in to comment.