{"id":41825036,"url":"https://github.com/pirtwo/scan-detector","last_synced_at":"2026-01-25T08:08:31.869Z","repository":{"id":65493215,"uuid":"448531831","full_name":"pirtwo/scan-detector","owner":"pirtwo","description":"Detect barcode scanner and keyboard input events separately in your web page or electronJS application with ease.","archived":false,"fork":false,"pushed_at":"2022-01-17T09:30:37.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-27T13:09:36.113Z","etag":null,"topics":["barcode","barcode-scanner","scanner"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/pirtwo.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":"2022-01-16T11:18:15.000Z","updated_at":"2023-10-06T06:03:30.000Z","dependencies_parsed_at":"2023-01-25T20:25:12.888Z","dependency_job_id":null,"html_url":"https://github.com/pirtwo/scan-detector","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pirtwo/scan-detector","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirtwo%2Fscan-detector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirtwo%2Fscan-detector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirtwo%2Fscan-detector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirtwo%2Fscan-detector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pirtwo","download_url":"https://codeload.github.com/pirtwo/scan-detector/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pirtwo%2Fscan-detector/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28748573,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T07:58:02.558Z","status":"ssl_error","status_checked_at":"2026-01-25T07:57:57.153Z","response_time":113,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["barcode","barcode-scanner","scanner"],"created_at":"2026-01-25T08:08:31.290Z","updated_at":"2026-01-25T08:08:31.862Z","avatar_url":"https://github.com/pirtwo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Scan Detector\n\nDetect barcode scanner and keyboard input events separately in your web or electronJS application with ease.\n\n### **install**\n\n```\n$ npm i scan-detector --save\n```\n\n### **Quick usage**\n\n```js\nconst ScanDetector = require(\"scan-detector\");\n\nlet detector = ScanDetector();\n\ndetector.attach();\n\ndocument.addEventListener(\"scanner\", (e) =\u003e {\n  // handle scan code\n});\n\ndocument.addEventListener(\"keyboard\", (e) =\u003e {\n  // handle keyboard input\n});\n\ndetector.detach();\n```\n\n### **Options**\n\n```js\nlet sd = ScanDetector({ element: document, minCodeLength: 4 });\n```\n\n| Option          | Type                      | Default  | Description                                     |\n| --------------- | ------------------------- | -------- | ----------------------------------------------- |\n| element         | html element              | document | html element to attach and listen for inputs    |\n| prefix          | array (char codes)        | []       | these characters will be discarded              |\n| suffix          | array (char codes)        | [9, 13]  | possible end characters, will be discarded      |\n| avgCharTime     | number (ms)               | 30       | average time between each scanner keydown event |\n| minCodeLength   | number                    | 6        | min length of scanned code                      |\n| customEncoder   | function(number keyCode)  | null     | will be called on each keydown event            |\n| onScanFinish    | function(string scanCode) | null     | will be called when scan is finished            |\n| preventDefault  | bool                      | false    | prevent default keydown behavior                |\n| stopPropagation | bool                      | false    | stops event propagation                         |\n| debugMode       | bool                      | false    | logs each keydown event in console              |\n\n### **Methods**\n\n#### **setOptions(options):**\n\nseta detector options.\n\n#### **getOptions():**\n\nreturns detector options.\n\n#### **attach():**\n\nattach detector to the element, it will listen\nto keydown event in the element.\n\n#### **detach():**\n\ndetach detector from element.\n\n### **Example**\n\n```js\nconst ScanDetector = require(\"scan-detector\");\n\nlet input = document.getElementById(\"text_input\");\n\nlet detector = ScanDetector({\n  element: document,\n  avgCharTime: 30,\n  minCodeLength: 6,\n  customEncoder: (event) =\u003e {\n    return event.key;\n  },\n  onScanFinish: (code) =\u003e {\n    return [...code.matchAll(/Alt([0-9]{3})/g)].reduce((t, v) =\u003e {\n      return (t += String.fromCharCode(+v[1]));\n    }, \"\");\n  },\n});\n\ndetector.attach();\n\ndocument.addEventListener(\"scanner\", (e) =\u003e {\n  input.value = e.detail;\n});\n\ndocument.addEventListener(\"keyboard\", (e) =\u003e {\n  console.log(e);\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpirtwo%2Fscan-detector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpirtwo%2Fscan-detector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpirtwo%2Fscan-detector/lists"}