{"id":16330910,"url":"https://github.com/ozluy/calculate-text-width","last_synced_at":"2025-10-25T22:30:18.540Z","repository":{"id":49652147,"uuid":"245252842","full_name":"ozluy/calculate-text-width","owner":"ozluy","description":"Function that calculates width of typed text. Auto calculate input width.","archived":false,"fork":false,"pushed_at":"2020-03-06T08:12:05.000Z","size":23,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-31T10:51:15.639Z","etag":null,"topics":["auto-width","autoresize","calculate","input","react-input-autowidth","react-input-size","text","text-width","width","width-calculation"],"latest_commit_sha":null,"homepage":"https://codesandbox.io/s/calculate-text-width-okr46","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/ozluy.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":"2020-03-05T19:42:42.000Z","updated_at":"2022-07-25T20:47:02.000Z","dependencies_parsed_at":"2022-09-12T15:00:13.648Z","dependency_job_id":null,"html_url":"https://github.com/ozluy/calculate-text-width","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ozluy%2Fcalculate-text-width","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ozluy%2Fcalculate-text-width/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ozluy%2Fcalculate-text-width/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ozluy%2Fcalculate-text-width/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ozluy","download_url":"https://codeload.github.com/ozluy/calculate-text-width/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238216901,"owners_count":19435614,"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":["auto-width","autoresize","calculate","input","react-input-autowidth","react-input-size","text","text-width","width","width-calculation"],"created_at":"2024-10-10T23:24:53.507Z","updated_at":"2025-10-25T22:30:18.202Z","avatar_url":"https://github.com/ozluy.png","language":"JavaScript","funding_links":["https://paypal.me/ozluy"],"categories":[],"sub_categories":[],"readme":"# Calculate Text Width\nFunction that calculates width of typed text\n\n[![npm version](https://badge.fury.io/js/calculate-text-width.svg)](https://badge.fury.io/js/calculate-text-width)\n![npm download](https://img.shields.io/npm/dt/calculate-text-width.svg)\n\n\n\u003ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https://codesandbox.io/s/calculate-text-width-okr46\"\u003e Code Sandbox Demo \u003c/a\u003e\n\n\nHow to use\n===\n \n```js\nimport calculateTextWidth from \"calculate-text-width\";\n\n/*\n requires two props \"value\" and \"font\"\n  - defaultFont: normal 500 14px sans-serif \n */\nconst calculatedWidth = calculateTextWidth('calculate my width', 'normal 500 14px sans-serif')\nconsole.log(calculatedWidth) // 114.37890625\n\n```\n\nHow to use with React\n===\n\n```jsx\nimport React, { useState, useMemo } from \"react\"\nimport calculateTextWidth from \"calculate-text-width\"\n\nexport default () =\u003e {\n  const [value, setValue] = useState(\"change me\")\n\n  return (\n    \u003c\u003e\n      \u003ch1\u003eCalcule Text Width\u003c/h1\u003e\n      \u003cinput\n        style={{\n          width: `${calculateTextWidth(value)}px`,\n          font: \"normal 500 14px sans-serif\"\n        }}\n        value={value}\n        type=\"text\"\n        onChange={evt =\u003e setValue(evt.target.value)}\n      /\u003e\n    \u003c/\u003e\n  )\n}\n\n```\n\n\u003ca href=\"https://paypal.me/ozluy\"\u003e \u003cimg src=\"https://raw.githubusercontent.com/ozluy/react-stripe-script-loader/master/buy-me-a-coffee-with-paypal.png\" /\u003e\u003c/a\u003e\n\nThank you\n\n#### Yusuf Özlü\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fozluy%2Fcalculate-text-width","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fozluy%2Fcalculate-text-width","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fozluy%2Fcalculate-text-width/lists"}