Skip to content

Latest commit

 

History

History

num-code-points

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

numCodePoints

Return the number of Unicode code points in a string.

Usage

var numCodePoints = require( '@stdlib/string/num-code-points' );

numCodePoints( str )

Returns the number of code points in a string.

var out = numCodePoints( 'last man standing' );
// returns 17

out = numCodePoints( 'Hidden Treasures' );
// returns 16

out = numCodePoints( '👋👋👋' );
// returns 3

Examples

var numCodePoints = require( '@stdlib/string/num-code-points' );

console.log( numCodePoints( 'last man standing' ) );
// => 17

console.log( numCodePoints( '六书/六書' ) );
// => 5

console.log( numCodePoints( '🐶🐮🐷🐰🐸' ) );
// => 5

console.log( numCodePoints( 'Hello 👋 World' ) );
// => 13

CLI

Usage

Usage: num-code-points [options] [<string>]

Options:

  -h,    --help                Print this message.
  -V,    --version             Print the package version.
  -l,    --lines               Analyze individual lines.

Examples

$ num-code-points beep
4

To use as a standard stream,

$ echo -n 'beep\nboop書' | num-code-points
10
$ echo -n 'beep\nboop書' | num-code-points -l
4
5