@stdlib/string
Version:
String manipulation functions.
58 lines (43 loc) • 1.61 kB
Plain Text
{{alias}}( str, [options,] clbk[, thisArg] )
Invokes a function for each character in a string.
When invoked, the provided function is provided three arguments:
- value: character.
- index: starting character index.
- str: input string.
Parameters
----------
str: string
Input string over which to iterate.
options: Object (optional)
Options.
options.mode: string (optional)
Type of characters over which to iterate. The following modes are
supported:
- grapheme: grapheme clusters. Appropriate for strings containing visual
characters which can span multiple Unicode code points (e.g., emoji).
- code_point: Unicode code points. Appropriate for strings containing
visual characters which are comprised of more than one Unicode code
unit (e.g., ideographic symbols and punctuation and mathematical
alphanumerics).
- code_unit': UTF-16 code units. Appropriate for strings containing
visual characters drawn from the basic multilingual plane (BMP) (e.g.,
common characters, such as those from the Latin, Greek, and Cyrillic
alphabets).
Default: 'grapheme'.
clbk: Function
The function to invoke for each character in the input string.
thisArg: any (optional)
Execution context.
Returns
-------
out: string
Input string.
Examples
--------
> var n = 0;
> function fcn() { n += 1; };
> {{alias}}( 'hello world!', fcn );
> n
12
See Also
--------