@vencord-companion/shared 0.0.1
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/dist/Logger.d.ts +8 -0
- package/dist/Logger.js +8 -0
- package/dist/Logger.js.map +1 -0
- package/dist/Position.d.ts +32 -0
- package/dist/Position.js +162 -0
- package/dist/Position.js.map +1 -0
- package/dist/Range.d.ts +30 -0
- package/dist/Range.js +134 -0
- package/dist/Range.js.map +1 -0
- package/dist/decorators.d.ts +13 -0
- package/dist/decorators.js +57 -0
- package/dist/decorators.js.map +1 -0
- package/dist/util.d.ts +19 -0
- package/dist/util.js +69 -0
- package/dist/util.js.map +1 -0
- package/package.json +25 -0
package/dist/Logger.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface Logger {
|
|
2
|
+
trace(message: string, ...args: any[]): void;
|
|
3
|
+
debug(message: string, ...args: any[]): void;
|
|
4
|
+
info(message: string, ...args: any[]): void;
|
|
5
|
+
warn(message: string, ...args: any[]): void;
|
|
6
|
+
error(message: string | Error, ...args: any[]): void;
|
|
7
|
+
}
|
|
8
|
+
export declare const NoopLogger: Logger;
|
package/dist/Logger.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../src/Logger.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,UAAU,GAAW,MAAM,CAAC,MAAM,CAAC;IAC5C,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC;IAChB,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC;IAChB,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC;IACf,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC;IACf,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC;CACnB,CAAC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface IPosition {
|
|
2
|
+
readonly line: number;
|
|
3
|
+
readonly character: number;
|
|
4
|
+
}
|
|
5
|
+
export declare class Position implements IPosition {
|
|
6
|
+
static Min(...positions: Position[]): Position;
|
|
7
|
+
static Max(...positions: Position[]): Position;
|
|
8
|
+
static isPosition(other: any): other is IPosition;
|
|
9
|
+
static of(obj: any): Position;
|
|
10
|
+
private _line;
|
|
11
|
+
private _character;
|
|
12
|
+
get line(): number;
|
|
13
|
+
get character(): number;
|
|
14
|
+
constructor(line: number, character: number);
|
|
15
|
+
isBefore(other: Position): boolean;
|
|
16
|
+
isBeforeOrEqual(other: Position): boolean;
|
|
17
|
+
isAfter(other: Position): boolean;
|
|
18
|
+
isAfterOrEqual(other: Position): boolean;
|
|
19
|
+
isEqual(other: Position): boolean;
|
|
20
|
+
compareTo(other: Position): number;
|
|
21
|
+
translate(change: {
|
|
22
|
+
lineDelta?: number;
|
|
23
|
+
characterDelta?: number;
|
|
24
|
+
}): IPosition;
|
|
25
|
+
translate(lineDelta?: number, characterDelta?: number): IPosition;
|
|
26
|
+
with(change: {
|
|
27
|
+
line?: number;
|
|
28
|
+
character?: number;
|
|
29
|
+
}): IPosition;
|
|
30
|
+
with(line?: number, character?: number): IPosition;
|
|
31
|
+
toJSON(): any;
|
|
32
|
+
}
|
package/dist/Position.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
export class Position {
|
|
2
|
+
static Min(...positions) {
|
|
3
|
+
if (positions.length === 0) {
|
|
4
|
+
throw new TypeError();
|
|
5
|
+
}
|
|
6
|
+
let [result] = positions;
|
|
7
|
+
for (let i = 1; i < positions.length; i++) {
|
|
8
|
+
const p = positions[i];
|
|
9
|
+
if (p.isBefore(result)) {
|
|
10
|
+
result = p;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
static Max(...positions) {
|
|
16
|
+
if (positions.length === 0) {
|
|
17
|
+
throw new TypeError();
|
|
18
|
+
}
|
|
19
|
+
let [result] = positions;
|
|
20
|
+
for (let i = 1; i < positions.length; i++) {
|
|
21
|
+
const p = positions[i];
|
|
22
|
+
if (p.isAfter(result)) {
|
|
23
|
+
result = p;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
static isPosition(other) {
|
|
29
|
+
if (!other) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (other instanceof Position) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
const { line, character } = other;
|
|
36
|
+
if (typeof line === "number" && typeof character === "number") {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
static of(obj) {
|
|
42
|
+
if (obj instanceof Position) {
|
|
43
|
+
return obj;
|
|
44
|
+
}
|
|
45
|
+
else if (this.isPosition(obj)) {
|
|
46
|
+
return new Position(obj.line, obj.character);
|
|
47
|
+
}
|
|
48
|
+
throw new Error("Invalid argument, is NOT a position-like object");
|
|
49
|
+
}
|
|
50
|
+
_line;
|
|
51
|
+
_character;
|
|
52
|
+
get line() {
|
|
53
|
+
return this._line;
|
|
54
|
+
}
|
|
55
|
+
get character() {
|
|
56
|
+
return this._character;
|
|
57
|
+
}
|
|
58
|
+
constructor(line, character) {
|
|
59
|
+
if (line < 0) {
|
|
60
|
+
throw new Error("line must be non-negative");
|
|
61
|
+
}
|
|
62
|
+
if (character < 0) {
|
|
63
|
+
throw new Error("character must be non-negative");
|
|
64
|
+
}
|
|
65
|
+
this._line = line;
|
|
66
|
+
this._character = character;
|
|
67
|
+
}
|
|
68
|
+
isBefore(other) {
|
|
69
|
+
if (this._line < other._line) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
if (other._line < this._line) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
return this._character < other._character;
|
|
76
|
+
}
|
|
77
|
+
isBeforeOrEqual(other) {
|
|
78
|
+
if (this._line < other._line) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
if (other._line < this._line) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
return this._character <= other._character;
|
|
85
|
+
}
|
|
86
|
+
isAfter(other) {
|
|
87
|
+
return !this.isBeforeOrEqual(other);
|
|
88
|
+
}
|
|
89
|
+
isAfterOrEqual(other) {
|
|
90
|
+
return !this.isBefore(other);
|
|
91
|
+
}
|
|
92
|
+
isEqual(other) {
|
|
93
|
+
return this._line === other._line && this._character === other._character;
|
|
94
|
+
}
|
|
95
|
+
compareTo(other) {
|
|
96
|
+
if (this._line < other._line) {
|
|
97
|
+
return -1;
|
|
98
|
+
}
|
|
99
|
+
else if (this._line > other.line) {
|
|
100
|
+
return 1;
|
|
101
|
+
}
|
|
102
|
+
// equal line
|
|
103
|
+
if (this._character < other._character) {
|
|
104
|
+
return -1;
|
|
105
|
+
}
|
|
106
|
+
else if (this._character > other._character) {
|
|
107
|
+
return 1;
|
|
108
|
+
}
|
|
109
|
+
// equal line and character
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
translate(lineDeltaOrChange, characterDelta = 0) {
|
|
113
|
+
if (lineDeltaOrChange === null || characterDelta === null) {
|
|
114
|
+
throw new Error("Illegal Argument");
|
|
115
|
+
}
|
|
116
|
+
let lineDelta;
|
|
117
|
+
if (typeof lineDeltaOrChange === "undefined") {
|
|
118
|
+
lineDelta = 0;
|
|
119
|
+
}
|
|
120
|
+
else if (typeof lineDeltaOrChange === "number") {
|
|
121
|
+
lineDelta = lineDeltaOrChange;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
lineDelta = typeof lineDeltaOrChange.lineDelta === "number" ? lineDeltaOrChange.lineDelta : 0;
|
|
125
|
+
characterDelta = typeof lineDeltaOrChange.characterDelta === "number" ? lineDeltaOrChange.characterDelta : 0;
|
|
126
|
+
}
|
|
127
|
+
if (lineDelta === 0 && characterDelta === 0) {
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
return new Position(this.line + lineDelta, this.character + characterDelta);
|
|
131
|
+
}
|
|
132
|
+
with(lineOrChange, character = this.character) {
|
|
133
|
+
if (lineOrChange === null || character === null) {
|
|
134
|
+
throw new Error("Illegal Argument");
|
|
135
|
+
}
|
|
136
|
+
let line;
|
|
137
|
+
if (typeof lineOrChange === "undefined") {
|
|
138
|
+
line = this.line;
|
|
139
|
+
}
|
|
140
|
+
else if (typeof lineOrChange === "number") {
|
|
141
|
+
line = lineOrChange;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
line = typeof lineOrChange.line === "number" ? lineOrChange.line : this.line;
|
|
145
|
+
character = typeof lineOrChange.character === "number" ? lineOrChange.character : this.character;
|
|
146
|
+
}
|
|
147
|
+
if (line === this.line && character === this.character) {
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
return new Position(line, character);
|
|
151
|
+
}
|
|
152
|
+
toJSON() {
|
|
153
|
+
return {
|
|
154
|
+
line: this.line,
|
|
155
|
+
character: this.character,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
[Symbol.for("debug.description")]() {
|
|
159
|
+
return `(${this.line}:${this.character})`;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=Position.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Position.js","sourceRoot":"","sources":["../src/Position.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,QAAQ;IACjB,MAAM,CAAC,GAAG,CAAC,GAAG,SAAqB;QAC/B,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,SAAS,EAAE,CAAC;QAC1B,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;QAEzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACxC,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YAEvB,I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,IAAI,CAAC,IAAI,IAAI,SAAS,KAAK,IAAI,CAAC,SAAS,EAAE,CAAC;YACrD,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACzC,CAAC;IAED,MAAM;QACF,OAAO;YACH,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,SAAS,EAAE,IAAI,CAAC,SAAS;SAC5B,CAAC;IACN,CAAC;IAED,CAAC,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAC7B,OAAO,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,SAAS,GAAG,CAAC;IAC9C,CAAC;CACJ"}
|
package/dist/Range.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { IPosition, Position } from "./Position";
|
|
2
|
+
export interface IRange {
|
|
3
|
+
start: IPosition;
|
|
4
|
+
end: IPosition;
|
|
5
|
+
}
|
|
6
|
+
export declare class Range implements IRange {
|
|
7
|
+
static isRange(thing: any): thing is IRange;
|
|
8
|
+
static of(obj: any): Range;
|
|
9
|
+
protected _start: Position;
|
|
10
|
+
protected _end: Position;
|
|
11
|
+
get start(): Position;
|
|
12
|
+
get end(): Position;
|
|
13
|
+
constructor(start: IPosition, end: IPosition);
|
|
14
|
+
constructor(start: Position, end: Position);
|
|
15
|
+
constructor(startLine: number, startColumn: number, endLine: number, endColumn: number);
|
|
16
|
+
contains(positionOrRange: Position | Range): boolean;
|
|
17
|
+
isEqual(other: Range): boolean;
|
|
18
|
+
intersection(other: Range): Range | undefined;
|
|
19
|
+
union(other: Range): Range;
|
|
20
|
+
get isEmpty(): boolean;
|
|
21
|
+
get isSingleLine(): boolean;
|
|
22
|
+
with(change: {
|
|
23
|
+
start?: Position;
|
|
24
|
+
end?: Position;
|
|
25
|
+
}): Range;
|
|
26
|
+
with(start?: Position, end?: Position): Range;
|
|
27
|
+
toJSON(): any;
|
|
28
|
+
}
|
|
29
|
+
export declare function getDebugDescriptionOfRange(range: Range): string;
|
|
30
|
+
export declare const zeroRange: Range;
|
package/dist/Range.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { Position } from "./Position";
|
|
2
|
+
export class Range {
|
|
3
|
+
static isRange(thing) {
|
|
4
|
+
if (thing instanceof Range) {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
if (!thing) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
return Position.isPosition(thing.start)
|
|
11
|
+
&& Position.isPosition(thing.end);
|
|
12
|
+
}
|
|
13
|
+
static of(obj) {
|
|
14
|
+
if (obj instanceof Range) {
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
17
|
+
if (this.isRange(obj)) {
|
|
18
|
+
return new Range(obj.start, obj.end);
|
|
19
|
+
}
|
|
20
|
+
throw new Error("Invalid argument, is NOT a range-like object");
|
|
21
|
+
}
|
|
22
|
+
_start;
|
|
23
|
+
_end;
|
|
24
|
+
get start() {
|
|
25
|
+
return this._start;
|
|
26
|
+
}
|
|
27
|
+
get end() {
|
|
28
|
+
return this._end;
|
|
29
|
+
}
|
|
30
|
+
constructor(startLineOrStart, startColumnOrEnd, endLine, endColumn) {
|
|
31
|
+
let start;
|
|
32
|
+
let end;
|
|
33
|
+
if (typeof startLineOrStart === "number" && typeof startColumnOrEnd === "number" && typeof endLine === "number" && typeof endColumn === "number") {
|
|
34
|
+
start = new Position(startLineOrStart, startColumnOrEnd);
|
|
35
|
+
end = new Position(endLine, endColumn);
|
|
36
|
+
}
|
|
37
|
+
else if (Position.isPosition(startLineOrStart) && Position.isPosition(startColumnOrEnd)) {
|
|
38
|
+
start = Position.of(startLineOrStart);
|
|
39
|
+
end = Position.of(startColumnOrEnd);
|
|
40
|
+
}
|
|
41
|
+
if (!start || !end) {
|
|
42
|
+
throw new Error("Invalid arguments");
|
|
43
|
+
}
|
|
44
|
+
if (start.isBefore(end)) {
|
|
45
|
+
this._start = start;
|
|
46
|
+
this._end = end;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this._start = end;
|
|
50
|
+
this._end = start;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
contains(positionOrRange) {
|
|
54
|
+
if (Range.isRange(positionOrRange)) {
|
|
55
|
+
return this.contains(positionOrRange.start)
|
|
56
|
+
&& this.contains(positionOrRange.end);
|
|
57
|
+
}
|
|
58
|
+
else if (Position.isPosition(positionOrRange)) {
|
|
59
|
+
if (Position.of(positionOrRange)
|
|
60
|
+
.isBefore(this._start)) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
if (this._end.isBefore(positionOrRange)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
isEqual(other) {
|
|
71
|
+
return this._start.isEqual(other._start) && this._end.isEqual(other._end);
|
|
72
|
+
}
|
|
73
|
+
intersection(other) {
|
|
74
|
+
const start = Position.Max(other.start, this._start);
|
|
75
|
+
const end = Position.Min(other.end, this._end);
|
|
76
|
+
if (start.isAfter(end)) {
|
|
77
|
+
// this happens when there is no overlap:
|
|
78
|
+
// |-----|
|
|
79
|
+
// |----|
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
return new Range(start, end);
|
|
83
|
+
}
|
|
84
|
+
union(other) {
|
|
85
|
+
if (this.contains(other)) {
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
else if (other.contains(this)) {
|
|
89
|
+
return other;
|
|
90
|
+
}
|
|
91
|
+
const start = Position.Min(other.start, this._start);
|
|
92
|
+
const end = Position.Max(other.end, this.end);
|
|
93
|
+
return new Range(start, end);
|
|
94
|
+
}
|
|
95
|
+
get isEmpty() {
|
|
96
|
+
return this._start.isEqual(this._end);
|
|
97
|
+
}
|
|
98
|
+
get isSingleLine() {
|
|
99
|
+
return this._start.line === this._end.line;
|
|
100
|
+
}
|
|
101
|
+
with(startOrChange, end = this.end) {
|
|
102
|
+
if (startOrChange === null || end === null) {
|
|
103
|
+
throw new Error("Illegal Argument");
|
|
104
|
+
}
|
|
105
|
+
let start;
|
|
106
|
+
if (!startOrChange) {
|
|
107
|
+
start = this.start;
|
|
108
|
+
}
|
|
109
|
+
else if (Position.isPosition(startOrChange)) {
|
|
110
|
+
start = startOrChange;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
start = startOrChange.start || this.start;
|
|
114
|
+
end = startOrChange.end || this.end;
|
|
115
|
+
}
|
|
116
|
+
if (start.isEqual(this._start) && end.isEqual(this.end)) {
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
return new Range(start, end);
|
|
120
|
+
}
|
|
121
|
+
toJSON() {
|
|
122
|
+
return [this.start, this.end];
|
|
123
|
+
}
|
|
124
|
+
[Symbol.for("debug.description")]() {
|
|
125
|
+
return getDebugDescriptionOfRange(this);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
export function getDebugDescriptionOfRange(range) {
|
|
129
|
+
return range.isEmpty
|
|
130
|
+
? `[${range.start.line}:${range.start.character})`
|
|
131
|
+
: `[${range.start.line}:${range.start.character} -> ${range.end.line}:${range.end.character})`;
|
|
132
|
+
}
|
|
133
|
+
export const zeroRange = Object.freeze(new Range(new Position(0, 0), new Position(0, 0)));
|
|
134
|
+
//# sourceMappingURL=Range.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Range.js","sourceRoot":"","sources":["../src/Range.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,QAAQ,EAAE,MAAM,YAAY,CAAC;AAOjD,MAAM,OAAO,KAAK;IACd,MAAM,CAAC,OAAO,CAAC,KAAU;QACrB,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,IAAI,CAAC,KAAK,EAAE,CAAC;YACT,OAAO,KAAK,CAAC;QACjB,CAAC;Q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,IAAI,KAAK,CAAC,GAAG,CAAC,SAAS,GAAG,CAAC;AACvG,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAU,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAU,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Caches the result of a function and provides an option to invalidate the cache.
|
|
3
|
+
*
|
|
4
|
+
* Only works on methods with no parameters
|
|
5
|
+
*
|
|
6
|
+
* @param invalidate An optional array of functions that a function to invalidate the cache will be pushed to.
|
|
7
|
+
* @returns A decorator function that can be used to cache the result of a method.
|
|
8
|
+
*/
|
|
9
|
+
export declare function Cache(invalidate?: (() => void)[]): <P extends () => any>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<(...args: Parameters<P>) => ReturnType<P>>) => TypedPropertyDescriptor<(...args: Parameters<P>) => ReturnType<P>> | void;
|
|
10
|
+
/**
|
|
11
|
+
* Same thing as {@link Cache} but for getters.
|
|
12
|
+
*/
|
|
13
|
+
export declare function CacheGetter(invalidate?: (() => void)[]): <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const SYM_UNCACHED = Symbol("uncached");
|
|
2
|
+
/**
|
|
3
|
+
* Caches the result of a function and provides an option to invalidate the cache.
|
|
4
|
+
*
|
|
5
|
+
* Only works on methods with no parameters
|
|
6
|
+
*
|
|
7
|
+
* @param invalidate An optional array of functions that a function to invalidate the cache will be pushed to.
|
|
8
|
+
* @returns A decorator function that can be used to cache the result of a method.
|
|
9
|
+
*/
|
|
10
|
+
export function Cache(invalidate) {
|
|
11
|
+
return function (target, propertyKey, descriptor) {
|
|
12
|
+
const sym = Symbol(`cache-${propertyKey.toString()}`);
|
|
13
|
+
target[sym] = SYM_UNCACHED;
|
|
14
|
+
const orig = descriptor.value;
|
|
15
|
+
if (typeof orig !== "function") {
|
|
16
|
+
throw new Error("Not a function");
|
|
17
|
+
}
|
|
18
|
+
if (orig.length !== 0) {
|
|
19
|
+
throw new Error("Function has parameters");
|
|
20
|
+
}
|
|
21
|
+
descriptor.value = function (...args) {
|
|
22
|
+
const t = this;
|
|
23
|
+
if (t[sym] === SYM_UNCACHED) {
|
|
24
|
+
invalidate?.push(() => {
|
|
25
|
+
t[sym] = SYM_UNCACHED;
|
|
26
|
+
});
|
|
27
|
+
t[sym] = orig.apply(t, args);
|
|
28
|
+
}
|
|
29
|
+
return t[sym];
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Same thing as {@link Cache} but for getters.
|
|
35
|
+
*/
|
|
36
|
+
export function CacheGetter(invalidate) {
|
|
37
|
+
return function (target, propertyKey, descriptor) {
|
|
38
|
+
const sym = Symbol(`cache-${propertyKey.toString()}`);
|
|
39
|
+
target[sym] = SYM_UNCACHED;
|
|
40
|
+
const orig = descriptor?.get;
|
|
41
|
+
if (typeof orig !== "function") {
|
|
42
|
+
throw new Error("Not a getter");
|
|
43
|
+
}
|
|
44
|
+
descriptor.get = function () {
|
|
45
|
+
const t = this;
|
|
46
|
+
if (t[sym] === SYM_UNCACHED) {
|
|
47
|
+
invalidate?.push(() => {
|
|
48
|
+
t[sym] = SYM_UNCACHED;
|
|
49
|
+
});
|
|
50
|
+
t[sym] = orig.apply(t);
|
|
51
|
+
}
|
|
52
|
+
return t[sym];
|
|
53
|
+
};
|
|
54
|
+
return descriptor;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,MAA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CAAC;QAE5C,MAAM,IAAI,GAAG,UAAU,EAAE,GAAG,CAAC;QAE7B,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;QACpC,CAAC;QACD,UAAU,CAAC,GAAG,GAAG;YACb,MAAM,CAAC,GAAG,IAAmB,CAAC;YAE9B,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,YAAY,EAAE,CAAC;gBAC1B,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE;oBAClB,CAAC,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC;gBAC1B,CAAC,CAAC,CAAC;gBACH,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAC3B,CAAC;YACD,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC,CAAC;QACF,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;AACN,CAAC"}
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare function debounce<F extends (...args: any) => any>(func: F, delay?: number): (...args: Parameters<F>) => undefined;
|
|
2
|
+
export declare function debounceAsync<F extends (...args: any) => Promise<any>>(func: F, delay?: number): (...args: Parameters<F>) => void;
|
|
3
|
+
export type SemVerVersion = readonly [major: number, minor: number, patch: number];
|
|
4
|
+
/**
|
|
5
|
+
* Compares two semantic version arrays
|
|
6
|
+
* @param a First version to compare
|
|
7
|
+
* @param b Second version to compare
|
|
8
|
+
* @returns
|
|
9
|
+
* -1 if a < b
|
|
10
|
+
* 0 if a = b
|
|
11
|
+
* 1 if a > b
|
|
12
|
+
*/
|
|
13
|
+
export declare function compareVersions(a: SemVerVersion, b: SemVerVersion): 0 | -1 | 1;
|
|
14
|
+
/**
|
|
15
|
+
* version are incompatible if the actual version is less than the minimum version
|
|
16
|
+
* or the actual version has a higher major than the min version
|
|
17
|
+
*/
|
|
18
|
+
export declare function areVersionsIncompatible(minVersion: SemVerVersion, actualVersion: SemVerVersion): boolean;
|
|
19
|
+
export declare function runtime_assert(condition: any, message?: string): asserts condition;
|
package/dist/util.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export function debounce(func, delay = 300) {
|
|
2
|
+
let timeout;
|
|
3
|
+
return function (...args) {
|
|
4
|
+
clearTimeout(timeout);
|
|
5
|
+
timeout = setTimeout(() => func(...args), delay);
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export function debounceAsync(func, delay = 300) {
|
|
9
|
+
// for some godforsaken reason it errors here if its let, but not a few lines up
|
|
10
|
+
var timeout;
|
|
11
|
+
let running = false;
|
|
12
|
+
return function (...args) {
|
|
13
|
+
if (running)
|
|
14
|
+
return;
|
|
15
|
+
running = true;
|
|
16
|
+
clearTimeout(timeout);
|
|
17
|
+
setTimeout(() => func(...args)
|
|
18
|
+
.finally(() => void (running = false)), delay);
|
|
19
|
+
return;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Compares two semantic version arrays
|
|
24
|
+
* @param a First version to compare
|
|
25
|
+
* @param b Second version to compare
|
|
26
|
+
* @returns
|
|
27
|
+
* -1 if a < b
|
|
28
|
+
* 0 if a = b
|
|
29
|
+
* 1 if a > b
|
|
30
|
+
*/
|
|
31
|
+
export function compareVersions(a, b) {
|
|
32
|
+
// Compare major version
|
|
33
|
+
if (a[0] < b[0])
|
|
34
|
+
return -1;
|
|
35
|
+
if (a[0] > b[0])
|
|
36
|
+
return 1;
|
|
37
|
+
// Major versions are equal, compare minor version
|
|
38
|
+
if (a[1] < b[1])
|
|
39
|
+
return -1;
|
|
40
|
+
if (a[1] > b[1])
|
|
41
|
+
return 1;
|
|
42
|
+
// Minor versions are equal, compare patch version
|
|
43
|
+
if (a[2] < b[2])
|
|
44
|
+
return -1;
|
|
45
|
+
if (a[2] > b[2])
|
|
46
|
+
return 1;
|
|
47
|
+
// All components are equal
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* version are incompatible if the actual version is less than the minimum version
|
|
52
|
+
* or the actual version has a higher major than the min version
|
|
53
|
+
*/
|
|
54
|
+
export function areVersionsIncompatible(minVersion, actualVersion) {
|
|
55
|
+
// Check if actual version is less than minimum version
|
|
56
|
+
if (compareVersions(actualVersion, minVersion) === -1)
|
|
57
|
+
return true;
|
|
58
|
+
// Check if actual version has a higher major version than minimum version
|
|
59
|
+
if (actualVersion[0] > minVersion[0])
|
|
60
|
+
return true;
|
|
61
|
+
// Versions are compatible
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
export function runtime_assert(condition, message = "") {
|
|
65
|
+
if (!condition) {
|
|
66
|
+
throw new Error(`Runtime assertion failed: ${message}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,QAAQ,CAEtB,IAAO,EAAE,KAAK,GAAG,GAAG;IAClB,IAAI,OAAe,CAAC;IAEpB,OAAO,UAAU,GAAG,IAAmB;QACnC,YAAY,CAAC,OAAO,CAAC,CAAC;QACtB,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;IACrD,CAAC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,aAAa,CAE3B,IAAO,EAAE,KAAK,GAAG,GAAG;IAClB,gFAAgF;IAChF,IAAI,OAAe,CAAC;IACpB,IAAI,OAAO,GAAG,KAAK,CAAC;IAEpB,OAAO,UAAU,GAAG,IAAmB;QACnC,IAAI,OAAO;YACP,OAAO;QACX,OAAO,GAAG,IAAI,CAAC;QACf,YAAY,CAAC,OAAO,CAAC,CAAC;QACtB,UAAU,CAAC,GA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AED,MAAM,UAAU,cAAc,CAAC,SAAc,EAAE,UAAkB,EAAE;IAC/D,IAAI,CAAC,SAAS,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,6BAA6B,OAAO,EAAE,CAAC,CAAC;IAC5D,CAAC;AACL,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vencord-companion/shared",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
"./*": "./dist/*.js"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [],
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "sadan",
|
|
13
|
+
"url": "https://sadan.zip"
|
|
14
|
+
},
|
|
15
|
+
"license": "LGPL-3.0-or-later",
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"vitest": "^3.2.4"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"preversion": "mkdir .git || :",
|
|
21
|
+
"bump": "npm version",
|
|
22
|
+
"postversion": "rmdir .git",
|
|
23
|
+
"build": "tsc -b"
|
|
24
|
+
}
|
|
25
|
+
}
|