instrumentality 0.0.1 → 0.0.2
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/README.md +3 -3
- package/dist/base.d.ts +7 -7
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +6 -5
- package/package.json +5 -1
- package/src/base.ts +7 -6
package/README.md
CHANGED
|
@@ -18,9 +18,9 @@ npm install git+https://github.com/clerkburk/ts-instrumentality.git
|
|
|
18
18
|
```
|
|
19
19
|
then
|
|
20
20
|
```ts
|
|
21
|
-
import * as
|
|
22
|
-
import * as
|
|
23
|
-
import * as
|
|
21
|
+
import * as ins from "instrumentality" // Base
|
|
22
|
+
import * as ind from "instrumentality/dom" // Browser (if available)
|
|
23
|
+
import * as inr from "instrumentality/road" // Filesystem using Node.js (if available)
|
|
24
24
|
```
|
|
25
25
|
thats literally it
|
|
26
26
|
|
package/dist/base.d.ts
CHANGED
|
@@ -57,8 +57,8 @@ export type Enumerate<N extends number, A extends number[] = []> = A['length'] e
|
|
|
57
57
|
* @property {@link timer} - The initial timestamp when the benchmark was created or last reset.
|
|
58
58
|
* @method {@link round} - Records the current elapsed time and restarts the timer.
|
|
59
59
|
* @method {@link reset} - Resets the benchmark timer to the current time and clears recorded rounds.
|
|
60
|
-
* @accessor {@link y} - Elapsed time in years
|
|
61
|
-
* @accessor {@link mn} - Elapsed time in months
|
|
60
|
+
* @accessor {@link y} - Elapsed time in years.
|
|
61
|
+
* @accessor {@link mn} - Elapsed time in months.
|
|
62
62
|
* @accessor {@link w} - Elapsed time in weeks.
|
|
63
63
|
* @accessor {@link d} - Elapsed time in days.
|
|
64
64
|
* @accessor {@link h} - Elapsed time in hours.
|
|
@@ -78,9 +78,9 @@ export declare class Benchmark {
|
|
|
78
78
|
round(): void;
|
|
79
79
|
/** Resets the benchmark timer to the current time and clears recorded rounds. */
|
|
80
80
|
reset(): void;
|
|
81
|
-
/** Elapsed time in years
|
|
81
|
+
/** Elapsed time in years, assuming 12 28-day months per year. */
|
|
82
82
|
get y(): number;
|
|
83
|
-
/** Elapsed time in months
|
|
83
|
+
/** Elapsed time in months, assuming each month has 28 days. */
|
|
84
84
|
get mn(): number;
|
|
85
85
|
/** Elapsed time in weeks. */
|
|
86
86
|
get w(): number;
|
|
@@ -101,6 +101,7 @@ export declare class Benchmark {
|
|
|
101
101
|
/** Elapsed time in picoseconds. */
|
|
102
102
|
get ps(): number;
|
|
103
103
|
}
|
|
104
|
+
export { Benchmark as Bench, Benchmark as Timer, Benchmark as Stopwatch };
|
|
104
105
|
/**
|
|
105
106
|
* Helper type that represents a view of a Uint8Array, exposing only view methods and properties, along with a readonly index signature for accessing elements.
|
|
106
107
|
*/
|
|
@@ -114,7 +115,7 @@ export declare const BASE122_ILLEGAL_INDEX: Readonly<Record<number, number>>;
|
|
|
114
115
|
/** Shortened payload marker used when escaping an illegal 7-bit value and no subsequent 7-bit chunk is available (the current chunk is reused as payload). */
|
|
115
116
|
export declare const BASE122_SHORT: 7;
|
|
116
117
|
/**
|
|
117
|
-
* Encodes indexed data into a base-122 representation, going as low as
|
|
118
|
+
* Encodes indexed data into a base-122 representation, going as low as 14% overhead for regular data, making base-64 look pathetic in comparison with its 33% overhead.
|
|
118
119
|
* The encoding process packs 7 bits of data into each character, and uses a two-byte sequence for reserved characters to ensure that the output string remains valid.
|
|
119
120
|
*
|
|
120
121
|
* @remarks The high density of base-122 comes with the trade-off of not being able to use the output string in certain contexts, such as URLs or file names.
|
|
@@ -141,6 +142,5 @@ export declare function encode122(data_: ArrayLike<number>): string;
|
|
|
141
142
|
* @throws If an invalid base-122 illegal index is encountered during decoding (shouldn't happen if the input was generated by {@link encode122}).
|
|
142
143
|
* @see {@link encode122} for encoding data into base-122.
|
|
143
144
|
*/
|
|
144
|
-
export declare function decode122(base122_: string): Uint8Array
|
|
145
|
-
export {};
|
|
145
|
+
export declare function decode122(base122_: string): Uint8Array<ArrayBuffer>;
|
|
146
146
|
//# sourceMappingURL=base.d.ts.map
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,QAAQ,GACR,aAAa,GACb,MAAM,GACN,gBAAgB,GAChB,UAAU,GACV,KAAK,GACL,QAAQ,GACR,OAAO,GACP,YAAY,GACZ,UAAU,GACV,MAAM,GACN,QAAQ,GACR,YAAY,GACZ,YAAY,CACf,GAAG;IAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAA;AAIpC,yJAAyJ;AACzJ,eAAO,MAAM,eAAe,YAAI,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAU,CAAA;AAC/D,iHAAiH;AACjH,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOzD,CAAA;AACV,8JAA8J;AAC9J,eAAO,MAAM,aAAa,EAAG,CAAc,CAAA;AAG3C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAmC1D;AAID;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,2BAgCzC"}
|
package/dist/base.js
CHANGED
|
@@ -62,8 +62,8 @@ export async function sleep(ms_, abs_) {
|
|
|
62
62
|
* @property {@link timer} - The initial timestamp when the benchmark was created or last reset.
|
|
63
63
|
* @method {@link round} - Records the current elapsed time and restarts the timer.
|
|
64
64
|
* @method {@link reset} - Resets the benchmark timer to the current time and clears recorded rounds.
|
|
65
|
-
* @accessor {@link y} - Elapsed time in years
|
|
66
|
-
* @accessor {@link mn} - Elapsed time in months
|
|
65
|
+
* @accessor {@link y} - Elapsed time in years.
|
|
66
|
+
* @accessor {@link mn} - Elapsed time in months.
|
|
67
67
|
* @accessor {@link w} - Elapsed time in weeks.
|
|
68
68
|
* @accessor {@link d} - Elapsed time in days.
|
|
69
69
|
* @accessor {@link h} - Elapsed time in hours.
|
|
@@ -83,9 +83,9 @@ export class Benchmark {
|
|
|
83
83
|
round() { this.rounds.push(this.ms); this.timer = performance.now(); }
|
|
84
84
|
/** Resets the benchmark timer to the current time and clears recorded rounds. */
|
|
85
85
|
reset() { this.rounds = []; this.timer = performance.now(); }
|
|
86
|
-
/** Elapsed time in years
|
|
86
|
+
/** Elapsed time in years, assuming 12 28-day months per year. */
|
|
87
87
|
get y() { return this.mn / 12; }
|
|
88
|
-
/** Elapsed time in months
|
|
88
|
+
/** Elapsed time in months, assuming each month has 28 days. */
|
|
89
89
|
get mn() { return this.w / 4; }
|
|
90
90
|
/** Elapsed time in weeks. */
|
|
91
91
|
get w() { return this.d / 7; }
|
|
@@ -106,6 +106,7 @@ export class Benchmark {
|
|
|
106
106
|
/** Elapsed time in picoseconds. */
|
|
107
107
|
get ps() { return this.ns * 1e3; }
|
|
108
108
|
}
|
|
109
|
+
export { Benchmark as Bench, Benchmark as Timer, Benchmark as Stopwatch };
|
|
109
110
|
/** Specific reserved 7-bit values codes that must be escaped when encoding data into base-122, as they are considered illegal in the encoding scheme. */
|
|
110
111
|
export const BASE122_ILLEGAL = [0, 10, 13, 34, 38, 92];
|
|
111
112
|
/** Mapping of illegal ascii codes to their corresponding indices in {@link BASE122_ILLEGAL} (reverse lookup). */
|
|
@@ -120,7 +121,7 @@ export const BASE122_ILLEGAL_INDEX = {
|
|
|
120
121
|
/** Shortened payload marker used when escaping an illegal 7-bit value and no subsequent 7-bit chunk is available (the current chunk is reused as payload). */
|
|
121
122
|
export const BASE122_SHORT = 0b111;
|
|
122
123
|
/**
|
|
123
|
-
* Encodes indexed data into a base-122 representation, going as low as
|
|
124
|
+
* Encodes indexed data into a base-122 representation, going as low as 14% overhead for regular data, making base-64 look pathetic in comparison with its 33% overhead.
|
|
124
125
|
* The encoding process packs 7 bits of data into each character, and uses a two-byte sequence for reserved characters to ensure that the output string remains valid.
|
|
125
126
|
*
|
|
126
127
|
* @remarks The high density of base-122 comes with the trade-off of not being able to use the output string in certain contexts, such as URLs or file names.
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "instrumentality",
|
|
3
|
+
"repository": {
|
|
4
|
+
"type": "git",
|
|
5
|
+
"url": "https://github.com/clerkburk/instrumentality.git"
|
|
6
|
+
},
|
|
3
7
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
8
|
+
"version": "0.0.2",
|
|
5
9
|
"main": "./dist/base.js",
|
|
6
10
|
"types": "./dist/base.d.ts",
|
|
7
11
|
"devDependencies": {
|
package/src/base.ts
CHANGED
|
@@ -101,8 +101,8 @@ A['length'] extends N ? A[number] : Enumerate<N, [...A, A['length']]>
|
|
|
101
101
|
* @property {@link timer} - The initial timestamp when the benchmark was created or last reset.
|
|
102
102
|
* @method {@link round} - Records the current elapsed time and restarts the timer.
|
|
103
103
|
* @method {@link reset} - Resets the benchmark timer to the current time and clears recorded rounds.
|
|
104
|
-
* @accessor {@link y} - Elapsed time in years
|
|
105
|
-
* @accessor {@link mn} - Elapsed time in months
|
|
104
|
+
* @accessor {@link y} - Elapsed time in years.
|
|
105
|
+
* @accessor {@link mn} - Elapsed time in months.
|
|
106
106
|
* @accessor {@link w} - Elapsed time in weeks.
|
|
107
107
|
* @accessor {@link d} - Elapsed time in days.
|
|
108
108
|
* @accessor {@link h} - Elapsed time in hours.
|
|
@@ -122,9 +122,9 @@ export class Benchmark {
|
|
|
122
122
|
round() { this.rounds.push(this.ms); this.timer = performance.now() }
|
|
123
123
|
/** Resets the benchmark timer to the current time and clears recorded rounds. */
|
|
124
124
|
reset() { this.rounds = []; this.timer = performance.now() }
|
|
125
|
-
/** Elapsed time in years
|
|
125
|
+
/** Elapsed time in years, assuming 12 28-day months per year. */
|
|
126
126
|
get y() { return this.mn / 12 }
|
|
127
|
-
/** Elapsed time in months
|
|
127
|
+
/** Elapsed time in months, assuming each month has 28 days. */
|
|
128
128
|
get mn() { return this.w / 4 }
|
|
129
129
|
/** Elapsed time in weeks. */
|
|
130
130
|
get w() { return this.d / 7 }
|
|
@@ -145,6 +145,7 @@ export class Benchmark {
|
|
|
145
145
|
/** Elapsed time in picoseconds. */
|
|
146
146
|
get ps() { return this.ns * 1e3 }
|
|
147
147
|
}
|
|
148
|
+
export { Benchmark as Bench, Benchmark as Timer, Benchmark as Stopwatch }
|
|
148
149
|
|
|
149
150
|
|
|
150
151
|
|
|
@@ -201,7 +202,7 @@ export const BASE122_SHORT = 0b111 as const
|
|
|
201
202
|
|
|
202
203
|
|
|
203
204
|
/**
|
|
204
|
-
* Encodes indexed data into a base-122 representation, going as low as
|
|
205
|
+
* Encodes indexed data into a base-122 representation, going as low as 14% overhead for regular data, making base-64 look pathetic in comparison with its 33% overhead.
|
|
205
206
|
* The encoding process packs 7 bits of data into each character, and uses a two-byte sequence for reserved characters to ensure that the output string remains valid.
|
|
206
207
|
*
|
|
207
208
|
* @remarks The high density of base-122 comes with the trade-off of not being able to use the output string in certain contexts, such as URLs or file names.
|
|
@@ -266,7 +267,7 @@ export function encode122(data_: ArrayLike<number>): string {
|
|
|
266
267
|
* @throws If an invalid base-122 illegal index is encountered during decoding (shouldn't happen if the input was generated by {@link encode122}).
|
|
267
268
|
* @see {@link encode122} for encoding data into base-122.
|
|
268
269
|
*/
|
|
269
|
-
export function decode122(base122_: string)
|
|
270
|
+
export function decode122(base122_: string) {
|
|
270
271
|
const out: number[] = []
|
|
271
272
|
let current = 0
|
|
272
273
|
let bitIndex = 0
|