@yaks/spend 0.0.0-stage → 0.2.36

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 (69) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +159 -2
  3. package/_dist/graph.d.ts +26 -0
  4. package/_dist/graph.d.ts.map +1 -0
  5. package/_dist/mod.d.ts +11 -0
  6. package/_dist/mod.d.ts.map +1 -0
  7. package/_dist/routes.d.ts +10 -0
  8. package/_dist/routes.d.ts.map +1 -0
  9. package/_dist/service.d.ts +41 -0
  10. package/_dist/service.d.ts.map +1 -0
  11. package/_dist/tally.d.ts +111 -0
  12. package/_dist/tally.d.ts.map +1 -0
  13. package/_dist/tools.d.ts +52 -0
  14. package/_dist/tools.d.ts.map +1 -0
  15. package/_dist/use.d.ts +31 -0
  16. package/_dist/use.d.ts.map +1 -0
  17. package/_dist/views.d.ts +27 -0
  18. package/_dist/views.d.ts.map +1 -0
  19. package/_dist/vocab.d.ts +7 -0
  20. package/_dist/vocab.d.ts.map +1 -0
  21. package/_dist/window.d.ts +132 -0
  22. package/_dist/window.d.ts.map +1 -0
  23. package/_dist/words.d.ts +40 -0
  24. package/_dist/words.d.ts.map +1 -0
  25. package/budget.js +131 -0
  26. package/budget.js.map +1 -0
  27. package/budget.ts +128 -0
  28. package/day.js +336 -0
  29. package/day.js.map +1 -0
  30. package/day.ts +364 -0
  31. package/deno.json +1 -0
  32. package/graph.js +59 -0
  33. package/graph.js.map +1 -0
  34. package/graph.ts +61 -0
  35. package/mod.js +11 -0
  36. package/mod.js.map +1 -0
  37. package/mod.ts +34 -0
  38. package/package.json +57 -4
  39. package/page.js +352 -0
  40. package/page.js.map +1 -0
  41. package/page.ts +491 -0
  42. package/routes.js +22 -0
  43. package/routes.js.map +1 -0
  44. package/routes.ts +19 -0
  45. package/service.js +124 -0
  46. package/service.js.map +1 -0
  47. package/service.ts +149 -0
  48. package/tally.js +385 -0
  49. package/tally.js.map +1 -0
  50. package/tally.ts +424 -0
  51. package/tools.js +243 -0
  52. package/tools.js.map +1 -0
  53. package/tools.ts +357 -0
  54. package/use.js +172 -0
  55. package/use.js.map +1 -0
  56. package/use.ts +226 -0
  57. package/views.js +79 -0
  58. package/views.js.map +1 -0
  59. package/views.ts +96 -0
  60. package/vocab.js +17 -0
  61. package/vocab.js.map +1 -0
  62. package/vocab.json +237 -0
  63. package/vocab.ts +18 -0
  64. package/window.js +259 -0
  65. package/window.js.map +1 -0
  66. package/window.ts +336 -0
  67. package/words.js +47 -0
  68. package/words.js.map +1 -0
  69. package/words.ts +77 -0
package/words.ts ADDED
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Numbers and rows as a reader takes them in: dollars, token counts, and
3
+ * what a row a tally names is, in a line. Pure, for the page and the report.
4
+ *
5
+ * @module
6
+ */
7
+ import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
8
+
9
+ /**
10
+ * Dollars, to the cent below a hundred and whole above.
11
+ *
12
+ * ```ts
13
+ * import { dollars } from './words.ts'
14
+ * import { equal } from '@yaks/testing'
15
+ *
16
+ * equal([dollars(4.216), dollars(1234.5)], ['$4.22', '$1,235'])
17
+ * ```
18
+ */
19
+ export let dollars = (n = 0): string =>
20
+ n >= 100 ? `$${Math.round(n).toLocaleString('en-US')}` : `$${n.toFixed(2)}`
21
+
22
+ /**
23
+ * A percent, to a tenth, and a share too small to show as less than that.
24
+ *
25
+ * ```ts
26
+ * import { percent } from './words.ts'
27
+ * import { equal } from '@yaks/testing'
28
+ *
29
+ * equal([percent(12.345), percent(0.04), percent(0)], ['12.3%', '<0.1%', '0%'])
30
+ * ```
31
+ */
32
+ export let percent = (n = 0): string =>
33
+ !n ? '0%' : n < 0.05 ? '<0.1%' : `${n.toFixed(1)}%`
34
+
35
+ /**
36
+ * A count of tokens, to three figures.
37
+ *
38
+ * ```ts
39
+ * import { tokens } from './words.ts'
40
+ * import { equal } from '@yaks/testing'
41
+ *
42
+ * equal([tokens(950), tokens(20600), tokens(53100000), tokens(1.2e9)], ['950', '20.6k', '53.1M', '1.2B'])
43
+ * ```
44
+ */
45
+ export let tokens = (n = 0): string => {
46
+ let at = (d: number, s: string) =>
47
+ `${Number((n / d).toPrecision(3)).toString()}${s}`
48
+ return n >= 1e9
49
+ ? at(1e9, 'B')
50
+ : n >= 1e6
51
+ ? at(1e6, 'M')
52
+ : n >= 1e3
53
+ ? at(1e3, 'k')
54
+ : String(Math.round(n))
55
+ }
56
+
57
+ let line = (text: unknown, n = 60) => {
58
+ let first = String(text ?? '').trim().split('\n')[0]
59
+ return first.length > n ? `${first.slice(0, n - 1)}…` : first
60
+ }
61
+
62
+ let comp = (b: Bundle, name: string) =>
63
+ b[name] as Record<string, unknown> | undefined
64
+
65
+ /** What a row a tally names is, in a line: a model by its name, a task or
66
+ * anything with a title by its id and title, a session by its id and the
67
+ * harness's id for it, an entry by what it says. */
68
+ export let label = (b: Bundle, id: string): string =>
69
+ comp(b, 'model')?.name
70
+ ? String(comp(b, 'model')!.name)
71
+ : comp(b, 'doc')?.title
72
+ ? `${id} ${line(comp(b, 'doc')!.title)}`
73
+ : comp(b, 'session')
74
+ ? `${id} ${line(comp(b, 'session')!.id ?? '')}`.trim()
75
+ : comp(b, 'content')
76
+ ? `${id} ${line(comp(b, 'content')!.body)}`
77
+ : id