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
81a1252
... +4 ...
e164bd3
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 | 1 | /** |
|
2 | 2 | * @typedef {Object} CoreOptions |
|
3 | - | * @property {string[]} [subset=[]] Whether to only escape the given subset of characters (`string[]`) |
|
4 | - | * @property {boolean} [escapeOnly=false] Whether to only escape possibly dangerous characters (`boolean`, default: `false`). Those characters are `"`, `&`, `'`, `<`, `>`, and `` ` `` |
|
3 | + | * @property {string[]} [subset=[]] |
|
4 | + | * Whether to only escape the given subset of characters. |
|
5 | + | * @property {boolean} [escapeOnly=false] |
|
6 | + | * Whether to only escape possibly dangerous characters. |
|
7 | + | * Those characters are `"`, `&`, `'`, `<`, `>`, and `` ` ``. |
|
5 | 8 | * |
|
6 | 9 | * @typedef {Object} FormatOptions |
|
7 | - | * @property {function (number, number, CoreWithFormatOptions): string} format |
|
10 | + | * @property {(code: number, next: number, options: CoreWithFormatOptions) => string} format |
|
11 | + | * Format strategy. |
|
8 | 12 | * |
|
9 | 13 | * @typedef {CoreOptions & FormatOptions & import('./util/format-smart.js').FormatSmartOptions} CoreWithFormatOptions |
|
10 | 14 | */ |
|
11 | 15 | ||
12 | 16 | /** |
|
13 | - | * Encode special characters in `value`. |
|
17 | + | * Encode certain characters in `value`. |
|
14 | 18 | * |
|
15 | 19 | * @param {string} value |
|
16 | - | * @param {CoreWithFormatOptions} [options] |
|
20 | + | * @param {CoreWithFormatOptions} options |
|
17 | 21 | * @returns {string} |
|
18 | 22 | */ |
|
19 | 23 | export function core(value, options) { |
75 | 79 | */ |
|
76 | 80 | function charactersToExpression(subset) { |
|
77 | 81 | /** @type {string[]} */ |
|
78 | - | var groups = [] |
|
79 | - | var index = -1 |
|
82 | + | const groups = [] |
|
83 | + | let index = -1 |
|
80 | 84 | ||
81 | 85 | while (++index < subset.length) { |
|
82 | 86 | groups.push(subset[index].replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')) |
1 | + | /** |
|
2 | + | * @typedef {import('./core.js').CoreOptions & import('./util/format-smart.js').FormatSmartOptions} Options |
|
3 | + | * @typedef {import('./core.js').CoreOptions} LightOptions |
|
4 | + | */ |
|
5 | + | ||
1 | 6 | import {core} from './core.js' |
|
2 | 7 | import {formatSmart} from './util/format-smart.js' |
|
3 | 8 | import {formatBasic} from './util/format-basic.js' |
|
4 | 9 | ||
5 | - | /** |
|
6 | - | * @typedef {import('./core.js').CoreOptions & import('./util/format-smart.js').FormatSmartOptions} StringifyEntitiesOptions |
|
7 | - | * @typedef {import('./core.js').CoreOptions} StringifyEntitiesLightOptions |
|
8 | - | */ |
|
9 | - | ||
10 | 10 | /** |
|
11 | 11 | * Encode special characters in `value`. |
|
12 | + | * |
|
12 | 13 | * @param {string} value |
|
13 | - | * @param {StringifyEntitiesOptions} [options] |
|
14 | + | * Value to encode. |
|
15 | + | * @param {Options} [options] |
|
16 | + | * Configuration. |
|
17 | + | * @returns {string} |
|
18 | + | * Encoded value. |
|
14 | 19 | */ |
|
15 | 20 | export function stringifyEntities(value, options) { |
|
16 | 21 | return core(value, Object.assign({format: formatSmart}, options)) |
|
17 | 22 | } |
|
18 | 23 | ||
19 | 24 | /** |
|
20 | 25 | * Encode special characters in `value` as hexadecimals. |
|
26 | + | * |
|
21 | 27 | * @param {string} value |
|
22 | - | * @param {StringifyEntitiesLightOptions} [options] |
|
28 | + | * Value to encode. |
|
29 | + | * @param {LightOptions} [options] |
|
30 | + | * Configuration. |
|
31 | + | * @returns {string} |
|
32 | + | * Encoded value. |
|
23 | 33 | */ |
|
24 | 34 | export function stringifyEntitiesLight(value, options) { |
|
25 | 35 | return core(value, Object.assign({format: formatBasic}, options)) |
1 | 1 | import {characterEntitiesLegacy} from 'character-entities-legacy' |
|
2 | - | import {characters} from '../constant/characters.js' |
|
2 | + | import {characterEntitiesHtml4} from 'character-entities-html4' |
|
3 | 3 | import {dangerous} from '../constant/dangerous.js' |
|
4 | 4 | ||
5 | - | var own = {}.hasOwnProperty |
|
5 | + | const own = {}.hasOwnProperty |
|
6 | 6 | ||
7 | 7 | /** |
|
8 | - | * Transform `code` into a named character reference. |
|
8 | + | * `characterEntitiesHtml4` but inverted. |
|
9 | + | * |
|
10 | + | * @type {Object.<string, string>} |
|
11 | + | */ |
|
12 | + | const characters = {} |
|
13 | + | ||
14 | + | /** @type {string} */ |
|
15 | + | let key |
|
16 | + | ||
17 | + | for (key in characterEntitiesHtml4) { |
|
18 | + | if (own.call(characterEntitiesHtml4, key)) { |
|
19 | + | characters[characterEntitiesHtml4[key]] = key |
|
20 | + | } |
|
21 | + | } |
|
22 | + | ||
23 | + | /** |
|
24 | + | * Configurable ways to encode characters as named references. |
|
9 | 25 | * |
|
10 | 26 | * @param {number} code |
|
11 | 27 | * @param {number} next |
|
12 | - | * @param {boolean} omit |
|
13 | - | * @param {boolean} attribute |
|
28 | + | * @param {boolean|undefined} omit |
|
29 | + | * @param {boolean|undefined} attribute |
|
14 | 30 | * @returns {string} |
|
15 | 31 | */ |
|
16 | 32 | export function toNamed(code, next, omit, attribute) { |
|
17 | - | var character = String.fromCharCode(code) |
|
18 | - | /** @type {string} */ |
|
19 | - | var name |
|
20 | - | /** @type {string} */ |
|
21 | - | var value |
|
33 | + | const character = String.fromCharCode(code) |
|
22 | 34 | ||
23 | 35 | if (own.call(characters, character)) { |
|
24 | - | name = characters[character] |
|
25 | - | value = '&' + name |
|
36 | + | const name = characters[character] |
|
37 | + | const value = '&' + name |
|
26 | 38 | ||
27 | 39 | if ( |
|
28 | 40 | omit && |
|
29 | - | own.call(characterEntitiesLegacy, name) && |
|
41 | + | characterEntitiesLegacy.includes(name) && |
|
30 | 42 | !dangerous.includes(name) && |
|
31 | 43 | (!attribute || |
|
32 | 44 | (next && |
1 | 1 | /** |
|
2 | - | * Transform `code` into a hexadecimal character reference. |
|
2 | + | * Configurable ways to encode characters as hexadecimal references. |
|
3 | 3 | * |
|
4 | 4 | * @param {number} code |
|
5 | 5 | * @param {number} next |
|
6 | - | * @param {boolean} omit |
|
6 | + | * @param {boolean|undefined} omit |
|
7 | 7 | * @returns {string} |
|
8 | 8 | */ |
|
9 | 9 | export function toHexadecimal(code, next, omit) { |
|
10 | - | var value = '&#x' + code.toString(16).toUpperCase() |
|
10 | + | const value = '&#x' + code.toString(16).toUpperCase() |
|
11 | 11 | return omit && next && !/[\dA-Fa-f]/.test(String.fromCharCode(next)) |
|
12 | 12 | ? value |
|
13 | 13 | : value + ';' |
1 | - | export var dangerous = [ |
|
1 | + | /** |
|
2 | + | * List of legacy (that don’t need a trailing `;`) named references which could, |
|
3 | + | * depending on what follows them, turn into a different meaning |
|
4 | + | * |
|
5 | + | * @type {Array.<string>} |
|
6 | + | */ |
|
7 | + | export const dangerous = [ |
|
2 | 8 | 'cent', |
|
3 | 9 | 'copy', |
|
4 | 10 | 'divide', |
Files | Coverage |
---|---|
format-basic.js | 100.00% |
format-smart.js | 100.00% |
to-decimal.js | 100.00% |
to-hexadecimal.js | 100.00% |
to-named.js | 100.00% |
Folder Totals (5 files) | 100.00% |
Project Totals (9 files) | 100.00% |
e164bd3
19a1998
4013683
1456670
f7a5014
81a1252