git-slot-machine 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +313 -0
  3. package/dist/animation/slotMachine.d.ts +9 -0
  4. package/dist/animation/slotMachine.d.ts.map +1 -0
  5. package/dist/animation/slotMachine.js +139 -0
  6. package/dist/animation/slotMachine.js.map +1 -0
  7. package/dist/api.d.ts +40 -0
  8. package/dist/api.d.ts.map +1 -0
  9. package/dist/api.js +154 -0
  10. package/dist/api.js.map +1 -0
  11. package/dist/balance.d.ts +11 -0
  12. package/dist/balance.d.ts.map +1 -0
  13. package/dist/balance.js +131 -0
  14. package/dist/balance.js.map +1 -0
  15. package/dist/commands/auth.d.ts +4 -0
  16. package/dist/commands/auth.d.ts.map +1 -0
  17. package/dist/commands/auth.js +91 -0
  18. package/dist/commands/auth.js.map +1 -0
  19. package/dist/commands/balance.d.ts +2 -0
  20. package/dist/commands/balance.d.ts.map +1 -0
  21. package/dist/commands/balance.js +32 -0
  22. package/dist/commands/balance.js.map +1 -0
  23. package/dist/commands/config.d.ts +3 -0
  24. package/dist/commands/config.d.ts.map +1 -0
  25. package/dist/commands/config.js +60 -0
  26. package/dist/commands/config.js.map +1 -0
  27. package/dist/commands/init.d.ts +2 -0
  28. package/dist/commands/init.d.ts.map +1 -0
  29. package/dist/commands/init.js +148 -0
  30. package/dist/commands/init.js.map +1 -0
  31. package/dist/commands/play.d.ts +7 -0
  32. package/dist/commands/play.d.ts.map +1 -0
  33. package/dist/commands/play.js +137 -0
  34. package/dist/commands/play.js.map +1 -0
  35. package/dist/commands/spin.d.ts +6 -0
  36. package/dist/commands/spin.d.ts.map +1 -0
  37. package/dist/commands/spin.js +17 -0
  38. package/dist/commands/spin.js.map +1 -0
  39. package/dist/commands/sync.d.ts +2 -0
  40. package/dist/commands/sync.d.ts.map +1 -0
  41. package/dist/commands/sync.js +52 -0
  42. package/dist/commands/sync.js.map +1 -0
  43. package/dist/commands/test.d.ts +6 -0
  44. package/dist/commands/test.d.ts.map +1 -0
  45. package/dist/commands/test.js +17 -0
  46. package/dist/commands/test.js.map +1 -0
  47. package/dist/config.d.ts +27 -0
  48. package/dist/config.d.ts.map +1 -0
  49. package/dist/config.js +144 -0
  50. package/dist/config.js.map +1 -0
  51. package/dist/index.d.ts +3 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +100 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/patterns.d.ts +27 -0
  56. package/dist/patterns.d.ts.map +1 -0
  57. package/dist/patterns.js +266 -0
  58. package/dist/patterns.js.map +1 -0
  59. package/dist/templates/post-commit.d.ts +2 -0
  60. package/dist/templates/post-commit.d.ts.map +1 -0
  61. package/dist/templates/post-commit.js +19 -0
  62. package/dist/templates/post-commit.js.map +1 -0
  63. package/dist/utils/git.d.ts +4 -0
  64. package/dist/utils/git.d.ts.map +1 -0
  65. package/dist/utils/git.js +42 -0
  66. package/dist/utils/git.js.map +1 -0
  67. package/jest.config.js +12 -0
  68. package/package.json +50 -0
  69. package/src/animation/slotMachine.ts +159 -0
  70. package/src/api.ts +203 -0
  71. package/src/balance.ts +118 -0
  72. package/src/commands/auth.ts +92 -0
  73. package/src/commands/balance.ts +28 -0
  74. package/src/commands/config.ts +59 -0
  75. package/src/commands/init.ts +121 -0
  76. package/src/commands/play.ts +150 -0
  77. package/src/commands/spin.ts +17 -0
  78. package/src/commands/sync.ts +49 -0
  79. package/src/commands/test.ts +19 -0
  80. package/src/config.ts +154 -0
  81. package/src/index.ts +114 -0
  82. package/src/patterns.test.ts +44 -0
  83. package/src/patterns.ts +292 -0
  84. package/src/templates/post-commit.ts +15 -0
  85. package/src/utils/git.ts +38 -0
  86. package/test.txt +2 -0
  87. package/tsconfig.json +20 -0
@@ -0,0 +1,292 @@
1
+ export enum PatternType {
2
+ ALL_SAME = 'ALL_SAME',
3
+ SIX_OF_KIND = 'SIX_OF_KIND',
4
+ STRAIGHT_7 = 'STRAIGHT_7',
5
+ FULLEST_HOUSE = 'FULLEST_HOUSE', // 4-3
6
+ FIVE_OF_KIND = 'FIVE_OF_KIND',
7
+ STRAIGHT_6 = 'STRAIGHT_6',
8
+ FOUR_OF_KIND = 'FOUR_OF_KIND',
9
+ ALL_LETTERS = 'ALL_LETTERS',
10
+ STRAIGHT_5 = 'STRAIGHT_5',
11
+ THREE_OF_KIND_PLUS_THREE = 'THREE_OF_KIND_PLUS_THREE', // 3-3-1
12
+ FULL_HOUSE = 'FULL_HOUSE', // 4-2-1 or 3-2-2
13
+ THREE_PAIR = 'THREE_PAIR',
14
+ THREE_OF_KIND = 'THREE_OF_KIND',
15
+ TWO_PAIR = 'TWO_PAIR',
16
+ ALL_NUMBERS = 'ALL_NUMBERS',
17
+ NO_WIN = 'NO_WIN'
18
+ }
19
+
20
+ export interface PatternResult {
21
+ type: PatternType;
22
+ name: string;
23
+ payout: number;
24
+ description: string;
25
+ highlightIndices: number[]; // Indices of characters to highlight
26
+ }
27
+
28
+ const PAYOUTS: Record<PatternType, { name: string; payout: number; description: string }> = {
29
+ [PatternType.ALL_SAME]: { name: 'JACKPOT', payout: 10000, description: 'All same character' },
30
+ [PatternType.SIX_OF_KIND]: { name: 'HEXTET', payout: 5000, description: 'Six of a kind' },
31
+ [PatternType.STRAIGHT_7]: { name: 'LUCKY SEVEN', payout: 2500, description: 'Seven in a row' },
32
+ [PatternType.FULLEST_HOUSE]: { name: 'FULLEST HOUSE', payout: 2000, description: '4 + 3 of a kind' },
33
+ [PatternType.FIVE_OF_KIND]: { name: 'FIVE OF A KIND', payout: 1000, description: 'Five of a kind' },
34
+ [PatternType.STRAIGHT_6]: { name: 'BIG STRAIGHT', payout: 500, description: 'Six in a row' },
35
+ [PatternType.FOUR_OF_KIND]: { name: 'FOUR OF A KIND', payout: 400, description: 'Four of a kind' },
36
+ [PatternType.ALL_LETTERS]: { name: 'ALL LETTERS', payout: 300, description: 'Only letters (a-f)' },
37
+ [PatternType.STRAIGHT_5]: { name: 'STRAIGHT', payout: 200, description: 'Five in a row' },
38
+ [PatternType.THREE_OF_KIND_PLUS_THREE]: { name: 'DOUBLE TRIPLE', payout: 150, description: 'Two three of a kinds' },
39
+ [PatternType.FULL_HOUSE]: { name: 'FULL HOUSE', payout: 100, description: 'Three and two of a kind' },
40
+ [PatternType.THREE_PAIR]: { name: 'THREE PAIR', payout: 150, description: 'Three pairs' },
41
+ [PatternType.THREE_OF_KIND]: { name: 'THREE OF A KIND', payout: 50, description: 'Three of a kind' },
42
+ [PatternType.TWO_PAIR]: { name: 'TWO PAIR', payout: 50, description: 'Two pairs' },
43
+ [PatternType.ALL_NUMBERS]: { name: 'ALL NUMBERS', payout: 10, description: 'Only numbers (0-9)' },
44
+ [PatternType.NO_WIN]: { name: 'NO WIN', payout: 0, description: 'No winning pattern' }
45
+ };
46
+
47
+ function countCharacters(hash: string): Map<string, number> {
48
+ const counts = new Map<string, number>();
49
+ for (const char of hash) {
50
+ counts.set(char, (counts.get(char) || 0) + 1);
51
+ }
52
+ return counts;
53
+ }
54
+
55
+ function getCountDistribution(counts: Map<string, number>): number[] {
56
+ return Array.from(counts.values()).sort((a, b) => b - a);
57
+ }
58
+
59
+ function hasSequentialRun(hash: string, length: number): boolean {
60
+ const hexValues = '0123456789abcdef';
61
+
62
+ for (let i = 0; i <= hash.length - length; i++) {
63
+ const substring = hash.substring(i, i + length);
64
+
65
+ // Check ascending
66
+ let isAscending = true;
67
+ for (let j = 0; j < substring.length - 1; j++) {
68
+ const currentIndex = hexValues.indexOf(substring[j]);
69
+ const nextIndex = hexValues.indexOf(substring[j + 1]);
70
+ if (nextIndex !== currentIndex + 1) {
71
+ isAscending = false;
72
+ break;
73
+ }
74
+ }
75
+ if (isAscending) return true;
76
+
77
+ // Check descending
78
+ let isDescending = true;
79
+ for (let j = 0; j < substring.length - 1; j++) {
80
+ const currentIndex = hexValues.indexOf(substring[j]);
81
+ const nextIndex = hexValues.indexOf(substring[j + 1]);
82
+ if (nextIndex !== currentIndex - 1) {
83
+ isDescending = false;
84
+ break;
85
+ }
86
+ }
87
+ if (isDescending) return true;
88
+ }
89
+
90
+ return false;
91
+ }
92
+
93
+ function isAllLetters(hash: string): boolean {
94
+ return /^[a-f]+$/i.test(hash);
95
+ }
96
+
97
+ function isAllNumbers(hash: string): boolean {
98
+ return /^[0-9]+$/.test(hash);
99
+ }
100
+
101
+ function countConsecutivePairs(hash: string): number {
102
+ // Count pairs of consecutive identical characters (e.g., "33" or "bb")
103
+ let pairCount = 0;
104
+ let i = 0;
105
+
106
+ while (i < hash.length - 1) {
107
+ if (hash[i] === hash[i + 1]) {
108
+ pairCount++;
109
+ i += 2; // Skip both characters of the pair
110
+ } else {
111
+ i++;
112
+ }
113
+ }
114
+
115
+ return pairCount;
116
+ }
117
+
118
+ function getHighlightIndices(hash: string, type: PatternType): number[] {
119
+ const lowerHash = hash.toLowerCase();
120
+
121
+ // For straights, highlight all characters in the sequential run
122
+ if (type === PatternType.STRAIGHT_7 || type === PatternType.STRAIGHT_6 || type === PatternType.STRAIGHT_5) {
123
+ const length = type === PatternType.STRAIGHT_7 ? 7 : type === PatternType.STRAIGHT_6 ? 6 : 5;
124
+ const hexValues = '0123456789abcdef';
125
+
126
+ for (let i = 0; i <= lowerHash.length - length; i++) {
127
+ const substring = lowerHash.substring(i, i + length);
128
+ let isSequential = true;
129
+
130
+ // Check ascending
131
+ for (let j = 0; j < substring.length - 1; j++) {
132
+ const currentIndex = hexValues.indexOf(substring[j]);
133
+ const nextIndex = hexValues.indexOf(substring[j + 1]);
134
+ if (nextIndex !== currentIndex + 1 && nextIndex !== currentIndex - 1) {
135
+ isSequential = false;
136
+ break;
137
+ }
138
+ }
139
+
140
+ if (isSequential) {
141
+ return Array.from({ length }, (_, idx) => i + idx);
142
+ }
143
+ }
144
+ }
145
+
146
+ // For all letters or all numbers, highlight everything
147
+ if (type === PatternType.ALL_LETTERS || type === PatternType.ALL_NUMBERS || type === PatternType.ALL_SAME) {
148
+ return [0, 1, 2, 3, 4, 5, 6];
149
+ }
150
+
151
+ // For frequency-based patterns, highlight characters that appear in the pattern
152
+ const counts = countCharacters(lowerHash);
153
+ const indices: number[] = [];
154
+
155
+ if (type === PatternType.SIX_OF_KIND || type === PatternType.FIVE_OF_KIND ||
156
+ type === PatternType.FOUR_OF_KIND || type === PatternType.THREE_OF_KIND) {
157
+ // Find the character with the highest count and highlight all occurrences
158
+ const targetCount = type === PatternType.SIX_OF_KIND ? 6 :
159
+ type === PatternType.FIVE_OF_KIND ? 5 :
160
+ type === PatternType.FOUR_OF_KIND ? 4 : 3;
161
+
162
+ for (const [char, count] of counts.entries()) {
163
+ if (count === targetCount) {
164
+ for (let i = 0; i < lowerHash.length; i++) {
165
+ if (lowerHash[i] === char) {
166
+ indices.push(i);
167
+ }
168
+ }
169
+ break;
170
+ }
171
+ }
172
+ }
173
+ else if (type === PatternType.FULLEST_HOUSE || type === PatternType.FULL_HOUSE ||
174
+ type === PatternType.THREE_OF_KIND_PLUS_THREE) {
175
+ // Highlight all paired/tripled characters
176
+ for (const [char, count] of counts.entries()) {
177
+ if (count >= 2) {
178
+ for (let i = 0; i < lowerHash.length; i++) {
179
+ if (lowerHash[i] === char) {
180
+ indices.push(i);
181
+ }
182
+ }
183
+ }
184
+ }
185
+ }
186
+ else if (type === PatternType.THREE_PAIR || type === PatternType.TWO_PAIR) {
187
+ // Highlight consecutive pairs only (e.g., "aa" and "bb" in "aa1bb2c")
188
+ let i = 0;
189
+ while (i < lowerHash.length - 1) {
190
+ if (lowerHash[i] === lowerHash[i + 1]) {
191
+ indices.push(i);
192
+ indices.push(i + 1);
193
+ i += 2; // Skip both characters of the pair
194
+ } else {
195
+ i++;
196
+ }
197
+ }
198
+ }
199
+
200
+ return indices.sort((a, b) => a - b);
201
+ }
202
+
203
+ export function detectPattern(hash: string): PatternResult {
204
+ // Validate input
205
+ if (hash.length !== 7) {
206
+ throw new Error('Hash must be 7 characters');
207
+ }
208
+ if (!/^[0-9a-f]+$/i.test(hash)) {
209
+ throw new Error('Hash must contain only hex characters');
210
+ }
211
+
212
+ const lowerHash = hash.toLowerCase();
213
+ const counts = countCharacters(lowerHash);
214
+ const distribution = getCountDistribution(counts);
215
+
216
+ // Detect pattern - check in order of rarity/value
217
+ let type: PatternType;
218
+
219
+ // Check for all same first (highest value)
220
+ if (distribution[0] === 7) {
221
+ type = PatternType.ALL_SAME;
222
+ }
223
+ // Check for 6 of a kind
224
+ else if (distribution[0] === 6) {
225
+ type = PatternType.SIX_OF_KIND;
226
+ }
227
+ // Check for straight 7 (very rare)
228
+ else if (hasSequentialRun(lowerHash, 7)) {
229
+ type = PatternType.STRAIGHT_7;
230
+ }
231
+ // Check for fullest house (4-3)
232
+ else if (distribution[0] === 4 && distribution[1] === 3) {
233
+ type = PatternType.FULLEST_HOUSE;
234
+ }
235
+ // Check for 5 of a kind
236
+ else if (distribution[0] === 5) {
237
+ type = PatternType.FIVE_OF_KIND;
238
+ }
239
+ // Check for straight 6
240
+ else if (hasSequentialRun(lowerHash, 6)) {
241
+ type = PatternType.STRAIGHT_6;
242
+ }
243
+ // Check for 4 of a kind
244
+ else if (distribution[0] === 4) {
245
+ type = PatternType.FOUR_OF_KIND;
246
+ }
247
+ // Check for all letters
248
+ else if (isAllLetters(lowerHash)) {
249
+ type = PatternType.ALL_LETTERS;
250
+ }
251
+ // Check for straight 5
252
+ else if (hasSequentialRun(lowerHash, 5)) {
253
+ type = PatternType.STRAIGHT_5;
254
+ }
255
+ // Check for double triple (3-3-1)
256
+ else if (distribution[0] === 3 && distribution[1] === 3) {
257
+ type = PatternType.THREE_OF_KIND_PLUS_THREE;
258
+ }
259
+ // Check for full house (3-2-2 or 3-2-1-1)
260
+ else if (distribution[0] === 3 && distribution[1] === 2) {
261
+ type = PatternType.FULL_HOUSE;
262
+ }
263
+ // Check for 3 of a kind
264
+ else if (distribution[0] === 3) {
265
+ type = PatternType.THREE_OF_KIND;
266
+ }
267
+ // Check for three consecutive pairs
268
+ else if (countConsecutivePairs(lowerHash) === 3) {
269
+ type = PatternType.THREE_PAIR;
270
+ }
271
+ // Check for two consecutive pairs
272
+ else if (countConsecutivePairs(lowerHash) === 2) {
273
+ type = PatternType.TWO_PAIR;
274
+ }
275
+ // Check for all numbers (break-even)
276
+ else if (isAllNumbers(lowerHash)) {
277
+ type = PatternType.ALL_NUMBERS;
278
+ }
279
+ // Everything else is no win (including one pair)
280
+ else {
281
+ type = PatternType.NO_WIN;
282
+ }
283
+
284
+ const config = PAYOUTS[type];
285
+ return {
286
+ type,
287
+ name: config.name,
288
+ payout: config.payout,
289
+ description: config.description,
290
+ highlightIndices: getHighlightIndices(hash, type)
291
+ };
292
+ }
@@ -0,0 +1,15 @@
1
+ export const POST_COMMIT_HOOK = `#!/bin/sh
2
+ # Git Slot Machine post-commit hook
3
+
4
+ # Get the commit hash
5
+ HASH=$(git rev-parse --short=7 HEAD)
6
+
7
+ # Check if git-slot-machine is installed
8
+ if command -v git-slot-machine >/dev/null 2>&1; then
9
+ git-slot-machine play "$HASH" --small
10
+ elif [ -f "./node_modules/.bin/git-slot-machine" ]; then
11
+ ./node_modules/.bin/git-slot-machine play "$HASH" --small
12
+ else
13
+ echo "git-slot-machine not found, skipping animation"
14
+ fi
15
+ `;
@@ -0,0 +1,38 @@
1
+ import { execSync } from 'child_process';
2
+
3
+ export function getCurrentCommitHash(): string {
4
+ try {
5
+ const fullHash = execSync('git rev-parse HEAD', {
6
+ encoding: 'utf-8',
7
+ stdio: ['pipe', 'pipe', 'pipe']
8
+ }).trim();
9
+
10
+ return fullHash.substring(0, 7);
11
+ } catch (error) {
12
+ throw new Error('Not a git repository or no commits yet');
13
+ }
14
+ }
15
+
16
+ export function getCurrentCommitFullHash(): string {
17
+ try {
18
+ const fullHash = execSync('git rev-parse HEAD', {
19
+ encoding: 'utf-8',
20
+ stdio: ['pipe', 'pipe', 'pipe']
21
+ }).trim();
22
+
23
+ return fullHash;
24
+ } catch (error) {
25
+ throw new Error('Not a git repository or no commits yet');
26
+ }
27
+ }
28
+
29
+ export function isGitRepo(): boolean {
30
+ try {
31
+ execSync('git rev-parse --is-inside-work-tree', {
32
+ stdio: ['pipe', 'pipe', 'pipe']
33
+ });
34
+ return true;
35
+ } catch {
36
+ return false;
37
+ }
38
+ }
package/test.txt ADDED
@@ -0,0 +1,2 @@
1
+ test
2
+ test
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "commonjs",
5
+ "lib": ["ES2022"],
6
+ "outDir": "./dist",
7
+ "rootDir": "./src",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "resolveJsonModule": true,
13
+ "declaration": true,
14
+ "declarationMap": true,
15
+ "sourceMap": true,
16
+ "types": ["node"]
17
+ },
18
+ "include": ["src/**/*"],
19
+ "exclude": ["node_modules", "dist", "**/*.test.ts"]
20
+ }