UNPKG

1.58 kBJavaScriptView Raw
1import { propertyPath } from '@stryker-mutator/util';
2import { schema } from '@stryker-mutator/api/core';
3import emojiRegex from 'emoji-regex';
4const emojiRe = emojiRegex();
5const { MutantStatus } = schema;
6export function wrapInClosure(codeFragment) {
7 return `
8 (function (window) {
9 ${codeFragment}
10 })((Function('return this'))());`;
11}
12export function padLeft(input) {
13 return input
14 .split('\n')
15 .map((str) => '\t' + str)
16 .join('\n');
17}
18export function plural(items) {
19 if (items > 1) {
20 return 's';
21 }
22 else {
23 return '';
24 }
25}
26export function serialize(thing) {
27 return JSON.stringify(thing);
28}
29export function deserialize(stringified) {
30 return JSON.parse(stringified);
31}
32export 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}
49export 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 * Print the name of (or path to) a stryker option
58 */
59export const optionsPath = propertyPath();
60//# sourceMappingURL=string-utils.js.map
\No newline at end of file