Skip to content

Commit 059657f

Browse files
committed
feat: initial commit
0 parents  commit 059657f

20 files changed

+7979
-0
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.js
2+
/dist

.eslintrc.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": [
3+
"eslint-config-dasprid"
4+
],
5+
"parserOptions": {
6+
"project": "tsconfig.eslint.json"
7+
},
8+
"settings": {
9+
"import/resolver": {
10+
"typescript": {}
11+
}
12+
}
13+
}

.github/workflows/commitlint.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Lint Commit Messages
2+
on:
3+
pull_request:
4+
5+
jobs:
6+
commitlint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
with:
11+
fetch-depth: 0
12+
13+
- name: Setup Node
14+
uses: actions/setup-node@v3
15+
with:
16+
node-version: 16.x
17+
18+
- name: Cache node modules
19+
uses: actions/cache@v3
20+
env:
21+
cache-name: cache-node-modules
22+
with:
23+
path: ~/.npm
24+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
25+
restore-keys: |
26+
${{ runner.os }}-build-${{ env.cache-name }}-
27+
${{ runner.os }}-build-
28+
${{ runner.os }}-
29+
30+
- name: Install dependencies
31+
run: npm ci
32+
33+
- name: Validate all commits from PR
34+
run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose

.github/workflows/release.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
release:
10+
name: Release
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Use Node.js 16.x
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: 16.x
20+
21+
- name: Cache node modules
22+
uses: actions/cache@v3
23+
env:
24+
cache-name: cache-node-modules
25+
with:
26+
path: ~/.npm
27+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
28+
restore-keys: |
29+
${{ runner.os }}-build-${{ env.cache-name }}-
30+
${{ runner.os }}-build-
31+
${{ runner.os }}-
32+
33+
- name: Install Dependencies
34+
run: npm ci
35+
36+
- name: Lint
37+
run: npm run lint
38+
39+
- name: Test
40+
run: npm run coverage
41+
42+
- name: Codecov
43+
uses: codecov/codecov-action@v3
44+
45+
- name: Build
46+
run: npm run build
47+
48+
- name: Semantic Release
49+
uses: cycjimmy/semantic-release-action@v3
50+
env:
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
53+
HUSKY: 0
54+
id: semantic
55+
with:
56+
semantic_version: 19.0.5
57+
extra_plugins: |
58+
@semantic-release/[email protected]
59+
@semantic-release/[email protected]

.github/workflows/test.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
test:
10+
name: Test
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Use Node.js 16.x
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: 16.x
20+
21+
- name: Cache node modules
22+
uses: actions/cache@v3
23+
env:
24+
cache-name: cache-node-modules
25+
with:
26+
path: ~/.npm
27+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
28+
restore-keys: |
29+
${{ runner.os }}-build-${{ env.cache-name }}-
30+
${{ runner.os }}-build-
31+
${{ runner.os }}-
32+
33+
- name: Install Dependencies
34+
run: npm ci
35+
36+
- name: Lint
37+
run: npm run lint
38+
39+
- name: Test
40+
run: npm run coverage
41+
42+
- name: Codecov
43+
uses: codecov/codecov-action@v3

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/node_modules
2+
/dist
3+
npm-debug.log*
4+
.eslintcache
5+
/coverage

.husky/commit-msg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx --no -- commitlint --edit ""

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx lint-staged

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2023, Bloop Box
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
2. Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation
11+
and/or other materials provided with the distribution.
12+
13+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Bloop NFC Scanner Browser SDK
2+
3+
SDK to ease the integration of the Bloop NFC Scanner into browser applications.
4+
5+
## Installation
6+
7+
```bash
8+
npm i bloop-nfc-scanner
9+
```
10+
11+
## Usage
12+
13+
The SDK has two modes of operations. You can either register a UID capture to continuously capture incoming UIDs or you
14+
can capture a single UID via a promise.
15+
16+
### Continuous capture
17+
18+
```typescript
19+
import {registerUidCapture} from 'bloop-nfc-scanner';
20+
21+
registerUidCapture(uid => {
22+
console.log(uid);
23+
});
24+
```
25+
26+
The register function returns a callback to unregister the capture again.
27+
28+
### Single capture
29+
30+
```typescript
31+
import {captureUid} from 'bloop-nfc-scanner';
32+
33+
const uid = await captureUid();
34+
console.log(uid);
35+
```
36+
37+
You can also pass in an AbortSignal in order to cancel a running capture.
38+
39+
## Demo
40+
41+
To see the full functionality including error handling and such, clone this repository and run the following commands:
42+
43+
```bash
44+
npm i
45+
npm start
46+
```

commitlint.config.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {extends: ['@commitlint/config-conventional']}

index.html

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8"/>
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
6+
<title>NFC Scanner Demo</title>
7+
<link
8+
rel="stylesheet"
9+
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
10+
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65"
11+
crossorigin="anonymous"
12+
>
13+
</head>
14+
<body>
15+
<div class="container py-4">
16+
<div class="vstack gap-3">
17+
<div class="card">
18+
<div class="card-body">
19+
<h5 class="card-title">Register continuous UID capture</h5>
20+
<div class="form-group my-4">
21+
<label>UID</label>
22+
<input type="text" class="form-control" id="continuous-uid" readonly>
23+
</div>
24+
<button class="btn btn-primary" id="button-register">Register</button>
25+
</div>
26+
</div>
27+
28+
<div class="card">
29+
<div class="card-body">
30+
<h5 class="card-title">Capture single UID</h5>
31+
<div class="form-group my-4">
32+
<label>UID</label>
33+
<input type="text" class="form-control" id="single-uid" readonly>
34+
</div>
35+
<button class="btn btn-primary" id="button-capture">Capture</button>
36+
</div>
37+
</div>
38+
</div>
39+
</div>
40+
41+
<script type="module">
42+
import {registerUidCapture, captureUid, AbortError} from './src';
43+
44+
const buttonRegister = document.getElementById('button-register');
45+
let unregisterUidCapture;
46+
47+
buttonRegister.addEventListener('click', () => {
48+
if (unregisterUidCapture) {
49+
unregisterUidCapture();
50+
unregisterUidCapture = undefined;
51+
buttonRegister.innerText = 'Register';
52+
return;
53+
}
54+
55+
unregisterUidCapture = registerUidCapture(
56+
uid => {
57+
document.getElementById('continuous-uid').value = uid;
58+
},
59+
error => {
60+
alert(error.message);
61+
},
62+
);
63+
buttonRegister.innerText = 'Unregister';
64+
});
65+
66+
const buttonCapture = document.getElementById('button-capture');
67+
let abortController;
68+
69+
buttonCapture.addEventListener('click', () => {
70+
if (abortController) {
71+
abortController.abort();
72+
return;
73+
}
74+
75+
abortController = new AbortController();
76+
buttonCapture.innerText = 'Abort';
77+
78+
captureUid(abortController.signal)
79+
.then(uid => {
80+
document.getElementById('single-uid').value = uid;
81+
abortController = undefined;
82+
buttonCapture.innerText = 'Capture';
83+
})
84+
.catch(error => {
85+
abortController = undefined;
86+
buttonCapture.innerText = 'Capture';
87+
88+
if (error instanceof AbortError) {
89+
return;
90+
}
91+
92+
alert(error instanceof Error ? error.message : 'An unknown error occurred');
93+
});
94+
});
95+
</script>
96+
</body>
97+
</html>

0 commit comments

Comments
 (0)