From 1f31fc70c763ce0bd10369755f077b573a856108 Mon Sep 17 00:00:00 2001 From: Joe Hildebrand Date: Wed, 7 Jun 2023 18:49:14 -0700 Subject: [PATCH] Fix bug with 'even with trailing spaces' rules; those chunks should not be marked as spaces --- docs/assets/search.js | 2 +- docs/classes/index.LineWrap.html | 46 +++++++++++---------- docs/classes/spacebreaker.SpaceBreaker.html | 4 +- docs/modules/index.html | 2 +- docs/modules/spacebreaker.html | 2 +- lib/index.js | 13 +++++- lib/spacebreaker.js | 12 +++--- test/index.test.js | 12 ++++++ test/spacebreaker.test.js | 1 + 9 files changed, 61 insertions(+), 33 deletions(-) diff --git a/docs/assets/search.js b/docs/assets/search.js index 71f45b3..f0edbca 100644 --- a/docs/assets/search.js +++ b/docs/assets/search.js @@ -1 +1 @@ -window.searchData = JSON.parse("{\"rows\":[{\"kind\":2,\"name\":\"index\",\"url\":\"modules/index.html\",\"classes\":\"\"},{\"kind\":128,\"name\":\"LineWrap\",\"url\":\"classes/index.LineWrap.html\",\"classes\":\"\",\"parent\":\"index\"},{\"kind\":1024,\"name\":\"OVERFLOW_VISIBLE\",\"url\":\"classes/index.LineWrap.html#OVERFLOW_VISIBLE\",\"classes\":\"\",\"parent\":\"index.LineWrap\"},{\"kind\":1024,\"name\":\"OVERFLOW_CLIP\",\"url\":\"classes/index.LineWrap.html#OVERFLOW_CLIP\",\"classes\":\"\",\"parent\":\"index.LineWrap\"},{\"kind\":1024,\"name\":\"OVERFLOW_ANYWHERE\",\"url\":\"classes/index.LineWrap.html#OVERFLOW_ANYWHERE\",\"classes\":\"\",\"parent\":\"index.LineWrap\"},{\"kind\":512,\"name\":\"constructor\",\"url\":\"classes/index.LineWrap.html#constructor\",\"classes\":\"\",\"parent\":\"index.LineWrap\"},{\"kind\":1024,\"name\":\"#graphemes\",\"url\":\"classes/index.LineWrap.html#_graphemes\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":1024,\"name\":\"#rules\",\"url\":\"classes/index.LineWrap.html#_rules\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":1024,\"name\":\"#opts\",\"url\":\"classes/index.LineWrap.html#_opts\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"classes/index.LineWrap.html#_opts.__type\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts\"},{\"kind\":1024,\"name\":\"ellipsis\",\"url\":\"classes/index.LineWrap.html#_opts.__type.ellipsis\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"firstCol\",\"url\":\"classes/index.LineWrap.html#_opts.__type.firstCol\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"hyphen\",\"url\":\"classes/index.LineWrap.html#_opts.__type.hyphen\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"indent\",\"url\":\"classes/index.LineWrap.html#_opts.__type.indent\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"indentChar\",\"url\":\"classes/index.LineWrap.html#_opts.__type.indentChar\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"indentEmpty\",\"url\":\"classes/index.LineWrap.html#_opts.__type.indentEmpty\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"indentFirst\",\"url\":\"classes/index.LineWrap.html#_opts.__type.indentFirst\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"isNewline\",\"url\":\"classes/index.LineWrap.html#_opts.__type.isNewline\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"locale\",\"url\":\"classes/index.LineWrap.html#_opts.__type.locale\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"newline\",\"url\":\"classes/index.LineWrap.html#_opts.__type.newline\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"newlineReplacement\",\"url\":\"classes/index.LineWrap.html#_opts.__type.newlineReplacement\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"overflow\",\"url\":\"classes/index.LineWrap.html#_opts.__type.overflow\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"width\",\"url\":\"classes/index.LineWrap.html#_opts.__type.width\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"escape\",\"url\":\"classes/index.LineWrap.html#_opts.__type.escape\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"#firstIndent\",\"url\":\"classes/index.LineWrap.html#_firstIndent\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":1024,\"name\":\"#indent\",\"url\":\"classes/index.LineWrap.html#_indent\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":1024,\"name\":\"#indentWidth\",\"url\":\"classes/index.LineWrap.html#_indentWidth\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":1024,\"name\":\"#replacementWidth\",\"url\":\"classes/index.LineWrap.html#_replacementWidth\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":1024,\"name\":\"#enderWidth\",\"url\":\"classes/index.LineWrap.html#_enderWidth\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":1024,\"name\":\"#workingWidth\",\"url\":\"classes/index.LineWrap.html#_workingWidth\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":2048,\"name\":\"#graphemeCount\",\"url\":\"classes/index.LineWrap.html#_graphemeCount\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":2048,\"name\":\"#fragments\",\"url\":\"classes/index.LineWrap.html#_fragments\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":2048,\"name\":\"#chunks\",\"url\":\"classes/index.LineWrap.html#_chunks\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":2048,\"name\":\"lines\",\"url\":\"classes/index.LineWrap.html#lines\",\"classes\":\"\",\"parent\":\"index.LineWrap\"},{\"kind\":2048,\"name\":\"wrap\",\"url\":\"classes/index.LineWrap.html#wrap\",\"classes\":\"\",\"parent\":\"index.LineWrap\"},{\"kind\":4194304,\"name\":\"EscapeString\",\"url\":\"types/index.EscapeString.html\",\"classes\":\"\",\"parent\":\"index\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"types/index.EscapeString.html#__type\",\"classes\":\"\",\"parent\":\"index.EscapeString\"},{\"kind\":2,\"name\":\"spacebreaker\",\"url\":\"modules/spacebreaker.html\",\"classes\":\"\"},{\"kind\":128,\"name\":\"SpaceBreaker\",\"url\":\"classes/spacebreaker.SpaceBreaker.html\",\"classes\":\"\",\"parent\":\"spacebreaker\"},{\"kind\":512,\"name\":\"constructor\",\"url\":\"classes/spacebreaker.SpaceBreaker.html#constructor\",\"classes\":\"\",\"parent\":\"spacebreaker.SpaceBreaker\"}],\"index\":{\"version\":\"2.3.9\",\"fields\":[\"name\",\"comment\"],\"fieldVectors\":[[\"name/0\",[0,33.081]],[\"comment/0\",[]],[\"name/1\",[1,33.081]],[\"comment/1\",[]],[\"name/2\",[2,33.081]],[\"comment/2\",[]],[\"name/3\",[3,33.081]],[\"comment/3\",[]],[\"name/4\",[4,33.081]],[\"comment/4\",[]],[\"name/5\",[5,27.973]],[\"comment/5\",[]],[\"name/6\",[6,33.081]],[\"comment/6\",[]],[\"name/7\",[7,33.081]],[\"comment/7\",[]],[\"name/8\",[8,33.081]],[\"comment/8\",[]],[\"name/9\",[9,27.973]],[\"comment/9\",[]],[\"name/10\",[10,33.081]],[\"comment/10\",[]],[\"name/11\",[11,33.081]],[\"comment/11\",[]],[\"name/12\",[12,33.081]],[\"comment/12\",[]],[\"name/13\",[13,27.973]],[\"comment/13\",[]],[\"name/14\",[14,33.081]],[\"comment/14\",[]],[\"name/15\",[15,33.081]],[\"comment/15\",[]],[\"name/16\",[16,33.081]],[\"comment/16\",[]],[\"name/17\",[17,33.081]],[\"comment/17\",[]],[\"name/18\",[18,33.081]],[\"comment/18\",[]],[\"name/19\",[19,33.081]],[\"comment/19\",[]],[\"name/20\",[20,33.081]],[\"comment/20\",[]],[\"name/21\",[21,33.081]],[\"comment/21\",[]],[\"name/22\",[22,33.081]],[\"comment/22\",[]],[\"name/23\",[23,33.081]],[\"comment/23\",[]],[\"name/24\",[24,33.081]],[\"comment/24\",[]],[\"name/25\",[13,27.973]],[\"comment/25\",[]],[\"name/26\",[25,33.081]],[\"comment/26\",[]],[\"name/27\",[26,33.081]],[\"comment/27\",[]],[\"name/28\",[27,33.081]],[\"comment/28\",[]],[\"name/29\",[28,33.081]],[\"comment/29\",[]],[\"name/30\",[29,33.081]],[\"comment/30\",[]],[\"name/31\",[30,33.081]],[\"comment/31\",[]],[\"name/32\",[31,33.081]],[\"comment/32\",[]],[\"name/33\",[32,33.081]],[\"comment/33\",[]],[\"name/34\",[33,33.081]],[\"comment/34\",[]],[\"name/35\",[34,33.081]],[\"comment/35\",[]],[\"name/36\",[9,27.973]],[\"comment/36\",[]],[\"name/37\",[35,27.973]],[\"comment/37\",[]],[\"name/38\",[35,27.973]],[\"comment/38\",[]],[\"name/39\",[5,27.973]],[\"comment/39\",[]]],\"invertedIndex\":[[\"__type\",{\"_index\":9,\"name\":{\"9\":{},\"36\":{}},\"comment\":{}}],[\"chunks\",{\"_index\":31,\"name\":{\"32\":{}},\"comment\":{}}],[\"constructor\",{\"_index\":5,\"name\":{\"5\":{},\"39\":{}},\"comment\":{}}],[\"ellipsis\",{\"_index\":10,\"name\":{\"10\":{}},\"comment\":{}}],[\"enderwidth\",{\"_index\":27,\"name\":{\"28\":{}},\"comment\":{}}],[\"escape\",{\"_index\":23,\"name\":{\"23\":{}},\"comment\":{}}],[\"escapestring\",{\"_index\":34,\"name\":{\"35\":{}},\"comment\":{}}],[\"firstcol\",{\"_index\":11,\"name\":{\"11\":{}},\"comment\":{}}],[\"firstindent\",{\"_index\":24,\"name\":{\"24\":{}},\"comment\":{}}],[\"fragments\",{\"_index\":30,\"name\":{\"31\":{}},\"comment\":{}}],[\"graphemecount\",{\"_index\":29,\"name\":{\"30\":{}},\"comment\":{}}],[\"graphemes\",{\"_index\":6,\"name\":{\"6\":{}},\"comment\":{}}],[\"hyphen\",{\"_index\":12,\"name\":{\"12\":{}},\"comment\":{}}],[\"indent\",{\"_index\":13,\"name\":{\"13\":{},\"25\":{}},\"comment\":{}}],[\"indentchar\",{\"_index\":14,\"name\":{\"14\":{}},\"comment\":{}}],[\"indentempty\",{\"_index\":15,\"name\":{\"15\":{}},\"comment\":{}}],[\"indentfirst\",{\"_index\":16,\"name\":{\"16\":{}},\"comment\":{}}],[\"indentwidth\",{\"_index\":25,\"name\":{\"26\":{}},\"comment\":{}}],[\"index\",{\"_index\":0,\"name\":{\"0\":{}},\"comment\":{}}],[\"isnewline\",{\"_index\":17,\"name\":{\"17\":{}},\"comment\":{}}],[\"lines\",{\"_index\":32,\"name\":{\"33\":{}},\"comment\":{}}],[\"linewrap\",{\"_index\":1,\"name\":{\"1\":{}},\"comment\":{}}],[\"locale\",{\"_index\":18,\"name\":{\"18\":{}},\"comment\":{}}],[\"newline\",{\"_index\":19,\"name\":{\"19\":{}},\"comment\":{}}],[\"newlinereplacement\",{\"_index\":20,\"name\":{\"20\":{}},\"comment\":{}}],[\"opts\",{\"_index\":8,\"name\":{\"8\":{}},\"comment\":{}}],[\"overflow\",{\"_index\":21,\"name\":{\"21\":{}},\"comment\":{}}],[\"overflow_anywhere\",{\"_index\":4,\"name\":{\"4\":{}},\"comment\":{}}],[\"overflow_clip\",{\"_index\":3,\"name\":{\"3\":{}},\"comment\":{}}],[\"overflow_visible\",{\"_index\":2,\"name\":{\"2\":{}},\"comment\":{}}],[\"replacementwidth\",{\"_index\":26,\"name\":{\"27\":{}},\"comment\":{}}],[\"rules\",{\"_index\":7,\"name\":{\"7\":{}},\"comment\":{}}],[\"spacebreaker\",{\"_index\":35,\"name\":{\"37\":{},\"38\":{}},\"comment\":{}}],[\"width\",{\"_index\":22,\"name\":{\"22\":{}},\"comment\":{}}],[\"workingwidth\",{\"_index\":28,\"name\":{\"29\":{}},\"comment\":{}}],[\"wrap\",{\"_index\":33,\"name\":{\"34\":{}},\"comment\":{}}]],\"pipeline\":[]}}"); \ No newline at end of file +window.searchData = JSON.parse("{\"rows\":[{\"kind\":2,\"name\":\"index\",\"url\":\"modules/index.html\",\"classes\":\"\"},{\"kind\":128,\"name\":\"LineWrap\",\"url\":\"classes/index.LineWrap.html\",\"classes\":\"\",\"parent\":\"index\"},{\"kind\":1024,\"name\":\"OVERFLOW_VISIBLE\",\"url\":\"classes/index.LineWrap.html#OVERFLOW_VISIBLE\",\"classes\":\"\",\"parent\":\"index.LineWrap\"},{\"kind\":1024,\"name\":\"OVERFLOW_CLIP\",\"url\":\"classes/index.LineWrap.html#OVERFLOW_CLIP\",\"classes\":\"\",\"parent\":\"index.LineWrap\"},{\"kind\":1024,\"name\":\"OVERFLOW_ANYWHERE\",\"url\":\"classes/index.LineWrap.html#OVERFLOW_ANYWHERE\",\"classes\":\"\",\"parent\":\"index.LineWrap\"},{\"kind\":512,\"name\":\"constructor\",\"url\":\"classes/index.LineWrap.html#constructor\",\"classes\":\"\",\"parent\":\"index.LineWrap\"},{\"kind\":1024,\"name\":\"#graphemes\",\"url\":\"classes/index.LineWrap.html#_graphemes\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":1024,\"name\":\"#rules\",\"url\":\"classes/index.LineWrap.html#_rules\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":1024,\"name\":\"#opts\",\"url\":\"classes/index.LineWrap.html#_opts\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"classes/index.LineWrap.html#_opts.__type\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts\"},{\"kind\":1024,\"name\":\"ellipsis\",\"url\":\"classes/index.LineWrap.html#_opts.__type.ellipsis\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"firstCol\",\"url\":\"classes/index.LineWrap.html#_opts.__type.firstCol\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"hyphen\",\"url\":\"classes/index.LineWrap.html#_opts.__type.hyphen\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"indent\",\"url\":\"classes/index.LineWrap.html#_opts.__type.indent\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"indentChar\",\"url\":\"classes/index.LineWrap.html#_opts.__type.indentChar\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"indentEmpty\",\"url\":\"classes/index.LineWrap.html#_opts.__type.indentEmpty\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"indentFirst\",\"url\":\"classes/index.LineWrap.html#_opts.__type.indentFirst\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"isNewline\",\"url\":\"classes/index.LineWrap.html#_opts.__type.isNewline\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"locale\",\"url\":\"classes/index.LineWrap.html#_opts.__type.locale\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"newline\",\"url\":\"classes/index.LineWrap.html#_opts.__type.newline\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"newlineReplacement\",\"url\":\"classes/index.LineWrap.html#_opts.__type.newlineReplacement\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"overflow\",\"url\":\"classes/index.LineWrap.html#_opts.__type.overflow\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"width\",\"url\":\"classes/index.LineWrap.html#_opts.__type.width\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"escape\",\"url\":\"classes/index.LineWrap.html#_opts.__type.escape\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"example7\",\"url\":\"classes/index.LineWrap.html#_opts.__type.example7\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"verbose\",\"url\":\"classes/index.LineWrap.html#_opts.__type.verbose\",\"classes\":\"\",\"parent\":\"index.LineWrap.#opts.__type\"},{\"kind\":1024,\"name\":\"#firstIndent\",\"url\":\"classes/index.LineWrap.html#_firstIndent\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":1024,\"name\":\"#indent\",\"url\":\"classes/index.LineWrap.html#_indent\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":1024,\"name\":\"#indentWidth\",\"url\":\"classes/index.LineWrap.html#_indentWidth\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":1024,\"name\":\"#replacementWidth\",\"url\":\"classes/index.LineWrap.html#_replacementWidth\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":1024,\"name\":\"#enderWidth\",\"url\":\"classes/index.LineWrap.html#_enderWidth\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":1024,\"name\":\"#workingWidth\",\"url\":\"classes/index.LineWrap.html#_workingWidth\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":2048,\"name\":\"#graphemeCount\",\"url\":\"classes/index.LineWrap.html#_graphemeCount\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":2048,\"name\":\"#fragments\",\"url\":\"classes/index.LineWrap.html#_fragments\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":2048,\"name\":\"#chunks\",\"url\":\"classes/index.LineWrap.html#_chunks\",\"classes\":\"tsd-is-private\",\"parent\":\"index.LineWrap\"},{\"kind\":2048,\"name\":\"lines\",\"url\":\"classes/index.LineWrap.html#lines\",\"classes\":\"\",\"parent\":\"index.LineWrap\"},{\"kind\":2048,\"name\":\"wrap\",\"url\":\"classes/index.LineWrap.html#wrap\",\"classes\":\"\",\"parent\":\"index.LineWrap\"},{\"kind\":4194304,\"name\":\"EscapeString\",\"url\":\"types/index.EscapeString.html\",\"classes\":\"\",\"parent\":\"index\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"types/index.EscapeString.html#__type\",\"classes\":\"\",\"parent\":\"index.EscapeString\"},{\"kind\":2,\"name\":\"spacebreaker\",\"url\":\"modules/spacebreaker.html\",\"classes\":\"\"},{\"kind\":128,\"name\":\"SpaceBreaker\",\"url\":\"classes/spacebreaker.SpaceBreaker.html\",\"classes\":\"\",\"parent\":\"spacebreaker\"},{\"kind\":512,\"name\":\"constructor\",\"url\":\"classes/spacebreaker.SpaceBreaker.html#constructor\",\"classes\":\"\",\"parent\":\"spacebreaker.SpaceBreaker\"}],\"index\":{\"version\":\"2.3.9\",\"fields\":[\"name\",\"comment\"],\"fieldVectors\":[[\"name/0\",[0,33.557]],[\"comment/0\",[]],[\"name/1\",[1,33.557]],[\"comment/1\",[]],[\"name/2\",[2,33.557]],[\"comment/2\",[]],[\"name/3\",[3,33.557]],[\"comment/3\",[]],[\"name/4\",[4,33.557]],[\"comment/4\",[]],[\"name/5\",[5,28.449]],[\"comment/5\",[]],[\"name/6\",[6,33.557]],[\"comment/6\",[]],[\"name/7\",[7,33.557]],[\"comment/7\",[]],[\"name/8\",[8,33.557]],[\"comment/8\",[]],[\"name/9\",[9,28.449]],[\"comment/9\",[]],[\"name/10\",[10,33.557]],[\"comment/10\",[]],[\"name/11\",[11,33.557]],[\"comment/11\",[]],[\"name/12\",[12,33.557]],[\"comment/12\",[]],[\"name/13\",[13,28.449]],[\"comment/13\",[]],[\"name/14\",[14,33.557]],[\"comment/14\",[]],[\"name/15\",[15,33.557]],[\"comment/15\",[]],[\"name/16\",[16,33.557]],[\"comment/16\",[]],[\"name/17\",[17,33.557]],[\"comment/17\",[]],[\"name/18\",[18,33.557]],[\"comment/18\",[]],[\"name/19\",[19,33.557]],[\"comment/19\",[]],[\"name/20\",[20,33.557]],[\"comment/20\",[]],[\"name/21\",[21,33.557]],[\"comment/21\",[]],[\"name/22\",[22,33.557]],[\"comment/22\",[]],[\"name/23\",[23,33.557]],[\"comment/23\",[]],[\"name/24\",[24,33.557]],[\"comment/24\",[]],[\"name/25\",[25,33.557]],[\"comment/25\",[]],[\"name/26\",[26,33.557]],[\"comment/26\",[]],[\"name/27\",[13,28.449]],[\"comment/27\",[]],[\"name/28\",[27,33.557]],[\"comment/28\",[]],[\"name/29\",[28,33.557]],[\"comment/29\",[]],[\"name/30\",[29,33.557]],[\"comment/30\",[]],[\"name/31\",[30,33.557]],[\"comment/31\",[]],[\"name/32\",[31,33.557]],[\"comment/32\",[]],[\"name/33\",[32,33.557]],[\"comment/33\",[]],[\"name/34\",[33,33.557]],[\"comment/34\",[]],[\"name/35\",[34,33.557]],[\"comment/35\",[]],[\"name/36\",[35,33.557]],[\"comment/36\",[]],[\"name/37\",[36,33.557]],[\"comment/37\",[]],[\"name/38\",[9,28.449]],[\"comment/38\",[]],[\"name/39\",[37,28.449]],[\"comment/39\",[]],[\"name/40\",[37,28.449]],[\"comment/40\",[]],[\"name/41\",[5,28.449]],[\"comment/41\",[]]],\"invertedIndex\":[[\"__type\",{\"_index\":9,\"name\":{\"9\":{},\"38\":{}},\"comment\":{}}],[\"chunks\",{\"_index\":33,\"name\":{\"34\":{}},\"comment\":{}}],[\"constructor\",{\"_index\":5,\"name\":{\"5\":{},\"41\":{}},\"comment\":{}}],[\"ellipsis\",{\"_index\":10,\"name\":{\"10\":{}},\"comment\":{}}],[\"enderwidth\",{\"_index\":29,\"name\":{\"30\":{}},\"comment\":{}}],[\"escape\",{\"_index\":23,\"name\":{\"23\":{}},\"comment\":{}}],[\"escapestring\",{\"_index\":36,\"name\":{\"37\":{}},\"comment\":{}}],[\"example7\",{\"_index\":24,\"name\":{\"24\":{}},\"comment\":{}}],[\"firstcol\",{\"_index\":11,\"name\":{\"11\":{}},\"comment\":{}}],[\"firstindent\",{\"_index\":26,\"name\":{\"26\":{}},\"comment\":{}}],[\"fragments\",{\"_index\":32,\"name\":{\"33\":{}},\"comment\":{}}],[\"graphemecount\",{\"_index\":31,\"name\":{\"32\":{}},\"comment\":{}}],[\"graphemes\",{\"_index\":6,\"name\":{\"6\":{}},\"comment\":{}}],[\"hyphen\",{\"_index\":12,\"name\":{\"12\":{}},\"comment\":{}}],[\"indent\",{\"_index\":13,\"name\":{\"13\":{},\"27\":{}},\"comment\":{}}],[\"indentchar\",{\"_index\":14,\"name\":{\"14\":{}},\"comment\":{}}],[\"indentempty\",{\"_index\":15,\"name\":{\"15\":{}},\"comment\":{}}],[\"indentfirst\",{\"_index\":16,\"name\":{\"16\":{}},\"comment\":{}}],[\"indentwidth\",{\"_index\":27,\"name\":{\"28\":{}},\"comment\":{}}],[\"index\",{\"_index\":0,\"name\":{\"0\":{}},\"comment\":{}}],[\"isnewline\",{\"_index\":17,\"name\":{\"17\":{}},\"comment\":{}}],[\"lines\",{\"_index\":34,\"name\":{\"35\":{}},\"comment\":{}}],[\"linewrap\",{\"_index\":1,\"name\":{\"1\":{}},\"comment\":{}}],[\"locale\",{\"_index\":18,\"name\":{\"18\":{}},\"comment\":{}}],[\"newline\",{\"_index\":19,\"name\":{\"19\":{}},\"comment\":{}}],[\"newlinereplacement\",{\"_index\":20,\"name\":{\"20\":{}},\"comment\":{}}],[\"opts\",{\"_index\":8,\"name\":{\"8\":{}},\"comment\":{}}],[\"overflow\",{\"_index\":21,\"name\":{\"21\":{}},\"comment\":{}}],[\"overflow_anywhere\",{\"_index\":4,\"name\":{\"4\":{}},\"comment\":{}}],[\"overflow_clip\",{\"_index\":3,\"name\":{\"3\":{}},\"comment\":{}}],[\"overflow_visible\",{\"_index\":2,\"name\":{\"2\":{}},\"comment\":{}}],[\"replacementwidth\",{\"_index\":28,\"name\":{\"29\":{}},\"comment\":{}}],[\"rules\",{\"_index\":7,\"name\":{\"7\":{}},\"comment\":{}}],[\"spacebreaker\",{\"_index\":37,\"name\":{\"39\":{},\"40\":{}},\"comment\":{}}],[\"verbose\",{\"_index\":25,\"name\":{\"25\":{}},\"comment\":{}}],[\"width\",{\"_index\":22,\"name\":{\"22\":{}},\"comment\":{}}],[\"workingwidth\",{\"_index\":30,\"name\":{\"31\":{}},\"comment\":{}}],[\"wrap\",{\"_index\":35,\"name\":{\"36\":{}},\"comment\":{}}]],\"pipeline\":[]}}"); \ No newline at end of file diff --git a/docs/classes/index.LineWrap.html b/docs/classes/index.LineWrap.html index 4a32905..32f57ee 100644 --- a/docs/classes/index.LineWrap.html +++ b/docs/classes/index.LineWrap.html @@ -21,7 +21,7 @@

Hierarchy

+
  • Defined in lib/index.js:23
  • @@ -68,7 +68,7 @@

    Parameters

    Optional opts: LineWrapOptions = {}

    Returns LineWrap

    +
  • Defined in lib/index.js:129
  • Properties

    @@ -78,7 +78,7 @@
    +
  • Defined in lib/index.js:41
  • OVERFLOW_CLIP: symbol = ...
    @@ -86,7 +86,7 @@
    +
  • Defined in lib/index.js:35
  • OVERFLOW_VISIBLE: symbol = ...
    @@ -95,43 +95,43 @@
    +
  • Defined in lib/index.js:29
  • #enderWidth: number

    Width of #opts.ellipsis or #opts.hyphen, in graphemes

    +
  • Defined in lib/index.js:75
  • #firstIndent: number

    How to indent the first line, expanded to string

    +
  • Defined in lib/index.js:51
  • #graphemes: Segmenter
    +
  • Defined in lib/index.js:43
  • #indent: string

    Indent expanded to string

    +
  • Defined in lib/index.js:57
  • #indentWidth: number

    Length of indent in graphemes

    +
  • Defined in lib/index.js:63
  • -
    #opts: {
        ellipsis: string;
        escape: EscapeString;
        firstCol: number;
        hyphen: string;
        indent: string | number;
        indentChar: string;
        indentEmpty: boolean;
        indentFirst: boolean;
        isNewline: RegExp;
        locale: string;
        newline: string;
        newlineReplacement: string;
        overflow: symbol;
        width: number;
    }
    +
    #opts: {
        ellipsis: string;
        escape: EscapeString;
        example7: boolean;
        firstCol: number;
        hyphen: string;
        indent: string | number;
        indentChar: string;
        indentEmpty: boolean;
        indentFirst: boolean;
        isNewline: RegExp;
        locale: string;
        newline: string;
        newlineReplacement: string;
        overflow: symbol;
        verbose: boolean;
        width: number;
    }

    Type declaration

      @@ -140,6 +140,8 @@
      ellipsis
      escape: EscapeString
    • +
      example7: boolean
    • +
    • firstCol: number
    • hyphen: string
    • @@ -162,28 +164,30 @@
      newlineReplacement
      overflow: symbol
    • +
      verbose: boolean
    • +
    • width: number
    +
  • Defined in lib/index.js:45
  • #replacementWidth: number

    Width of #opts.newlineReplacement, in graphemes

    +
  • Defined in lib/index.js:69
  • #rules: SpaceBreaker
    +
  • Defined in lib/index.js:44
  • #workingWidth: number

    The working area, width - indent.

    +
  • Defined in lib/index.js:81
  • Methods

    @@ -193,7 +197,7 @@

    Returns Generator<Break, void, unknown>

    +
  • Defined in lib/index.js:285
    • @@ -218,7 +222,7 @@

      Parameters

      brk: Break

    Returns Generator<Break, void, unknown>

    +
  • Defined in lib/index.js:215
    • @@ -233,7 +237,7 @@

      Parameters

      str: string

    Returns number

    +
  • Defined in lib/index.js:200
    • @@ -252,7 +256,7 @@
      text: Returns Generator<string, void, undefined>
    +
  • Defined in lib/index.js:332
    • @@ -268,7 +272,7 @@

      Parameters

      text: string

    Returns string

    +
  • Defined in lib/index.js:398
  • +
  • Defined in lib/spacebreaker.js:1
  • Index

    diff --git a/lib/index.js b/lib/index.js index af09a50..6b14026 100644 --- a/lib/index.js +++ b/lib/index.js @@ -133,6 +133,7 @@ export class LineWrap { this.#opts = { escape: noEscape, ellipsis: '\u{2026}', + example7: false, firstCol: NaN, hyphen: '-', indent: '', @@ -144,10 +145,14 @@ export class LineWrap { newline: '\n', newlineReplacement: ' ', overflow: LineWrap.OVERFLOW_VISIBLE, + verbose: false, width: 80, ...opts, } - this.#rules = new SpaceBreaker() + this.#rules = new SpaceBreaker({ + example7: this.#opts.example7, + verbose: this.#opts.verbose, + }) this.#graphemes = new Intl.Segmenter(this.#opts.locale, { granularity: 'grapheme', }) @@ -273,7 +278,7 @@ export class LineWrap { /** * Split a string into chunks. Each existing newline in the input creates a * chunk boundary. Each URL is a chunk. Each remaining linebreak segment - * is a chunk, which has had the escape function performed on it. + * is a chunk * * @param {string} text */ @@ -338,6 +343,10 @@ export class LineWrap { let spLen = 0 for (const chunk of this.#chunks(text)) { for (const frag of this.#fragments(chunk)) { + if (this.#opts.verbose) { + // eslint-disable-next-line no-console + console.log(frag) + } const fs = /** @type {string} */ (frag.string) // All fragments are either shorter than the working width, or we're // configured to go over. diff --git a/lib/spacebreaker.js b/lib/spacebreaker.js index a34b033..ada598e 100644 --- a/lib/spacebreaker.js +++ b/lib/spacebreaker.js @@ -99,12 +99,12 @@ function LBspacesStart(state) { if (state.next.cls === SP) { switch (state.cur.cls) { - case ZW: // See LB8 - case OP: // See LB14 - case QU: // See LB15 + case B2: // See LB17 case CL: // See LB16 case CP: // See LB16 - case B2: // See LB17 + case OP: // See LB14 + case QU: // See LB15 + case ZW: // See LB8 return PASS default: state.extra.fancy = true @@ -127,7 +127,9 @@ function LBspacesStart(state) { function LBbreakAfterSpace(state) { // SP ÷ if (state.cur.cls === SP) { - state.setProp('space', true) + // This is space at the end of an "even after spaces" run, so the chunk + // isn't actually empty. Do not set the space property. + // state.setProp('space', true) return MAY_BREAK } return PASS diff --git a/test/index.test.js b/test/index.test.js index fade552..65f6d1f 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -65,4 +65,16 @@ describe('line wrapping', () => { new LineWrap({width: 4, indent: 4}) }) }) + + it('does verbose logging', () => { + /* eslint-disable no-console */ + const old = console.log + const res = [] + console.log = (...args) => res.push(args) + const lw = new LineWrap({width: 4, verbose: true}) + assert.equal(lw.wrap('abcde'), 'abcde') + assert(res.length > 0) + console.log = old + /* eslint-enable no-console */ + }) }) diff --git a/test/spacebreaker.test.js b/test/spacebreaker.test.js index 859c09d..2c47ce4 100644 --- a/test/spacebreaker.test.js +++ b/test/spacebreaker.test.js @@ -28,5 +28,6 @@ describe('special space breaking', () => { assertBreaks('a ', [[1, false], [2, true]]) assertBreaks('a\u200Bb', [[2, false], [3, false]]) assertBreaks('\u2014 \u2014', [[4, false]]) + assertBreaks('utf8 base64" Default:', [[4, false], [5, true], [13, false], [21, false]]) }) })