Skip to content

Commit

Permalink
add .graceful method
Browse files Browse the repository at this point in the history
ideas for better name please?!?! :)
  • Loading branch information
sindresorhus committed Feb 16, 2016
1 parent 54a9b99 commit 4c9e2f3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions index.js
Expand Up @@ -18,3 +18,7 @@ module.exports = function (str) {

return crlf > lf ? '\r\n' : '\n';
};

module.exports.graceful = function (str) {
return module.exports(str) || '\n';
};
11 changes: 10 additions & 1 deletion readme.md
Expand Up @@ -19,7 +19,16 @@ detectNewline('foo\nbar\nbaz\r\n');
//=> '\n'
```

Returns `null` when no newline character is found.

## API

### detectNewline(input)

Returns detected newline or `null` when no newline character is found.

### detectNewline.graceful(input)

Returns detected newline or `\n` when no newline character is found.


## Related
Expand Down
1 change: 1 addition & 0 deletions test.js
Expand Up @@ -7,4 +7,5 @@ test(t => {
t.is(m('foo\nbar\nbaz\r\n'), '\n');
t.is(m('foo\nbar\r\n'), '\n');
t.is(m('foo'), null);
t.is(m.graceful('foo'), '\n');
});

0 comments on commit 4c9e2f3

Please sign in to comment.