utils
utils copied to clipboard
Various JavaScript / TypeScript utilities of wide relevance to the MetaMask codebase.
## Description Add support of CAIP-19 assets type/ID.
## Description This exports two new TypeScript declarations: - `EIP1993Provider`: Encodes a provider for [`EIP1993`](https://eips.ethereum.org/EIPS/eip-1193#specification) - `LegacyEthereumProvider`: Encodes a legacy Ethereum JSON RPC provider. Based on original work in https://github.com/MetaMask/eth-json-rpc-provider/pull/14...
Failed to compile. ./node_modules/@metamask/utils/dist/chunk-6C35XQOF.mjs Attempted import error: 'Struct' is not exported from 'superstruct'. The build process failed in a file named chunk-6C35XQOF.mjs within the @metamask/utils package. The code in this...
[_Are the Types Wrong?_](https://arethetypeswrong.github.io/) is a tool that scans a library and highlights potential issues with importing it via Node, CommonJS, and ESM. Running this tool against `@metamask/utils` shows [the...
If you have an object type such as: ``` typescript { foo: Json } ``` and you use it to change state within an Immer `produce` callback — such the...
As time has grown, this package has grown to include a lot of different types of utilities. That's great, but at the same time, the size of this package has...
It's fairly common in many of our projects to have some kind of helper that looks like this: ``` typescript async function waitFor(duration: number): Promise { return new Promise((resolve) =>...
Specifically, these functions return a `string` when they should return a `Hex`: - `numberToHex` - `bigIntToHex` - `getChecksumAddress`
Following https://github.com/MetaMask/utils/commit/0d68084b8d8f64a59606b6559b901be4db7c0560 the `JsonRpcRequestStruct` is now incompatible with superstruct functions such as `pick` and `omit`. Trying to use them will result in a type error, see https://github.com/MetaMask/snaps/actions/runs/6823234052/job/18556824093 for an example.
Here's the problem: ```text > JSON.stringify({ foo: undefined }) '{}' ``` Any request or response objects that are serialized before being transported will lose any fields with the value `undefined`....