{"id":17448332,"url":"https://github.com/mesqueeb/commafy-anything","last_synced_at":"2025-07-13T21:08:25.234Z","repository":{"id":34915070,"uuid":"189783115","full_name":"mesqueeb/commafy-anything","owner":"mesqueeb","description":"Return a number as string with , or K. A simple and small integration","archived":false,"fork":false,"pushed_at":"2025-02-19T18:42:15.000Z","size":999,"stargazers_count":2,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-09T17:42:47.012Z","etag":null,"topics":["comma","commafy","number-format","numbers-to-text","typescript"],"latest_commit_sha":null,"homepage":"https://npmjs.com/commafy-anything","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/mesqueeb.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,"zenodo":null},"funding":{"github":"mesqueeb","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2019-06-01T22:32:34.000Z","updated_at":"2025-02-19T18:42:19.000Z","dependencies_parsed_at":"2024-06-05T01:56:13.134Z","dependency_job_id":"35c5872a-1abf-4728-9d91-484e3bef9e92","html_url":"https://github.com/mesqueeb/commafy-anything","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/mesqueeb/commafy-anything","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesqueeb%2Fcommafy-anything","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesqueeb%2Fcommafy-anything/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesqueeb%2Fcommafy-anything/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesqueeb%2Fcommafy-anything/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mesqueeb","download_url":"https://codeload.github.com/mesqueeb/commafy-anything/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesqueeb%2Fcommafy-anything/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265205775,"owners_count":23727511,"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":["comma","commafy","number-format","numbers-to-text","typescript"],"created_at":"2024-10-17T20:07:04.131Z","updated_at":"2025-07-13T21:08:25.221Z","avatar_url":"https://github.com/mesqueeb.png","language":"TypeScript","funding_links":["https://github.com/sponsors/mesqueeb"],"categories":[],"sub_categories":[],"readme":"# Commafy anything 🍡\n\n\u003ca href=\"https://www.npmjs.com/package/commafy-anything\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/commafy-anything.svg\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/commafy-anything\"\u003e\u003cimg src=\"https://img.shields.io/npm/dw/commafy-anything.svg\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n\n```\nnpm i commafy-anything\n```\n\nReturn a number as string with `,` or `K`. A simple and small integration.\n\n## Motivation\n\nU built this package because I needed to add comma's and K to numbers! And I wanted to build it myself. 😄\n\n## Meet the family (more tiny utils with TS support)\n\n- [is-what 🙉](https://github.com/mesqueeb/is-what)\n- [is-where 🙈](https://github.com/mesqueeb/is-where)\n- [merge-anything 🥡](https://github.com/mesqueeb/merge-anything)\n- [check-anything 👁](https://github.com/mesqueeb/check-anything)\n- [remove-anything ✂️](https://github.com/mesqueeb/remove-anything)\n- [getorset-anything 🐊](https://github.com/mesqueeb/getorset-anything)\n- [map-anything 🗺](https://github.com/mesqueeb/map-anything)\n- [filter-anything ⚔️](https://github.com/mesqueeb/filter-anything)\n- [copy-anything 🎭](https://github.com/mesqueeb/copy-anything)\n- [case-anything 🐫](https://github.com/mesqueeb/case-anything)\n- [flatten-anything 🏏](https://github.com/mesqueeb/flatten-anything)\n- [nestify-anything 🧅](https://github.com/mesqueeb/nestify-anything)\n\n## Usage\n\n```js\nimport { commafy } from 'commafy-anything'\n\ncommafy(1000) === '1,000'\ncommafy(10000) === '10,000'\ncommafy(100000) === '100,000'\ncommafy(1000000) === '1,000,000'\n// etc.\n```\n\n### K\n\nYou can show numbers as 1K.\n\n```js\nconst options = { K: true }\n// when smaller than 1000 will be shown as is, without K\ncommafy(123, options) === '123'\n\n// when larger than 1000 it will round up/down behind the K\ncommafy(1234, options) === '1K'\ncommafy(10234, options) === '10K'\ncommafy(100234, options) === '100K'\ncommafy(1000234, options) === '1,000K'\n\ncommafy(1955, options) === '2K'\ncommafy(10955, options) === '11K'\ncommafy(100955, options) === '101K'\ncommafy(1000955, options) === '1,001K'\n```\n\n### Thousands\n\nYou can disable a comma to be added when the number is between `1000` ~ `9999`.\n\n```js\n// default:\ncommafy(1000) === '1,000'\n\nconst options = { thousandsComma: false }\ncommafy(1000, options) === '1000'\ncommafy(9999, options) === '9999'\n\n// beyond 9999 it will always have a comma\ncommafy(10000, options) === '10,000'\n```\n\n### Spaced decimals\n\nYou can add spaces to decimals.\n\n```js\n// default:\ncommafy(1.0001) === '1.0001'\ncommafy(1.00001) === '1.00001'\ncommafy(1.000001) === '1.000001'\ncommafy(1.0000001) === '1.0000001'\n\n// spaced decimals:\nconst options = { spacedDecimals: true }\ncommafy(1.0001, options) === '1.0001'\ncommafy(1.00001, options) === '1.000 01'\ncommafy(1.000001, options) === '1.000 001'\ncommafy(1.0000001, options) === '1.000 0001'\n```\n\n### Strip decimals\n\nYou can add strip away decimals.\n\n```js\n// default:\ncommafy(1.0001) === '1.0001'\n\n// strip decimals:\nconst options = { stripDecimals: true }\ncommafy(1.001, options) === '1'\ncommafy(1.999, options) === '1'\n```\n\n## Source code\n\nI'm using simple regular expressions. The source code is in TypeScript, but the essense of my source code looks something like this:\n\n```js\nfunction commafy(num, { stripDecimals, spacedDecimals } = {}) {\n  const str = num.toString().split('.')\n  if (str[0].length \u003e= 4) {\n    str[0] = str[0].replace(/(\\d)(?=(\\d{3})+$)/g, '$1,')\n  }\n  if (stripDecimals) return str[0]\n  if (spacedDecimals \u0026\u0026 str[1] \u0026\u0026 str[1].length \u003e= 5) {\n    str[1] = str[1].replace(/(\\d{3})/g, '$1 ').trim()\n  }\n  return str.join('.')\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmesqueeb%2Fcommafy-anything","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmesqueeb%2Fcommafy-anything","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmesqueeb%2Fcommafy-anything/lists"}