1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
<!DOCTYPE html>
<html lang="en-US" class="iffy">
<meta charset="utf-8">
<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="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>
<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>
|