wooorm / trim-lines

Compare 2482b85 ... +26 ... df5611d

Coverage Reach
index.js

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 1 of 9 files from the diff.
Other files ignored by Codecov
package.json has changed.
readme.md has changed.
test.js has changed.
.travis.yml was deleted.
.prettierignore has changed.
.gitignore has changed.

@@ -1,10 +1,69 @@
Loading
1 -
'use strict'
1 +
const tab = 9 /* `\t` */
2 +
const space = 32 /* ` ` */
2 3
3 -
module.exports = trimLines
4 +
/**
5 +
 * Remove initial and final spaces and tabs around line endings in `value`.
6 +
 * Does not trim initial and final spaces and tabs of the value itself.
7 +
 *
8 +
 * @param {string} value
9 +
 *   Value to trim.
10 +
 * @returns {string}
11 +
 *   Trimmed value.
12 +
 */
13 +
export function trimLines(value) {
14 +
  const source = String(value)
15 +
  const search = /\r?\n|\r/g
16 +
  let match = search.exec(source)
17 +
  let last = 0
18 +
  /** @type {Array<string>} */
19 +
  const lines = []
4 20
5 -
var ws = /[ \t]*\n+[ \t]*/g
6 -
var newline = '\n'
21 +
  while (match) {
22 +
    lines.push(
23 +
      trimLine(source.slice(last, match.index), last > 0, true),
24 +
      match[0]
25 +
    )
7 26
8 -
function trimLines(value) {
9 -
  return String(value).replace(ws, newline)
27 +
    last = match.index + match[0].length
28 +
    match = search.exec(source)
29 +
  }
30 +
31 +
  lines.push(trimLine(source.slice(last), last > 0, false))
32 +
33 +
  return lines.join('')
34 +
}
35 +
36 +
/**
37 +
 * @param {string} value
38 +
 *   Line to trim.
39 +
 * @param {boolean} start
40 +
 *   Whether to trim the start of the line.
41 +
 * @param {boolean} end
42 +
 *   Whether to trim the end of the line.
43 +
 * @returns {string}
44 +
 *   Trimmed line.
45 +
 */
46 +
function trimLine(value, start, end) {
47 +
  let startIndex = 0
48 +
  let endIndex = value.length
49 +
50 +
  if (start) {
51 +
    let code = value.codePointAt(startIndex)
52 +
53 +
    while (code === tab || code === space) {
54 +
      startIndex++
55 +
      code = value.codePointAt(startIndex)
56 +
    }
57 +
  }
58 +
59 +
  if (end) {
60 +
    let code = value.codePointAt(endIndex - 1)
61 +
62 +
    while (code === tab || code === space) {
63 +
      endIndex--
64 +
      code = value.codePointAt(endIndex - 1)
65 +
    }
66 +
  }
67 +
68 +
  return endIndex > startIndex ? value.slice(startIndex, endIndex) : ''
10 69
}

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.

28 Commits

Hiding 4 contexual commits
Hiding 1 contexual commits
+5
+5
+15
+15
Hiding 1 contexual commits
Hiding 7 contexual commits
+39
+39
Hiding 4 contexual commits
+8
+8
Hiding 1 contexual commits
-2
-2
Files Coverage
index.js 100.00%
Project Totals (1 files) 100.00%
Loading