
string-normalize-space is a node.js module implementing one single function, normalizeSpace, following the definition from XPath 1.0.
So it's basically like String.prototype.trim(), but works also inside the string.
Installation
npm install string-normalize-space
Usage
const {normalizeSpace} = require ('string-normalize-space')
const ab = normalizeSpace (' A\r\n\t B ')
Notes
Unlike numerous similar modules, this one doesn't rely on any regular expressions.
As mentioned before, the XPath 1.0 specification is followed, so only 4 characters are considered "space". No effort is made to support extended Unicode space characters.