string-char-walker
v1.0.0
Published
Library to walk through strings and print or process each character, with unicode support (emojis, accents).
Maintainers
Readme
string-char-walker
Library to walk through strings and print or process each character, with unicode support (emojis, accents).
Installation
npm install string-char-walkerUsage
const { printChars, walk } = require('string-char-walker');
// Print a string character by character
printChars('Hello world');
// [0] H
// [1] e
// [2] l
// ...
// Or use walk with your own logic for each character
walk('Hello', (char, index) => {
console.log(`Character at position ${index}: ${char}`);
});It also works with ES modules:
import { printChars, walk } from 'string-char-walker';API
walk(str, callback)
Walks through str and calls callback(char, index) for each character. Uses the native string iterator, so emojis and accented characters are handled correctly. Throws a TypeError if str is not a string.
printChars(str)
Walks through str and prints each character to the console with its index.
License
MIT
