| # https://git.io/about-funding-files | ||
| github: ryanve | ||
| ko_fi: ryanve |
| module.exports = { | ||
| rules: { | ||
| "indent": ["error", 2], | ||
| "quotes": ["error", "double"] | ||
| } | ||
| } |
+21
| ## MIT License <br> © [contributors](../../graphs/contributors) | ||
| ``` | ||
| 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. | ||
| ``` |
+0
-0
@@ -0,0 +0,0 @@ root = true |
+13
-0
@@ -27,2 +27,9 @@ declare module eol { | ||
| /** | ||
| * Dubnormalize. Used internally. Mixin friendly. | ||
| * Create normalizer where linebreaks become your desire. | ||
| * @return anonymous function | ||
| */ | ||
| export function dub(text: string): (text: string) => string; | ||
| /** | ||
| * Add linebreak before text | ||
@@ -40,2 +47,8 @@ * @return string with linebreak added before text | ||
| /** | ||
| * Detect or inspect linebreaks | ||
| * @return array of matched linebreaks | ||
| */ | ||
| export function match(text: string): Array<string>; | ||
| /** | ||
| * Split text by newline | ||
@@ -42,0 +55,0 @@ * @return array of lines |
+21
-15
| !function(root, name, make) { | ||
| if (typeof module != 'undefined' && module.exports) module.exports = make() | ||
| if (typeof module != "undefined" && module.exports) module.exports = make() | ||
| else root[name] = make() | ||
| }(this, 'eol', function() { | ||
| }(this, "eol", function() { | ||
| var api = {} | ||
| var isWindows = typeof process != 'undefined' && 'win32' === process.platform | ||
| var linebreak = isWindows ? '\r\n' : '\n' | ||
| var isWindows = typeof process != "undefined" && "win32" === process.platform | ||
| var linebreak = isWindows ? "\r\n" : "\n" | ||
| var newline = /\r\n|\r|\n/g | ||
@@ -19,12 +19,16 @@ | ||
| function converts(to) { | ||
| function convert(text) { | ||
| function dub(to) { | ||
| function change(text) { | ||
| return text.replace(newline, to) | ||
| } | ||
| convert.toString = function() { | ||
| change.toString = function() { | ||
| return to | ||
| } | ||
| return convert | ||
| return change | ||
| } | ||
| function match(text) { | ||
| return text.match(newline) || [] | ||
| } | ||
| function split(text) { | ||
@@ -34,10 +38,12 @@ return text.split(newline) | ||
| api['lf'] = converts('\n') | ||
| api['cr'] = converts('\r') | ||
| api['crlf'] = converts('\r\n') | ||
| api['auto'] = converts(linebreak) | ||
| api['before'] = before | ||
| api['after'] = after | ||
| api['split'] = split | ||
| api["lf"] = dub("\n") | ||
| api["cr"] = dub("\r") | ||
| api["crlf"] = dub("\r\n") | ||
| api["auto"] = dub(linebreak) | ||
| api["before"] = before | ||
| api["after"] = after | ||
| api["match"] = match | ||
| api["split"] = split | ||
| api["dub"] = dub | ||
| return api | ||
| }); |
+125
-30
| <!DOCTYPE html> | ||
| <html lang="en-US" class="scheme--white"> | ||
| <html lang="en-US" class="iffy"> | ||
| <meta charset="utf-8"> | ||
| <title>EOL converter</title> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1"> | ||
| <meta name="description" content="Newline character converter"> | ||
| <title>EOL opensource library</title> | ||
| <meta name="viewport" content="width=device-width"> | ||
| <meta name="description" content="JavaScript newline conversion library"> | ||
| <meta name="color-scheme" content="dark light"> | ||
| <meta name="theme-color" content="darkviolet"> | ||
| <link rel="help" href="https://github.com/ryanve/eol#readme"> | ||
| <link rel="help" href="https://en.wikipedia.org/wiki/Newline"> | ||
| <link rel="help" href="https://s9a.page/iffy"> | ||
| <style media=(color)> | ||
| .iyff {filter:hue-rotate(120deg)} | ||
| .ffiy {filter:hue-rotate(240deg)} | ||
| .ffyi {filter:hue-rotate(30deg)} | ||
| .yiff {filter:hue-rotate(330deg)} | ||
| .iffy {fill:var(--iffy);stroke:var(--yffi)} | ||
| .yffi {fill:var(--yffi);stroke:var(--iffy)} | ||
| .iffy.iffy {background-color:var(--iffy);color:var(--yffi)} | ||
| .yffi.yffi {background-color:var(--yffi);color:var(--iffy)} | ||
| .iffy ::selection {color:var(--iffy);background:var(--else)} | ||
| .yffi ::selection {color:var(--yffi);background:var(--else)} | ||
| .iffy *{background-color:transparent;color:unset;--else:aquamarine} | ||
| .yffi *{background-color:transparent;color:unset;--else:dodgerblue} | ||
| *{--iffy:#528;--yffi:#ed3} | ||
| @media (prefers-color-scheme:dark){*{--yffi:khaki}} | ||
| @media (prefers-contrast:more){*{--iffy:indigo}} | ||
| @media (prefers-contrast:less){*{--yffi:peachpuff}} | ||
| </style> | ||
| <link rel="stylesheet" href="style.css"> | ||
| <header class="m-b-3"> | ||
| <h1 class="m-b-1">eol converter</h1> | ||
| <a class="button scheme--light" href="https://github.com/ryanve/eol">Github</a> | ||
| <a class="button scheme--light" href="https://www.npmjs.com/package/eol">npm</a> | ||
| <header class="iffy" id="hi"> | ||
| <h1> | ||
| <cite>eol</cite> | ||
| opensource | ||
| newline | ||
| conversion | ||
| </h1> | ||
| <nav aria-label="opensource"> | ||
| <a class="bttn yffi ffyi" href="https://github.com/ryanve/eol">github</a> | ||
| <a class="bttn yffi ffiy" href="https://www.npmjs.com/package/eol">npm</a> | ||
| </nav> | ||
| <p> | ||
| <code>eol</code> is an opensource | ||
| <a class="ffyi" href="https://en.wikipedia.org/wiki/Newline">newline</a> | ||
| conversion <code>node</code> module. | ||
| <code>eol</code> helps you smoothly convert <i>line endings</i> | ||
| in <a class="ffyi" href="https://nodejs.org">node</a> applications. | ||
| <code>eol</code> is written in JavaScript and supports TypeScript too. | ||
| The words <i>newline</i>, <i>linebreak</i>, <i>line ending</i> | ||
| are used interchangeably here. | ||
| They mark an <i>end of line</i>. | ||
| Feel free to play with <code>eol</code> | ||
| in the console on this page for learning purposes. | ||
| </p> | ||
| </header> | ||
| <form class="js-converter__form"> | ||
| <fieldset class="m-b-2"> | ||
| <label class="block m-b-2"> | ||
| <b>Input</b> | ||
| <textarea class="area border-radius scheme--white js-converter__input"></textarea> | ||
| </label> | ||
| <button type="submit" class="button scheme--dark">Convert line endings to</button> | ||
| <label class="inline-block m-b-2"> | ||
| <select class="button scheme--light text--uppercase js-converter__method" aria-label="Convert to"> | ||
| <option selected>lf</option> | ||
| <option>crlf</option> | ||
| <option>cr</option> | ||
| </select> | ||
| </label> | ||
| </fieldset> | ||
| <section> | ||
| <h2 class="inherit-size">Output</h2> | ||
| <div class="area scheme--white border-radius js-converter__output" contenteditable></div> | ||
| </section> | ||
| </form> | ||
| <section class="yffi" id="methods"> | ||
| <h2>methods</h2> | ||
| <dl> | ||
| <dt><code>eol.auto(<var>text</var>)</code> | ||
| <dd>Normalize <var>text</var> to match the current operating system | ||
| <dd>Returns string with <i>line endings</i> normalized accordingly | ||
| <dt><code>eol.crlf(<var>text</var>)</code> | ||
| <dd>Normalize <i>line endings</i> in <var>text</var> to CRLF (Windows, DOS) | ||
| <dd>Returns string normalized to <q>\r\n</q> <i>line endings</i> | ||
| <dt><code>eol.lf(<var>text</var>)</code> | ||
| <dd>Normalize <i>line endings</i> in <var>text</var> to LF (Unix, OS X) | ||
| <dd>Returns string normalized to <q>\n</q> <i>line endings</i> | ||
| <dt><code>eol.cr(<var>text</var>)</code> | ||
| <dd>Normalize <i>line endings</i> in <var>text</var> to CR (Mac OS) | ||
| <dd>Returns string normalized to <q>\r</q> <i>line endings</i> | ||
| <dt><code>eol.dub(<var>text</var>)</code> | ||
| <dd>Generate normalizer that replaces <i>line endings</i> with <var>text</var> | ||
| <dd>Returns composed pure function like methods above | ||
| <dd>Normalizers are usable as glue to join arrays | ||
| <dt><code>eol.before(<var>text</var>)</code> | ||
| <dd>Add <i>linebreak</i> before <var>text</var> | ||
| <dd>Returns string with <i>linebreak</i> added <em>before</em> <var>text</var> | ||
| <dt><code>eol.after(<var>text</var>)</code> | ||
| <dd>Add <i>linebreak</i> after <var>text</var> | ||
| <dd>Returns string with <i>linebreak</i> added <em>after</em> <var>text</var> | ||
| <dt><code>eol.match(<var>text</var>)</code> | ||
| <dd>Detect or inspect <i>linebreaks</i> in <var>text</var> | ||
| <dd>Returns array of matched <i>linebreaks</i> | ||
| <dt><code>eol.split(<var>text</var>)</code> | ||
| <dd>Split <var>text</var> by <i>newline</i> | ||
| <dd>Returns array of lines | ||
| </dl> | ||
| </section> | ||
| <section class="yffi ffyi" id="samples"> | ||
| <h2>samples</h2> | ||
| <h3>normalizing</h3> | ||
| <pre>eol.lf("hello<b>\r\n</b>world<b>\r\n</b>")<br>// "hello<b>\n</b>world<b>\n</b>"</pre> | ||
| <h3>remove empty lines</h3> | ||
| <pre>eol.split(text).filter(line => line).join(eol.lf)</pre> | ||
| <h3>detect or inspect</h3> | ||
| <pre>eol.match("hello<b>\n</b>world<b>\n</b>")<br>// ["\n","\n"]</pre> | ||
| <h3>coercion</h3> | ||
| <pre>String(eol.lf) // "\n"</pre> | ||
| <pre>String(eol.cr) // "\r"</pre> | ||
| <pre>String(eol.crlf) // "\r\n"</pre> | ||
| <h3>generating normalizers</h3> | ||
| <pre>let lflf = eol.dub("\n\n")<br>lflf("hello<b>\n</b>world<b>\n</b>")<br>// "hello<b>\n\n</b>world<b>\n\n</b>"</pre> | ||
| </section> | ||
| <footer class="yffi yiff" id="thankyou"> | ||
| <h2>thank you</h2> | ||
| <p> | ||
| Thank you for being part of the opensource community. | ||
| Hope you enjoy using <code>eol</code> | ||
| </p> | ||
| <p> | ||
| <a class="ffyi" href="https://github.com/ryanve/eol">All the code is on github</a> | ||
| where <a class="ffyi" href="https://github.com/sponsors/ryanve">you may sponsor its creator</a> | ||
| if you like | ||
| </p> | ||
| <p> | ||
| Color here uses the <a class="ffyi" href="https://s9a.page/iffy">iffy opensource library</a>. | ||
| If you enjoy space <a class="ffyi" href="https://ryanve.dev/ssv">you may also enjoy ssv</a> | ||
| </p> | ||
| <p> | ||
| <a class="iffy" href="#hi">=p</a> | ||
| </p> | ||
| </footer> | ||
| <script src="eol.js"></script> | ||
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.slim.min.js"></script> | ||
| <script src="ui.js"></script> |
+5
-4
| { | ||
| "name": "eol", | ||
| "description": "Newline character converter", | ||
| "version": "0.9.1", | ||
| "homepage": "https://github.com/ryanve/eol", | ||
| "version": "0.10.0", | ||
| "homepage": "https://ryanve.github.io/eol", | ||
| "funding": "https://github.com/sponsors/ryanve", | ||
| "license": "MIT", | ||
@@ -12,3 +13,3 @@ "author": "Ryan Van Etten", | ||
| "scripts": { | ||
| "lint": "eslint . --ext .js", | ||
| "lint": "npx eslint", | ||
| "preversion": "npm test", | ||
@@ -46,4 +47,4 @@ "pretest": "npm run lint", | ||
| "aok": "^1.9.0", | ||
| "eslint": "^3.15.0" | ||
| "eslint": "^9.9.1" | ||
| } | ||
| } |
+118
-38
@@ -1,55 +0,70 @@ | ||
| # eol | ||
| [Newline](http://en.wikipedia.org/wiki/Newline) character converter for JavaScript. Available [on npm](https://www.npmjs.com/package/eol). | ||
| # [eol](https://ryanve.github.io/eol) | ||
| ``` | ||
| npm install eol --save | ||
| ``` | ||
| [Newline](http://en.wikipedia.org/wiki/Newline) character converter node module for [JavaScript](eol.js) or [TypeScript](eol.d.ts) | ||
| ### `require` or `import` | ||
| ### [npm.im/eol](https://npmjs.com/package/eol) | ||
| ```js | ||
| const eol = require('eol') | ||
| ``` | ||
| * `npm install eol` | ||
| * <code><b>let</b> eol = <b>require</b>("eol")</code> | ||
| * <code><b>import</b> eol <b>from</b> "eol"</code> | ||
| ```js | ||
| import eol from 'eol' | ||
| ``` | ||
| ## [API](https://ryanve.github.io/eol#methods) | ||
| ## API | ||
| ### eol.auto(<var>text</var>) | ||
| ### `eol.auto(text)` | ||
| - Normalize line endings in <var>text</var> for the current operating system | ||
| - <b>@return</b> string with line endings normalized to `\r\n` or `\n` | ||
| * Normalize line endings in <var>text</var> to match the current operating system | ||
| * Returns string with line endings normalized to `\r\n` or `\n` | ||
| ### `eol.crlf(text)` | ||
| - Normalize line endings in <var>text</var> to <b>CRLF</b> (Windows, DOS) | ||
| - <b>@return</b> string with line endings normalized to `\r\n` | ||
| ### eol.crlf(<var>text</var>) | ||
| ### `eol.lf(text)` | ||
| - Normalize line endings in <var>text</var> to <b>LF</b> (Unix, OS X) | ||
| - <b>@return</b> string with line endings normalized to `\n` | ||
| * Normalize line endings in <var>text</var> to <b>CRLF</b> (Windows, DOS) | ||
| * Returns string with line endings normalized to `\r\n` | ||
| ### `eol.cr(text)` | ||
| - Normalize line endings in <var>text</var> to <b>CR</b> (Mac OS) | ||
| - <b>@return</b> string with line endings normalized to `\r` | ||
| ### eol.lf(<var>text</var>) | ||
| ### `eol.before(text)` | ||
| - Add linebreak before <var>text</var> | ||
| - <b>@return</b> string with linebreak added before text | ||
| * Normalize line endings in <var>text</var> to <b>LF</b> (Unix, OS X) | ||
| * Returns string with line endings normalized to `\n` | ||
| ### `eol.after(text)` | ||
| - Add linebreak after <var>text</var> | ||
| - <b>@return</b> string with linebreak added after text | ||
| ### eol.cr(<var>text</var>) | ||
| ### `eol.split(text)` | ||
| - Split <var>text</var> by newline | ||
| - <b>@return</b> array of lines | ||
| * Normalize line endings in <var>text</var> to <b>CR</b> (Mac OS) | ||
| * Returns string with line endings normalized to `\r` | ||
| ### eol.dub(<var>text</var>) | ||
| * Generate normalizer where linebreaks become <var>text</var> | ||
| * Used [internally](eol.js) to generate the [normalizers](#api) above | ||
| * Returns composed pure function with [creative potential](#dubbing) | ||
| ### eol.before(<var>text</var>) | ||
| * Add linebreak before <var>text</var> | ||
| * Returns string with linebreak added before text | ||
| * Uses `eol.auto` linebreak | ||
| * `eol.lf(eol.before(text))` ⋮ | ||
| ### eol.after(<var>text</var>) | ||
| * Add linebreak after <var>text</var> | ||
| * Returns string with linebreak added after text | ||
| * Uses `eol.auto` linebreak | ||
| * `eol.lf(eol.after(text))` ⋮ | ||
| ### eol.match(<var>text</var>) | ||
| * Detect or inspect linebreaks in <var>text</var> | ||
| * Returns array of matched linebreaks | ||
| ### eol.split(<var>text</var>) | ||
| * Split <var>text</var> by newline | ||
| * Returns array of lines | ||
| ### Joining | ||
| Coercing `eol.auto`|`eol.crlf`|`eol.lf`|`eol.cr` to string yields the appropriate character. This is useful for joining. | ||
| Coercing [normalizers](#api) to string yields the appropriate character...useful glue for joining | ||
| ```js | ||
| String(eol.lf) // "\n" | ||
| eol.split(text).join(eol.auto) // same as eol.auto(text) | ||
| eol.split(text).join(eol.auto) // === eol.auto(text) | ||
| eol.split(text).filter(line => line).join(eol.auto) // text joined after removing empty lines | ||
@@ -59,3 +74,68 @@ eol.split(text).slice(-3).join(eol.auto) // last 3 lines joined | ||
| ## License | ||
| MIT | ||
| ### Matching | ||
| Detect or inspect via match | ||
| ```js | ||
| eol.match(" ") // [] | ||
| eol.match("world\nwide\nweb") // ["\n","\n"] | ||
| ``` | ||
| ### Dubbing | ||
| Generate alternate [normalizers](#api) | ||
| ``` | ||
| let extra = eol.dub("\n\n\n") | ||
| extra("...") | ||
| ``` | ||
| ``` | ||
| let huh = eol.dub("???") | ||
| huh("...") | ||
| ``` | ||
| ## modularitY | ||
| ### [edit-file](https://github.com/ryanve/edit-file) | ||
| ```js | ||
| let eol = require("eol") | ||
| let edit = require("edit-file") | ||
| edit("sample.txt", eol.lf) | ||
| ``` | ||
| ### [map-file](https://github.com/ryanve/map-file) | ||
| ```js | ||
| let eol = require("eol") | ||
| let map = require("map-file") | ||
| map({ | ||
| from: "from.txt", | ||
| to: "to.txt", | ||
| map: eol.lf | ||
| }) | ||
| ``` | ||
| ### [ssv](https://ryanve.github.io/ssv) | ||
| ```js | ||
| let ssv = require("ssv") | ||
| let eol = require("eol") | ||
| let deep = eol.split("spaced.txt").map(ssv.split) | ||
| ``` | ||
| ### Yours | ||
| Have an `eol` sample to share? | ||
| [Then please do](../../issues/new) :test_tube: :test_tube: :test_tube: :test_tube: | ||
| ## [opensource](package.json) | ||
| [<b>MIT</b> License](LICENSE.md) | ||
| [**∞/0**](#eol) |
+60
-56
@@ -1,81 +0,85 @@ | ||
| .scheme--white { background: whitesmoke; color: black } | ||
| .scheme--dark { background: blue; color: whitesmoke } | ||
| .scheme--light { background: gainsboro; color: blue } | ||
| :focus { outline-color: blue } | ||
| :focus { | ||
| box-shadow: 0 0 1ch 1ch var(--yffi, currentColor); | ||
| outline: thick dotted var(--iffy, currentColor); | ||
| } | ||
| *, :before, :after { box-sizing: border-box } | ||
| html { font: 1em/2 sans-serif; } | ||
| body { width: 100%; margin: auto; padding: 1em } | ||
| a { text-decoration: none } | ||
| a:hover { text-decoration: underline } | ||
| textarea, select { font: inherit } | ||
| textarea { max-width: 100%; margin: 0 } | ||
| header, section { display: block } | ||
| fieldset { padding: 0; border: 0 } | ||
| label { margin: 0; padding: 0 } | ||
| h1, h2 { line-height: 1 } | ||
| :any-link:hover { | ||
| text-decoration-style: double; | ||
| } | ||
| .border-radius { | ||
| border-radius: .25em; | ||
| * { | ||
| box-sizing: border-box; | ||
| } | ||
| .inherit-size { | ||
| font-size: inherit; | ||
| html { | ||
| font-family: sans-serif; | ||
| font-size: max(3ch, 2vw + 1vh); | ||
| line-height: 1.618; | ||
| } | ||
| .button { | ||
| font-size: inherit; | ||
| font-style: inherit; | ||
| font-weight: bold; | ||
| min-height: 2.5em; | ||
| display: inline-block; | ||
| border: 0; | ||
| border-radius: .25em; | ||
| padding: .33333em .66666em; | ||
| pre { | ||
| font-family: monospace; | ||
| font-size: 0.666rem; | ||
| margin: 0; | ||
| white-space: pre-line; | ||
| } | ||
| .button:focus { | ||
| text-decoration: underline; | ||
| body { | ||
| display: flex; | ||
| flex-flow: column; | ||
| margin: auto; | ||
| overflow-wrap: anywhere; | ||
| } | ||
| .button:enabled:hover { | ||
| cursor: pointer; | ||
| text-decoration: underline; | ||
| body > * { | ||
| contain: layout; | ||
| padding: 1em; | ||
| padding-block: calc(1em + 1vh); | ||
| padding-inline: calc(1em + 1vw); | ||
| } | ||
| .m-b-1 { | ||
| margin-bottom: .5em; | ||
| a:only-child, | ||
| nav a { | ||
| padding: .5ch; | ||
| } | ||
| .m-b-2 { | ||
| margin-bottom: 1em; | ||
| q { | ||
| font-family: monospace; | ||
| quotes: '"' '"'; | ||
| } | ||
| .m-b-3 { | ||
| margin-bottom: 2em; | ||
| p { | ||
| max-width: 26em; | ||
| margin-block: 3ch; | ||
| margin-inline: auto; | ||
| } | ||
| .inline-block { | ||
| display: inline-block; | ||
| dt { | ||
| font-size: 1.146rem; | ||
| margin-block: 3ch 0; | ||
| } | ||
| .block { | ||
| display: block; | ||
| dd { | ||
| margin-block: 0; | ||
| } | ||
| .area { | ||
| white-space: pre-wrap; | ||
| border: 2px solid gainsboro; | ||
| padding: .25em; | ||
| display: block; | ||
| overflow: auto; | ||
| resize: vertical; | ||
| width: 100%; | ||
| height: 7.5em; | ||
| line-height: 1.1; | ||
| @media (orientation: portrait) { | ||
| dd { | ||
| margin-block: 1ch; | ||
| } | ||
| } | ||
| .text--uppercase { | ||
| text-transform: uppercase; | ||
| } | ||
| h1 { | ||
| font-size: 1.618em; | ||
| font-weight: unset; | ||
| margin-bottom: 1ch; | ||
| } | ||
| h2 { | ||
| font-size: 1.382em; | ||
| } | ||
| cite { | ||
| font-style: unset; | ||
| font-weight: bold; | ||
| } |
+42
-37
@@ -10,39 +10,44 @@ !function(root) { | ||
| 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() | ||
| 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) | ||
| 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('lf function coerces to string', String(eol.lf) === '\n') | ||
| aok('crlf function coerces to string', String(eol.crlf) === '\r\n') | ||
| aok('cr function coerces to string', String(eol.cr) === '\r') | ||
| aok('auto function coerces to string', String(eol.auto) === isWindows ? '\r\n' : '\n') | ||
| aok('split return type', eol.split('0\n1\n2') instanceof Array) | ||
| aok('split lf', eol.split('0\n1\n2').join('') === '012') | ||
| aok('split cr', eol.split('0\r1\r2').join('') === '012') | ||
| aok('split crlf', eol.split('0\r\n1\r\n2').join('') === '012') | ||
| aok('split mixed', eol.split('0\r\n1\n2\r3\r\n4').join('') === '01234') | ||
| aok('split join', eol.split('0\n1\n\n2\n').join(eol.auto) === eol.auto('0\n1\n\n2\n')) | ||
| aok('split filter join', eol.split('A\n\nB').filter(identity).join(eol.lf) === 'A\nB') | ||
| aok('split slice join', eol.split('A\nB\nC\nD').slice(-2).join(eol.lf) === 'C\nD') | ||
| aok("dub method", typeof eol.dub == "function") | ||
| aok("dub return", typeof eol.dub() == "function") | ||
| 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("lf function coerces to string", String(eol.lf) === "\n") | ||
| aok("crlf function coerces to string", String(eol.crlf) === "\r\n") | ||
| aok("cr function coerces to string", String(eol.cr) === "\r") | ||
| aok("auto function coerces to string", String(eol.auto) === isWindows ? "\r\n" : "\n") | ||
| aok("match none", !eol.match(" ").length) | ||
| aok("match some", eol.match("\n").length) | ||
| aok("match www", eol.match("world\nwide\nweb").length > 1) | ||
| aok("split return type", eol.split("0\n1\n2") instanceof Array) | ||
| aok("split lf", eol.split("0\n1\n2").join("") === "012") | ||
| aok("split cr", eol.split("0\r1\r2").join("") === "012") | ||
| aok("split crlf", eol.split("0\r\n1\r\n2").join("") === "012") | ||
| aok("split mixed", eol.split("0\r\n1\n2\r3\r\n4").join("") === "01234") | ||
| aok("split join", eol.split("0\n1\n\n2\n").join(eol.auto) === eol.auto("0\n1\n\n2\n")) | ||
| aok("split filter join", eol.split("A\n\nB").filter(identity).join(eol.lf) === "A\nB") | ||
| aok("split slice join", eol.split("A\nB\nC\nD").slice(-2).join(eol.lf) === "C\nD") | ||
| 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) { | ||
| aok(method + " retains", contains(normalized, chars[i])) | ||
| aok(method + " normalizes", !aok.fail(chars, function(c) { | ||
| return contains(chars[i], c) === contains(normalized, c) | ||
@@ -54,13 +59,13 @@ })) | ||
| aok('auto is aware', eol[isWindows ? 'crlf' : 'lf'](sample) === eol.auto(sample)) | ||
| aok('auto matches only 1 and self', aok.pass(meths, function(method) { | ||
| 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('before', eol.lf(eol.before('text')) === '\ntext') | ||
| aok('before2', eol.lf(eol.before('\ntext\n')) === '\n\ntext\n') | ||
| aok('after', eol.lf(eol.after('text')) === 'text\n') | ||
| aok('after2', eol.lf(eol.after('\ntext\n')) === '\ntext\n\n') | ||
| aok("before", eol.lf(eol.before("text")) === "\ntext") | ||
| aok("before2", eol.lf(eol.before("\ntext\n")) === "\n\ntext\n") | ||
| aok("after", eol.lf(eol.after("text")) === "text\n") | ||
| aok("after2", eol.lf(eol.after("\ntext\n")) === "\ntext\n\n") | ||
| aok.log('All tests passed =)') | ||
| aok.log("All tests passed =)") | ||
| }(this); |
| { | ||
| "env": { | ||
| "browser": true, | ||
| "jquery": true, | ||
| "commonjs": true, | ||
| "node": true | ||
| }, | ||
| "extends": "eslint:recommended", | ||
| "rules": { | ||
| "indent": ["error", 2], | ||
| "quotes": ["error", "single"] | ||
| } | ||
| } |
| * text=auto |
Sorry, the diff of this file is not supported yet
-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. |
-9
| /* global eol */ | ||
| $('.js-converter__form').on('submit', function(e) { | ||
| e.preventDefault() | ||
| var $form = $(this) | ||
| var $output = $form.find('.js-converter__output') | ||
| var method = $form.find('.js-converter__method')[0].value | ||
| var text = $form.find('.js-converter__input')[0].value | ||
| $output.text(eol[method](text)) | ||
| }); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
17650
42.12%227
3.65%141
131.15%11
-15.38%1
Infinity%