Skip to content

Commit

Permalink
Merge pull request #4 from Sleavely/1.0-rc
Browse files Browse the repository at this point in the history
1.0 release candidate
  • Loading branch information
Sleavely committed Dec 10, 2019
2 parents 211d24d + 8115efa commit 4a98f53
Show file tree
Hide file tree
Showing 25 changed files with 7,679 additions and 385 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage/
dist/
node_modules/
10 changes: 10 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "standard",
"rules": {
"comma-dangle": ["error", "always-multiline"],
"no-trailing-spaces": "error"
},
"env": {
"jest": true
}
}
155 changes: 154 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,154 @@
node_modules
# Created by https://www.gitignore.io/api/node,linux,macos,windows
# Edit at https://www.gitignore.io/?templates=node,linux,macos,windows

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.gitignore.io/api/node,linux,macos,windows
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
language: node_js
node_js:
- "0.8"
- "0.10"
- "0.11"
- "5"
- "6"
- "8"
- "10"
- "12"
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

(MIT License)

Copyright (c) 2016 Joakim Hedlund
Copyright (c) 2019 Joakim Hedlund

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:

Expand Down
13 changes: 0 additions & 13 deletions MakeFile

This file was deleted.

105 changes: 66 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# Bark JS

Parse barcode inputs into a unified format.

Parse barcode inputs into a unified GS1-128 format.

## What it does

Bark normalises and treats all barcode inputs as the GS1-128 format.

Bark attempts to figure out which standard the string uses (EAN-8, EAN-13, ITF-14, GS1-128, etc.) and extracts the relevant data. It is accessed by querying Bark for the GS1 Application Identifier's Data Title. For a reference of the Data Titles, see the right-most column here: [GS1 General Specifications Section 3: GS1 Application Identifier Definitions (PDF)](http://www.gs1.se/globalassets/gs1-application-identifiers-in-numerical-order.pdf)
Bark parses GS1-128 barcodes and extracts the catalogued data according to the [GS1 General Specifications (PDF)](https://www.gs1.org/sites/default/files/docs/barcodes/GS1_General_Specifications.pdf)

## How to use it

Expand All @@ -20,48 +17,78 @@ npm install bark-js
Let's pretend we scan [the box in this photo](https://goo.gl/photos/HCE7WrNHDKvQL5ei8).

```javascript
var Bark = require('bark-js');
var yourInput = '015730033004265615171019';

console.log(Bark.parse( yourInput )); // parse returns the GTIN, or undefined

// Always set after successful parse
console.log(Bark.type); // GS1-128

// These Application Identifiers (AIs) exist in the barcode
console.log(Bark.get('GTIN')); // 57300330042656
console.log(Bark.get('BEST BEFORE')); // 171019

// The SERIAL AI is not set on this barcode
console.log(Bark.get('SERIAL')); // null
const bark = require('bark-js')

bark( '015730033004265615171019' )
// returns:
{
symbology: 'unknown',
elements: [
{
ai: '01',
title: 'GTIN',
value: '57300330042656',
raw: '57300330042656'
},
{
ai: '15',
title: 'BEST BEFORE or BEST BY',
value: '2017-10-19',
raw: '171019'
}
],
originalBarcode: '015730033004265615171019'
}
```

If you are going to scan regular barcodes too (e.g. EAN-13, ITF-14, etc.) and only want to get the GTIN, we suggest you use the `id()` method.

The important distinction from `parse()` is that `id()` will return the string itself if the barcode was not interpreted as GS1-128.
If you are going to scan simple barcodes too (e.g. UPC-A, EAN-13, ITF-14, etc.) you can set the `assumeGtin` option to convert shorter barcodes (11-14 digits) into GS1-128 codes with a GTIN AI:

```javascript
var Bark = require('bark-js');
var yourInput = '015730033004265615171019';
const bark = require('bark-js')

bark( '09002490100094', { assumeGtin: true } )
// returns:
{
symbology: 'unknown',
elements: [
{
ai: '01',
title: 'GTIN',
value: '09002490100094',
raw: '09002490100094'
}
],
originalBarcode: '0109002490100094'
}
```

console.log(Bark.id( yourInput )); // 57300330042656
Depending on your barcode reader, you may receive FNC characters that arent the `<GS>` (ASCII 29) character. To set the group separator yourself, pass the `fnc` option:

yourInput = 'Foo-And-Oth3r-Bars';
console.log(Bark.id( yourInput )); // Foo-And-Oth3r-Bars
```javascript
const bark = require('bark-js')

bark( '10FRIDGEX0109002490100094', { fnc: 'X' } )
// returns:
{
symbology: 'unknown',
elements: [
{
ai: '10',
title: 'BATCH/LOT',
value: 'FRIDGE',
raw: 'FRIDGEX'
},
{
ai: '01',
title: 'GTIN',
value: '09002490100094',
raw: '09002490100094'
}
],
originalBarcode: '10FRIDGEX0109002490100094'
}
```

## Contributing

Pull requests to Sleavely/Bark-JS are encouraged and appreciated!

## Licence

(MIT License)

Copyright (c) 2017 Joakim Hedlund

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.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./lib/bark');
module.exports = exports = require('./src/index')
Loading

0 comments on commit 4a98f53

Please sign in to comment.