forked from lwansbrough/react-native-markdown
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.js
More file actions
57 lines (47 loc) · 816 Bytes
/
util.js
File metadata and controls
57 lines (47 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const currency = [
// Currency Symbols
"\\$\\u058F\\u060B\\u09F2\\u09F3\\u09FB\\u0AF1",
"\\u0BF9\\u0E3F\\u17DB\\uA838\\uFDFC\\uFE69",
"\\uFF04\\uFFE0\\uFFE1\\uFFE5\\uFFE6",
"\\u20A0-\\u20BD",
"\\xA2-\\xA5",
].join("");
const prefixCharacters = [
// Quotes
"\"",
"'",
"`",
// Brackets
"<",
"(",
"{",
"\\[",
currency,
].join("");
const suffixCharacters = [
// Quotes
"\"",
"'",
"`",
// Brackets
">",
")",
"}",
"\\]",
// Punctuation
",",
".",
":",
";",
"!",
"\\?",
// Misc
"%",
"/",
currency,
].join("");
const matchRegex = new RegExp(`([${prefixCharacters}]*[^\\b]*?.\\b(?:'\\w)*[${suffixCharacters}]*\\s*)`, "g");
export const splitWordsWithPunctuation =
text => text.
replace(/[\n\s\u00A0]+/g, "\u00A0").
match(matchRegex);