|
1 | 1 | import _ from "lodash"; |
2 | | -import { default as FunboxList } from "../constants/funbox-list"; |
3 | 2 | import { CompletedEvent } from "@monkeytype/contracts/schemas/results"; |
4 | | -import { intersect } from "@monkeytype/util/arrays"; |
5 | 3 |
|
6 | 4 | export function isTestTooShort(result: CompletedEvent): boolean { |
7 | 5 | const { mode, mode2, customText, testDuration, bailedOut } = result; |
@@ -48,138 +46,3 @@ export function isTestTooShort(result: CompletedEvent): boolean { |
48 | 46 |
|
49 | 47 | return false; |
50 | 48 | } |
51 | | - |
52 | | -export function areFunboxesCompatible(funboxesString: string): boolean { |
53 | | - const funboxes = funboxesString.split("#").filter((f) => f !== "none"); |
54 | | - |
55 | | - const funboxesToCheck = FunboxList.filter((f) => funboxes.includes(f.name)); |
56 | | - |
57 | | - const allFunboxesAreValid = funboxesToCheck.length === funboxes.length; |
58 | | - const oneWordModifierMax = |
59 | | - funboxesToCheck.filter( |
60 | | - (f) => |
61 | | - f.frontendFunctions?.includes("getWord") ?? |
62 | | - f.frontendFunctions?.includes("pullSection") ?? |
63 | | - f.frontendFunctions?.includes("withWords") |
64 | | - ).length <= 1; |
65 | | - const layoutUsability = |
66 | | - funboxesToCheck.filter((f) => |
67 | | - f.properties?.find((fp) => fp === "changesLayout") |
68 | | - ).length === 0 || |
69 | | - funboxesToCheck.filter((f) => |
70 | | - f.properties?.find((fp) => fp === "ignoresLayout" || fp === "usesLayout") |
71 | | - ).length === 0; |
72 | | - const oneNospaceOrToPushMax = |
73 | | - funboxesToCheck.filter((f) => |
74 | | - f.properties?.find((fp) => fp === "nospace" || fp.startsWith("toPush")) |
75 | | - ).length <= 1; |
76 | | - const oneWordOrderMax = |
77 | | - funboxesToCheck.filter((f) => |
78 | | - f.properties?.find((fp) => fp.startsWith("wordOrder")) |
79 | | - ).length <= 1; |
80 | | - const oneChangesWordsVisibilityMax = |
81 | | - funboxesToCheck.filter((f) => |
82 | | - f.properties?.find((fp) => fp === "changesWordsVisibility") |
83 | | - ).length <= 1; |
84 | | - const oneFrequencyChangesMax = |
85 | | - funboxesToCheck.filter((f) => |
86 | | - f.properties?.find((fp) => fp === "changesWordsFrequency") |
87 | | - ).length <= 1; |
88 | | - const noFrequencyChangesConflicts = |
89 | | - funboxesToCheck.filter((f) => |
90 | | - f.properties?.find((fp) => fp === "changesWordsFrequency") |
91 | | - ).length === 0 || |
92 | | - funboxesToCheck.filter((f) => |
93 | | - f.properties?.find((fp) => fp === "ignoresLanguage") |
94 | | - ).length === 0; |
95 | | - const capitalisationChangePosibility = |
96 | | - funboxesToCheck.filter((f) => |
97 | | - f.properties?.find((fp) => fp === "noLetters") |
98 | | - ).length === 0 || |
99 | | - funboxesToCheck.filter((f) => |
100 | | - f.properties?.find((fp) => fp === "changesCapitalisation") |
101 | | - ).length === 0; |
102 | | - const noConflictsWithSymmetricChars = |
103 | | - funboxesToCheck.filter((f) => |
104 | | - f.properties?.find((fp) => fp === "conflictsWithSymmetricChars") |
105 | | - ).length === 0 || |
106 | | - funboxesToCheck.filter((f) => |
107 | | - f.properties?.find((fp) => fp === "symmetricChars") |
108 | | - ).length === 0; |
109 | | - const canSpeak = |
110 | | - funboxesToCheck.filter((f) => |
111 | | - f.properties?.find((fp) => fp === "speaks" || fp === "unspeakable") |
112 | | - ).length <= 1; |
113 | | - const hasLanguageToSpeak = |
114 | | - funboxesToCheck.filter((f) => f.properties?.find((fp) => fp === "speaks")) |
115 | | - .length === 0 || |
116 | | - funboxesToCheck.filter((f) => |
117 | | - f.properties?.find((fp) => fp === "ignoresLanguage") |
118 | | - ).length === 0; |
119 | | - const oneToPushOrPullSectionMax = |
120 | | - funboxesToCheck.filter( |
121 | | - (f) => |
122 | | - f.properties?.some((fp) => fp.startsWith("toPush:")) ?? |
123 | | - f.frontendFunctions?.includes("pullSection") |
124 | | - ).length <= 1; |
125 | | - // const oneApplyCSSMax = |
126 | | - // funboxesToCheck.filter((f) => f.frontendFunctions?.includes("applyCSS")) |
127 | | - // .length <= 1; //todo: move all funbox stuff to the shared package, this is ok to remove for now |
128 | | - const onePunctuateWordMax = |
129 | | - funboxesToCheck.filter((f) => |
130 | | - f.frontendFunctions?.includes("punctuateWord") |
131 | | - ).length <= 1; |
132 | | - const oneCharCheckerMax = |
133 | | - funboxesToCheck.filter((f) => |
134 | | - f.frontendFunctions?.includes("isCharCorrect") |
135 | | - ).length <= 1; |
136 | | - const oneCharReplacerMax = |
137 | | - funboxesToCheck.filter((f) => f.frontendFunctions?.includes("getWordHtml")) |
138 | | - .length <= 1; |
139 | | - const oneChangesCapitalisationMax = |
140 | | - funboxesToCheck.filter((f) => |
141 | | - f.properties?.find((fp) => fp === "changesCapitalisation") |
142 | | - ).length <= 1; |
143 | | - const allowedConfig = {} as Record<string, string[] | boolean[]>; |
144 | | - let noConfigConflicts = true; |
145 | | - for (const f of funboxesToCheck) { |
146 | | - if (!f.frontendForcedConfig) continue; |
147 | | - for (const key in f.frontendForcedConfig) { |
148 | | - const allowedConfigValue = allowedConfig[key]; |
149 | | - const funboxValue = f.frontendForcedConfig[key]; |
150 | | - if (allowedConfigValue !== undefined && funboxValue !== undefined) { |
151 | | - if ( |
152 | | - intersect<string | boolean>(allowedConfigValue, funboxValue, true) |
153 | | - .length === 0 |
154 | | - ) { |
155 | | - noConfigConflicts = false; |
156 | | - break; |
157 | | - } |
158 | | - } else if (funboxValue !== undefined) { |
159 | | - allowedConfig[key] = funboxValue; |
160 | | - } |
161 | | - } |
162 | | - } |
163 | | - |
164 | | - return ( |
165 | | - allFunboxesAreValid && |
166 | | - oneWordModifierMax && |
167 | | - layoutUsability && |
168 | | - oneNospaceOrToPushMax && |
169 | | - oneChangesWordsVisibilityMax && |
170 | | - oneFrequencyChangesMax && |
171 | | - noFrequencyChangesConflicts && |
172 | | - capitalisationChangePosibility && |
173 | | - noConflictsWithSymmetricChars && |
174 | | - canSpeak && |
175 | | - hasLanguageToSpeak && |
176 | | - oneToPushOrPullSectionMax && |
177 | | - // oneApplyCSSMax && |
178 | | - onePunctuateWordMax && |
179 | | - oneCharCheckerMax && |
180 | | - oneCharReplacerMax && |
181 | | - oneChangesCapitalisationMax && |
182 | | - noConfigConflicts && |
183 | | - oneWordOrderMax |
184 | | - ); |
185 | | -} |
0 commit comments