Created
December 4, 2022 04:32
-
-
Save Vigowebs/6257541066c251c2681a07ff6c699e77 to your computer and use it in GitHub Desktop.
The Intl.Segmenter object enables locale-sensitive text segmentation, enabling you to get meaningful items (graphemes, words or sentences) from a string. Currently Intl.Segmenter is not supported in Firefox and Firefox for Android browsers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const segmenterEn = new Intl.Segmenter('en', { granularity: 'word' }); | |
const string1 = 'Split JavaScript Strings!'; | |
[...segmenterEn.segment(string1)] | |
// [ | |
// {segment: 'Split', index: 0, input: 'Split JavaScript Strings!', isWordLike: true} | |
// {segment: ' ', index: 5, input: 'Split JavaScript Strings!', isWordLike: false} | |
// {segment: 'JavaScript', index: 6, input: 'Split JavaScript Strings!', isWordLike: true} | |
// ... | |
// ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment