cntstr
v2.0.1
Published
A utility to count the number of characters in a given string
Maintainers
Readme
cntstr
A tiny utility to count the number of characters in a string.
📦 Installation
npm install cntstror with Yarn:
yarn add cntstr🚀 Usage
JavaScript(CommonJS)
const { countStr } = require('cntstr');
const str = 'hello';
console.log(countStr(str)); // Output: 5TypeScript(ESModule)
import { countStr } from 'cntstr';
const str: string = 'hello';
console.log(countStr(str)); // Output: 5🧠 Function
export const countStr = (str: string): number => {
return str.length;
};- Takes a string as input
- Returns the total number of characters
- Works with multibyte characters as counted by
.length
❗ Note: This function uses JavaScript's built-in
.lengthmethod, which may not accurately count complex characters like emoji (👨👩👧👦). For full Unicode-aware counting, consider usinggrapheme-splitter.
📄 License
MIT
