@ibiliaze/stringman 3.16.0 → 3.17.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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './seat';
2
+ import { fishyMatchesAll } from './ticket';
2
3
  /**
3
4
  * Clean up extra whitespace in a string.
4
5
  *
@@ -159,6 +160,7 @@ export declare const ticket: {
159
160
  dashed?: boolean;
160
161
  }) => string;
161
162
  validateTicketCode: (code: string) => boolean;
163
+ fishyMatchesAll: typeof fishyMatchesAll;
162
164
  };
163
165
  export declare const order: {
164
166
  createNumericOrderId: () => string;
package/dist/index.js CHANGED
@@ -306,5 +306,6 @@ exports.ticket = {
306
306
  getTicketId: ticket_1.getTicketId,
307
307
  buildTicketCode: ticket_1.buildTicketCode,
308
308
  validateTicketCode: ticket_1.validateTicketCode,
309
+ fishyMatchesAll: ticket_1.fishyMatchesAll,
309
310
  };
310
311
  exports.order = { createNumericOrderId: order_1.createNumericOrderId };
package/dist/ticket.d.ts CHANGED
@@ -59,6 +59,15 @@ export declare const buildTicketCodeNumeric: (args: {
59
59
  * Checks: numeric, correct total length (17), and Luhn checksum.
60
60
  */
61
61
  export declare const validateTicketCodeNumeric: (code: string) => boolean;
62
+ /**
63
+ * Check if a fishy ticket's core digits (last 6 before the final digit)
64
+ * match ALL ticket codes in the list.
65
+ *
66
+ * @param {string[]} tickets - list of ticket codes
67
+ * @param {string} fishyCode - the suspect ticket code
68
+ * @returns {boolean} true if fishyCode matches all, false otherwise
69
+ */
70
+ export declare function fishyMatchesAll(tickets: string[], fishyCode: string): boolean;
62
71
  /**
63
72
  * A stable, human-readable internal ID for a seat within a fixture.
64
73
  * (Not used in the printed/scanned code — just handy elsewhere.)
package/dist/ticket.js CHANGED
@@ -5,6 +5,7 @@
5
5
  // =====================================================================================
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.validateTicketCode = exports.buildTicketCode = exports.getTicketId = exports.validateTicketCodeNumeric = exports.buildTicketCodeNumeric = exports.rndBlockNum = exports.fixtureBlockNum = exports.seatBlockNum = exports.fixtureIdBlockNum = exports.venueBlockNum = exports.luhn10 = void 0;
8
+ exports.fishyMatchesAll = fishyMatchesAll;
8
9
  const node_crypto_1 = require("node:crypto");
9
10
  // ---------- config: block lengths (easy to tweak in one place) ----------
10
11
  const CODE_LEN = {
@@ -176,6 +177,32 @@ const validateTicketCodeNumeric = (code) => {
176
177
  }
177
178
  };
178
179
  exports.validateTicketCodeNumeric = validateTicketCodeNumeric;
180
+ /**
181
+ * Check if a fishy ticket's core digits (last 6 before the final digit)
182
+ * match ALL ticket codes in the list.
183
+ *
184
+ * @param {string[]} tickets - list of ticket codes
185
+ * @param {string} fishyCode - the suspect ticket code
186
+ * @returns {boolean} true if fishyCode matches all, false otherwise
187
+ */
188
+ function fishyMatchesAll(tickets, fishyCode) {
189
+ try {
190
+ // Need at least 7 chars to have "XXXXXX" + last digit
191
+ if (typeof fishyCode !== 'string' || fishyCode.length < 7)
192
+ return false;
193
+ const fishyCore = fishyCode.slice(-7, -1); // last 6 chars before very last
194
+ return tickets.every(code => {
195
+ if (typeof code !== 'string' || code.length < 7)
196
+ return false;
197
+ const core = code.slice(-7, -1);
198
+ return core === fishyCore;
199
+ });
200
+ }
201
+ catch (e) {
202
+ console.error(e);
203
+ return false;
204
+ }
205
+ }
179
206
  // =====================================================================================
180
207
  /**
181
208
  * A stable, human-readable internal ID for a seat within a fixture.
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@ibiliaze/stringman",
3
- "version": "3.16.0",
3
+ "version": "3.17.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
9
  "pub": "npm publish --access public",
10
- "git": "git add .; git commit -m 'changes'; git tag -a 3.16.0 -m '3.16.0'; git push origin 3.16.0; git push",
10
+ "git": "git add .; git commit -m 'changes'; git tag -a 3.17.0 -m '3.17.0'; git push origin 3.17.0; git push",
11
11
  "push": "npm run build; npm run git; npm run pub"
12
12
  },
13
13
  "author": "Ibi Hasanli",
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './seat';
2
- import { buildTicketCode, getTicketId, validateTicketCode } from './ticket';
2
+ import { buildTicketCode, getTicketId, validateTicketCode, fishyMatchesAll } from './ticket';
3
3
  import { createNumericOrderId } from './order';
4
4
 
5
5
  /**
@@ -282,6 +282,7 @@ export const ticket = {
282
282
  getTicketId,
283
283
  buildTicketCode,
284
284
  validateTicketCode,
285
+ fishyMatchesAll,
285
286
  };
286
287
 
287
288
  export const order = { createNumericOrderId };
package/src/ticket.ts CHANGED
@@ -187,6 +187,32 @@ export const validateTicketCodeNumeric = (code: string) => {
187
187
  }
188
188
  };
189
189
 
190
+ /**
191
+ * Check if a fishy ticket's core digits (last 6 before the final digit)
192
+ * match ALL ticket codes in the list.
193
+ *
194
+ * @param {string[]} tickets - list of ticket codes
195
+ * @param {string} fishyCode - the suspect ticket code
196
+ * @returns {boolean} true if fishyCode matches all, false otherwise
197
+ */
198
+ export function fishyMatchesAll(tickets: string[], fishyCode: string): boolean {
199
+ try {
200
+ // Need at least 7 chars to have "XXXXXX" + last digit
201
+ if (typeof fishyCode !== 'string' || fishyCode.length < 7) return false;
202
+
203
+ const fishyCore = fishyCode.slice(-7, -1); // last 6 chars before very last
204
+
205
+ return tickets.every(code => {
206
+ if (typeof code !== 'string' || code.length < 7) return false;
207
+ const core = code.slice(-7, -1);
208
+ return core === fishyCore;
209
+ });
210
+ } catch (e) {
211
+ console.error(e);
212
+ return false;
213
+ }
214
+ }
215
+
190
216
  // =====================================================================================
191
217
  /**
192
218
  * A stable, human-readable internal ID for a seat within a fixture.