Converts anything to string with normalized form. JavaScript equivalent of XSLT normalize-space()
$ npm install --save normalize-space
The function first converts any incoming value to string then converts all the whitespace characters to a single space.
It works the same way as XSLT normalize-space().
If the incoming parameter is a Node
( result of Document.querySelector() ) or a NodeList
( result of Document.querySelectorAll() ) the module also converts it to string and normalizes its content.
var normalize = require('normalize-space');
normalize(' a \n\n\n a ');
//=> 'a a'
Use the browser-specific file:
<script src="normalize-space/browser/index.js" type="text/javascript"></script>
<script>
console.log(window.normalize(' a \n\n\n a ')); //=> 'a a'
</script>
normalize-space is licensed under the MIT Open Source license. For more information, see the LICENSE file in this repository.