@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.
- package/LICENSE +202 -0
- package/README.md +159 -2
- package/_dist/graph.d.ts +26 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/mod.d.ts +11 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/routes.d.ts +10 -0
- package/_dist/routes.d.ts.map +1 -0
- package/_dist/service.d.ts +41 -0
- package/_dist/service.d.ts.map +1 -0
- package/_dist/tally.d.ts +111 -0
- package/_dist/tally.d.ts.map +1 -0
- package/_dist/tools.d.ts +52 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/use.d.ts +31 -0
- package/_dist/use.d.ts.map +1 -0
- package/_dist/views.d.ts +27 -0
- package/_dist/views.d.ts.map +1 -0
- package/_dist/vocab.d.ts +7 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/_dist/window.d.ts +132 -0
- package/_dist/window.d.ts.map +1 -0
- package/_dist/words.d.ts +40 -0
- package/_dist/words.d.ts.map +1 -0
- package/budget.js +131 -0
- package/budget.js.map +1 -0
- package/budget.ts +128 -0
- package/day.js +336 -0
- package/day.js.map +1 -0
- package/day.ts +364 -0
- package/deno.json +1 -0
- package/graph.js +59 -0
- package/graph.js.map +1 -0
- package/graph.ts +61 -0
- package/mod.js +11 -0
- package/mod.js.map +1 -0
- package/mod.ts +34 -0
- package/package.json +57 -4
- package/page.js +352 -0
- package/page.js.map +1 -0
- package/page.ts +491 -0
- package/routes.js +22 -0
- package/routes.js.map +1 -0
- package/routes.ts +19 -0
- package/service.js +124 -0
- package/service.js.map +1 -0
- package/service.ts +149 -0
- package/tally.js +385 -0
- package/tally.js.map +1 -0
- package/tally.ts +424 -0
- package/tools.js +243 -0
- package/tools.js.map +1 -0
- package/tools.ts +357 -0
- package/use.js +172 -0
- package/use.js.map +1 -0
- package/use.ts +226 -0
- package/views.js +79 -0
- package/views.js.map +1 -0
- package/views.ts +96 -0
- package/vocab.js +17 -0
- package/vocab.js.map +1 -0
- package/vocab.json +237 -0
- package/vocab.ts +18 -0
- package/window.js +259 -0
- package/window.js.map +1 -0
- package/window.ts +336 -0
- package/words.js +47 -0
- package/words.js.map +1 -0
- 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
|