@twin.org/qr 0.0.1-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +21 -0
- package/dist/cjs/index.cjs +2006 -0
- package/dist/esm/index.mjs +2000 -0
- package/dist/types/data/qrAlphaNumeric.d.ts +23 -0
- package/dist/types/data/qrByte8.d.ts +23 -0
- package/dist/types/data/qrNumber.d.ts +23 -0
- package/dist/types/helpers/bitBuffer.d.ts +36 -0
- package/dist/types/helpers/mathHelper.d.ts +23 -0
- package/dist/types/helpers/polynomial.d.ts +45 -0
- package/dist/types/helpers/qrHelper.d.ts +49 -0
- package/dist/types/helpers/rsBlock.d.ts +30 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/models/IBitmapRendererOptions.d.ts +15 -0
- package/dist/types/models/IRendererOptions.d.ts +13 -0
- package/dist/types/models/ITextRendererOptions.d.ts +14 -0
- package/dist/types/models/errorCorrectLevel.d.ts +27 -0
- package/dist/types/models/maskPattern.d.ts +43 -0
- package/dist/types/models/qrCellData.d.ts +4 -0
- package/dist/types/models/qrDataBase.d.ts +42 -0
- package/dist/types/models/qrDataMode.d.ts +23 -0
- package/dist/types/qr.d.ts +35 -0
- package/dist/types/renderers/jpegRenderer.d.ts +14 -0
- package/dist/types/renderers/pngRenderer.d.ts +14 -0
- package/dist/types/renderers/textRenderer.d.ts +14 -0
- package/docs/changelog.md +5 -0
- package/docs/examples.md +1 -0
- package/docs/reference/classes/JpegRenderer.md +37 -0
- package/docs/reference/classes/PngRenderer.md +37 -0
- package/docs/reference/classes/QR.md +98 -0
- package/docs/reference/classes/TextRenderer.md +37 -0
- package/docs/reference/index.md +23 -0
- package/docs/reference/interfaces/IBitmapRendererOptions.md +47 -0
- package/docs/reference/interfaces/IRendererOptions.md +24 -0
- package/docs/reference/interfaces/ITextRendererOptions.md +47 -0
- package/docs/reference/type-aliases/ErrorCorrectLevel.md +6 -0
- package/docs/reference/type-aliases/QRCellData.md +5 -0
- package/docs/reference/variables/ErrorCorrectLevel.md +32 -0
- package/locales/en.json +34 -0
- package/package.json +64 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Class: QR
|
|
2
|
+
|
|
3
|
+
Class to generates QR codes from data.
|
|
4
|
+
Based on https://github.com/kazuhikoarase/qrcode-generator/ .
|
|
5
|
+
|
|
6
|
+
## Constructors
|
|
7
|
+
|
|
8
|
+
### new QR()
|
|
9
|
+
|
|
10
|
+
> **new QR**(`typeNumber`, `errorCorrectLevel`): [`QR`](QR.md)
|
|
11
|
+
|
|
12
|
+
Create a new instance of QR.
|
|
13
|
+
|
|
14
|
+
#### Parameters
|
|
15
|
+
|
|
16
|
+
• **typeNumber**: `number` = `6`
|
|
17
|
+
|
|
18
|
+
0 to 40, 0 means autodetect.
|
|
19
|
+
|
|
20
|
+
• **errorCorrectLevel**: [`ErrorCorrectLevel`](../type-aliases/ErrorCorrectLevel.md) = `ErrorCorrectLevel.L`
|
|
21
|
+
|
|
22
|
+
'L','M','Q','H'.
|
|
23
|
+
|
|
24
|
+
#### Returns
|
|
25
|
+
|
|
26
|
+
[`QR`](QR.md)
|
|
27
|
+
|
|
28
|
+
#### Throws
|
|
29
|
+
|
|
30
|
+
Error if the typeNumber is invalid.
|
|
31
|
+
|
|
32
|
+
## Methods
|
|
33
|
+
|
|
34
|
+
### addText()
|
|
35
|
+
|
|
36
|
+
> **addText**(`qrData`): `void`
|
|
37
|
+
|
|
38
|
+
Add text data to the QR Code.
|
|
39
|
+
|
|
40
|
+
#### Parameters
|
|
41
|
+
|
|
42
|
+
• **qrData**: `string`
|
|
43
|
+
|
|
44
|
+
The data to add.
|
|
45
|
+
|
|
46
|
+
#### Returns
|
|
47
|
+
|
|
48
|
+
`void`
|
|
49
|
+
|
|
50
|
+
***
|
|
51
|
+
|
|
52
|
+
### addNumber()
|
|
53
|
+
|
|
54
|
+
> **addNumber**(`qrData`): `void`
|
|
55
|
+
|
|
56
|
+
Add number to the QR Code.
|
|
57
|
+
|
|
58
|
+
#### Parameters
|
|
59
|
+
|
|
60
|
+
• **qrData**: `string`
|
|
61
|
+
|
|
62
|
+
The data to add.
|
|
63
|
+
|
|
64
|
+
#### Returns
|
|
65
|
+
|
|
66
|
+
`void`
|
|
67
|
+
|
|
68
|
+
***
|
|
69
|
+
|
|
70
|
+
### addAlphaNumeric()
|
|
71
|
+
|
|
72
|
+
> **addAlphaNumeric**(`qrData`): `void`
|
|
73
|
+
|
|
74
|
+
Add alpha numeric to the QR Code.
|
|
75
|
+
|
|
76
|
+
#### Parameters
|
|
77
|
+
|
|
78
|
+
• **qrData**: `string`
|
|
79
|
+
|
|
80
|
+
The data to add.
|
|
81
|
+
|
|
82
|
+
#### Returns
|
|
83
|
+
|
|
84
|
+
`void`
|
|
85
|
+
|
|
86
|
+
***
|
|
87
|
+
|
|
88
|
+
### generate()
|
|
89
|
+
|
|
90
|
+
> **generate**(): [`QRCellData`](../type-aliases/QRCellData.md)
|
|
91
|
+
|
|
92
|
+
Generate the display buffer.
|
|
93
|
+
|
|
94
|
+
#### Returns
|
|
95
|
+
|
|
96
|
+
[`QRCellData`](../type-aliases/QRCellData.md)
|
|
97
|
+
|
|
98
|
+
Boolean buffer of pixels.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Class: TextRenderer
|
|
2
|
+
|
|
3
|
+
Class to render qr data as text.
|
|
4
|
+
|
|
5
|
+
## Constructors
|
|
6
|
+
|
|
7
|
+
### new TextRenderer()
|
|
8
|
+
|
|
9
|
+
> **new TextRenderer**(): [`TextRenderer`](TextRenderer.md)
|
|
10
|
+
|
|
11
|
+
#### Returns
|
|
12
|
+
|
|
13
|
+
[`TextRenderer`](TextRenderer.md)
|
|
14
|
+
|
|
15
|
+
## Methods
|
|
16
|
+
|
|
17
|
+
### render()
|
|
18
|
+
|
|
19
|
+
> `static` **render**(`cellData`, `options`?): `Promise`\<`string`\>
|
|
20
|
+
|
|
21
|
+
Render the QR code data as text.
|
|
22
|
+
|
|
23
|
+
#### Parameters
|
|
24
|
+
|
|
25
|
+
• **cellData**: [`QRCellData`](../type-aliases/QRCellData.md)
|
|
26
|
+
|
|
27
|
+
The cell data for the QR code.
|
|
28
|
+
|
|
29
|
+
• **options?**: [`ITextRendererOptions`](../interfaces/ITextRendererOptions.md)
|
|
30
|
+
|
|
31
|
+
The options for rendering.
|
|
32
|
+
|
|
33
|
+
#### Returns
|
|
34
|
+
|
|
35
|
+
`Promise`\<`string`\>
|
|
36
|
+
|
|
37
|
+
The text content.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @twin.org/qr
|
|
2
|
+
|
|
3
|
+
## Classes
|
|
4
|
+
|
|
5
|
+
- [QR](classes/QR.md)
|
|
6
|
+
- [JpegRenderer](classes/JpegRenderer.md)
|
|
7
|
+
- [PngRenderer](classes/PngRenderer.md)
|
|
8
|
+
- [TextRenderer](classes/TextRenderer.md)
|
|
9
|
+
|
|
10
|
+
## Interfaces
|
|
11
|
+
|
|
12
|
+
- [IBitmapRendererOptions](interfaces/IBitmapRendererOptions.md)
|
|
13
|
+
- [IRendererOptions](interfaces/IRendererOptions.md)
|
|
14
|
+
- [ITextRendererOptions](interfaces/ITextRendererOptions.md)
|
|
15
|
+
|
|
16
|
+
## Type Aliases
|
|
17
|
+
|
|
18
|
+
- [ErrorCorrectLevel](type-aliases/ErrorCorrectLevel.md)
|
|
19
|
+
- [QRCellData](type-aliases/QRCellData.md)
|
|
20
|
+
|
|
21
|
+
## Variables
|
|
22
|
+
|
|
23
|
+
- [ErrorCorrectLevel](variables/ErrorCorrectLevel.md)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Interface: IBitmapRendererOptions
|
|
2
|
+
|
|
3
|
+
Options for rendering.
|
|
4
|
+
|
|
5
|
+
## Extends
|
|
6
|
+
|
|
7
|
+
- [`IRendererOptions`](IRendererOptions.md)
|
|
8
|
+
|
|
9
|
+
## Properties
|
|
10
|
+
|
|
11
|
+
### background?
|
|
12
|
+
|
|
13
|
+
> `optional` **background**: `string` \| `Color`
|
|
14
|
+
|
|
15
|
+
Background color.
|
|
16
|
+
|
|
17
|
+
***
|
|
18
|
+
|
|
19
|
+
### foreground?
|
|
20
|
+
|
|
21
|
+
> `optional` **foreground**: `string` \| `Color`
|
|
22
|
+
|
|
23
|
+
Foreground color.
|
|
24
|
+
|
|
25
|
+
***
|
|
26
|
+
|
|
27
|
+
### cellSize?
|
|
28
|
+
|
|
29
|
+
> `optional` **cellSize**: `number`
|
|
30
|
+
|
|
31
|
+
The cell size.
|
|
32
|
+
|
|
33
|
+
#### Inherited from
|
|
34
|
+
|
|
35
|
+
[`IRendererOptions`](IRendererOptions.md).[`cellSize`](IRendererOptions.md#cellsize)
|
|
36
|
+
|
|
37
|
+
***
|
|
38
|
+
|
|
39
|
+
### marginSize?
|
|
40
|
+
|
|
41
|
+
> `optional` **marginSize**: `number`
|
|
42
|
+
|
|
43
|
+
The margin size.
|
|
44
|
+
|
|
45
|
+
#### Inherited from
|
|
46
|
+
|
|
47
|
+
[`IRendererOptions`](IRendererOptions.md).[`marginSize`](IRendererOptions.md#marginsize)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Interface: IRendererOptions
|
|
2
|
+
|
|
3
|
+
Options for rendering.
|
|
4
|
+
|
|
5
|
+
## Extended by
|
|
6
|
+
|
|
7
|
+
- [`IBitmapRendererOptions`](IBitmapRendererOptions.md)
|
|
8
|
+
- [`ITextRendererOptions`](ITextRendererOptions.md)
|
|
9
|
+
|
|
10
|
+
## Properties
|
|
11
|
+
|
|
12
|
+
### cellSize?
|
|
13
|
+
|
|
14
|
+
> `optional` **cellSize**: `number`
|
|
15
|
+
|
|
16
|
+
The cell size.
|
|
17
|
+
|
|
18
|
+
***
|
|
19
|
+
|
|
20
|
+
### marginSize?
|
|
21
|
+
|
|
22
|
+
> `optional` **marginSize**: `number`
|
|
23
|
+
|
|
24
|
+
The margin size.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Interface: ITextRendererOptions
|
|
2
|
+
|
|
3
|
+
Options for rendering as text.
|
|
4
|
+
|
|
5
|
+
## Extends
|
|
6
|
+
|
|
7
|
+
- [`IRendererOptions`](IRendererOptions.md)
|
|
8
|
+
|
|
9
|
+
## Properties
|
|
10
|
+
|
|
11
|
+
### cellSize?
|
|
12
|
+
|
|
13
|
+
> `optional` **cellSize**: `number`
|
|
14
|
+
|
|
15
|
+
The cell size.
|
|
16
|
+
|
|
17
|
+
#### Inherited from
|
|
18
|
+
|
|
19
|
+
[`IRendererOptions`](IRendererOptions.md).[`cellSize`](IRendererOptions.md#cellsize)
|
|
20
|
+
|
|
21
|
+
***
|
|
22
|
+
|
|
23
|
+
### marginSize?
|
|
24
|
+
|
|
25
|
+
> `optional` **marginSize**: `number`
|
|
26
|
+
|
|
27
|
+
The margin size.
|
|
28
|
+
|
|
29
|
+
#### Inherited from
|
|
30
|
+
|
|
31
|
+
[`IRendererOptions`](IRendererOptions.md).[`marginSize`](IRendererOptions.md#marginsize)
|
|
32
|
+
|
|
33
|
+
***
|
|
34
|
+
|
|
35
|
+
### onChar?
|
|
36
|
+
|
|
37
|
+
> `optional` **onChar**: `string`
|
|
38
|
+
|
|
39
|
+
The character to use for on pixels.
|
|
40
|
+
|
|
41
|
+
***
|
|
42
|
+
|
|
43
|
+
### offChar?
|
|
44
|
+
|
|
45
|
+
> `optional` **offChar**: `string`
|
|
46
|
+
|
|
47
|
+
The character to use for off pixels.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Type Alias: ErrorCorrectLevel
|
|
2
|
+
|
|
3
|
+
> **ErrorCorrectLevel**: *typeof* [`ErrorCorrectLevel`](../variables/ErrorCorrectLevel.md)\[keyof *typeof* [`ErrorCorrectLevel`](../variables/ErrorCorrectLevel.md)\]
|
|
4
|
+
|
|
5
|
+
Error correction level to use for the QR Code.
|
|
6
|
+
Based on https://github.com/kazuhikoarase/qrcode-generator/ .
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Variable: ErrorCorrectLevel
|
|
2
|
+
|
|
3
|
+
> `const` **ErrorCorrectLevel**: `object`
|
|
4
|
+
|
|
5
|
+
Error correction level to use for the QR Code.
|
|
6
|
+
Based on https://github.com/kazuhikoarase/qrcode-generator/ .
|
|
7
|
+
|
|
8
|
+
## Type declaration
|
|
9
|
+
|
|
10
|
+
### L
|
|
11
|
+
|
|
12
|
+
> `readonly` **L**: `1` = `1`
|
|
13
|
+
|
|
14
|
+
7% Error correction.
|
|
15
|
+
|
|
16
|
+
### M
|
|
17
|
+
|
|
18
|
+
> `readonly` **M**: `0` = `0`
|
|
19
|
+
|
|
20
|
+
15% Error correction.
|
|
21
|
+
|
|
22
|
+
### Q
|
|
23
|
+
|
|
24
|
+
> `readonly` **Q**: `3` = `3`
|
|
25
|
+
|
|
26
|
+
25% Error correction.
|
|
27
|
+
|
|
28
|
+
### H
|
|
29
|
+
|
|
30
|
+
> `readonly` **H**: `2` = `2`
|
|
31
|
+
|
|
32
|
+
30% Error correction.
|
package/locales/en.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"error": {
|
|
3
|
+
"qr": {
|
|
4
|
+
"typeNumberRange": "The typeNumber parameter should be a number >= 0 and <= 40, it is {typeNumber}",
|
|
5
|
+
"dataOverflow": "There is not enough space in the QR code to store the data, {lengthInBits} > {totalDataCount}, try increasing the typeNumber from {typeNumber}, or use 0 for auto detect",
|
|
6
|
+
"typeNumberOverflow": "There is not enough space in the QR code to store the data, {lengthInBits} > {totalDataCount}, typeNumber cannot be greater than 40"
|
|
7
|
+
},
|
|
8
|
+
"rendererOptions": {
|
|
9
|
+
"cellSizeZero": "The cellSize must be a number > 0, it is \"{cellSize}\"",
|
|
10
|
+
"marginSizeZero": "The marginSize must be a number >= 0, it is \"{marginSize}\""
|
|
11
|
+
},
|
|
12
|
+
"qRAlphaNumeric": {
|
|
13
|
+
"illegalCharacter ": "Illegal character in string \"{value}\""
|
|
14
|
+
},
|
|
15
|
+
"qRNumber": {
|
|
16
|
+
"illegalCharacter ": "Illegal character in string \"{value}\""
|
|
17
|
+
},
|
|
18
|
+
"mathHelper": {
|
|
19
|
+
"lessThanOne ": "The value can not be less than 1, it is \"{value}\""
|
|
20
|
+
},
|
|
21
|
+
"qrHelper": {
|
|
22
|
+
"correctionLevelRange ": "The errorCorrectLevel parameter should be one of the following: \"L\", \"M\", \"Q\", \"H\", it is \"{errorCorrectLevel}\"",
|
|
23
|
+
"modeRange ": "The mode parameter should be one of the following: \"Byte\", \"Numeric\", \"Alphanumeric\", it is \"{mode}\"",
|
|
24
|
+
"maskPatternRange ": "The maskPattern parameter should be a number >= 0 and <= 7, it is \"{maskPattern}\""
|
|
25
|
+
},
|
|
26
|
+
"rSBlock": {
|
|
27
|
+
"correctionLevelRange ": "The errorCorrectLevel parameter should be one of the following: \"L\", \"M\", \"Q\", \"H\", it is \"{errorCorrectLevel}\""
|
|
28
|
+
},
|
|
29
|
+
"qRDataBase": {
|
|
30
|
+
"invalidMode": "Invalid mode {mode} for typeNumber {typeNumber}",
|
|
31
|
+
"invalidTypeNumber": "Invalid typeNumber {typeNumber}, it should be less than <= 40"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@twin.org/qr",
|
|
3
|
+
"version": "0.0.1-next.1",
|
|
4
|
+
"description": "Package for creating QR codes",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/twinfoundation/framework.git",
|
|
8
|
+
"directory": "packages/qr"
|
|
9
|
+
},
|
|
10
|
+
"author": "martyn.janes@iota.org",
|
|
11
|
+
"license": "Apache-2.0",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=20.0.0"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"clean": "rimraf dist coverage",
|
|
18
|
+
"build": "tspc",
|
|
19
|
+
"test": "vitest --run --config ./vitest.config.ts --no-cache",
|
|
20
|
+
"coverage": "vitest --run --coverage --config ./vitest.config.ts --no-cache",
|
|
21
|
+
"bundle:esm": "rollup --config rollup.config.mjs --environment MODULE:esm",
|
|
22
|
+
"bundle:cjs": "rollup --config rollup.config.mjs --environment MODULE:cjs",
|
|
23
|
+
"bundle": "npm run bundle:esm && npm run bundle:cjs",
|
|
24
|
+
"docs:clean": "rimraf docs/reference",
|
|
25
|
+
"docs:generate": "typedoc",
|
|
26
|
+
"docs": "npm run docs:clean && npm run docs:generate",
|
|
27
|
+
"dist": "npm run clean && npm run build && npm run test && npm run bundle && npm run docs"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@twin.org/core": "0.0.1-next.1",
|
|
31
|
+
"@twin.org/image": "0.0.1-next.1",
|
|
32
|
+
"@twin.org/nameof": "next"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@twin.org/nameof-transformer": "next",
|
|
36
|
+
"@vitest/coverage-v8": "2.1.1",
|
|
37
|
+
"copyfiles": "2.4.1",
|
|
38
|
+
"rimraf": "6.0.1",
|
|
39
|
+
"rollup": "4.21.3",
|
|
40
|
+
"rollup-plugin-typescript2": "0.36.0",
|
|
41
|
+
"ts-patch": "3.2.1",
|
|
42
|
+
"typedoc": "0.26.7",
|
|
43
|
+
"typedoc-plugin-markdown": "4.2.7",
|
|
44
|
+
"typescript": "5.6.2",
|
|
45
|
+
"vitest": "2.1.1"
|
|
46
|
+
},
|
|
47
|
+
"main": "./dist/cjs/index.cjs",
|
|
48
|
+
"module": "./dist/esm/index.mjs",
|
|
49
|
+
"types": "./dist/types/index.d.ts",
|
|
50
|
+
"exports": {
|
|
51
|
+
".": {
|
|
52
|
+
"require": "./dist/cjs/index.cjs",
|
|
53
|
+
"import": "./dist/esm/index.mjs",
|
|
54
|
+
"types": "./dist/types/index.d.ts"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"files": [
|
|
58
|
+
"dist/cjs",
|
|
59
|
+
"dist/esm",
|
|
60
|
+
"dist/types",
|
|
61
|
+
"locales",
|
|
62
|
+
"docs"
|
|
63
|
+
]
|
|
64
|
+
}
|