normalize-space

1.0.2 • Public • Published

normalize-space Build Status

Converts anything to string with normalized form. JavaScript equivalent of XSLT normalize-space()

Install

$ npm install --save normalize-space

Usage

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.

Usage with Node.js

var normalize = require('normalize-space');
 
normalize('  a   \n\n\n    a  ');
//=> 'a a'

Usage with browser

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> 

License

normalize-space is licensed under the MIT Open Source license. For more information, see the LICENSE file in this repository.

Package Sidebar

Install

npm i normalize-space

Weekly Downloads

227

Version

1.0.2

License

MIT

Last publish

Collaborators

  • pbakondy