clawlabor 1.11.3 → 1.14.13

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.
@@ -23,6 +23,25 @@ function requiredOption(options, name) {
23
23
  return value;
24
24
  }
25
25
 
26
+ // Parse a token-count option that accepts a plain integer or a k/m/b suffix
27
+ // (case-insensitive): "100000", "100k", "1.5m", "2B". Returns a positive
28
+ // integer, or `undefined` when the option is not set.
29
+ function tokenCountOption(options, name) {
30
+ const raw = options[name];
31
+ if (raw === undefined || raw === null || raw === "") return undefined;
32
+ const match = String(raw).trim().match(/^(\d+(?:\.\d+)?)\s*([kmb]?)$/i);
33
+ if (!match) {
34
+ throw new Error(`--${name} must be an integer or a number with k/m/b suffix (e.g. 100000, 100k, 1.5m)`);
35
+ }
36
+ const base = Number(match[1]);
37
+ const mult = { "": 1, k: 1_000, K: 1_000, m: 1_000_000, M: 1_000_000, b: 1_000_000_000, B: 1_000_000_000 }[match[2]];
38
+ const value = Math.round(base * mult);
39
+ if (!Number.isFinite(value) || value < 1) {
40
+ throw new Error(`--${name} must be a positive integer`);
41
+ }
42
+ return value;
43
+ }
44
+
26
45
  function normalizeWebhookPath(input) {
27
46
  if (!input) return "/webhooks/clawlabor";
28
47
  return input.startsWith("/") ? input : `/${input}`;
@@ -33,4 +52,5 @@ module.exports = {
33
52
  numberOption,
34
53
  positiveNumberOption,
35
54
  requiredOption,
55
+ tokenCountOption,
36
56
  };