-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 86f6aaf
Showing
9 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
end_of_line = lf | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- 'stable' | ||
- '0.12' | ||
- '0.10' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
var fn = module.exports = function (x) { | ||
return fn.end(fn.start(x)); | ||
}; | ||
|
||
fn.start = function (x) { | ||
return x.replace(/^[\r\n]+/, ''); | ||
}; | ||
|
||
fn.end = function (x) { | ||
return x.replace(/[\r\n]+$/, ''); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
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: | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "trim-newlines", | ||
"version": "0.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": ">=0.10.0" | ||
}, | ||
"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": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# trim-newlines [![Build Status](https://travis-ci.org/sindresorhus/trim-newlines.svg?branch=master)](https://travis-ci.org/sindresorhus/trim-newlines) | ||
|
||
> Trim [newlines](https://en.wikipedia.org/wiki/Newline) from the start and/or end of a string | ||
|
||
## Install | ||
|
||
``` | ||
$ npm install --save trim-newlines | ||
``` | ||
|
||
|
||
## Usage | ||
|
||
```js | ||
var trimNewlines = require('trim-newlines'); | ||
|
||
trimNewlines('\nunicorn\r\n'); | ||
//=> 'unicorn' | ||
``` | ||
|
||
|
||
## API | ||
|
||
### trimNewlines(input) | ||
|
||
Trim from the start and end of a string. | ||
|
||
### trimNewlines.start(input) | ||
|
||
Trim from the start of a string. | ||
|
||
### trimNewlines.end(input) | ||
|
||
Trim from the end of a string. | ||
|
||
|
||
## Related | ||
|
||
- [trim-left](https://github.com/sindresorhus/trim-left) - Similar to `String#trim()` but removes only whitespace on the left | ||
- [trim-right](https://github.com/sindresorhus/trim-right) - Similar to `String#trim()` but removes only whitespace on the right. | ||
|
||
|
||
## License | ||
|
||
MIT © [Sindre Sorhus](http://sindresorhus.com) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import test from 'ava'; | ||
import fn from './'; | ||
|
||
test('main', t => { | ||
t.is(fn('\nx\n'), 'x'); | ||
t.is(fn('\n\n\nx\n\n\n'), 'x'); | ||
t.is(fn('\r\nx\r\n'), 'x'); | ||
t.is(fn('\n\r\n\nx\n\r\n\n'), 'x'); | ||
t.end(); | ||
}); | ||
|
||
test('start', t => { | ||
t.is(fn.start('\nx'), 'x'); | ||
t.is(fn.start('\r\nx'), 'x'); | ||
t.is(fn.start('\n\n\n\nx'), 'x'); | ||
t.is(fn.start('\n\n\r\n\nx'), 'x'); | ||
t.is(fn.start('x\n\n\r\n\n'), 'x\n\n\r\n\n'); | ||
t.end(); | ||
}); | ||
|
||
test('end', t => { | ||
t.is(fn.end('x\n'), 'x'); | ||
t.is(fn.end('x\r\n'), 'x'); | ||
t.is(fn.end('x\n\n\n\n'), 'x'); | ||
t.is(fn.end('x\n\n\r\n\n'), 'x'); | ||
t.is(fn.end('\n\n\r\n\nx'), '\n\n\r\n\nx'); | ||
t.end(); | ||
}); |