Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 2x | import {REGEXP_EXTENDED_ASCII, REGEXP_LATIN_WORD, REGEXP_WORD} from "../helpers/regexp/regexp"
import {toStr} from "../helpers/string/to_string"
import {nvl} from "../helpers/nvl"
/*
* Split string to words. You can set specified patter to split
* */
export const words = (s, pattern, flags) => {
let regexp;
if (!pattern) {
regexp = REGEXP_EXTENDED_ASCII.test(s) ? REGEXP_LATIN_WORD : REGEXP_WORD;
} else if (pattern instanceof RegExp) {
regexp = pattern;
} else {
regexp = new RegExp(pattern, nvl(flags, ''))
}
return nvl(toStr(s).match(regexp), []);
}
|