Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Sep 29, 2015
0 parents commit 86f6aaf
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- 'stable'
- '0.12'
- '0.10'
13 changes: 13 additions & 0 deletions index.js
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]+$/, '');
};
21 changes: 21 additions & 0 deletions license
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.
42 changes: 42 additions & 0 deletions package.json
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": "*"
}
}
46 changes: 46 additions & 0 deletions readme.md
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)
28 changes: 28 additions & 0 deletions test.js
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();
});

0 comments on commit 86f6aaf

Please sign in to comment.