Skip to content

Commit

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

[{package.json,*.yml}]
[*.yml]
indent_style = space
indent_size = 2
3 changes: 1 addition & 2 deletions .gitattributes
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
@@ -0,0 +1 @@
package-lock=false
5 changes: 3 additions & 2 deletions .travis.yml
@@ -1,4 +1,5 @@
language: node_js
node_js:
- '6'
- '4'
- '12'
- '10'
- '8'
42 changes: 42 additions & 0 deletions index.d.ts
@@ -0,0 +1,42 @@
declare const trimNewlines: {
/**
Trim from the start and end of a string.
@example
```js
import trimNewlines = require('trim-newlines');
trimNewlines('\n🦄\r\n');
//=> '🦄'
```
*/
(string: string): string;

/**
Trim from the start of a string.
@example
```js
import trimNewlines = require('trim-newlines');
trimNewlines.start('\n🦄\r\n');
//=> '🦄\r\n'
```
*/
start(string: string): string;

/**
Trim from the end of a string.
@example
```js
import trimNewlines = require('trim-newlines');
trimNewlines.end('\n🦄\r\n');
//=> '\n🦄'
```
*/
end(string: string): string;
};

export = trimNewlines;
6 changes: 3 additions & 3 deletions index.js
@@ -1,4 +1,4 @@
'use strict';
module.exports = x => x.replace(/^[\r\n]+/, '').replace(/[\r\n]+$/, '');
module.exports.start = x => x.replace(/^[\r\n]+/, '');
module.exports.end = x => x.replace(/[\r\n]+$/, '');
module.exports = string => string.replace(/^[\r\n]+/, '').replace(/[\r\n]+$/, '');
module.exports.start = string => string.replace(/^[\r\n]+/, '');
module.exports.end = string => string.replace(/[\r\n]+$/, '');
6 changes: 6 additions & 0 deletions index.test-d.ts
@@ -0,0 +1,6 @@
import {expectType} from 'tsd';
import trimNewlines = require('.');

expectType<string>(trimNewlines('\n🦄\r\n'));
expectType<string>(trimNewlines.start('\n\n🦄\n'));
expectType<string>(trimNewlines.end('\n🦄\n\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.
82 changes: 42 additions & 40 deletions package.json
@@ -1,42 +1,44 @@
{
"name": "trim-newlines",
"version": "2.0.0",
"description": "Trim newlines from the start and/or end of a string",
"license": "MIT",
"repository": "sindresorhus/trim-newlines",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"trim",
"newline",
"newlines",
"linebreak",
"lf",
"crlf",
"left",
"right",
"start",
"end",
"string",
"str",
"remove",
"delete",
"strip"
],
"devDependencies": {
"ava": "*",
"xo": "*"
}
"name": "trim-newlines",
"version": "2.0.0",
"description": "Trim newlines from the start and/or end of a string",
"license": "MIT",
"repository": "sindresorhus/trim-newlines",
"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": [
"trim",
"newline",
"newlines",
"linebreak",
"lf",
"crlf",
"left",
"right",
"start",
"end",
"string",
"str",
"remove",
"delete",
"strip"
],
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
18 changes: 12 additions & 6 deletions readme.md
Expand Up @@ -6,7 +6,7 @@
## Install

```
$ npm install --save trim-newlines
$ npm install trim-newlines
```


Expand All @@ -15,22 +15,28 @@ $ npm install --save trim-newlines
```js
const trimNewlines = require('trim-newlines');

trimNewlines('\nunicorn\r\n');
//=> 'unicorn'
trimNewlines('\n🦄\r\n');
//=> '🦄'

trimNewlines.start('\n🦄\r\n');
//=> '🦄\r\n'

trimNewlines.end('\n🦄\r\n');
//=> '\n🦄'
```


## API

### trimNewlines(input)
### trimNewlines(string)

Trim from the start and end of a string.

### trimNewlines.start(input)
### trimNewlines.start(string)

Trim from the start of a string.

### trimNewlines.end(input)
### trimNewlines.end(string)

Trim from the end of a string.

Expand Down
30 changes: 15 additions & 15 deletions test.js
@@ -1,25 +1,25 @@
import test from 'ava';
import m from '.';
import trimNewlines from '.';

test('main', t => {
t.is(m('\nx\n'), 'x');
t.is(m('\n\n\nx\n\n\n'), 'x');
t.is(m('\r\nx\r\n'), 'x');
t.is(m('\n\r\n\nx\n\r\n\n'), 'x');
t.is(trimNewlines('\nx\n'), 'x');
t.is(trimNewlines('\n\n\nx\n\n\n'), 'x');
t.is(trimNewlines('\r\nx\r\n'), 'x');
t.is(trimNewlines('\n\r\n\nx\n\r\n\n'), 'x');
});

test('start', t => {
t.is(m.start('\nx'), 'x');
t.is(m.start('\r\nx'), 'x');
t.is(m.start('\n\n\n\nx'), 'x');
t.is(m.start('\n\n\r\n\nx'), 'x');
t.is(m.start('x\n\n\r\n\n'), 'x\n\n\r\n\n');
t.is(trimNewlines.start('\nx'), 'x');
t.is(trimNewlines.start('\r\nx'), 'x');
t.is(trimNewlines.start('\n\n\n\nx'), 'x');
t.is(trimNewlines.start('\n\n\r\n\nx'), 'x');
t.is(trimNewlines.start('x\n\n\r\n\n'), 'x\n\n\r\n\n');
});

test('end', t => {
t.is(m.end('x\n'), 'x');
t.is(m.end('x\r\n'), 'x');
t.is(m.end('x\n\n\n\n'), 'x');
t.is(m.end('x\n\n\r\n\n'), 'x');
t.is(m.end('\n\n\r\n\nx'), '\n\n\r\n\nx');
t.is(trimNewlines.end('x\n'), 'x');
t.is(trimNewlines.end('x\r\n'), 'x');
t.is(trimNewlines.end('x\n\n\n\n'), 'x');
t.is(trimNewlines.end('x\n\n\r\n\n'), 'x');
t.is(trimNewlines.end('\n\n\r\n\nx'), '\n\n\r\n\nx');
});

0 comments on commit 75db891

Please sign in to comment.