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
84af157
... +10 ...
73c2a0d
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
1 | - | 'use strict' |
|
1 | + | /** |
|
2 | + | * @typedef {Object} StringifyOptions |
|
3 | + | * @property {boolean} [padLeft=true] Whether to pad a space before a token (`boolean`, default: `true`). |
|
4 | + | * @property {boolean} [padRight=false] Whether to pad a space after a token (`boolean`, default: `false`). |
|
5 | + | */ |
|
2 | 6 | ||
3 | - | exports.parse = parse |
|
4 | - | exports.stringify = stringify |
|
5 | - | ||
6 | - | var comma = ',' |
|
7 | - | var space = ' ' |
|
8 | - | var empty = '' |
|
9 | - | ||
10 | - | // Parse comma-separated tokens to an array. |
|
11 | - | function parse(value) { |
|
12 | - | var values = [] |
|
13 | - | var input = String(value || empty) |
|
14 | - | var index = input.indexOf(comma) |
|
15 | - | var lastIndex = 0 |
|
16 | - | var end = false |
|
17 | - | var val |
|
7 | + | /** |
|
8 | + | * Parse comma separated tokens to an array. |
|
9 | + | * |
|
10 | + | * @param {string} value |
|
11 | + | * @returns {Array.<string>} |
|
12 | + | */ |
|
13 | + | export function parse(value) { |
|
14 | + | /** @type {Array.<string>} */ |
|
15 | + | var tokens = [] |
|
16 | + | var input = String(value || '') |
|
17 | + | var index = input.indexOf(',') |
|
18 | + | var start = 0 |
|
19 | + | /** @type {boolean} */ |
|
20 | + | var end |
|
21 | + | /** @type {string} */ |
|
22 | + | var token |
|
18 | 23 | ||
19 | 24 | while (!end) { |
|
20 | 25 | if (index === -1) { |
|
21 | 26 | index = input.length |
|
22 | 27 | end = true |
|
23 | 28 | } |
|
24 | 29 | ||
25 | - | val = input.slice(lastIndex, index).trim() |
|
30 | + | token = input.slice(start, index).trim() |
|
26 | 31 | ||
27 | - | if (val || !end) { |
|
28 | - | values.push(val) |
|
32 | + | if (token || !end) { |
|
33 | + | tokens.push(token) |
|
29 | 34 | } |
|
30 | 35 | ||
31 | - | lastIndex = index + 1 |
|
32 | - | index = input.indexOf(comma, lastIndex) |
|
36 | + | start = index + 1 |
|
37 | + | index = input.indexOf(',', start) |
|
33 | 38 | } |
|
34 | 39 | ||
35 | - | return values |
|
40 | + | return tokens |
|
36 | 41 | } |
|
37 | 42 | ||
38 | - | // Compile an array to comma-separated tokens. |
|
39 | - | // `options.padLeft` (default: `true`) pads a space left of each token, and |
|
40 | - | // `options.padRight` (default: `false`) pads a space to the right of each token. |
|
41 | - | function stringify(values, options) { |
|
43 | + | /** |
|
44 | + | * Serialize an array of strings to comma separated tokens. |
|
45 | + | * |
|
46 | + | * @param {Array.<string>} values |
|
47 | + | * @param {StringifyOptions} [options] |
|
48 | + | * @returns {string} |
|
49 | + | */ |
|
50 | + | export function stringify(values, options) { |
|
42 | 51 | var settings = options || {} |
|
43 | - | var left = settings.padLeft === false ? empty : space |
|
44 | - | var right = settings.padRight ? space : empty |
|
45 | 52 | ||
46 | 53 | // Ensure the last empty entry is seen. |
|
47 | - | if (values[values.length - 1] === empty) { |
|
48 | - | values = values.concat(empty) |
|
54 | + | if (values[values.length - 1] === '') { |
|
55 | + | values = values.concat('') |
|
49 | 56 | } |
|
50 | 57 | ||
51 | - | return values.join(right + comma + left).trim() |
|
58 | + | return values |
|
59 | + | .join( |
|
60 | + | (settings.padRight ? ' ' : '') + |
|
61 | + | ',' + |
|
62 | + | (settings.padLeft === false ? '' : ' ') |
|
63 | + | ) |
|
64 | + | .trim() |
|
52 | 65 | } |
Files | Coverage |
---|---|
index.js | 100.00% |
Project Totals (1 files) | 100.00% |
73c2a0d
9013005
8ca4dee
5cc9f6e
8efa6fc
7bbe51f
e1066b5
425a955
3cedbda
c26ebab
7d442ac
84af157