opticedge-cloud-utils 1.1.32 → 1.1.33

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.
@@ -2,6 +2,10 @@ type CardParts = {
2
2
  name: string;
3
3
  number: string | null;
4
4
  };
5
+ interface ParsedVariantName {
6
+ name: string;
7
+ variant: string;
8
+ }
5
9
  /**
6
10
  * Split a card label into `{ name, number }`.
7
11
  *
@@ -15,5 +19,6 @@ type CardParts = {
15
19
  * 3. If no valid number found — returns `{ name: original, number: null }`.
16
20
  */
17
21
  export declare function splitNameAndNumber(input: string, realNumber?: string | null): CardParts;
22
+ export declare function parseCardVariant(value: string): ParsedVariantName;
18
23
  export declare function productExists(productId: number, token: string, fetchTimeoutMs: number): Promise<boolean | null>;
19
24
  export {};
@@ -2,6 +2,7 @@
2
2
  // src/pricecharting.ts
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.splitNameAndNumber = splitNameAndNumber;
5
+ exports.parseCardVariant = parseCardVariant;
5
6
  exports.productExists = productExists;
6
7
  const logger_1 = require("./logger");
7
8
  const regex_1 = require("./regex");
@@ -53,6 +54,22 @@ function splitNameAndNumber(input, realNumber) {
53
54
  return { name: s, number: null };
54
55
  return { name: namePart, number: numberPart };
55
56
  }
57
+ function parseCardVariant(value) {
58
+ const trimmedValue = value.trim();
59
+ // Matches names ending with a bracketed variant:
60
+ // Arcanine [Reverse Holo]
61
+ const match = trimmedValue.match(/^(.*?)\s+\[([^\]]+)\]\s*$/);
62
+ if (!match) {
63
+ return {
64
+ name: trimmedValue,
65
+ variant: 'Regular'
66
+ };
67
+ }
68
+ return {
69
+ name: match[1].trim(),
70
+ variant: match[2].trim()
71
+ };
72
+ }
56
73
  async function productExists(productId, token, fetchTimeoutMs) {
57
74
  if (!Number.isInteger(productId) || productId <= 0) {
58
75
  (0, logger_1.log)(logger_1.LogLevel.WARNING, '[productExists] invalid productId', { productId });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opticedge-cloud-utils",
3
- "version": "1.1.32",
3
+ "version": "1.1.33",
4
4
  "description": "Common utilities for cloud functions",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,6 +11,11 @@ interface ProductExistsResponse {
11
11
  'error-message'?: string
12
12
  }
13
13
 
14
+ interface ParsedVariantName {
15
+ name: string
16
+ variant: string
17
+ }
18
+
14
19
  const PRODUCT_NOT_FOUND_MESSAGE = 'no such product'
15
20
  const PRODUCT_API_URL = 'https://www.pricecharting.com/api/product'
16
21
 
@@ -62,6 +67,26 @@ export function splitNameAndNumber(input: string, realNumber?: string | null): C
62
67
  return { name: namePart, number: numberPart }
63
68
  }
64
69
 
70
+ export function parseCardVariant(value: string): ParsedVariantName {
71
+ const trimmedValue = value.trim()
72
+
73
+ // Matches names ending with a bracketed variant:
74
+ // Arcanine [Reverse Holo]
75
+ const match = trimmedValue.match(/^(.*?)\s+\[([^\]]+)\]\s*$/)
76
+
77
+ if (!match) {
78
+ return {
79
+ name: trimmedValue,
80
+ variant: 'Regular'
81
+ }
82
+ }
83
+
84
+ return {
85
+ name: match[1].trim(),
86
+ variant: match[2].trim()
87
+ }
88
+ }
89
+
65
90
  export async function productExists(
66
91
  productId: number,
67
92
  token: string,