-
Notifications
You must be signed in to change notification settings - Fork 1
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
11 changed files
with
687 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
root: true, | ||
env: { | ||
node: true | ||
}, | ||
extends: [ | ||
'digitalbazaar', | ||
'digitalbazaar/jsdoc', | ||
'digitalbazaar/module' | ||
] | ||
}; |
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,72 @@ | ||
name: Main CI | ||
|
||
on: [push] | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
strategy: | ||
matrix: | ||
node-version: [20.x] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm install | ||
- name: Run eslint | ||
run: npm run lint | ||
test-node: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
strategy: | ||
matrix: | ||
node-version: [18.x, 20.x] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v5 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm install | ||
- name: Run test with Node.js ${{ matrix.node-version }} | ||
run: npm run test-node | ||
test-karma: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
strategy: | ||
matrix: | ||
node-version: [20.x] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm install | ||
- name: Run karma tests | ||
run: npm run test-karma | ||
coverage: | ||
needs: [test-node, test-karma] | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
strategy: | ||
matrix: | ||
node-version: [20.x] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm install | ||
- name: Generate coverage report | ||
run: npm run coverage-ci | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v4 | ||
with: | ||
file: ./coverage/lcov.info | ||
fail_ci_if_error: true | ||
token: ${{ secrets.CODECOV_TOKEN }} |
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,16 @@ | ||
*.sublime-project | ||
*.sublime-workspace | ||
*.sw[op] | ||
*~ | ||
.DS_Store | ||
.c9 | ||
.c9revisions | ||
.cproject | ||
.nyc_output | ||
.project | ||
.settings | ||
coverage | ||
node_modules | ||
npm-debug.log | ||
package-lock.json | ||
v8.log |
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,6 @@ | ||
# @digitalbazaar/base45 ChangeLog | ||
|
||
## 1.0.0 - 2024-xx-xx | ||
|
||
- Initial version. | ||
- See git for history. |
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,27 @@ | ||
Copyright (c) 2024, Digital Bazaar, Inc. | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* 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. | ||
|
||
* Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
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 HOLDER 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. |
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 |
---|---|---|
@@ -1 +1,119 @@ | ||
# RFC 9285 Base45 Encoder/Decoder _(@digitalbazaar/base45)_ | ||
|
||
> Encoder/decoder for [The Base45 Data Encoding][] for [Node.js][] and Web browsers | ||
## Table of Contents | ||
|
||
- [Background](#background) | ||
- [Install](#install) | ||
- [Usage](#usage) | ||
- [Security](#security) | ||
- [Contribute](#contribute) | ||
- [Commercial Support](#commercial-support) | ||
- [License](#license) | ||
|
||
## Background | ||
|
||
This library provides an encoder and decoder for RFC 9285 [The Base45 Encoding | ||
Scheme][] using an alphabet designed for efficient use in QR codes using | ||
Alphanumeric mode. It works in both [Node.js][] and in Web browsers with no | ||
dependencies. | ||
|
||
## Install | ||
|
||
- Node.js >=18 is supported. | ||
|
||
To install for [Node.js][] or in a Web project using npm: | ||
|
||
``` | ||
npm install @digitalbazaar/base45 | ||
``` | ||
|
||
To install locally or for development: | ||
|
||
``` | ||
git clone https://github.com/digitalbazaar/base45.git | ||
cd base45 | ||
npm install | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
import {encode, decode} from '@digitalbazaar/base45'; | ||
``` | ||
|
||
### Encoding | ||
|
||
* `encode(input])` | ||
* **`input`**: `Uint8Array` - bytes to encode | ||
* Returns a base45 encoded string. | ||
|
||
```js | ||
import {encode} from '@digitalbazaar/base45'; | ||
|
||
const input1 = Uint8Array([1, 2, 3, 4]); | ||
const encoded1 = encode(input1); | ||
// > X507H0 | ||
``` | ||
|
||
### Decoding | ||
|
||
* `decode(input)` | ||
* **`input`**: `String` - string to decode | ||
* Returns a `Uint8Array` with the decoded bytes. | ||
|
||
```js | ||
import {decode} from '@digitalbazaar/base45'; | ||
|
||
const input2 = 'X507H0'; | ||
const decoded2 = decode(input2); | ||
// > Uint8Array [ 1, 2, 3, 4 ] | ||
``` | ||
|
||
### String Handling | ||
|
||
This library uses [Uint8Array][] for encoder input and decoder output. If | ||
conversion to and from strings is needed it can be done with a variety of tools | ||
such as [TextEncoder][] and [TextDecoder][] using the [Encoding][] standard. | ||
|
||
```js | ||
const input3 = new TextEncoder().encode('abc'); | ||
const encoded3 = encode(input3); | ||
// > 0EC92 | ||
|
||
const decoded4 = decode(encoded3); | ||
const output4 = new TextDecoder().decode(decoded4); | ||
// > abc | ||
``` | ||
|
||
## Security | ||
|
||
- Processing large inputs could result in high resource usage. | ||
|
||
## Contribute | ||
|
||
Please follow the [Bedrock contributing | ||
guidelines](https://github.com/digitalbazaar/bedrock/blob/master/CONTRIBUTING.md). | ||
|
||
PRs accepted. | ||
|
||
If editing the README, please conform to the | ||
[standard-readme](https://github.com/RichardLitt/standard-readme) | ||
specification. | ||
|
||
## Commercial Support | ||
|
||
Commercial support for this library is available upon request from | ||
Digital Bazaar: support@digitalbazaar.com | ||
|
||
## License | ||
|
||
[New BSD License (3-clause)](LICENSE) © Digital Bazaar | ||
|
||
[Encoding]: https://encoding.spec.whatwg.org/ | ||
[Node.js]: https://nodejs.org/ | ||
[TextDecoder]: https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder | ||
[TextEncoder]: https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder | ||
[The Base45 Data Encoding]: https://www.rfc-editor.org/rfc/rfc9285 | ||
[Uint8Array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array |
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,66 @@ | ||
/* | ||
* Copyright (c) 2011-2024 Digital Bazaar, Inc. All rights reserved. | ||
*/ | ||
module.exports = function(config) { | ||
config.set({ | ||
// base path that will be used to resolve all patterns (eg. files, exclude) | ||
basePath: '', | ||
|
||
// frameworks to use | ||
frameworks: [ | ||
'mocha' | ||
], | ||
|
||
// list of files / patterns to load in the browser | ||
files: [ | ||
{ | ||
pattern: 'tests/*.spec.js', | ||
watched: false, served: true, included: true | ||
} | ||
], | ||
|
||
// list of files to exclude | ||
exclude: [], | ||
|
||
// preprocess matching files before serving them to the browser | ||
// available preprocessors: | ||
// https://npmjs.org/browse/keyword/karma-preprocessor | ||
preprocessors: { | ||
'tests/*.js': [ | ||
'webpack', | ||
'sourcemap' | ||
] | ||
}, | ||
|
||
webpack: { | ||
mode: 'development', | ||
devtool: 'inline-source-map' | ||
}, | ||
|
||
// test results reporter to use | ||
// possible values: 'dots', 'progress' | ||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter | ||
//reporters: ['progress'], | ||
reporters: ['mocha'], | ||
|
||
// start these browsers | ||
// available browser launchers: | ||
// https://npmjs.org/browse/keyword/karma-launcher | ||
//browsers: ['ChromeHeadless', 'Chrome', 'Firefox', 'Safari'], | ||
browsers: ['ChromeHeadless'], | ||
|
||
// Continuous Integration mode | ||
// if true, Karma captures browsers, runs the tests and exits | ||
singleRun: true, | ||
|
||
// Mocha | ||
client: { | ||
mocha: { | ||
// increase from default 2s | ||
timeout: 10000, | ||
reporter: 'html' | ||
//delay: true | ||
} | ||
} | ||
}); | ||
}; |
Oops, something went wrong.