{"id":13656825,"url":"https://github.com/lukeed/maskr","last_synced_at":"2025-10-09T18:24:09.637Z","repository":{"id":57291657,"uuid":"93020368","full_name":"lukeed/maskr","owner":"lukeed","description":"A tiny (156B) utility to compare a string against a template mask.","archived":false,"fork":false,"pushed_at":"2017-06-01T06:07:58.000Z","size":9,"stargazers_count":22,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-18T18:45:39.645Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://jsfiddle.net/lukeed/fxcs6ret/","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/lukeed.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":"2017-06-01T05:37:42.000Z","updated_at":"2023-10-09T16:08:37.000Z","dependencies_parsed_at":"2022-09-11T12:31:47.154Z","dependency_job_id":null,"html_url":"https://github.com/lukeed/maskr","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fmaskr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fmaskr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fmaskr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fmaskr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukeed","download_url":"https://codeload.github.com/lukeed/maskr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250539519,"owners_count":21447328,"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-08-02T05:00:32.852Z","updated_at":"2025-10-09T18:24:04.596Z","avatar_url":"https://github.com/lukeed.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# maskr [![Build Status](https://travis-ci.org/lukeed/maskr.svg?branch=master)](https://travis-ci.org/lukeed/maskr)\n\n\u003e A tiny (156B) utility to compare a string against a template mask.\n\n[Demo][demo]\n\nTechnically, this is still a WIP! See the [Roadmap](#roadmap).\n\nUse this module to compare a value against a desired template. Put differently, you can format a string however you'd like.\n\nThis is probably most useful for \"masking\" `\u003cinput /\u003e` values. There are no `EventListener`s included in this module\n\n## Install\n\n```\n$ npm install --save maskr\n```\n\n\n## Usage\n\n```js\nconst maskr = require('maskr');\nconst demo = '(___) ___-____';\n\nmaskr(demo, '');\n//=\u003e { value:'(___) ___-____', cursor:1 }\n\nmaskr(demo, '12345678');\n//=\u003e { value:'(123) 456-78__', cursor:12 }\n\nmaskr(demo, '1234567890');\n//=\u003e { value:'(123) 456-7890', cursor:14 }\n```\n\n_**Example `\u003cform /\u003e` Usage:** ([demo][demo])_\n\n```js\nconst maskr = require('maskr');\nconst form = document.getElementById('form');\nconst inputs = form.querySelectorAll('input');\n\nfunction setValue(ev) {\n  if (ev !== void 0 \u0026\u0026 ev.type === 'keydown') {\n    ev.preventDefault();\n    this._value += ev.key;\n  }\n  const mask = this.getAttribute('data-mask');\n  const { value, cursor } = maskr(mask, this._value);\n  // set visible value \u0026 cursor position\n  this.value = value;\n  this.setSelectionRange(cursor, cursor);\n}\n\n[].forEach.call(inputs, el =\u003e {\n  if (!el.hasAttribute('data-mask')) return;\n  // init internal tracking\n  el._value = el.value || '';\n  // first-run if has value\n  (el.value.length \u003e 0) \u0026\u0026 setValue.call(el);\n  // attach listeners\n  el.onfocus = el.onkeydown = setValue.bind(el);\n});\n```\n\n\n## API\n\n### maskr(mask, input)\n\n#### mask\n\nType: `string`\n\nThe template/mask to be used.\n\n#### input\n\nType: `string`\n\nThe value string to match against the `mask`.\n\n\n## Roadmap\n\n* **1.0**\n  - Recognize `_` character only (signifes \"any\")\n  - Find fastest + lightest implementation\n* **2.0**\n  - Recognize `_` (any), `a` (alpha), and `9` (numeric) characters\n  - Likely change API/Type definition\n  - Add options: `showEmpty`, custom definitions, ...\n* **3.0**\n  - Use `?` for optional masked input\n  - TBD\n\n\n## Benchmarks\n\n```\nmaskr\n  --\u003e 6,415,566 ops/sec ±0.31% (94 runs sampled)\n```\n\n## License\n\nMIT © [Luke Edwards](https://lukeed.com)\n\n[demo]: https://jsfiddle.net/lukeed/fxcs6ret/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fmaskr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukeed%2Fmaskr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fmaskr/lists"}