-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
10 changed files
with
132 additions
and
2 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 @@ | ||
* 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,2 @@ | ||
//github.com/ryanve/universal#grunt | ||
module.exports = require('./node_modules/universal/GruntFile'); |
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 |
---|---|---|
@@ -1,2 +1,20 @@ | ||
eol | ||
=== | ||
# eol | ||
#### [Newline](http://en.wikipedia.org/wiki/Newline) character converter for JavaScript | ||
|
||
## API | ||
|
||
### `eol.crlf(text)` | ||
- Normalize <var>text</var> to <b>CRLF</b> (Windows, DOS) line endings | ||
- <b>@return</b> string | ||
|
||
### `eol.lf(text)` | ||
- Normalize <var>text</var> to <b>LF</b> (Unix, OS X) line endings | ||
- <b>@return</b> string | ||
|
||
### `eol.cr(text)` | ||
- Normalize <var>text</var> to <b>CR</b> (Mac OS) line endings | ||
- <b>@return</b> string | ||
|
||
## License | ||
|
||
[MIT](package.json#L6-L7) |
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 @@ | ||
/*! | ||
* eol 0.1.0+201403121730 | ||
* https://github.com/ryanve/eol | ||
* MIT License (c) 2014 Ryan Van Etten | ||
*/ | ||
|
||
(function(root, name, make) { | ||
if (typeof module != 'undefined' && module.exports) module.exports = make(); | ||
else root[name] = make(); | ||
}(this, 'eol', function() { | ||
function converts(to) { | ||
return function(text) { | ||
return text.replace(newline, to); | ||
}; | ||
} | ||
var api = {}, newline = /\r\n|\r|\n/g; | ||
api['lf'] = converts('\n'); | ||
api['cr'] = converts('\r'); | ||
api['crlf'] = converts('\r\n'); | ||
return api; | ||
})); |
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,6 @@ | ||
/*! | ||
* eol 0.1.0+201403121730 | ||
* https://github.com/ryanve/eol | ||
* MIT License (c) 2014 Ryan Van Etten | ||
*/ | ||
!function(a,b,c){"undefined"!=typeof module&&module.exports?module.exports=c():a[b]=c()}(this,"eol",function(){function a(a){return function(b){return b.replace(c,a)}}var b={},c=/\r\n|\r|\n/g;return b.lf=a("\n"),b.cr=a("\r"),b.crlf=a("\r\n"),b}); |
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,22 @@ | ||
{ | ||
"name": "eol", | ||
"description": "Newline character converter", | ||
"version": "0.1.0", | ||
"homepage": "https://github.com/ryanve/eol", | ||
"license": "MIT", | ||
"author": "Ryan Van Etten", | ||
"keywords": ["eol", "newline", "convert", "converter", "conversion", "character", "ender"], | ||
"main": "./eol.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ryanve/eol.git" | ||
}, | ||
"devDependencies": { | ||
"aok": "~1.8.1", | ||
"universal": "~0.0.2", | ||
"grunt": "~0.4.2", | ||
"grunt-contrib-uglify": "~0.3.0", | ||
"grunt-contrib-concat": "~0.3.0", | ||
"grunt-contrib-jshint": "~0.8.0" | ||
} | ||
} |
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 @@ | ||
(function(root, name, make) { | ||
if (typeof module != 'undefined' && module.exports) module.exports = make(); | ||
else root[name] = make(); | ||
}(this, 'eol', function() { | ||
function converts(to) { | ||
return function(text) { | ||
return text.replace(newline, to); | ||
}; | ||
} | ||
var api = {}, newline = /\r\n|\r|\n/g; | ||
api['lf'] = converts('\n'); | ||
api['cr'] = converts('\r'); | ||
api['crlf'] = converts('\r\n'); | ||
return api; | ||
})); |
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 @@ | ||
<!DOCTYPE html> | ||
<title>Tests</title> | ||
<style> | ||
html { font-family:sans-serif; background:#efefef; color:#111 } | ||
body { width:96%; margin:auto; font-size:1em; line-height:1.6 } | ||
pre, code, kbd { font-family:monospace; -moz-tab-size:2; -o-tab-size:2; tab-size:2 } | ||
h3 b { font-weight:700 } | ||
h3, pre b { font-weight:400 } | ||
pre { padding:0 .5em; white-space:pre-line } | ||
pre span { white-space:pre-wrap } | ||
pre b { color:#008080 } | ||
pre small { font-size:inherit; font-family:inherit; color:#707070 } | ||
kbd { display:inline-block; padding:.2em } | ||
pre kbd { padding:0 } | ||
</style> | ||
|
||
<h1>To run tests</h1> | ||
<h3>Install <a href="../package.json">devDependencies</a></h3> | ||
<pre><span><b>$</b> <kbd>npm install</kbd></span></pre> | ||
<h3><b>Browser</b>: open the console</h3> | ||
<h3><b>CLI</b>: run tests via <a href="https://github.com/ryanve/aok#grunt-aok">grunt aok</a></h3> | ||
<pre><span><b>$</b> <kbd>grunt aok</kbd></span></pre> | ||
<h1>To edit tests</h1> | ||
<p>Edit <a href="https://github.com/ryanve/aok#readme">aok</a> tests in <a href="index.js">index.js</a></p> | ||
|
||
<script src="../src/index.js"></script> | ||
<script src="../node_modules/aok/aok.min.js"></script> | ||
<script src="./index.js"></script> |
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,16 @@ | ||
(function(root) { | ||
var common = typeof module != 'undefined' && !!module.exports; | ||
var aok = common ? require('aok') : root.aok; | ||
var eol = common ? require('../src') : root.eol; | ||
|
||
function contains(str, needle, guard) { | ||
if (guard) needle = str, str = this; | ||
return !!~str.indexOf(needle); | ||
} | ||
|
||
aok.pass(['lf', 'cr', 'crlf'], function(method, i) { | ||
var sample = ' ' + this.join() + 'text' + this.join(), normal = eol[method](sample); | ||
aok(method + ' retains', contains(normal, this[i])); | ||
aok(method + ' normalizes', ('crlf' === method ? 0 : 2) === aok.fail(this, contains, normal)); | ||
}, ['\n', '\r', '\r\n']); | ||
}(this)); |