diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..2125666 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/GruntFile.js b/GruntFile.js new file mode 100644 index 0000000..b0ebb04 --- /dev/null +++ b/GruntFile.js @@ -0,0 +1,2 @@ +//github.com/ryanve/universal#grunt +module.exports = require('./node_modules/universal/GruntFile'); \ No newline at end of file diff --git a/README.md b/README.md index c44cef7..7e4bef3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,20 @@ -eol -=== +# eol +#### [Newline](http://en.wikipedia.org/wiki/Newline) character converter for JavaScript + +## API + +### `eol.crlf(text)` +- Normalize text to CRLF (Windows, DOS) line endings +- @return string + +### `eol.lf(text)` +- Normalize text to LF (Unix, OS X) line endings +- @return string + +### `eol.cr(text)` +- Normalize text to CR (Mac OS) line endings +- @return string + +## License + +[MIT](package.json#L6-L7) \ No newline at end of file diff --git a/eol.js b/eol.js new file mode 100644 index 0000000..0327fa6 --- /dev/null +++ b/eol.js @@ -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; +})); \ No newline at end of file diff --git a/eol.min.js b/eol.min.js new file mode 100644 index 0000000..760769a --- /dev/null +++ b/eol.min.js @@ -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}); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..67bb4c9 --- /dev/null +++ b/package.json @@ -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" + } +} \ No newline at end of file diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..b8f269f --- /dev/null +++ b/src/index.js @@ -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; +})); \ No newline at end of file diff --git a/test/index.html b/test/index.html new file mode 100644 index 0000000..3e3b7ec --- /dev/null +++ b/test/index.html @@ -0,0 +1,28 @@ + +
$ npm install
+$ grunt aok
+