https://github.com/junosuarez/clean-whitespace
normalize whitepsace characters to \t \n and space
https://github.com/junosuarez/clean-whitespace
Last synced: over 1 year ago
JSON representation
normalize whitepsace characters to \t \n and space
- Host: GitHub
- URL: https://github.com/junosuarez/clean-whitespace
- Owner: junosuarez
- License: mit
- Created: 2013-09-13T22:17:03.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2013-09-14T00:08:47.000Z (almost 13 years ago)
- Last Synced: 2025-04-10T15:36:24.188Z (over 1 year ago)
- Language: JavaScript
- Size: 113 KB
- Stars: 6
- Watchers: 7
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# clean-whitespace
normalize whitepsace characters to \t \n and space
## usage
```js
var cleanWhitespace = require('clean-whitespace')
var clean = cleanWhitespace(gnarlyStringsUsersCopyAndPastedFromWord)
var options = {tab: ' '}
var spaces = cleanWhitespace('\t\t', options)
// => ' '
```
Cleans and normalizes whitespace, handling line breaks, characters, whitespace, and invisible characters.
### Options
The second parameter is an options object with any of the following:
- **tab** : string, default '\t' - replacement for tab characters
- **tabSpace** : number - if specified, matches `tabSpace` repeated spaces as a tab character, eg:
```js
cleanWhitespace(' hi', {tabSpace: 2}) // => '\thi'
```
- **space** : string, default ' ' - replacement for space characters
- **line** : string, default '\n' - replacement for linebreak characters
- **invisible** : string, default '' - replacement for invisible characters
## api
### `cleanWhitespace(String, options? : Object) => String`
Cleans extended whitespace characters from strings.
## installation
$ npm install clean-whitespace
## running the tests
From package root:
$ npm install
$ npm test
## contributors
- jden
## license
MIT. (c) MMXIII AgileMD http://agilemd.com