generated from garrettmills/template-npm-typescript
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.3 KiB
54 lines
1.3 KiB
|
|
/** Alias for a value that might come in a Promise. */
|
|
export type Awaitable<T> = T | Promise<T>
|
|
|
|
/** String that has been decrypted. */
|
|
export type DecodedValue = string
|
|
|
|
/** String that has been encrypted. */
|
|
export type EncodedValue = string
|
|
|
|
/** Collection of encoded keys, by name. */
|
|
export type EncodedKeyPackage = { [name: string]: EncodedValue }
|
|
|
|
/** A key used for encryption. */
|
|
export type KeyValue = string
|
|
|
|
/**
|
|
* Interface that designates a particular value as able to be constructed.
|
|
*/
|
|
export interface Instantiable<T> {
|
|
new(...args: any[]): T
|
|
}
|
|
|
|
/**
|
|
* Returns true if the given value is instantiable.
|
|
* @param what
|
|
*/
|
|
export function isInstantiable<T>(what: unknown): what is Instantiable<T> {
|
|
return (
|
|
Boolean(what)
|
|
&& (typeof what === 'object' || typeof what === 'function')
|
|
&& (what !== null)
|
|
&& 'constructor' in what
|
|
&& typeof what.constructor === 'function'
|
|
)
|
|
}
|
|
|
|
/**
|
|
* Serialized payload of a given value.
|
|
*/
|
|
export type EncodedPayload<T> = string
|
|
|
|
/**
|
|
* Determines that a given item is a valid serialized payload.
|
|
* @param what
|
|
*/
|
|
export function isEncodedPayload(what: unknown): what is EncodedPayload<unknown> {
|
|
if ( typeof what !== 'string' ) {
|
|
return false
|
|
}
|
|
|
|
return what.startsWith('multicrypt:')
|
|
}
|