Skip to content
This repository was archived by the owner on Oct 17, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const segmenter1 = new Intl.Segmenter('fr-FR');
const options1 = segmenter1.resolvedOptions();

console.log(options1.locale);
// expected output: "fr-FR"

console.log(options1.granularity);
// expected output: "grapheme"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const string1 = 'Que ma joie demeure';

const segmenterFrGrapheme = new Intl.Segmenter('fr', { granularity: 'grapheme' });
const graphemeSegments = segmenterFrGrapheme.segment(string1);

console.log(Array.from(graphemeSegments)[0]);
// expected output:
// Object {segment: 'Q', index: 0, input: 'Que ma joie demeure'}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const locales1 = ['ban', 'id-u-co-pinyin', 'de-ID'];
const options1 = { localeMatcher: 'lookup', granularity: 'string' };

console.log(Intl.Segmenter.supportedLocalesOf(locales1, options1));
// expected output: Array ["id-u-co-pinyin", "de-ID"]
// (Note: the exact output may be browser-dependent)
10 changes: 10 additions & 0 deletions live-examples/js-examples/intl/intl-segmenter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const segmenterFr = new Intl.Segmenter('fr', { granularity: 'word' });
const string1 = 'Que ma joie demeure';

const iterator1 = segmenterFr.segment(string1)[Symbol.iterator]();

console.log(iterator1.next().value.segment);
// expected output: 'Que'

console.log(iterator1.next().value.segment);
// expected output: ' '
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const segmenterFr = new Intl.Segmenter('fr', { granularity: 'word' });
const string1 = 'Que ma joie demeure';

const iterator1 = segmenterFr.segment(string1)[Symbol.iterator]();

for (const segment of iterator1) {
if (segment.segment.length > 4) {
console.log(segment.segment);
}
}

// expected output: "demeure"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const segmenterFr = new Intl.Segmenter('fr', { granularity: 'word' });
const string1 = 'Que ma joie demeure';

const segments = segmenterFr.segment(string1);

console.log(segments.containing(5));
// expected output:
// Object {segment: 'ma', index: 4, input: 'Que ma joie demeure', isWordLike: true}
36 changes: 36 additions & 0 deletions live-examples/js-examples/intl/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,42 @@
"title": "JavaScript Demo: Intl.RelativeTimeFormat.prototype.supportedLocalesOf",
"type": "js"
},
"intlSegmenter": {
"exampleCode": "./live-examples/js-examples/intl/intl-segmenter.js",
"fileName": "intl-segmenter.html",
"title": "JavaScript Demo: Intl.Segmenter",
"type": "js"
},
"intlSegmenterPrototypeResolvedOptions": {
"exampleCode": "./live-examples/js-examples/intl/intl-segmenter-prototype-resolvedoptions.js",
"fileName": "intl-segmenter-prototype-resolvedoptions.html",
"title": "JavaScript Demo: Intl.Segmenter.prototype.resolvedOptions",
"type": "js"
},
"intlSegmenterPrototypeSegment": {
"exampleCode": "./live-examples/js-examples/intl/intl-segmenter-prototype-segment.js",
"fileName": "intl-segmenter-prototype-segment.html",
"title": "JavaScript Demo: Intl.Segmenter.prototype.segment",
"type": "js"
},
"intlSegmenterSupportedLocalesOf": {
"exampleCode": "./live-examples/js-examples/intl/intl-segmenter-supportedlocalesof.js",
"fileName": "intl-segmenter-supportedlocalesof.html",
"title": "JavaScript Demo: Intl.Segmenter.supportedLocalesOf",
"type": "js"
},
"intlSegmentsPrototypeIterator": {
"exampleCode": "./live-examples/js-examples/intl/intl-segments-prototype-@@iterator.js",
"fileName": "intl-segments-prototype-@@iterator.html",
"title": "JavaScript Demo: Intl.Segments.prototype.@@iterator",
"type": "js"
},
"intlSegmentsPrototypeContaining": {
"exampleCode": "./live-examples/js-examples/intl/intl-segments-prototype-containing.js",
"fileName": "intl-segments-prototype-containing.html",
"title": "JavaScript Demo: Intl.Segments.prototype.containing",
"type": "js"
},
"intlSupportedValuesOf": {
"exampleCode": "./live-examples/js-examples/intl/intl-supportedvaluesof.js",
"fileName": "intl-supportedvaluesof.html",
Expand Down