{"_id":"@drunkencure/tweet-character-counter","_rev":"2-2d1bcffcd121e336083a95021ca5eefa","name":"@drunkencure/tweet-character-counter","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@drunkencure/tweet-character-counter","version":"1.0.0","keywords":["twitter","tweet","character","counter","length","validator","text","unicode","emoji","twttr","charcount","text-length","tweet-length","280","string","message","social"],"author":{"name":"drunkencure"},"license":"MIT","_id":"@drunkencure/tweet-character-counter@1.0.0","maintainers":[{"name":"drunkencure","email":"drunkencure@gmail.com"}],"dist":{"shasum":"cc713cf9ad9296250d077a5f5a37c535a4e44163","tarball":"https://registry.npmjs.org/@drunkencure/tweet-character-counter/-/tweet-character-counter-1.0.0.tgz","fileCount":4,"integrity":"sha512-SLgUDvplDoWuw29F/BSW1SH3HA/ITK/9ejOgvRskNIEbjQJyAMNC0OAw5nVGj73uYVAM0LhxhPXgNyTHogsUFg==","signatures":[{"sig":"MEUCIQC1PiCFd7ZM/K/lTQBM17P8n5icNJLTRNm/TMVsUgC8tgIgDIaTH3T4jzfIeeplffxs/AI/jzdLC8BdyrQXtjFz8wY=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":4993},"main":"index.js","type":"module","gitHead":"b04f3dd9621f76f14c485b86a3cc4db8be31e496","_npmUser":{"name":"drunkencure","email":"drunkencure@gmail.com"},"_npmVersion":"10.8.1","description":"Accurately count tweet characters and validate tweet length according to Twitter's rules, including emoji and Unicode handling.","directories":{},"_nodeVersion":"22.4.1","dependencies":{"twitter-text":"^3.1.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"esbuild":"^0.20.0"},"_npmOperationalInternal":{"tmp":"tmp/tweet-character-counter_1.0.0_1744081203065_0.1007618764050715","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@drunkencure/tweet-character-counter","version":"1.0.1","description":"Accurately count tweet characters and validate tweet length according to Twitter's rules, including emoji and Unicode handling.","main":"index.js","author":{"name":"drunkencure"},"license":"MIT","type":"module","dependencies":{"twitter-text":"^3.1.0"},"devDependencies":{"esbuild":"^0.20.0"},"publishConfig":{"access":"public"},"keywords":["twitter","tweet","character","counter","length","validator","text","unicode","emoji","twttr","charcount","text-length","tweet-length","280","string","message","social"],"_id":"@drunkencure/tweet-character-counter@1.0.1","gitHead":"ccbb307660b2f4cbe4d1a7248495958bb41df738","_nodeVersion":"22.4.1","_npmVersion":"10.8.1","dist":{"integrity":"sha512-tPGcnQIs9QuFJGcQ8UTJSSuNmnxdXiuT8TMTDzSsHZTplbtcj/T2N+84OkIZSW6kcNvtIQhAELjduCDU+TdP5A==","shasum":"3c30386c13fb1817618df20486db5213d52b7c51","tarball":"https://registry.npmjs.org/@drunkencure/tweet-character-counter/-/tweet-character-counter-1.0.1.tgz","fileCount":4,"unpackedSize":5118,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDRVrwxhjh75jRZLHbAN/nnoZ5xEcCh4mJOsIdYURyy2gIhAPReWWP7EftQ/4XbqzNHPXug6AlRFRAgYgPZ5iLQyxrJ"}]},"_npmUser":{"name":"drunkencure","email":"drunkencure@gmail.com"},"directories":{},"maintainers":[{"name":"drunkencure","email":"drunkencure@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/tweet-character-counter_1.0.1_1744094483897_0.5154089986977386"},"_hasShrinkwrap":false}},"time":{"created":"2025-04-08T03:00:02.955Z","modified":"2025-04-08T06:41:24.242Z","1.0.0":"2025-04-08T03:00:03.253Z","1.0.1":"2025-04-08T06:41:24.053Z"},"author":{"name":"drunkencure"},"license":"MIT","keywords":["twitter","tweet","character","counter","length","validator","text","unicode","emoji","twttr","charcount","text-length","tweet-length","280","string","message","social"],"description":"Accurately count tweet characters and validate tweet length according to Twitter's rules, including emoji and Unicode handling.","maintainers":[{"name":"drunkencure","email":"drunkencure@gmail.com"}],"readme":"# @drunkencure/tweet-character-counter\n\nA reliable tweet character counter and validator for developers.  \nBuilt with Unicode, emoji, and Twitter-specific length rules in mind.\n\n## ✍️ Based on Official Twitter Character Counting Rules\n\nThis package implements character counting rules based on the official Twitter (X) documentation:  \n📄 [Counting characters when composing Tweets](https://docs.x.com/resources/fundamentals/counting-characters)\n\nIt follows the same behavior as described in Twitter’s own [`twitter-text`](https://github.com/twitter/twitter-text) library, including:\n\n- ✅ Emoji sequences count as 2 characters\n- ✅ CJK (Chinese, Japanese, Korean) glyphs count as 2 characters\n- ✅ Latin-based characters, general punctuation, and certain Unicode ranges count as 1 character\n- ✅ URLs are always counted as 23 characters\n- ✅ Media links posted from official clients count as 0 characters\n- ✅ Text is normalized using NFC (Normalization Form C) before counting\n- ✅ Length is calculated based on Unicode code points, **not** UTF-8 byte length\n\n> 🧠 This implementation is compatible with Twitter’s character weight configuration as documented and open-sourced by Twitter/X.\n\n---\n\n## 📦 Installation\n\n```bash\nnpm install @drunkencure/tweet-character-counter\n```\n\n## 🚀 Usage (with JavaScript)\n\n```\nimport tcc from '@drunkencure/tweet-character-counter';\n\n// Optional: configure maximum tweet length and reserved characters (e.g., for URLs or newlines)\ntcc.configure({\n  maxTweetLength: 280,\n  reservedLength: 24, // Example: 23 for a URL + 1 for a newline\n// Use this to reserve space for content automatically added to the tweet,\n// such as links or line breaks that are not part of the user input.\n});\n\nconst text = \"안녕하세요! 이건 테스트 트윗입니다 😊\";\nconst length = tcc.count(text);\nconst isValid = tcc.isValidLength(text);\n\nconsole.log(length);    // e.g. 37\nconsole.log(isValid);   // true or false\n```\n\n\n## 🧰 API Reference\n\n### `configure(options)`\nConfigure max tweet length and reserved space (like URL or newline buffers).\n\n- `options.maxTweetLength` – default: `280`\n- `options.reservedLength` – default: `0`\n\n### `count(text)`\nReturns the weighted character count of the given text.\n\n### `isValidLength(text)`\nReturns `true` if the given text is within the allowed length.\n\n### `getConfig()`\nReturns the current configuration object.\n\n### `getMaxTextLength()`\nReturns the current max text length (after subtracting reserved characters).\n\n\n## 🧪 CLI Test Tool\n\nThis package includes a simple CLI utility (test.js) that allows you to test tweet text length directly from the terminal.\n\n### ▶️ How to Use\n\nMake sure the file is named test.js and located in your project root.\nRun it using Node.js:\n\n```\nnode test.js \"Your tweet-like sentence goes here\"\n```\n\n### 🧾 Example Output\n\n```\n$ node test.js \"Hello world! Testing tweet 🐦\"\n\n=== Tweet Text Check ===\nInput: \"Hello world! Testing tweet 🐦\"\nCharacter count (Twitter rules): 29\nIs it a valid tweet?: ✅ Yes\n```\n\n## 🪪 License\n\nMIT © [drunkencure](https://github.com/drunkencure) ","readmeFilename":"README.md"}