|
1 | 1 | # `@urbit/aura` |
2 | 2 |
|
3 | | -This NPM package is intended to ease the flow of developing FE applications for urbit, by adding parsing and formatting functions for the various urbit auras |
| 3 | +Hoon literal syntax parsing and rendering. Approaching two nines of parity with hoon stdlib. |
4 | 4 |
|
5 | | -## API |
| 5 | +Supports all standard auras (except `@dr` and `@uc`). |
6 | 6 |
|
7 | | -```typescript |
8 | | -// @da manipulation |
9 | | -function parseDa(da: string): bigint; |
10 | | -function formatDa(da: bigint): string; |
11 | | -// Given a bigint representing an urbit date, returns a unix timestamp. |
12 | | -function daToUnix(da: bigint): number; |
13 | | -// Given a unix timestamp, returns a bigint representing an urbit date |
14 | | -function unixToDa(unix: number): bigint; |
| 7 | +## API overview |
| 8 | + |
| 9 | +Atoms are native `bigint`s. Top-level library functions reflect the hoon stdlib. Aliases are provided for your comfort. Summary of exports below. |
15 | 10 |
|
16 | | -// @p manipulation |
17 | | -// Convert a number to a @p-encoded string. |
18 | | -function patp(arg: string | number | bigint): string; |
19 | | -function hex2patp(hex: string): string; |
20 | | -function patp2hex(name: string): string; |
21 | | -function patp2bn(name: string): bigint; |
22 | | -function patp2dec(name: string): string; |
23 | | -// Determine the ship class of a @p value. |
24 | | -function clan(who: string): string; |
25 | | -// Determine the parent of a @p value. |
26 | | -function sein(name: string): strin; |
27 | | -// Validate a @p string. |
28 | | -function isValidPatp(str: string): boolean; |
29 | | -// Ensure @p is sigged. |
30 | | -function preSig(ship: string): string; |
31 | | -// Remove sig from @p |
32 | | -function deSig(ship: string): string; |
33 | | -// Trim @p to short form |
34 | | -function cite(ship: string): string | null; |
| 11 | +### Parsing |
| 12 | + |
| 13 | +```typescript |
| 14 | +const parse = slav; |
| 15 | +const tryParse = slaw; |
| 16 | +function valid(:aura, :string): boolean; |
| 17 | +function slav(:aura, :string): bigint; // throws on failure |
| 18 | +function slaw(:aura, :string): bigint | null; |
| 19 | +function nuck(:string): coin | null; |
| 20 | +``` |
35 | 21 |
|
36 | | -// @q manipulation |
37 | | -// Convert a number to a @q-encoded string. |
38 | | -function patq(arg: string | number | bigint): string; |
39 | | -function hex2patq(arg: string): string; |
40 | | -function patq2hex(name: string): string; |
41 | | -function patq2bn(name: string): bigint; |
42 | | -function patq2dec(name: string): string; |
43 | | -// Validate a @q string. |
44 | | -function isValidPatq(str: string): boolean; |
45 | | -// Equality comparison on @q values. |
46 | | -function eqPatq(p: string, q: string): boolean; |
| 22 | +### Rendering |
47 | 23 |
|
48 | | -// @ud manipulation |
49 | | -function parseUd(ud: string): bigint; |
50 | | -function formatUd(ud: bigint): string; |
| 24 | +```typescript |
| 25 | +const render = scot; |
| 26 | +function scot(:aura, :bigint): string; |
| 27 | +function rend(:coin): string; |
| 28 | +``` |
51 | 29 |
|
52 | | -// @uv manipulation |
53 | | -function parseUv(x: string): bigint; |
54 | | -function formatUv(x: bigint | string): string; |
| 30 | +### Utilities |
55 | 31 |
|
56 | | -// @uw manipulation |
57 | | -function parseUw(x: string): bigint; |
58 | | -function formatUw(x: bigint | string): string; |
| 32 | +We provide some utilities for desirable operations on specific auras. These too generally match their hoon stdlib equivalents. |
59 | 33 |
|
60 | | -// @ux manipulation |
61 | | -function parseUx(ux: string): string; |
62 | | -function formatUx(hex: string): string; |
63 | | -``; |
| 34 | +```typescript |
| 35 | +const da = { |
| 36 | + function toUnix(:bigint): number, |
| 37 | + function fromUnix(:number): bigint, |
| 38 | +}; |
| 39 | +const p = { |
| 40 | + type rank = 'czar' | 'king' | 'duke' | 'earl' | 'pawn', |
| 41 | + type size = 'galaxy' | 'star' | 'planet' | 'moon' | 'comet', |
| 42 | + function cite(:bigint | string): string, |
| 43 | + function sein(:bigint): bigint, |
| 44 | + function sein(:string): string, // throws on bad input |
| 45 | + function clan(:bigint | string): rank, // throws on bad input |
| 46 | + function kind(:bigint | string): size, // throws on bad input |
| 47 | + function rankToSize(:rank): size, |
| 48 | + function sizeToRank(:size): rank, |
| 49 | +}; |
64 | 50 | ``` |
0 commit comments