Skip to content

Commit

Permalink
Merge pull request #3 from ryanve/next
Browse files Browse the repository at this point in the history
0.3.0 release
  • Loading branch information
ryanve authored Sep 11, 2016
2 parents 65e704f + c6800e8 commit 562298e
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 125 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
2 changes: 0 additions & 2 deletions GruntFile.js

This file was deleted.

19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
MIT License

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.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# eol
#### [Newline](http://en.wikipedia.org/wiki/Newline) character converter for JavaScript

```sh
npm install eol --save
```

```js
var eol = require('eol')
```

## API

### `eol.auto(text)`
Expand All @@ -20,5 +28,4 @@
- <b>@return</b> string with line endings normalized to `\r`

## License

[MIT](package.json#L6-L7)
MIT
35 changes: 17 additions & 18 deletions eol.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
/*!
* eol 0.2.0+201403200220
* https://github.com/ryanve/eol
* MIT License, 2014 Ryan Van Etten
*/
!function(root, name, make) {
if (typeof module != 'undefined' && module.exports) module.exports = make();
else root[name] = make();
if (typeof module != 'undefined' && module.exports) module.exports = make()
else root[name] = make()
}(this, 'eol', function() {

var api = {}
var isWindows = typeof process != 'undefined' && 'win32' === process.platform
var newline = /\r\n|\r|\n/g

function converts(to) {
return function(text) {
return text.replace(newline, to);
};
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');
api['auto'] = converts(
typeof process != 'undefined' && 'win32' === process.platform ? '\r\n' : '\n'
);
return api;
});

api['lf'] = converts('\n')
api['cr'] = converts('\r')
api['crlf'] = converts('\r\n')
api['auto'] = converts(isWindows ? '\r\n' : '\n')

return api
});
6 changes: 0 additions & 6 deletions eol.min.js

This file was deleted.

47 changes: 28 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,53 @@
{
"name": "eol",
"description": "Newline character converter",
"version": "0.2.0",
"version": "0.3.0",
"homepage": "https://github.com/ryanve/eol",
"license": "MIT",
"author": "Ryan Van Etten",
"keywords": ["eol", "newline", "convert", "converter", "conversion", "character", "ender"],
"main": "./eol.js",
"keywords": [
"eol",
"newline",
"newlines",
"convert",
"converter",
"conversion",
"character",
"formatting",
"format",
"string",
"file",
"ender"
],
"main": "eol.js",
"scripts": {
"pretest": "jshint eol.js && jshint test.js",
"test": "node test.js"
},
"repository": {
"type": "git",
"url": "https://github.com/ryanve/eol.git"
},
"bugs": {
"url": "https://github.com/ryanve/eol/issues"
},
"devDependencies": {
"aok": "~1.8.1",
"universal": "~0.0.5",
"grunt": "~0.4.4",
"grunt-contrib-uglify": "~0.3.0",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-jshint": "~0.8.0"
"aok": "^1.9.0",
"jshint": "^2.9.3"
},
"jshintConfig": {
"asi": true,
"boss": true,
"browser": true,
"debug": true,
"devel": true,
"eqnull": true,
"evil": true,
"expr": true,
"globals": {
"define": true,
"ender": true
},
"jquery": true,
"latedef": "nofunc",
"laxcomma": true,
"maxerr": 10,
"maxerr": 5,
"node": true,
"sub": true,
"supernew": true,
"undef": true,
"unused": true
}
}
}
18 changes: 0 additions & 18 deletions src/index.js

This file was deleted.

14 changes: 14 additions & 0 deletions test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en-US">
<title>Tests</title>
<style>
html { font: 1em/1.6 sans-serif; background: ghostwhite; color: #333 }
body { width: 94%; margin: auto }
</style>

<h1>Tests</h1>
<p>Open the console to view test results

<script src="eol.js"></script>
<script src="node_modules/aok/aok.js"></script>
<script src="test.js"></script>
43 changes: 43 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
!function(root) {
function contains(str, needle) {
return !!~str.indexOf(needle);
}

var common = typeof module != 'undefined' && !!module.exports
var aok = common ? require('aok') : root.aok
var eol = common ? require('./') : root.eol
var isWindows = typeof process != 'undefined' && 'win32' === process.platform
var meths = ['lf', 'cr', 'crlf', 'auto']
var chars = ['\n', '\r', '\r\n', isWindows ? '\r\n' : '\n']
var sample = ' ' + chars.join() + 'text' + chars.join()

aok.prototype.fail = function() {
throw new Error('FAILED TEST: ' + this.id)
}

aok('contains sees contained text', contains('ab', 'a') === true)
aok('sample contains newlines', contains(sample, '\n') && contains(sample, '\r'))
aok('returns other strings as is', eol.auto('random') === 'random')
aok('returns empty strings as is', eol.auto('') === '')
aok('whitespace intact', eol.lf(' \t ') === ' \t ')
aok('lf repeat newlines intact', eol.lf('\n\n\r\r') === '\n\n\n\n')
aok('cr repeat newlines intact', eol.cr('\n\n\r\r') === '\r\r\r\r')
aok('crlf repeat newlines intact', eol.crlf('\r\n\r\n') === '\r\n\r\n')

aok.pass(meths, function(method, i) {
var normalized = eol[method](sample)
aok(method + ' retains', contains(normalized, chars[i]))
aok(method + ' normalizes', !aok.fail(chars, function(c) {
return contains(chars[i], c) === contains(normalized, c)
}))

return eol.auto(sample) === normalized
})

aok('auto is aware', eol[isWindows ? 'crlf' : 'lf'](sample) === eol.auto(sample))
aok('auto matches only 1 and self', aok.pass(meths, function(method) {
return eol.auto(sample) === eol[method](sample);
}) === 2)

aok.log('All tests passed =)')
}(this);
28 changes: 0 additions & 28 deletions test/index.html

This file was deleted.

32 changes: 0 additions & 32 deletions test/index.js

This file was deleted.

0 comments on commit 562298e

Please sign in to comment.