• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hcodes / yaspeller / 6833347907

11 Nov 2023 09:11AM UTC coverage: 71.485% (-0.1%) from 71.618%
6833347907

push

github

web-flow
Merge pull request #197 from hcodes/new_api

Update major yandex-speller package

211 of 380 branches covered (0.0%)

539 of 754 relevant lines covered (71.49%)

5.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.0
/lib/helpers/ignore.js
1
'use strict';
2

3
const { consoleError } = require('./console');
1✔
4

5
/**
6
 * Has ignored text?
7
 *
8
 * @param {string} text
9
 * @returns {boolean}
10
 */
11
function hasIgnoredText(text) {
12
    return text.search(/yaspeller\s+ignore/) !== -1;
27✔
13
}
14

15
/**
16
 * Ignore lines.
17
 *
18
 * @param {string} text
19
 * @returns {text}
20
 */
21
function ignoreLines(text) {
22
    return text
6✔
23
        .replace(/^.*?\/\/\s*yaspeller\s+ignore\s*$/mg, '')
24
        .replace(/^.*?<!--\s*yaspeller\s+ignore\s*-->.*?$/mg, '')
25
        .replace(/^.*?\/\*\s*yaspeller\s+ignore\s*\*\/.*?$/mg, '');
26
}
27

28
/**
29
 * Ignore blocks.
30
 *
31
 * @param {string} text
32
 * @returns {text}
33
 */
34
function ignoreBlocks(text) {
35
    return text
6✔
36
        .replace(/\/\*\s*yaspeller\s+ignore:start\s*\*\/[^]*?\/\*\s*yaspeller\s+ignore:end\s*\*\//g, '')
37
        .replace(/<!--\s*yaspeller\s+ignore:start\s*-->[^]*?<!--\s*yaspeller\s+ignore:end\s*-->/g, '')
38
        .replace(/\/\/\s*yaspeller\s+ignore:start[^]*?\/\/\s*yaspeller\s+ignore:end.*?(\r?\n|$)/g, '');
39
}
40

41
/**
42
 * Ignore HTML comments.
43
 *
44
 * @param {string} text
45
 * @returns {text}
46
 */
47
function ignoreComments(text) {
48
    const comments = [
9✔
49
        ['<!--', '-->'],
50
        ['<!ENTITY', '>'],
51
        ['<!DOCTYPE', '>'],
52
        ['<\\?xml', '\\?>'],
53
        ['<!\\[CDATA\\[', '\\]\\]>']
54
    ];
55

56
    for (const tag of comments) {
9✔
57
        text = text.replace(
45✔
58
            new RegExp(tag[0] + '[^]*?' + tag[1], 'gi'),
59
            ' '
60
        );
61
    }
62

63
    return text;
9✔
64
}
65

66
/**
67
 * Ignore tags.
68
 *
69
 * @param {string} text
70
 * @param {Array} tags
71
 * @returns {text}
72
 */
73
function ignoreTags(text, tags) {
74
    for (const name of tags) {
3✔
75
        const openingTags = '<' + name + '(\\s[^>]*?)?>';
4✔
76
        const closingTags = '</' + name + '>';
4✔
77

78
        text = text.replace(
4✔
79
            new RegExp(openingTags + '[^]*?' + closingTags, 'gi'),
80
            ' … ' // For repeated words. Example: the `code` the.
81
        );
82
    }
83

84
    return text;
3✔
85
}
86

87
/**
88
 * Prepares regular expressions to remove text.
89
 *
90
 * @param {Array|undefined} data
91
 *
92
 * @returns {Array}
93
 */
94
function prepareRegExpToIgnoreText(data) {
95
    const result = [];
1✔
96

97
    if (typeof data === 'string') {
1!
98
        data = [data];
1✔
99
    }
100

101
    Array.isArray(data) && data.forEach(re => {
1✔
102
        try {
1✔
103
            if (typeof re === 'string') {
1!
104
                result.push(new RegExp(re, 'g'));
1✔
105
            }
106

107
            if (Array.isArray(re)) {
1!
108
                result.push(new RegExp(re[0], typeof re[1] === 'undefined' ? 'g' : re[1]));
×
109
            }
110
        } catch (e) {
111
            consoleError(`Error in RegExp "${re}": ${e}`);
×
112
        }
113
    });
114

115
    return result;
1✔
116
}
117

118
module.exports = {
1✔
119
    hasIgnoredText,
120
    ignoreBlocks,
121
    ignoreComments,
122
    ignoreLines,
123
    ignoreTags,
124
    prepareRegExpToIgnoreText,
125
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc