@juit/librebarcode 1.0.0

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-ASL.md ADDED
@@ -0,0 +1,211 @@
1
+ # Apache License
2
+
3
+ Version 2.0, January 2004
4
+
5
+ [http://www.apache.org/licenses/](http://www.apache.org/licenses/)
6
+
7
+ ##### TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ ### 1. Definitions.
10
+
11
+ "**License**" shall mean the terms and conditions for use, reproduction,
12
+ and distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "**Licensor**" shall mean the copyright owner or entity authorized by
15
+ the copyright owner that is granting the License.
16
+
17
+ "**Legal Entity**" shall mean the union of the acting entity and all
18
+ other entities that control, are controlled by, or are under common
19
+ control with that entity. For the purposes of this definition,
20
+ "**control**" means **(i)** the power, direct or indirect, to cause the
21
+ direction or management of such entity, whether by contract or
22
+ otherwise, _or_ **(ii)** ownership of fifty percent (50%) or more of
23
+ the outstanding shares, _or_ **(iii)** beneficial ownership of such
24
+ entity.
25
+
26
+ "**You**" (or "**Your**") shall mean an individual or Legal Entity
27
+ exercising permissions granted by this License.
28
+
29
+ "**Source**" form shall mean the preferred form for making
30
+ modifications, including but not limited to software source code,
31
+ documentation source, and configuration files.
32
+
33
+ "**Object**" form shall mean any form resulting from mechanical
34
+ transformation or translation of a Source form, including but not
35
+ limited to compiled object code, generated documentation, and
36
+ conversions to other media types.
37
+
38
+ "**Work**" shall mean the work of authorship, whether in Source or
39
+ Object form, made available under the License, as indicated by a
40
+ copyright notice that is included in or attached to the work (an example
41
+ is provided in the Appendix below).
42
+
43
+ "**Derivative Works**" shall mean any work, whether in Source or Object
44
+ form, that is based on (or derived from) the Work and for which the
45
+ editorial revisions, annotations, elaborations, or other modifications
46
+ represent, as a whole, an original work of authorship. For the purposes
47
+ of this License, Derivative Works shall not include works that remain
48
+ separable from, or merely link (or bind by name) to the interfaces of,
49
+ the Work and Derivative Works thereof.
50
+
51
+ "**Contribution**" shall mean any work of authorship, including the
52
+ original version of the Work and any modifications or additions to that
53
+ Work or Derivative Works thereof, that is intentionally submitted to
54
+ Licensor for inclusion in the Work by the copyright owner or by an
55
+ individual or Legal Entity authorized to submit on behalf of the
56
+ copyright owner. For the purposes of this definition, "**submitted**"
57
+ means any form of electronic, verbal, or written communication sent to
58
+ the Licensor or its representatives, including but not limited to
59
+ communication on electronic mailing lists, source code control systems,
60
+ and issue tracking systems that are managed by, or on behalf of, the
61
+ Licensor for the purpose of discussing and improving the Work, but
62
+ excluding communication that is conspicuously marked or otherwise
63
+ designated in writing by the copyright owner as "**Not a
64
+ Contribution**".
65
+
66
+ "**Contributor**" shall mean Licensor and any individual or Legal Entity
67
+ on behalf of whom a Contribution has been received by Licensor and
68
+ subsequently incorporated within the Work.
69
+
70
+ ### 2. Grant of Copyright License.
71
+
72
+ Subject to the terms and conditions of this License, each Contributor
73
+ hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
74
+ royalty-free, irrevocable copyright license to reproduce, prepare
75
+ Derivative Works of, publicly display, publicly perform, sublicense,
76
+ and distribute the Work and such Derivative Works in Source or Object
77
+ form.
78
+
79
+ ### 3. Grant of Patent License.
80
+
81
+ Subject to the terms and conditions of this License, each Contributor
82
+ hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
83
+ royalty-free, irrevocable (except as stated in this section) patent
84
+ license to make, have made, use, offer to sell, sell, import, and
85
+ otherwise transfer the Work, where such license applies only to those
86
+ patent claims licensable by such Contributor that are necessarily
87
+ infringed by their Contribution(s) alone or by combination of their
88
+ Contribution(s) with the Work to which such Contribution(s) was
89
+ submitted. If You institute patent litigation against any entity
90
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
91
+ the Work or a Contribution incorporated within the Work constitutes
92
+ direct or contributory patent infringement, then any patent licenses
93
+ granted to You under this License for that Work shall terminate as of
94
+ the date such litigation is filed.
95
+
96
+ ### 4. Redistribution.
97
+
98
+ You may reproduce and distribute copies of the Work or Derivative Works
99
+ thereof in any medium, with or without modifications, and in Source or
100
+ Object form, provided that You meet the following conditions:
101
+
102
+ <ol type="a">
103
+ <li>You must give any other recipients of the Work or Derivative Works
104
+ a copy of this License; and
105
+ <li>You must cause any modified files to carry prominent notices
106
+ stating that You changed the files; and
107
+ <li>You must retain, in the Source form of any Derivative Works that
108
+ You distribute, all copyright, patent, trademark, and attribution
109
+ notices from the Source form of the Work, excluding those notices
110
+ that do not pertain to any part of the Derivative Works; and
111
+ <li>If the Work includes a "NOTICE" text file as part of its
112
+ distribution, then any Derivative Works that You distribute must
113
+ include a readable copy of the attribution notices contained within
114
+ such NOTICE file, excluding those notices that do not pertain to any
115
+ part of the Derivative Works, in at least one of the following
116
+ places: within a NOTICE text file distributed as part of the
117
+ Derivative Works; within the Source form or documentation, if
118
+ provided along with the Derivative Works; or, within a display
119
+ generated by the Derivative Works, if and wherever such third-party
120
+ notices normally appear. The contents of the NOTICE file are for
121
+ informational purposes only and do not modify the License. You may
122
+ add Your own attribution notices within Derivative Works that You
123
+ distribute, alongside or as an addendum to the NOTICE text from the
124
+ Work, provided that such additional attribution notices cannot be
125
+ construed as modifying the License.
126
+ </ol>
127
+
128
+ You may add Your own copyright statement to Your modifications and may
129
+ provide additional or different license terms and conditions for use,
130
+ reproduction, or distribution of Your modifications, or for any such
131
+ Derivative Works as a whole, provided Your use, reproduction, and
132
+ distribution of the Work otherwise complies with the conditions stated
133
+ in this License.
134
+
135
+ ### 5. Submission of Contributions.
136
+
137
+ Unless You explicitly state otherwise, any Contribution intentionally
138
+ submitted for inclusion in the Work by You to the Licensor shall be
139
+ under the terms and conditions of this License, without any additional
140
+ terms or conditions. Notwithstanding the above, nothing herein shall
141
+ supersede or modify the terms of any separate license agreement you may
142
+ have executed with Licensor regarding such Contributions.
143
+
144
+ ### 6. Trademarks.
145
+
146
+ This License does not grant permission to use the trade names,
147
+ trademarks, service marks, or product names of the Licensor, except as
148
+ required for reasonable and customary use in describing the origin of
149
+ the Work and reproducing the content of the NOTICE file.
150
+
151
+ ### 7. Disclaimer of Warranty.
152
+
153
+ Unless required by applicable law or agreed to in writing, Licensor
154
+ provides the Work (and each Contributor provides its Contributions) on
155
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
156
+ express or implied, including, without limitation, any warranties or
157
+ conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR
158
+ A PARTICULAR PURPOSE. You are solely responsible for determining the
159
+ appropriateness of using or redistributing the Work and assume any risks
160
+ associated with Your exercise of permissions under this License.
161
+
162
+ ### 8. Limitation of Liability.
163
+
164
+ In no event and under no legal theory, whether in tort (including
165
+ negligence), contract, or otherwise, unless required by applicable law
166
+ (such as deliberate and grossly negligent acts) or agreed to in writing,
167
+ shall any Contributor be liable to You for damages, including any
168
+ direct, indirect, special, incidental, or consequential damages of any
169
+ character arising as a result of this License or out of the use or
170
+ inability to use the Work (including but not limited to damages for loss
171
+ of goodwill, work stoppage, computer failure or malfunction, or any and
172
+ all other commercial damages or losses), even if such Contributor has
173
+ been advised of the possibility of such damages.
174
+
175
+ ### 9. Accepting Warranty or Additional Liability.
176
+
177
+ While redistributing the Work or Derivative Works thereof, You may
178
+ choose to offer, and charge a fee for, acceptance of support, warranty,
179
+ indemnity, or other liability obligations and/or rights consistent with
180
+ this License. However, in accepting such obligations, You may act only
181
+ on Your own behalf and on Your sole responsibility, not on behalf of any
182
+ other Contributor, and only if You agree to indemnify, defend, and hold
183
+ each Contributor harmless for any liability incurred by, or claims
184
+ asserted against, such Contributor by reason of your accepting any
185
+ such warranty or additional liability.
186
+
187
+ ##### END OF TERMS AND CONDITIONS
188
+
189
+ ## APPENDIX: How to apply the Apache License to your work.
190
+
191
+ To apply the Apache License to your work, attach the following
192
+ boilerplate notice, with the fields enclosed by brackets "[]"
193
+ replaced with your own identifying information. (Don't include the
194
+ brackets!) The text should be enclosed in the appropriate comment
195
+ syntax for the file format. We also recommend that a file or class name
196
+ and description of purpose be included on the same "printed page" as the
197
+ copyright notice for easier identification within third-party archives.
198
+
199
+ > #### Copyright [yyyy] [name of copyright owner]
200
+ >
201
+ > Licensed under the Apache License, Version 2.0 (the "License");
202
+ > you may not use this file except in compliance with the License.
203
+ > You may obtain a copy of the License at
204
+ >
205
+ > [http://www.apache.org/licenses/](http://www.apache.org/licenses/)
206
+ >
207
+ > Unless required by applicable law or agreed to in writing, software
208
+ > distributed under the License is distributed on an "AS IS" BASIS,
209
+ > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
210
+ > See the License for the specific language governing permissions and
211
+ > limitations under the License.
package/LICENSE-OFL.md ADDED
@@ -0,0 +1,97 @@
1
+ Copyright 2017-2019 The Libre Barcode Project Authors
2
+ (https://github.com/graphicore/librebarcode)
3
+
4
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
5
+ This license is copied below, and is also available with a FAQ at:
6
+ https://scripts.sil.org/OFL
7
+
8
+
9
+ # SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+
11
+ ### PREAMBLE
12
+
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ ### DEFINITIONS
29
+
30
+ "Font Software" refers to the set of files released by the Copyright
31
+ Holder(s) under this license and clearly marked as such. This may
32
+ include source files, build scripts and documentation.
33
+
34
+ "Reserved Font Name" refers to any names specified as such after the
35
+ copyright statement(s).
36
+
37
+ "Original Version" refers to the collection of Font Software components as
38
+ distributed by the Copyright Holder(s).
39
+
40
+ "Modified Version" refers to any derivative made by adding to, deleting,
41
+ or substituting -- in part or in whole -- any of the components of the
42
+ Original Version, by changing formats or by porting the Font Software to a
43
+ new environment.
44
+
45
+ "Author" refers to any designer, engineer, programmer, technical
46
+ writer or other person who contributed to the Font Software.
47
+
48
+ ### PERMISSION & CONDITIONS
49
+
50
+ Permission is hereby granted, free of charge, to any person obtaining
51
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
52
+ redistribute, and sell modified and unmodified copies of the Font
53
+ Software, subject to the following conditions:
54
+
55
+ 1) Neither the Font Software nor any of its individual components,
56
+ in Original or Modified Versions, may be sold by itself.
57
+
58
+ 2) Original or Modified Versions of the Font Software may be bundled,
59
+ redistributed and/or sold with any software, provided that each copy
60
+ contains the above copyright notice and this license. These can be
61
+ included either as stand-alone text files, human-readable headers or
62
+ in the appropriate machine-readable metadata fields within text or
63
+ binary files as long as those fields can be easily viewed by the user.
64
+
65
+ 3) No Modified Version of the Font Software may use the Reserved Font
66
+ Name(s) unless explicit written permission is granted by the corresponding
67
+ Copyright Holder. This restriction only applies to the primary font name as
68
+ presented to the users.
69
+
70
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
71
+ Software shall not be used to promote, endorse or advertise any
72
+ Modified Version, except to acknowledge the contribution(s) of the
73
+ Copyright Holder(s) and the Author(s) or with their explicit written
74
+ permission.
75
+
76
+ 5) The Font Software, modified or unmodified, in part or in whole,
77
+ must be distributed entirely under this license, and must not be
78
+ distributed under any other license. The requirement for fonts to
79
+ remain under this license does not apply to any document created
80
+ using the Font Software.
81
+
82
+ ### TERMINATION
83
+
84
+ This license becomes null and void if any of the above conditions are
85
+ not met.
86
+
87
+ ### DISCLAIMER
88
+
89
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
90
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
91
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
92
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
93
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
94
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
95
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
96
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
97
+ OTHER DEALINGS IN THE FONT SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,126 @@
1
+ LibreBarcode Fonts and Encoders
2
+ ===============================
3
+
4
+ This project provides two encoders for the **Code128** and **EAN** fonts
5
+ developed by the [LibreBarcode](https://github.com/graphicore/librebarcode)
6
+ project.
7
+
8
+ * [Code128](#code128)
9
+ * [EAN-13, UPC/A and EAN-8](#ean-13-upca-ean-8)
10
+ * [EAN/GS-1 Checksums](#eangs-1-checksums)
11
+ * [Font Assets](#font-assets)
12
+ * [License (encoders)](LICENSE-ASL.md)
13
+ * [License (fonts)](LICENSE-OFL.md)
14
+
15
+ Code128
16
+ -------
17
+
18
+ The `code128()` encoder takes a string (the barcode to be encoded) and returns
19
+ a string that can be fed to the **Code128** font to correctly display the
20
+ barcode.
21
+
22
+ It attempts to calculate the shortest possible barcode given the input, and
23
+ supports encoding of _all_ 128 characters in the US-ASCII range, plus support
24
+ for the Code128 specific `FNC1`, `FNC2`, `FNC3` and `FNC4` characters.
25
+
26
+ Control characters can be entered directly in the string to encode using their
27
+ JavaScript equivalent (e.g. `\n` for newline, `\x1D` for the group separator)
28
+ and the four _speial_ characters `\uf001`, `\uf002`, `\uf003`, `\uf004`, can
29
+ be used to encode `FNC1`, `FNC2`, `FNC3` and `FNC4` respectively.
30
+
31
+ Those are also exported by the library as `FNC1`, `FNC2`, `FNC3` and `FNC4`.
32
+
33
+ ```typescript
34
+ import { FNC1, code128 } from '@juit/librebarcode'
35
+
36
+ const gs1 =
37
+ FNC1 + // FNC1 indicates this is a standard "GS1" barcode
38
+ '02' + // application identifier "02": Identification of trade items
39
+ '05411361083574' + // Ardo Spring Onions, 250g
40
+ '15' + // application identifier "15": Best before date (YYMMDD)
41
+ '250929' + // Expires 29.09.2025
42
+ '37' + // application identifier "37": Count of trade items
43
+ '144' // Contains 144 packages
44
+
45
+ const encoded = code128(gs1)
46
+ // now you can feed the "encoded" string to the font!
47
+ ```
48
+
49
+
50
+
51
+ EAN-13, UPC/A, EAN-8
52
+ --------------------
53
+
54
+ Similarly to **Code128**, but for EAN the `ean()` encoder takes a string of
55
+ digits and produces a a string that can be fed to the **EAN** font to correctly
56
+ display the barcode.
57
+
58
+ The string to encode should have one of the following lengths:
59
+
60
+ * 13 digits: standard EAN-13 barcode
61
+ * 12 digits: standard UPC/A barcode
62
+ * 8 digits: standard EAN-8 barcode
63
+
64
+ The encoder also supports the standard 2-digits and 5-digits supplemental
65
+ barcodes and the lengths will then become:
66
+
67
+ * 18 digits: standard EAN-13 barcode with 5-digits supplemental barcode
68
+ * 17 digits: standard UPC/A barcode with 5-digits supplemental barcode
69
+ * 15 digits: standard EAN-13 barcode with 2-digits supplemental barcode
70
+ * 12 digits: standard UPC/A barcode with 2-digits supplemental barcode
71
+ * 5 digits: **only** the 5-digits supplemental barcode
72
+ * 2 digits: **only** the 2-digits supplemental barcode
73
+
74
+ ```typescript
75
+ import { ean } from '@juit/librebarcode'
76
+
77
+ const encoded = ean('5411361083574') // EAN-13 barcode for Ardo Spring Onions
78
+ // now you can feed the "encoded" string to the font!
79
+ ```
80
+
81
+
82
+
83
+ EAN/GS-1 Checksums
84
+ -------------------
85
+
86
+ Unlike the _"compatible"_ EAN-13 encoder developed and provided by the
87
+ [LibreBarcode](https://github.com/graphicore/librebarcode) project, this
88
+ library doesn't try to calculate the EAN-13 checksum while encoding strings.
89
+
90
+ A separate function `checksum()` can be used to calculate the checksum for
91
+ an *arbitrary* sequence of digits according to the EAN/GS-1 calculation rules:
92
+
93
+ ```typescript
94
+ import { ean } from '@juit/librebarcode'
95
+
96
+ const checksum = ean('541136108357')
97
+ // here checksum will be the number 4
98
+ ```
99
+
100
+
101
+
102
+ Font Assets
103
+ -----------
104
+
105
+ Embedded with this library, you can find three fonts for your encoding needs:
106
+
107
+ * `./assets/LibreBarcode128-Regular.ttf`: the regular **Code128** font without
108
+ any underlying text. Use this one for GS1 barcodes, as encoding of the `FNC1`
109
+ character messes up the text, and anyhow the text should be represented as
110
+ `(xx)yyyyyyyyyy(zz)wwwwwwww...` (application identifiers with parentheses).
111
+ * `./assets/LibreBarcode128Text-Regular.ttf`: the **Code128** font with
112
+ underlying text. Use this one for standard Code128 barcodes.
113
+ * `./assets/LibreBarcodeEAN13Text-Regular.ttf`: the **EAN** font.
114
+
115
+ You can find their file locations in the `fonts` export:
116
+
117
+ ```typescript
118
+ import { fonts } from '@juit/librebarcode'
119
+
120
+ // Here fonts will look somewhat similar to
121
+ // {
122
+ // 'LibreBarcode128-Regular.ttf': '... path on your disk .../LibreBarcode128-Regular.ttf',
123
+ // 'LibreBarcode128Text-Regular.ttf': '... path on your disk .../LibreBarcode128Text-Regular.ttf',
124
+ // 'LibreBarcodeEAN13Text-Regular.ttf': '... path on your disk .../LibreBarcodeEAN13Text-Regular.ttf'
125
+ // }
126
+ ```
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=checksum.cjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "mappings": "",
5
+ "names": []
6
+ }
File without changes
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=checksum.mjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "mappings": "",
5
+ "names": []
6
+ }