{"id":15680290,"url":"https://github.com/denyncrawford/barcode-scanner","last_synced_at":"2025-09-21T02:02:26.956Z","repository":{"id":62422137,"uuid":"377664426","full_name":"denyncrawford/barcode-scanner","owner":"denyncrawford","description":"Deno native barcode scanner driver","archived":false,"fork":false,"pushed_at":"2021-06-19T23:02:53.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-05T11:38:05.319Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/denyncrawford.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-17T00:47:54.000Z","updated_at":"2024-07-30T20:48:37.000Z","dependencies_parsed_at":"2022-11-01T17:32:44.173Z","dependency_job_id":null,"html_url":"https://github.com/denyncrawford/barcode-scanner","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denyncrawford%2Fbarcode-scanner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denyncrawford%2Fbarcode-scanner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denyncrawford%2Fbarcode-scanner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denyncrawford%2Fbarcode-scanner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/denyncrawford","download_url":"https://codeload.github.com/denyncrawford/barcode-scanner/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246300702,"owners_count":20755412,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T16:41:20.705Z","updated_at":"2025-09-21T02:02:26.849Z","avatar_url":"https://github.com/denyncrawford.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Barcode Scanner \n\nIt is a simple utility inspired by [simple-barcode-scanner](https://github.com/hadeeb/simple-barcode-scanner) but made as a native and global keyboard scanner driver for Deno, this means that it doesn't depend on any browser and it listens even when no GUI/UI/TERMINAL (stdin) is focused. \n\nMost barcode scanners act like a keyboard, Barcode Scanner handles this by listening for native events without using the DOM API. This is useful for scanning without focusing on any screen and works for multiple devices.\n\n### Why?\n\nI needed a way to use multiple scanners on a PC without depending on one window being focused. It is not viable / reliable to use on GUIs and browser running on machines used by several users at time.\n\n**Don't be scare!** Barcode Scanner is pretty simple too and it can be used with a single scanner on a simple app :D, but with the security that data is not getting lost anymore.\n\n### How?\n\nBarcode scanners are HID devices also, but there's one trick, they are **FORBIDEN** by some systems... Basically they doesn't allow HID connections for keyboards and mouses for security reasons. So while looking for a solution I found that it is not that useful and we can't take a direct connection from the device. \n\n**So, how it is native?**: **We use [GKM](https://github.com/denyncrawford/deno-gkm)** to capture native/global keys and keybindings events. This is because neither Node or Deno support native events for keyboards and mouses. Anyway, it is incredibly fast as well. \n\n##  📦 Import\n\n```javascript\nimport BarcodeScanner from \"https://deno.land/x/barcode_scanner@1.0.0/mod.ts\";\n```\n\n## 🖥️ Usage\n\nYou can use NBS as a global listener or as a dedicated device listener.\n\n### Basic (global):\n\n\u003e This will listen to all devices and will catch all codes from the multiple emitting devices. This is the way if you have just one device or if your device doesn't allow prefixing. \n\n```javascript\nimport BarcodeScanner from \"./mod.ts\";\n\nconst options = {...foo}\n\nconst scanner = new BarcodeScanner(options);\n\n// Add a global listener\n\nfor await (const code of scanner.reader()) {\n  console.log(code)\n}\n\n// Stop the listener\nscanner.off();\n```\n\n### Dedicated device:\n\nAs I said before, some devices allow code prefixing functions and you can use it to scope the NBS events.\n\nTo do this, you have to prefix your device with your chosen device ID string and then specify it at `options.devicePrefix`.\n\n\u003e **Note**: NBS doesn't prefix your device, you must use one that does. Please read your device user guide. \n\n```javascript\nimport BarcodeScanner from \"./mod.ts\";\n\nconst options = {\n  devicePrefix: 'id1'\n}\n\nconst scanner = new BarcodeScanner(options);\n\n// Add a global device scoped listener\nfor await (const code of scanner.reader()) {\n  // This only works for the device(s) prefixed with id\n  console.log(code)\n}\n// Remove the listener\nscanner.off();\n```\n\n\u003e **Note**: We un-prefix the code for you ;) you can log it as clean as it is on the paper.\n\n# EventEmitter API deprecation\n\n**Please note** that node and browser versións uses an EventEmitter like API, it is deprecated now and we are aiming the usage of Deno's way. It is compatible just with the deno stream API, out of the box. **If you want to use it as before (with the events API) you must see the next example**:\n\n```typescript\nimport Readable from 'https://deno.land/std@0.99.0/node/_stream/readable.ts';\nimport BarcodeScanner from '../mod.ts'\n\nconst scanner = Readable.from(new BarcodeScanner({\n  endKeys: ['Intro', 'Enter']\n}).reader());\n\nscanner.on('data', (code: string) =\u003e {\n  console.log(code)\n});\n```\n\n# 🧰 API\n\n### BarcodeScanner\nCreates an instance of Scanner to use the code events.\n\n**Parameters**\n\n- `Options?` **Object**\n\n  - `latency` **Number** Max time duration (in ms) between consecutive inputs\n\n    _default: `50`_\n\n  - `minLength` **Number** Min length of a valid barcode\n\n    _default: `3`_\n\n  - `endKeys` **string** | **Array\u003cstring\u003e** Key name indicating end of barcode\n\n    Refer [Key Values | MDN](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)\n\n    _default: `[\"Return\"]`_\n\n  - `validKey` **RegExp** Regular expression to check for a valid key in barcode\n\n    Refer [Key Values | MDN](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)\n\n    _default: `/^\\w$/`_\n  \n  - `devicePrefix` **string** Prefix ID for device scoped events\n\n    _default: `null`\n\n  \u003e **Please note**: `options.endKeys` is always \"Return\", if you know that your device or one of them have a different endKey, you must add those endKeys into the array. Eg: `['L', 'F1', ...]`.\n\nReturns **Scanner**\n\n### Scanner\n\n- `reader` **Async iterator**: Starts listening for barcode scans.\n  \n  _yields: Event Object\n\n- `off` **Function**: Stop listening for barcode scans and remove the listener.\n  _returns: `void`\n  \n# 🌐 Using on web and node\n\nPlease if you are on browser use [simple-barcode-scanner](https://github.com/hadeeb/simple-barcode-scanner)\n\nIf you want the multi-device update use my fork [@denyncrawford/simple-barcode-scanner](https://github.com/denyncrawford/simple-barcode-scanner/tree/device-instance)\n\nPlease check [native-barcode-scanner](https://github.com/denyncrawford/native-barcode-scanner) for using in node.\n\n# 🔥 Spam\n\nThis modules uses [GKM](https://github.com/denyncrawford/deno-gkm): If you want to listen global input events, go check it out!.\n\n# 👥 Credits\n\nDeveloper: [denyncrawford](https://github.com/denyncrawford/)\n\nThis idea couln't be possible without [simple-barcode-scanner](https://github.com/hadeeb/simple-barcode-scanner), thanks.\n\n# 🏗️ Contributing\n\n1. Create an issue related to the problem or idea and check if it is viable\n2. Fork it :D\n3. Create a new branch with your changes.\n4. Make a PR.\n\n# 📜 License\n\nMIT License\n\nCopyright (c) 2020 Miguel Rangel\n\n[See full licese](https://github.com/denyncrawford/barcode-scanner/tree/main/LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenyncrawford%2Fbarcode-scanner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdenyncrawford%2Fbarcode-scanner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenyncrawford%2Fbarcode-scanner/lists"}