1 | import { propertyPath } from '@stryker-mutator/util';
|
2 | import { schema } from '@stryker-mutator/api/core';
|
3 | import emojiRegex from 'emoji-regex';
|
4 | const emojiRe = emojiRegex();
|
5 | const { MutantStatus } = schema;
|
6 | export function wrapInClosure(codeFragment) {
|
7 | return `
|
8 | (function (window) {
|
9 | ${codeFragment}
|
10 | })((Function('return this'))());`;
|
11 | }
|
12 | export function padLeft(input) {
|
13 | return input
|
14 | .split('\n')
|
15 | .map((str) => '\t' + str)
|
16 | .join('\n');
|
17 | }
|
18 | export function plural(items) {
|
19 | if (items > 1) {
|
20 | return 's';
|
21 | }
|
22 | else {
|
23 | return '';
|
24 | }
|
25 | }
|
26 | export function serialize(thing) {
|
27 | return JSON.stringify(thing);
|
28 | }
|
29 | export function deserialize(stringified) {
|
30 | return JSON.parse(stringified);
|
31 | }
|
32 | export function getEmojiForStatus(status) {
|
33 | switch (status) {
|
34 | case MutantStatus.Killed:
|
35 | return '✅';
|
36 | case MutantStatus.NoCoverage:
|
37 | return '🙈';
|
38 | case MutantStatus.Ignored:
|
39 | return '🤥';
|
40 | case MutantStatus.Survived:
|
41 | return '👽';
|
42 | case MutantStatus.Timeout:
|
43 | return '⌛';
|
44 | case MutantStatus.RuntimeError:
|
45 | case MutantStatus.CompileError:
|
46 | return '💥';
|
47 | }
|
48 | }
|
49 | export function stringWidth(input) {
|
50 | let length = input.length;
|
51 | for (const match of input.matchAll(emojiRe)) {
|
52 | length = length - match[0].length + 2;
|
53 | }
|
54 | return length;
|
55 | }
|
56 |
|
57 |
|
58 |
|
59 | export const optionsPath = propertyPath();
|
60 |
|
\ | No newline at end of file |