Skip to content

Commit

Permalink
Add @0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanve committed Mar 12, 2014
1 parent ff77840 commit 11f4c85
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 2 deletions.
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
2 changes: 2 additions & 0 deletions GruntFile.js
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');
22 changes: 20 additions & 2 deletions README.md
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)
21 changes: 21 additions & 0 deletions eol.js
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;
}));
6 changes: 6 additions & 0 deletions eol.min.js
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});
22 changes: 22 additions & 0 deletions package.json
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"
}
}
15 changes: 15 additions & 0 deletions src/index.js
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;
}));
28 changes: 28 additions & 0 deletions test/index.html
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>
16 changes: 16 additions & 0 deletions test/index.js
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));

0 comments on commit 11f4c85

Please sign in to comment.