instrumentality 0.0.1 → 0.0.3
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 +4 -4
- package/dist/base.d.ts +7 -7
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +6 -5
- package/dist/road.d.ts +8 -8
- package/dist/road.d.ts.map +1 -1
- package/dist/road.js +12 -14
- package/package.json +5 -1
- package/src/base.ts +7 -7
- package/src/road.ts +13 -15
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|

|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
## The INSTRUMENTALITY project
|
|
5
|
+
## The INSTRUMENTALITY project (concept)
|
|
6
6
|
A utility library for TypeScript/Node.js
|
|
7
7
|
|
|
8
8
|
|
|
@@ -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
|
package/dist/base.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,MAAO,SAAQ,KAAK;IAAY,IAAI,SAA0B;CAAE;AAK7E;;;;;;;;;GASG;AACH,wBAAsB,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,OAAO,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAazH;AAID;;;;;;GAMG;AACH,wBAAsB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAgB1E;AAID;;;;;GAKG;AACH,KAAK,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,IACvD,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;AAGhE;;;;;GAKG;AACH,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,IAChD;IAAC,GAAG,UAAU,CAAC,CAAC,CAAC;IAAE,GAAG,UAAU,CAAC,CAAC,CAAC;CAAC,CAAC,QAAQ,CAA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,EAAE,CAAA;AAIzE;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,UAAU,EACxC,IAAI,GACJ,UAAU,GACV,SAAS,GACT,aAAa,GACb,MAAM,GACN,WAAW,GACX,UAAU,GACV,eAAe,GACf,OAAO,GACP,MAAM,GACN,SAAS,GACT,SAAS,GACT,MAAM,GACN,QAAQ,GACR,OAAO,MAAM,CAAC,QAAQ,GACtB,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;AAGD;;;;;;;;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/dist/road.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare class RdErr extends bs.InsErr {
|
|
|
14
14
|
* @returns The constructor function corresponding to the file mode.
|
|
15
15
|
* @throws If the file mode is unknown, throws a {@link RdErr}.
|
|
16
16
|
*/
|
|
17
|
-
export declare function
|
|
17
|
+
export declare function resolveMode(statmode: number): typeof File | typeof Folder | typeof SymbolicLink | typeof BlockDevice;
|
|
18
18
|
/**
|
|
19
19
|
* Creates a new instance of the appropriate subclass of {@link Road} based on the file mode of the specified path.
|
|
20
20
|
*
|
|
@@ -34,7 +34,7 @@ export declare function factory(lookFor: string): Promise<BlockDevice | File | F
|
|
|
34
34
|
export declare function lockFor(roadOrPath: Road | string): Promise<void> | undefined;
|
|
35
35
|
export declare abstract class Road {
|
|
36
36
|
/** The absolute path to the file or directory that this Road instance represents.
|
|
37
|
-
* Intentionally made protected to prevent external modification, as changing this value could lead to inconsistencies and unexpected behavior. */
|
|
37
|
+
* @remarks Intentionally made protected to prevent external modification, as changing this value could lead to inconsistencies and unexpected behavior. */
|
|
38
38
|
protected pointsTo: string;
|
|
39
39
|
/** Indicates whether the file or directory represented by this Road instance can be modified.
|
|
40
40
|
* Changing this value does not affect the actual file system permissions, but rather serves as a safeguard within the application to prevent accidental modifications. */
|
|
@@ -59,7 +59,7 @@ export declare abstract class Road {
|
|
|
59
59
|
* @throws If the specified path does not exist, throws a fs.{@link Error}.
|
|
60
60
|
* @throws If the type of the file or directory at the specified path does not match the type of this instance, throws a {@link RdErr}. Useful for subclasses.
|
|
61
61
|
*/
|
|
62
|
-
constructor(lookFor: string, typeCheck: boolean);
|
|
62
|
+
constructor(lookFor: string, typeCheck: boolean | 1 | 0);
|
|
63
63
|
/**
|
|
64
64
|
* Verifies that the file or directory represented by this Road instance exists, is of the same type as this instance, and (optionally) is writable.
|
|
65
65
|
*
|
|
@@ -91,18 +91,18 @@ export declare abstract class Road {
|
|
|
91
91
|
/**
|
|
92
92
|
* Checks if the file or directory represented by this Road is both visible and of the same type as expected.
|
|
93
93
|
*/
|
|
94
|
-
existsSync(): boolean;
|
|
95
94
|
exists(): Promise<boolean>;
|
|
95
|
+
existsSync(): boolean;
|
|
96
96
|
/**
|
|
97
97
|
* @returns The file system stats for the file or directory.
|
|
98
|
-
* @see {@link fs.
|
|
98
|
+
* @see {@link fs.lstat}
|
|
99
99
|
*/
|
|
100
|
-
|
|
100
|
+
stats(): Promise<fs.Stats>;
|
|
101
101
|
/**
|
|
102
102
|
* @returns The file system stats for the file or directory.
|
|
103
|
-
* @see {@link fs.
|
|
103
|
+
* @see {@link fs.lstatSync}
|
|
104
104
|
*/
|
|
105
|
-
|
|
105
|
+
statsSync(): fs.Stats;
|
|
106
106
|
/**
|
|
107
107
|
* @returns The amount of path segments in the absolute path to the file or directory represented by this Road instance, minus one (i.e., the depth of the file or directory in the file system hierarchy).
|
|
108
108
|
* @remarks As subclasses of {@link Road} require all paths to be absolute/normalized and valid, this method is guaranteed to return a non-negative integer.
|
package/dist/road.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"road.d.ts","sourceRoot":"","sources":["../src/road.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAI9B,OAAO,KAAK,EAAE,MAAM,aAAa,CAAA;AAGjC,OAAO,KAAK,EAAE,MAAM,WAAW,CAAA;AAI/B;;GAEG;AACH,qBAAa,KAAM,SAAQ,EAAE,CAAC,MAAM;IAAY,IAAI,SAA+B;CAAE;AAIrF;;;;;;GAMG;AACH,wBAAgB,
|
|
1
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KAAK,CAAC,CAAwB;IACtD,aAAa,IAAI,KAAK,CAAwB;IACxC,SAAS,IAAI,OAAO,CAAC,KAAK,CAAC,CAAwB;CACnE;AACD,qBAAa,WAAY,SAAQ,YAAY;CAAI;AACjD,qBAAa,eAAgB,SAAQ,YAAY;CAAI;AACrD,qBAAa,IAAK,SAAQ,YAAY;CAAI;AAC1C,qBAAa,MAAO,SAAQ,YAAY;CAAI;AAI5C,eAAO,IAAI,SAAS,EAAE,oBAAoB,CAAC,MAAM,CAAC,GAAG,IAAW,CAAA;AAChE,eAAO,IAAI,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,IAAW,CAAA;AAE9C;;;;GAIG;AACH,wBAAgB,oBAAoB,SASnC;AACD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,QAW3C;AAGD,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,UAAU,EAAE;IAAE,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,CAAC,CAAA;CAAE,EAAE,WAAW,EAAE,OAAO,GAAG,CAAC,GAAG,UAAU,GAAG,eAAe,CAQ1I"}
|
package/dist/road.js
CHANGED
|
@@ -21,7 +21,7 @@ export class RdErr extends bs.InsErr {
|
|
|
21
21
|
* @returns The constructor function corresponding to the file mode.
|
|
22
22
|
* @throws If the file mode is unknown, throws a {@link RdErr}.
|
|
23
23
|
*/
|
|
24
|
-
export function
|
|
24
|
+
export function resolveMode(statmode) {
|
|
25
25
|
switch (statmode & fsc.S_IFMT) {
|
|
26
26
|
case fsc.S_IFREG: return File;
|
|
27
27
|
case fsc.S_IFDIR: return Folder;
|
|
@@ -42,12 +42,12 @@ export function modeCtor(statmode) {
|
|
|
42
42
|
*/
|
|
43
43
|
export function factorySync(lookFor) {
|
|
44
44
|
fs.accessSync(lookFor, fsc.F_OK);
|
|
45
|
-
return new (
|
|
45
|
+
return new (resolveMode(fs.lstatSync(lookFor).mode))(lookFor, false);
|
|
46
46
|
}
|
|
47
47
|
/** Async version of {@link factorySync}. */
|
|
48
48
|
export async function factory(lookFor) {
|
|
49
49
|
await fp.access(lookFor, fsc.F_OK);
|
|
50
|
-
return new (
|
|
50
|
+
return new (resolveMode((await fp.lstat(lookFor)).mode))(lookFor, false);
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
53
|
* A map that keeps track of locked roads to prevent concurrent modifications. The keys are the absolute paths of the roads, and the values are promises that resolve when the lock is released.
|
|
@@ -67,7 +67,7 @@ export function lockFor(roadOrPath) {
|
|
|
67
67
|
}
|
|
68
68
|
export class Road {
|
|
69
69
|
/** The absolute path to the file or directory that this Road instance represents.
|
|
70
|
-
* Intentionally made protected to prevent external modification, as changing this value could lead to inconsistencies and unexpected behavior. */
|
|
70
|
+
* @remarks Intentionally made protected to prevent external modification, as changing this value could lead to inconsistencies and unexpected behavior. */
|
|
71
71
|
pointsTo;
|
|
72
72
|
/** Indicates whether the file or directory represented by this Road instance can be modified.
|
|
73
73
|
* Changing this value does not affect the actual file system permissions, but rather serves as a safeguard within the application to prevent accidental modifications. */
|
|
@@ -76,14 +76,14 @@ export class Road {
|
|
|
76
76
|
/** Accessor for the absolute path to the file or directory that this Road instance represents. */
|
|
77
77
|
get isAt() { return this.pointsTo; }
|
|
78
78
|
/** Accessor for the name of the file or directory that this Road instance represents. */
|
|
79
|
-
get name() { return
|
|
79
|
+
get name() { return this.isAt.slice(this.isAt.lastIndexOf(ph.sep) + 1); }
|
|
80
80
|
/** Same as {@link isAt} but for compatibility with external libraries that try to convert the object to a string. */
|
|
81
81
|
toString() { return this.isAt; }
|
|
82
82
|
/** Returns the OS file type of the file or directory.
|
|
83
83
|
* Return value (OS type) and the type of this instance are not guaranteed to be the same, as the file system may have changed since this instance was created. */
|
|
84
|
-
typeSync() { return (
|
|
84
|
+
typeSync() { return (resolveMode(fs.lstatSync(this.isAt).mode)); }
|
|
85
85
|
/** Async version of {@link typeSync}. */
|
|
86
|
-
async type() { return (
|
|
86
|
+
async type() { return (resolveMode((await fp.lstat(this.isAt)).mode)); }
|
|
87
87
|
/**
|
|
88
88
|
* Constructs a new Road instance representing the file or directory at the specified path.
|
|
89
89
|
*
|
|
@@ -186,20 +186,18 @@ export class Road {
|
|
|
186
186
|
/**
|
|
187
187
|
* Checks if the file or directory represented by this Road is both visible and of the same type as expected.
|
|
188
188
|
*/
|
|
189
|
-
existsSync() { return this.verifySync(fsc.F_OK, true); }
|
|
190
189
|
async exists() { return this.verify(fsc.F_OK, true); }
|
|
190
|
+
existsSync() { return this.verifySync(fsc.F_OK, true); }
|
|
191
191
|
/**
|
|
192
192
|
* @returns The file system stats for the file or directory.
|
|
193
|
-
* @see {@link fs.
|
|
193
|
+
* @see {@link fs.lstat}
|
|
194
194
|
*/
|
|
195
|
-
|
|
195
|
+
async stats() { return fp.lstat(this.isAt); }
|
|
196
196
|
/**
|
|
197
197
|
* @returns The file system stats for the file or directory.
|
|
198
|
-
* @see {@link fs.
|
|
198
|
+
* @see {@link fs.lstatSync}
|
|
199
199
|
*/
|
|
200
|
-
|
|
201
|
-
return fp.lstat(this.isAt);
|
|
202
|
-
}
|
|
200
|
+
statsSync() { return fs.lstatSync(this.isAt); }
|
|
203
201
|
/**
|
|
204
202
|
* @returns The amount of path segments in the absolute path to the file or directory represented by this Road instance, minus one (i.e., the depth of the file or directory in the file system hierarchy).
|
|
205
203
|
* @remarks As subclasses of {@link Road} require all paths to be absolute/normalized and valid, this method is guaranteed to return a non-negative integer.
|
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.3",
|
|
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.
|
|
@@ -256,7 +257,6 @@ export function encode122(data_: ArrayLike<number>): string {
|
|
|
256
257
|
}
|
|
257
258
|
|
|
258
259
|
|
|
259
|
-
|
|
260
260
|
/**
|
|
261
261
|
* Decodes a base-122 encoded string back into its original byte representation.
|
|
262
262
|
* The decoding process reverses the encoding, extracting 7 bits of data from each character and handling two-byte sequences for illegal characters.
|
|
@@ -266,7 +266,7 @@ export function encode122(data_: ArrayLike<number>): string {
|
|
|
266
266
|
* @throws If an invalid base-122 illegal index is encountered during decoding (shouldn't happen if the input was generated by {@link encode122}).
|
|
267
267
|
* @see {@link encode122} for encoding data into base-122.
|
|
268
268
|
*/
|
|
269
|
-
export function decode122(base122_: string)
|
|
269
|
+
export function decode122(base122_: string) {
|
|
270
270
|
const out: number[] = []
|
|
271
271
|
let current = 0
|
|
272
272
|
let bitIndex = 0
|
package/src/road.ts
CHANGED
|
@@ -24,7 +24,7 @@ export class RdErr extends bs.InsErr { override name = "Instrumentality-Road-Err
|
|
|
24
24
|
* @returns The constructor function corresponding to the file mode.
|
|
25
25
|
* @throws If the file mode is unknown, throws a {@link RdErr}.
|
|
26
26
|
*/
|
|
27
|
-
export function
|
|
27
|
+
export function resolveMode(statmode: number) {
|
|
28
28
|
switch (statmode & fsc.S_IFMT) {
|
|
29
29
|
case fsc.S_IFREG: return File
|
|
30
30
|
case fsc.S_IFDIR: return Folder
|
|
@@ -48,12 +48,12 @@ export function modeCtor(statmode: number) {
|
|
|
48
48
|
*/
|
|
49
49
|
export function factorySync(lookFor: string) {
|
|
50
50
|
fs.accessSync(lookFor, fsc.F_OK)
|
|
51
|
-
return new (
|
|
51
|
+
return new (resolveMode(fs.lstatSync(lookFor).mode))(lookFor, false)
|
|
52
52
|
}
|
|
53
53
|
/** Async version of {@link factorySync}. */
|
|
54
54
|
export async function factory(lookFor: string) {
|
|
55
55
|
await fp.access(lookFor, fsc.F_OK)
|
|
56
|
-
return new (
|
|
56
|
+
return new (resolveMode((await fp.lstat(lookFor)).mode))(lookFor, false)
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
|
|
@@ -79,7 +79,7 @@ export function lockFor(roadOrPath: Road | string) {
|
|
|
79
79
|
|
|
80
80
|
export abstract class Road {
|
|
81
81
|
/** The absolute path to the file or directory that this Road instance represents.
|
|
82
|
-
* Intentionally made protected to prevent external modification, as changing this value could lead to inconsistencies and unexpected behavior. */
|
|
82
|
+
* @remarks Intentionally made protected to prevent external modification, as changing this value could lead to inconsistencies and unexpected behavior. */
|
|
83
83
|
protected pointsTo: string
|
|
84
84
|
/** Indicates whether the file or directory represented by this Road instance can be modified.
|
|
85
85
|
* Changing this value does not affect the actual file system permissions, but rather serves as a safeguard within the application to prevent accidental modifications. */
|
|
@@ -89,14 +89,14 @@ export abstract class Road {
|
|
|
89
89
|
/** Accessor for the absolute path to the file or directory that this Road instance represents. */
|
|
90
90
|
get isAt() { return this.pointsTo }
|
|
91
91
|
/** Accessor for the name of the file or directory that this Road instance represents. */
|
|
92
|
-
get name() { return
|
|
92
|
+
get name() { return this.isAt.slice(this.isAt.lastIndexOf(ph.sep) + 1) }
|
|
93
93
|
/** Same as {@link isAt} but for compatibility with external libraries that try to convert the object to a string. */
|
|
94
94
|
toString() { return this.isAt }
|
|
95
95
|
/** Returns the OS file type of the file or directory.
|
|
96
96
|
* Return value (OS type) and the type of this instance are not guaranteed to be the same, as the file system may have changed since this instance was created. */
|
|
97
|
-
typeSync() { return (
|
|
97
|
+
typeSync() { return (resolveMode(fs.lstatSync(this.isAt).mode)) }
|
|
98
98
|
/** Async version of {@link typeSync}. */
|
|
99
|
-
async type() { return (
|
|
99
|
+
async type() { return (resolveMode((await fp.lstat(this.isAt)).mode)) }
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
102
|
* Constructs a new Road instance representing the file or directory at the specified path.
|
|
@@ -107,7 +107,7 @@ export abstract class Road {
|
|
|
107
107
|
* @throws If the specified path does not exist, throws a fs.{@link Error}.
|
|
108
108
|
* @throws If the type of the file or directory at the specified path does not match the type of this instance, throws a {@link RdErr}. Useful for subclasses.
|
|
109
109
|
*/
|
|
110
|
-
constructor(lookFor: string, typeCheck: boolean) {
|
|
110
|
+
constructor(lookFor: string, typeCheck: boolean | 1 | 0) {
|
|
111
111
|
this.pointsTo = ph.resolve(lookFor)
|
|
112
112
|
if (typeCheck && !(this instanceof this.typeSync())) // `this` directly refers to the subclass
|
|
113
113
|
throw new RdErr(`Type missmatch: Path '${this.isAt}' is not of constructed type ${this.constructor.name}.`)
|
|
@@ -201,20 +201,18 @@ export abstract class Road {
|
|
|
201
201
|
/**
|
|
202
202
|
* Checks if the file or directory represented by this Road is both visible and of the same type as expected.
|
|
203
203
|
*/
|
|
204
|
-
existsSync() { return this.verifySync(fsc.F_OK, true) }
|
|
205
204
|
async exists() { return this.verify(fsc.F_OK, true) }
|
|
205
|
+
existsSync() { return this.verifySync(fsc.F_OK, true) }
|
|
206
206
|
/**
|
|
207
207
|
* @returns The file system stats for the file or directory.
|
|
208
|
-
* @see {@link fs.
|
|
208
|
+
* @see {@link fs.lstat}
|
|
209
209
|
*/
|
|
210
|
-
|
|
210
|
+
async stats() { return fp.lstat(this.isAt) }
|
|
211
211
|
/**
|
|
212
212
|
* @returns The file system stats for the file or directory.
|
|
213
|
-
* @see {@link fs.
|
|
213
|
+
* @see {@link fs.lstatSync}
|
|
214
214
|
*/
|
|
215
|
-
|
|
216
|
-
return fp.lstat(this.isAt)
|
|
217
|
-
}
|
|
215
|
+
statsSync() { return fs.lstatSync(this.isAt) }
|
|
218
216
|
|
|
219
217
|
/**
|
|
220
218
|
* @returns The amount of path segments in the absolute path to the file or directory represented by this Road instance, minus one (i.e., the depth of the file or directory in the file system hierarchy).
|