aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-07-01 16:37:50 +0200
committerlonkaars <loek@pipeframe.xyz>2023-07-01 16:37:50 +0200
commitce9e0788317b25e5d297ed38d9fed0754a341288 (patch)
tree29563a39c73ded16cd93eb7b5c5664d1ece944ac /util
parent8ff39cbe6300ca479584fe7d85ff03a1f65bc9b0 (diff)
WIP sentence API
Diffstat (limited to 'util')
-rw-r--r--util/array.ts6
-rw-r--r--util/types.ts8
2 files changed, 14 insertions, 0 deletions
diff --git a/util/array.ts b/util/array.ts
index 5b8c512..f032935 100644
--- a/util/array.ts
+++ b/util/array.ts
@@ -6,6 +6,8 @@ declare global {
peek(): T;
/** @summary create Set from this array */
set(): Set<T>;
+ /** @summary clear array */
+ clear(): void;
}
}
@@ -21,3 +23,7 @@ Array.prototype.set = function() {
return new Set(this);
}
+Array.prototype.clear = function() {
+ while (this.length > 0) this.pop();
+}
+
diff --git a/util/types.ts b/util/types.ts
new file mode 100644
index 0000000..f03a242
--- /dev/null
+++ b/util/types.ts
@@ -0,0 +1,8 @@
+/**
+ * @type DeepPartial<T> makes all properties of type T optional, but keep
+ * array types intact
+ */
+export type DeepPartial<T> = {
+ [K in keyof T]?: T[K] extends Array<infer U> ? Array<U> : DeepPartial<T[K]>;
+};
+