Skip to content

Commit fe9535c

Browse files
committed
Fix to_graphemes on JS when Intl.Segmenter not available
1 parent a785f86 commit fe9535c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/gleam_stdlib.mjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,12 @@ export function string_length(string) {
147147
}
148148

149149
export function graphemes(string) {
150-
return List.fromArray(
151-
Array.from(graphemes_iterator(string)).map((item) => item.segment)
152-
);
150+
const iterator = graphemes_iterator(string);
151+
if (iterator) {
152+
return List.fromArray(Array.from(iterator).map((item) => item.segment));
153+
} else {
154+
return List.fromArray(string.match(/./gsu));
155+
}
153156
}
154157

155158
function graphemes_iterator(string) {

0 commit comments

Comments
 (0)