about summary refs log tree commit diff
path: root/src/lib/type-guards.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/type-guards.ts')
-rw-r--r--src/lib/type-guards.ts14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/lib/type-guards.ts b/src/lib/type-guards.ts
new file mode 100644
index 000000000..8fe651ffb
--- /dev/null
+++ b/src/lib/type-guards.ts
@@ -0,0 +1,14 @@
+export function isObj(v: unknown): v is Record<string, unknown> {
+  return !!v && typeof v === 'object'
+}
+
+export function hasProp<K extends PropertyKey>(
+  data: object,
+  prop: K,
+): data is Record<K, unknown> {
+  return prop in data
+}
+
+export function isStrArray(v: unknown): v is string[] {
+  return Array.isArray(v) && v.every(item => typeof item === 'string')
+}