MCPcopy Index your code
hub / github.com/monkeytypegame/monkeytype / saveLocalPB

Function saveLocalPB

frontend/src/ts/db.ts:189–264  ·  view source on GitHub ↗
(
  mode: M,
  mode2: Mode2<M>,
  punctuation: boolean,
  numbers: boolean,
  language: Language,
  difficulty: Difficulty,
  lazyMode: boolean,
  wpm: number,
  acc: number,
  raw: number,
  consistency: number,
)

Source from the content-addressed store, hash-verified

187}
188
189function saveLocalPB<M extends Mode>(
190 mode: M,
191 mode2: Mode2<M>,
192 punctuation: boolean,
193 numbers: boolean,
194 language: Language,
195 difficulty: Difficulty,
196 lazyMode: boolean,
197 wpm: number,
198 acc: number,
199 raw: number,
200 consistency: number,
201): void {
202 if (mode === "quote") return;
203 if (!dbSnapshot) return;
204 function cont(): void {
205 if (!dbSnapshot) return;
206 let found = false;
207
208 dbSnapshot.personalBests ??= {
209 time: {},
210 words: {},
211 quote: {},
212 zen: {},
213 custom: {},
214 };
215
216 dbSnapshot.personalBests[mode] ??= {
217 [mode2]: [],
218 };
219
220 dbSnapshot.personalBests[mode][mode2] ??=
221 [] as unknown as PersonalBests[M][Mode2<M>];
222
223 (
224 dbSnapshot.personalBests[mode][mode2] as unknown as PersonalBest[]
225 ).forEach((pb) => {
226 if (
227 (pb.punctuation ?? false) === punctuation &&
228 (pb.numbers ?? false) === numbers &&
229 pb.difficulty === difficulty &&
230 pb.language === language &&
231 (pb.lazyMode ?? false) === lazyMode
232 ) {
233 found = true;
234 pb.wpm = wpm;
235 pb.acc = acc;
236 pb.raw = raw;
237 pb.timestamp = Date.now();
238 pb.consistency = consistency;
239 pb.lazyMode = lazyMode;
240 }
241 });
242 if (!found) {
243 //nothing found
244 (dbSnapshot.personalBests[mode][mode2] as unknown as PersonalBest[]).push(
245 {
246 language,

Callers 1

saveLocalResultFunction · 0.85

Calls 1

contFunction · 0.85

Tested by

no test coverage detected