@dbx-tools/shared-core 0.3.3 → 0.3.5

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/string.ts +39 -0
package/package.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "publishConfig": {
23
23
  "access": "public"
24
24
  },
25
- "version": "0.3.3",
25
+ "version": "0.3.5",
26
26
  "types": "index.ts",
27
27
  "type": "module",
28
28
  "exports": {
package/src/string.ts CHANGED
@@ -7,6 +7,19 @@
7
7
  */
8
8
  import { fnvHashWithOptions } from "./hash";
9
9
 
10
+ /**
11
+ * Options controlling {@link tokenizeWithOptions}. All default off except
12
+ * `camelCase`.
13
+ *
14
+ * - `distinct` - drop duplicate tokens (first occurrence wins).
15
+ * - `lowerCase` - lowercase every token.
16
+ * - `capitalize` - upper-case each token's first letter (then
17
+ * {@link TOKENIZE_OVERRIDES} fix up `ai` -> `AI` and `v2` -> `V2`).
18
+ * - `omitUriScheme` - strip a leading `scheme://` before tokenizing.
19
+ * - `omitEmailDomain` - keep only the local part of an email.
20
+ * - `camelCase` - split on camelCase boundaries / digit runs / acronyms
21
+ * (default `true`); when `false`, split only on non-alphanumerics.
22
+ */
10
23
  export type TokenizeOptions = {
11
24
  distinct?: boolean;
12
25
  lowerCase?: boolean;
@@ -493,3 +506,29 @@ function renderMap(node: Record<string, Description>, pad: string): string {
493
506
  export function pluralize(count: number, noun: string): string {
494
507
  return `${count} ${noun}${count === 1 ? "" : "s"}`;
495
508
  }
509
+
510
+ /**
511
+ * Title-case a snake / kebab / camel identifier into a human-readable label:
512
+ * tokenize (lowercased, capitalized), then join with spaces. Falls back to
513
+ * the raw `value` when it yields no tokens (e.g. punctuation-only input).
514
+ * `bge_large_en` -> `"Bge Large En"`, `promptId` -> `"Prompt Id"`.
515
+ *
516
+ * The single source of truth for the "humanize a column / field name" idiom -
517
+ * reused by the chat data-grid headers and the export renderer. Extra
518
+ * {@link TokenizeOptions} (e.g. `camelCase: false`) merge over the defaults.
519
+ */
520
+ export function toLabel(value: string, options?: TokenizeOptions): string {
521
+ const tokens = [
522
+ ...tokenizeWithOptions({ lowerCase: true, capitalize: true, ...options }, value),
523
+ ];
524
+ return tokens.length > 0 ? tokens.join(" ") : value;
525
+ }
526
+
527
+ /**
528
+ * Upper-case the first character of `value`, leaving the rest untouched.
529
+ * `"working"` -> `"Working"`. Collapses the
530
+ * `s.charAt(0).toUpperCase() + s.slice(1)` idiom.
531
+ */
532
+ export function capitalize(value: string): string {
533
+ return value ? value.charAt(0).toUpperCase() + value.slice(1) : value;
534
+ }