@metamask/utils
Version:
Various JavaScript/TypeScript utilities of wide relevance to the MetaMask codebase
20 lines • 879 B
text/typescript
import type { Struct } from "@metamask/superstruct";
/**
* Defines a new string-struct matching a regular expression.
*
* @example
* const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);
* type EthAddress = Infer<typeof EthAddressStruct>; // string
*
* const CaipChainIdStruct = defineTypedPattern<`${string}:${string}`>(
* 'CaipChainId',
* /^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}$/u;
* );
* type CaipChainId = Infer<typeof CaipChainIdStruct>; // `${string}:${string}`
* @param name - Type name.
* @param pattern - Regular expression to match.
* @template Pattern - The pattern type, defaults to `string`.
* @returns A new string-struct that matches the given pattern.
*/
export declare function definePattern<Pattern extends string = string>(name: string, pattern: RegExp): Struct<Pattern, null>;
//# sourceMappingURL=superstruct.d.mts.map