Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
DASPRiD committed Apr 1, 2023
0 parents commit 059657f
Show file tree
Hide file tree
Showing 20 changed files with 7,979 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.js
/dist
13 changes: 13 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": [
"eslint-config-dasprid"
],
"parserOptions": {
"project": "tsconfig.eslint.json"
},
"settings": {
"import/resolver": {
"typescript": {}
}
}
}
34 changes: 34 additions & 0 deletions .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Lint Commit Messages
on:
pull_request:

jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16.x

- name: Cache node modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install dependencies
run: npm ci

- name: Validate all commits from PR
run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
59 changes: 59 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Release

on:
push:
branches:
- main

jobs:
release:
name: Release
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 16.x

- name: Cache node modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install Dependencies
run: npm ci

- name: Lint
run: npm run lint

- name: Test
run: npm run coverage

- name: Codecov
uses: codecov/codecov-action@v3

- name: Build
run: npm run build

- name: Semantic Release
uses: cycjimmy/semantic-release-action@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
HUSKY: 0
id: semantic
with:
semantic_version: 19.0.5
extra_plugins: |
@semantic-release/[email protected]
@semantic-release/[email protected]
43 changes: 43 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Test

on:
pull_request:
branches:
- main

jobs:
test:
name: Test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 16.x

- name: Cache node modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install Dependencies
run: npm ci

- name: Lint
run: npm run lint

- name: Test
run: npm run coverage

- name: Codecov
uses: codecov/codecov-action@v3
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/node_modules
/dist
npm-debug.log*
.eslintcache
/coverage
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no -- commitlint --edit ""
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2023, Bloop Box
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Bloop NFC Scanner Browser SDK

SDK to ease the integration of the Bloop NFC Scanner into browser applications.

## Installation

```bash
npm i bloop-nfc-scanner
```

## Usage

The SDK has two modes of operations. You can either register a UID capture to continuously capture incoming UIDs or you
can capture a single UID via a promise.

### Continuous capture

```typescript
import {registerUidCapture} from 'bloop-nfc-scanner';

registerUidCapture(uid => {
console.log(uid);
});
```

The register function returns a callback to unregister the capture again.

### Single capture

```typescript
import {captureUid} from 'bloop-nfc-scanner';

const uid = await captureUid();
console.log(uid);
```

You can also pass in an AbortSignal in order to cancel a running capture.

## Demo

To see the full functionality including error handling and such, clone this repository and run the following commands:

```bash
npm i
npm start
```
1 change: 1 addition & 0 deletions commitlint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {extends: ['@commitlint/config-conventional']}
97 changes: 97 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>NFC Scanner Demo</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65"
crossorigin="anonymous"
>
</head>
<body>
<div class="container py-4">
<div class="vstack gap-3">
<div class="card">
<div class="card-body">
<h5 class="card-title">Register continuous UID capture</h5>
<div class="form-group my-4">
<label>UID</label>
<input type="text" class="form-control" id="continuous-uid" readonly>
</div>
<button class="btn btn-primary" id="button-register">Register</button>
</div>
</div>

<div class="card">
<div class="card-body">
<h5 class="card-title">Capture single UID</h5>
<div class="form-group my-4">
<label>UID</label>
<input type="text" class="form-control" id="single-uid" readonly>
</div>
<button class="btn btn-primary" id="button-capture">Capture</button>
</div>
</div>
</div>
</div>

<script type="module">
import {registerUidCapture, captureUid, AbortError} from './src';

const buttonRegister = document.getElementById('button-register');
let unregisterUidCapture;

buttonRegister.addEventListener('click', () => {
if (unregisterUidCapture) {
unregisterUidCapture();
unregisterUidCapture = undefined;
buttonRegister.innerText = 'Register';
return;
}

unregisterUidCapture = registerUidCapture(
uid => {
document.getElementById('continuous-uid').value = uid;
},
error => {
alert(error.message);
},
);
buttonRegister.innerText = 'Unregister';
});

const buttonCapture = document.getElementById('button-capture');
let abortController;

buttonCapture.addEventListener('click', () => {
if (abortController) {
abortController.abort();
return;
}

abortController = new AbortController();
buttonCapture.innerText = 'Abort';

captureUid(abortController.signal)
.then(uid => {
document.getElementById('single-uid').value = uid;
abortController = undefined;
buttonCapture.innerText = 'Capture';
})
.catch(error => {
abortController = undefined;
buttonCapture.innerText = 'Capture';

if (error instanceof AbortError) {
return;
}

alert(error instanceof Error ? error.message : 'An unknown error occurred');
});
});
</script>
</body>
</html>
Loading

0 comments on commit 059657f

Please sign in to comment.