Tiny module for splitting string by its hyphen (and hyphen-like chars). It is recognizing following characters:
\u002D
- HYPHEN-MINUS (-)\u2010
- HYPHEN (‐)\u2011
- NON-BREAKING HYPHEN (‑)\u2012
- FIGURE DASH (‒)\u2013
- EN DASH (–)\u2014
- EM DASH (—)\u2015
- HORIZONTAL BAR (―)\u2E3A
- TWO-EM DASH (⸺)\u2E3B
- THREE-EM DASH (⸻)\uFE58
- SMALL EM DASH (﹘)\uFE63
- SMALL HYPHEN-MINUS (﹣)\uFF0D
- FULLWIDTH HYPHEN-MINUS (-)
$ npm i -S qm-txt-splitbyhyphen
const splitByHyphen = require("qm-txt-splitbyhyphen");
splitByHyphen("tere|fere"); //-> undefined
splitByHyphen("tere - fere"); //-> ["tere", "fere"]
splitByHyphen("a-b‐c‑d‒e–f⸺g"); //-> ["a", "b", "c", "d", "e", "f", "g"]
TitleSplit mode in witch splits string by only one hyphen e.g:
splitByHyphen("a-b-c-d-e-f-g", 1); // -> ["a", "b-c-d-e-f-g"]
splitByHyphen("a-b-c-d-e-f-g", 2); // -> ["a-b", "c-d-e-f-g"]
splitByHyphen("a-b-c-d-e-f-g", 3); // -> ["a-b-c", "d-e-f-g"]
splitByHyphen("a-b-c-d-e-f-g", 0); // default it is off -> ["a", "b", "c", "d", "e", "f", "g"]
splitByHyphen("a-b-c-d-e-f-g", 99); // -> ["a", "b", "c", "d", "e", "f", "g"]
MIT © qaraluch