-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit aec2cca
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,4 @@ | ||
# Used by "mix format" | ||
[ | ||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] | ||
] |
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,121 @@ | ||
name: mix test | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
mix-format: | ||
name: Check formatting | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Elixir | ||
uses: erlef/setup-beam@v1 | ||
with: | ||
otp-version: '24.0' | ||
elixir-version: '1.12.2' | ||
|
||
- name: Check formatting | ||
run: mix format --check-formatted | ||
|
||
dialyzer: | ||
name: Dialyzer | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Elixir | ||
uses: erlef/setup-beam@v1 | ||
with: | ||
otp-version: '24.0' | ||
elixir-version: '1.12.2' | ||
|
||
- name: Retrieve cached mix deps | ||
uses: actions/cache@v2 | ||
with: | ||
path: deps | ||
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} | ||
restore-keys: | | ||
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix- | ||
- name: Retrieve cached _build | ||
uses: actions/cache@v2 | ||
with: | ||
path: _build | ||
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-build-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-build- | ||
- name: Retrieve cached PLT | ||
uses: actions/cache@v2 | ||
with: | ||
path: .dialyzer | ||
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-dialyzer-${{ hashFiles('**/mix.lock') }}-${{ hashFiles('**/lib/*.ex') }} | ||
restore-keys: | | ||
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-dialyzer-${{ hashFiles('**/mix.lock') }}-${{ hashFiles('**/lib/*.ex') }} | ||
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-dialyzer-${{ hashFiles('**/mix.lock') }}- | ||
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-dialyzer- | ||
- name: Install dependencies | ||
run: | | ||
mix local.rebar --force | ||
mix local.hex --force | ||
mix deps.get | ||
mix deps.compile | ||
- name: Run Dialyzer | ||
run: mix dialyzer --format short 2>&1 | ||
|
||
test-elixir: | ||
name: Test with OTP ${{ matrix.otp }} and Elixir ${{ matrix.elixir }} | ||
runs-on: ubuntu-latest | ||
|
||
env: | ||
MIX_ENV: test | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- otp: '23.0' | ||
elixir: '1.12.2' | ||
- otp: '24.0' | ||
elixir: '1.12.2' | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Elixir | ||
uses: erlef/setup-beam@v1 | ||
with: | ||
otp-version: ${{ matrix.otp }} | ||
elixir-version: ${{ matrix.elixir }} | ||
|
||
- name: Retrieve cached mix deps | ||
uses: actions/cache@v2 | ||
with: | ||
path: deps | ||
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} | ||
restore-keys: | | ||
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix- | ||
- name: Retrieve cached _build | ||
uses: actions/cache@v2 | ||
with: | ||
path: _build | ||
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-build-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-build- | ||
- name: Install dependencies | ||
run: | | ||
mix local.rebar --force | ||
mix local.hex --force | ||
mix deps.get | ||
mix deps.compile | ||
- name: Compile project | ||
run: mix compile | ||
|
||
- name: Run tests | ||
run: mix test |
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,29 @@ | ||
# The directory Mix will write compiled artifacts to. | ||
/_build/ | ||
|
||
# If you run "mix test --cover", coverage assets end up here. | ||
/cover/ | ||
|
||
# The directory Mix downloads your dependencies sources to. | ||
/deps/ | ||
|
||
# Where third-party dependencies like ExDoc output generated docs. | ||
/doc/ | ||
|
||
# Ignore .fetch files in case you like to edit your project deps locally. | ||
/.fetch | ||
|
||
# If the VM crashes, it generates a dump, let's ignore it too. | ||
erl_crash.dump | ||
|
||
# Also ignore archive artifacts (built via "mix archive.build"). | ||
*.ez | ||
|
||
# Ignore package tarball (built via "mix hex.build"). | ||
barcode_generator-*.tar | ||
|
||
# Temporary files, for example, from tests. | ||
/tmp/ | ||
|
||
# Dialyzer | ||
/.dialyzer |
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,2 @@ | ||
elixir 1.12.2-otp-24 | ||
erlang 24.0.3 |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021-present Jeroen Visser | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,86 @@ | ||
# BarcodeGenerator | ||
|
||
[Online documentation](https://hexdocs.pm/barcode_generator) | [Hex.pm](https://hex.pm/packages/barcode_generator) | ||
|
||
<!-- MDOC !--> | ||
|
||
`BarcodeGenerator` generates a list of barcodes from a given start and end barcode. | ||
|
||
This library allows you to generate GTIN barcodes by passing it the first and last barcode of a | ||
range. | ||
|
||
## Examples | ||
|
||
### Validating | ||
|
||
`BarcodeGenerator` allows simple check-digit validation for GTIN barcodes, both in binary and | ||
numeric format: | ||
|
||
```elixir | ||
BarcodeGenerator.valid?("6291041500206") | ||
# true | ||
|
||
BarcodeGenerator.valid?(6291041500206) | ||
# true | ||
|
||
BarcodeGenerator.valid?("6291041500200") | ||
# false | ||
|
||
BarcodeGenerator.valid?(6291041500200) | ||
# false | ||
``` | ||
|
||
### Generating | ||
|
||
`BarcodeGenerator` can generate barcodes in three different ways: | ||
|
||
#### Plain list | ||
|
||
`BarcodeGenerator.generate/2` generates barcodes in a simple list format. | ||
|
||
```elixir | ||
BarcodeGenerator.generate(6_291_041_500_200, 6_291_041_500_299) | ||
``` | ||
|
||
#### Stream | ||
|
||
`BarcodeGenerator.generate_stream/2` returns a `Stream` that can be enumerated. Barcodes are | ||
generated as the stream is consumed, reducing memory footprint. | ||
|
||
```elixir | ||
stream = BarcodeGenerator.generate_stream(6_291_041_500_200, 6_291_041_500_299) | ||
barcodes = Enum.to_list(stream) | ||
``` | ||
|
||
#### Flow (optional dependency) | ||
|
||
`BarcodeGenerator.generate_flow/3` returns a `Flow`, but requires that | ||
[`flow`](https://hex.pm/packages/flow) is present as dependency. Generating barcodes using Flow is | ||
heavily optimized to use all available resources to generate as quickly as possible. | ||
|
||
`BarcodeGenerator.generate_flow/3` accepts an optional third argument, `opts`, which is passed to | ||
`Flow.from_enumerable/2`, and defaults to `max_demand: 1000`. | ||
|
||
```elixir | ||
# Assuming `{:flow, "~> 1.0"}` is in mix.exs | ||
flow = BarcodeGenerator.generate_flow(6_291_041_500_200, 6_291_041_500_299) | ||
barcodes = Enum.to_list(flow) | ||
``` | ||
|
||
<!-- MDOC !--> | ||
|
||
## Installation | ||
|
||
Add `barcode_generator` to your list of dependencies in `mix.exs`: | ||
|
||
```elixir | ||
def deps do | ||
[{:barcode_generator, "~> 1.0.0"}] | ||
end | ||
``` | ||
|
||
## License | ||
|
||
This library is MIT licensed. See the | ||
[LICENSE](https://raw.github.com/jeroenvisser101/barcode_generator/main/LICENSE) | ||
file in this repository for details. |
Oops, something went wrong.