underscore
underscore copied to clipboard
_.size to return symbol count of strings.
Continuing the discussion, at the moment:
_.size('π')
// => 2
Since str.length is trivial I think it --may-- be handy if _.size returned the number of symbols in a string instead.
_.size('π')
// => 1
I'm not sure what you're looking to count with this function. I recently read about combining characters and character width, and a few examples are pretty convincing. It's impossible to count the number of symbols, summing character widths is pointless, number of code points depends on the unicode normalisation form, byte count is derived from length, other properties depend on the version of Unicode the browser is using, ...
I'm not sure what you're looking to count with this function.
Based on my example, I imagine:
_.size(string) === _.toArray(string).length;
It's impossible to count the number of symbols, summing character widths is pointless, number of code points depends on the unicode normalisation form, byte count is derived from length, other properties depend on the version of Unicode the browser is using, ...
Unless you want to truncate, or produce some slice/substring.
@michaelficarra on a related note following up on your link I added
added support for regional indicator symbols
[..."πΊπΈ"] // => ["πΊ", "πΈ"]
_.toArray("πΊπΈ") // => ["πΊπΈ"]
added support for zero-width-joiners

and added support for variation selector characters:

and added support for unicode modifiers to lodash methods:

:+1: