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

Function generateCode

src/index.ts:40–64  ·  view source on GitHub ↗
(options: GenerateOptions = {})

Source from the content-addressed store, hash-verified

38export { Strategy, analyze, predictCodeQuality, registerRng }
39
40export function generateCode(options: GenerateOptions = {}): string {
41 const length: CodeLength = options.length === 4 ? 4 : 6
42 const strategy: Strategy = options.strategy ?? Strategy.Mixed
43
44 if (options.mode === 'banking') {
45 return generateBankingCode({ ...options, length })
46 }
47
48 const impl = getStrategyImpl(length, strategy, options)
49
50 const maxAttempts = 100
51 let code = ''
52
53 for (let i = 0; i < maxAttempts; i++) {
54 code = impl()
55 if (code.length !== length) {
56 code = code.slice(0, length)
57 }
58 if (isCodeAllowed(code, options)) {
59 return code
60 }
61 }
62
63 return code.slice(0, length)
64}
65
66function generateBankingCode(options: GenerateOptions = {}): string {
67 const length: CodeLength = options.length === 4 ? 4 : 6

Callers 2

core.test.tsFile · 0.90
random.test.tsFile · 0.90

Calls 3

getStrategyImplFunction · 0.90
isCodeAllowedFunction · 0.90
generateBankingCodeFunction · 0.85

Tested by

no test coverage detected