Skip to content

Commit dd1335c

Browse files
authored
Merge pull request #8 from urbit/m/re
lib: refactor and restructure
2 parents 1419b81 + d1efc74 commit dd1335c

File tree

26 files changed

+2834
-1201
lines changed

26 files changed

+2834
-1201
lines changed

.github/workflows/size.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

README.md

Lines changed: 39 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,50 @@
11
# `@urbit/aura`
22

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.
44

5-
## API
5+
Supports all standard auras (except `@dr` and `@uc`).
66

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.
1510

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+
```
3521

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
4723

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+
```
5129

52-
// @uv manipulation
53-
function parseUv(x: string): bigint;
54-
function formatUv(x: bigint | string): string;
30+
### Utilities
5531

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.
5933

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+
};
6450
```

package-lock.json

Lines changed: 0 additions & 85 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"@tsconfig/recommended": "^1.0.2",
3030
"dts-cli": "^2.0.0",
3131
"husky": "^7.0.4",
32-
"jsverify": "^0.8.4",
3332
"tslib": "^2.5.0",
3433
"typescript": "^5.0.4"
3534
},

0 commit comments

Comments
 (0)