Rework storage adapters

This commit is contained in:
Jon Staab
2025-04-16 12:53:49 -07:00
parent 5785710137
commit c5ea7edf6b
6 changed files with 273 additions and 114 deletions
+16
View File
@@ -1,7 +1,20 @@
import {bech32, utf8} from "@scure/base"
type Obj<T = any> = Record<string, T>
// ----------------------------------------------------------------------------
// Working with nil
// ----------------------------------------------------------------------------
export type Nil = null | undefined
export const isNil = <T>(x: T, ...args: unknown[]) => x === undefined || x === null
export const isNotNil = <T>(x: T, ...args: unknown[]) => x !== undefined || x !== null
export const assertNotNil = <T>(x: T, ...args: unknown[]) => x!
// ----------------------------------------------------------------------------
// Basic functional programming utilities
// ----------------------------------------------------------------------------
@@ -610,6 +623,9 @@ export const toIterable = (x: any) => (isIterable(x) ? x : [x])
/** Ensures value is array by wrapping if needed */
export const ensurePlural = <T>(x: T | T[]) => (x instanceof Array ? x : [x])
/** Ensures values are not undefined */
export const removeNil = <T>(xs: T[]) => xs.filter(isNotNil).map(assertNotNil)
// ----------------------------------------------------------------------------
// Objects
// ----------------------------------------------------------------------------