Skip to content

Commit

Permalink
Require Node.js 8, add TypeScript definition (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 9, 2019
1 parent 06b2f98 commit fbb3392
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 82 deletions.
5 changes: 1 addition & 4 deletions .editorconfig
Expand Up @@ -7,9 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[package.json]
[*.yml]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
2 changes: 1 addition & 1 deletion .gitattributes
@@ -1 +1 @@
* text=auto
* text=auto eol=lf
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
node_modules
yarn.lock
13 changes: 0 additions & 13 deletions .jshintrc

This file was deleted.

1 change: 1 addition & 0 deletions .npmrc
@@ -0,0 +1 @@
package-lock=false
6 changes: 2 additions & 4 deletions .travis.yml
@@ -1,6 +1,4 @@
sudo: false
language: node_js
node_js:
- 'iojs'
- '0.12'
- '0.10'
- '10'
- '8'
14 changes: 14 additions & 0 deletions index.d.ts
@@ -0,0 +1,14 @@
/**
Remove leading, trailing and repeated whitespace from a string.
@example
```
import condenseWhitespace = require('condense-whitespace');
condenseWhitespace(' foo bar baz ');
//=> 'foo bar baz'
```
*/
declare function condenseWhitespace(str: string): string;

export = condenseWhitespace;
6 changes: 3 additions & 3 deletions index.js
@@ -1,8 +1,8 @@
'use strict';
module.exports = function (str, opts) {
if (typeof str !== 'string') {
module.exports = string => {
if (typeof string !== 'string') {
throw new TypeError('Expected a string');
}

return str.trim().replace(/\s{2,}/g, ' ');
return string.trim().replace(/\s{2,}/g, ' ');
};
4 changes: 4 additions & 0 deletions index.test-d.ts
@@ -0,0 +1,4 @@
import {expectType} from 'tsd';
import condense = require('.');

expectType<string>(condense(' \n\n\t Hello World \t\n'));
20 changes: 4 additions & 16 deletions license
@@ -1,21 +1,9 @@
The MIT License (MIT)
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
73 changes: 38 additions & 35 deletions package.json
@@ -1,37 +1,40 @@
{
"name": "condense-whitespace",
"version": "1.0.0",
"description": "Remove leading, trailing and repeated whitespace from a string",
"license": "MIT",
"repository": "sindresorhus/condense-whitespace",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "ava"
},
"files": [
"index.js"
],
"keywords": [
"whitespace",
"space",
"condense",
"collapse",
"compact",
"repeated",
"string",
"str",
"trim",
"remove",
"strip"
],
"devDependencies": {
"ava": "*"
}
"name": "condense-whitespace",
"version": "1.0.0",
"description": "Remove leading, trailing and repeated whitespace from a string",
"license": "MIT",
"repository": "sindresorhus/condense-whitespace",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"whitespace",
"space",
"condense",
"collapse",
"compact",
"repeated",
"string",
"str",
"trim",
"remove",
"strip"
],
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
6 changes: 3 additions & 3 deletions readme.md
Expand Up @@ -6,14 +6,14 @@
## Install

```
$ npm install --save condense-whitespace
$ npm install condense-whitespace
```


## Usage

```js
var condenseWhitespace = require('condense-whitespace');
const condenseWhitespace = require('condense-whitespace');

condenseWhitespace(' foo bar baz ');
//=> 'foo bar baz'
Expand All @@ -27,4 +27,4 @@ condenseWhitespace(' foo bar baz ');

## License

MIT © [Sindre Sorhus](http://sindresorhus.com)
MIT © [Sindre Sorhus](https://sindresorhus.com)
6 changes: 3 additions & 3 deletions test.js
@@ -1,6 +1,6 @@
import test from 'ava';
import m from './';
import condenseWhitespace from '.';

test(t => {
t.is(m(' foo bar baz '), 'foo bar baz');
test('main', t => {
t.is(condenseWhitespace(' foo bar baz '), 'foo bar baz');
});

0 comments on commit fbb3392

Please sign in to comment.