MCPcopy Index your code
hub / github.com/TeaCoder52/patcode / getStrategyImpl

Function getStrategyImpl

src/strategy.ts:11–87  ·  view source on GitHub ↗
(
	length: CodeLength,
	strategy: Strategy,
	options: GenerateOptions
)

Source from the content-addressed store, hash-verified

9import * as s6 from './patterns6'
10
11export function getStrategyImpl(
12 length: CodeLength,
13 strategy: Strategy,
14 options: GenerateOptions
15): () => string {
16 const digits = utils.getAllowedDigits(options)
17 const rng = utils.getRng(options)
18
19 const ctx: CustomStrategyContext = {
20 length,
21 pickDigit: () => utils.pickDigit(digits, rng),
22 pickTwoDifferentDigits: () => utils.pickTwoDifferentDigits(digits, rng),
23 pickThreeDifferentDigits: () =>
24 utils.pickThreeDifferentDigits(digits, rng),
25 fromDigits: utils.fromDigits,
26 isTooSimple: utils.isTooSimpleSequence,
27 isAllSame: utils.isAllSame,
28 }
29
30 if (strategy === 'custom') {
31 if (!options.customStrategy) {
32 throw new Error(
33 'customStrategy must be provided when strategy = "custom"'
34 )
35 }
36 return () => options.customStrategy!(ctx)
37 }
38
39 if (length === 4) {
40 const map: Record<string, () => string> = {
41 pairs: () => s4.patternMixed4(digits, rng),
42 triples: () =>
43 utils.pickRandom([s4.patternAAAB, s4.patternABBB], rng)(
44 digits,
45 rng
46 ),
47 mirror: () => s4.patternABBA(digits, rng),
48 wave: () => s4.patternABAB(digits, rng),
49 escalator: () =>
50 utils.pickRandom([s4.patternAABC, s4.patternABBC], rng)(
51 digits,
52 rng
53 ),
54 pairWave: () =>
55 utils.pickRandom([s4.patternAABB, s4.patternABAB], rng)(
56 digits,
57 rng
58 ),
59 mixed: () => s4.patternMixed4(digits, rng),
60 }
61 return map[strategy] || map.mixed
62 }
63
64 const map6: Record<string, () => string> = {
65 pairs: () =>
66 utils.pickRandom(
67 [s6.patternAABBCC, s6.patternAAABBB, s6.patternABBABB],
68 rng

Callers 2

strategy.test.tsFile · 0.90
generateCodeFunction · 0.90

Calls 3

pickDigitMethod · 0.80

Tested by

no test coverage detected