{"id":15646465,"url":"https://github.com/martinheidegger/monospace-char-width","last_synced_at":"2025-07-12T22:40:14.176Z","repository":{"id":57302569,"uuid":"44869471","full_name":"martinheidegger/monospace-char-width","owner":"martinheidegger","description":"A JavaScript CommonJS package that deals with double-width characters in monospace content","archived":false,"fork":false,"pushed_at":"2015-10-31T18:37:12.000Z","size":140,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-05T00:42:04.626Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/martinheidegger.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-24T14:21:57.000Z","updated_at":"2023-03-20T03:51:23.000Z","dependencies_parsed_at":"2022-09-20T19:51:45.796Z","dependency_job_id":null,"html_url":"https://github.com/martinheidegger/monospace-char-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/martinheidegger%2Fmonospace-char-width","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinheidegger%2Fmonospace-char-width/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinheidegger%2Fmonospace-char-width/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinheidegger%2Fmonospace-char-width/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martinheidegger","download_url":"https://codeload.github.com/martinheidegger/monospace-char-width/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246254149,"owners_count":20747949,"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-10-03T12:13:00.381Z","updated_at":"2025-03-29T23:17:33.159Z","avatar_url":"https://github.com/martinheidegger.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![ISC License](https://img.shields.io/badge/license-ISC-blue.svg?style=flat)](LICENSE.md)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)\n[![npm version](https://badge.fury.io/js/monospace-char-width.svg)](https://badge.fury.io/js/monospace-char-width)\n\n# monospace-char-width\n\n`monospace-char-width` is a JavaScript CommonJS package that deals with the fact that some characters in monospace font environments (like terminals) are displayed with the size of two characters while others occupy the space of one character.\n\nIt is derived (forked) from [visualwidth-js](https://github.com/tokuhirom/visualwidth-js) which is custom implemented and seems better tested with japanese than the similar package [wcwidth](https://github.com/timoxley/wcwidth) which is a derivate of [wcwidth.c](http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c). It differes from both of those packages by only returning the width of one character (as integer!) which is important for performance\nreasons.\n\n\n## Installation \u0026 Usage\nInstall the package with `npm i monospace-char-width --save` and pass the character you want to test like this:\n\n```JavaScript\nvar mcw = require('monospace-char-width')\n\nfunction charSize(string, pos) {\n    mcw(string.charCodeAt(pos), pos \u003e 0 ? string.charCodeAt(pos-1) : 0)\n}\n\ncharSize('abcd', 0) // 1\n```\n\n## Surrogates or Why two character codes?\nThe size of some characters depends on surrogates which means that depending on the character before their size changes. For it to work appropriately you need to pass-in both the current character code and the one before that.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinheidegger%2Fmonospace-char-width","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartinheidegger%2Fmonospace-char-width","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinheidegger%2Fmonospace-char-width/lists"}