{"id":21487918,"url":"https://github.com/arthurdenner/format-string-by-pattern","last_synced_at":"2025-10-08T02:43:23.142Z","repository":{"id":32416061,"uuid":"132925434","full_name":"arthurdenner/format-string-by-pattern","owner":"arthurdenner","description":"A module that formats a string based on a pattern","archived":false,"fork":false,"pushed_at":"2023-07-11T00:56:42.000Z","size":2301,"stargazers_count":77,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-03T03:09:33.774Z","etag":null,"topics":["format","format-string-by-pattern","hacktoberfest","pattern","string"],"latest_commit_sha":null,"homepage":"https://format-string-by-pattern.netlify.com/","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/arthurdenner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"arthurdenner","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["https://www.buymeacoffee.com/arthurdenner"]}},"created_at":"2018-05-10T16:16:23.000Z","updated_at":"2025-02-28T09:28:45.000Z","dependencies_parsed_at":"2024-06-18T16:41:42.204Z","dependency_job_id":"4426a775-a466-4dd2-a03d-f44536760518","html_url":"https://github.com/arthurdenner/format-string-by-pattern","commit_stats":{"total_commits":640,"total_committers":4,"mean_commits":160.0,"dds":0.559375,"last_synced_commit":"a9f2378fd7b98d8039f9a61bed28c45f80812f4b"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arthurdenner%2Fformat-string-by-pattern","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arthurdenner%2Fformat-string-by-pattern/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arthurdenner%2Fformat-string-by-pattern/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arthurdenner%2Fformat-string-by-pattern/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arthurdenner","download_url":"https://codeload.github.com/arthurdenner/format-string-by-pattern/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161267,"owners_count":21057554,"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":["format","format-string-by-pattern","hacktoberfest","pattern","string"],"created_at":"2024-11-23T13:40:32.979Z","updated_at":"2025-10-08T02:43:18.075Z","avatar_url":"https://github.com/arthurdenner.png","language":"TypeScript","readme":"\u003ch1 align=\"center\"\u003e\n  format-string-by-pattern\n\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://www.npmjs.org/package/format-string-by-pattern\"\u003e\u003cimg src=\"https://img.shields.io/npm/dw/format-string-by-pattern?style=flat\" alt=\"npm\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.org/package/format-string-by-pattern\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/format-string-by-pattern.svg?style=flat\" alt=\"npm\"\u003e\u003c/a\u003e\n\u003ca href=\"https://codecov.io/gh/arthurdenner/format-string-by-pattern\"\u003e\u003cimg src=\"https://img.shields.io/codecov/c/github/arthurdenner/format-string-by-pattern\" alt=\"codecov\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://david-dm.org/arthurdenner/format-string-by-pattern\"\u003e\u003cimg src=\"https://david-dm.org/arthurdenner/format-string-by-pattern/status.svg\" alt=\"dependencies Status\"\u003e\u003c/a\u003e\n\u003ca href=\"https://unpkg.com/format-string-by-pattern/dist/format-string-by-pattern.umd.js\"\u003e\u003cimg src=\"https://img.badgesize.io/https://unpkg.com/format-string-by-pattern/dist/format-string-by-pattern.umd.js?compression=gzip\" alt=\"gzip size\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagephobia.now.sh/result?p=format-string-by-pattern\"\u003e\u003cimg src=\"https://packagephobia.now.sh/badge?p=format-string-by-pattern\" alt=\"install size\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Overview\n\nThis module consists on a function that receives a pattern and a value and returns this value formatted according to the pattern. It doesn't work with every pattern, but it works with a lot of use cases, especially if you build functions on top of this module.\n\n## Install\n\n```\nyarn add format-string-by-pattern\n```\n\n```\nnpm i format-string-by-pattern\n```\n\n### UMD\n\n```\n\u003cscript src=\"https://unpkg.com/format-string-by-pattern/dist/format-string-by-pattern.umd.js\"\u003e\u003c/script\u003e\n```\n\n## Usage\n\n```js\nconst formatStringByPattern = require('format-string-by-pattern');\n\nformatStringByPattern('YYYY-MM-DD', '20180508');\n// '2018-05-08'\n\nformatStringByPattern('2018-05-08', '20151217');\n// '2015-12-17'\n\nconst formatOnlyNumbers = (anyString) =\u003e {\n  const onlyNumbers = anyString.replace(/[^\\d]/g, '');\n\n  return formatStringByPattern('999-999-9999', onlyNumbers);\n};\nformatOnlyNumbers('1A2B3C4D5E6F7G8H9');\n// '123-456-789'\n\n// It works with curry too\nconst someFormat = formatStringByPattern('00.00');\nsomeFormat(1234);\n// 12.34\n```\n\n\u003e NOTE: The returned value will be sliced to the size of the pattern.\n\nThis library is pretty useful with forms, where you need to parse the input values.\nSee the usage with the [react-final-form](https://github.com/final-form/react-final-form) library [here](https://codesandbox.io/s/no20p7z3l).\n\n## API\n\n### formatStringByPattern(pattern, valueToFormat)\n\nReturns a `string`.\n\n#### pattern\n\nType: `string`\n\nA string where anything that is not a number or letter will be treated as a separator.\n\n#### valueToFormat\n\nType: `string` or `number`\n\nA value to be formatted.\n\n## License\n\nMIT © [Arthur Denner](https://github.com/arthurdenner/)\n","funding_links":["https://github.com/sponsors/arthurdenner","https://www.buymeacoffee.com/arthurdenner"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farthurdenner%2Fformat-string-by-pattern","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farthurdenner%2Fformat-string-by-pattern","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farthurdenner%2Fformat-string-by-pattern/lists"}