@metamask/utils 11.0.1 → 11.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.definePattern = void 0;
4
+ const superstruct_1 = require("@metamask/superstruct");
5
+ /**
6
+ * Defines a new string-struct matching a regular expression.
7
+ *
8
+ * @example
9
+ * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);
10
+ * type EthAddress = Infer<typeof EthAddressStruct>; // string
11
+ *
12
+ * const CaipChainIdStruct = defineTypedPattern<`${string}:${string}`>(
13
+ * 'CaipChainId',
14
+ * /^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}$/u;
15
+ * );
16
+ * type CaipChainId = Infer<typeof CaipChainIdStruct>; // `${string}:${string}`
17
+ * @param name - Type name.
18
+ * @param pattern - Regular expression to match.
19
+ * @template Pattern - The pattern type, defaults to `string`.
20
+ * @returns A new string-struct that matches the given pattern.
21
+ */
22
+ function definePattern(name, pattern) {
23
+ return (0, superstruct_1.define)(name, (value) => {
24
+ return typeof value === 'string' && pattern.test(value);
25
+ });
26
+ }
27
+ exports.definePattern = definePattern;
28
+ //# sourceMappingURL=superstruct.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"superstruct.cjs","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;;AACA,uDAA+C;AAE/C;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,aAAa,CAC3B,IAAY,EACZ,OAAe;IAEf,OAAO,IAAA,oBAAM,EAAU,IAAI,EAAE,CAAC,KAAc,EAAoB,EAAE;QAChE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;AACL,CAAC;AAPD,sCAOC","sourcesContent":["import type { Struct } from '@metamask/superstruct';\nimport { define } from '@metamask/superstruct';\n\n/**\n * Defines a new string-struct matching a regular expression.\n *\n * @example\n * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);\n * type EthAddress = Infer<typeof EthAddressStruct>; // string\n *\n * const CaipChainIdStruct = defineTypedPattern<`${string}:${string}`>(\n * 'CaipChainId',\n * /^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}$/u;\n * );\n * type CaipChainId = Infer<typeof CaipChainIdStruct>; // `${string}:${string}`\n * @param name - Type name.\n * @param pattern - Regular expression to match.\n * @template Pattern - The pattern type, defaults to `string`.\n * @returns A new string-struct that matches the given pattern.\n */\nexport function definePattern<Pattern extends string = string>(\n name: string,\n pattern: RegExp,\n): Struct<Pattern, null> {\n return define<Pattern>(name, (value: unknown): boolean | string => {\n return typeof value === 'string' && pattern.test(value);\n });\n}\n"]}
@@ -0,0 +1,20 @@
1
+ import type { Struct } from "@metamask/superstruct";
2
+ /**
3
+ * Defines a new string-struct matching a regular expression.
4
+ *
5
+ * @example
6
+ * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);
7
+ * type EthAddress = Infer<typeof EthAddressStruct>; // string
8
+ *
9
+ * const CaipChainIdStruct = defineTypedPattern<`${string}:${string}`>(
10
+ * 'CaipChainId',
11
+ * /^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}$/u;
12
+ * );
13
+ * type CaipChainId = Infer<typeof CaipChainIdStruct>; // `${string}:${string}`
14
+ * @param name - Type name.
15
+ * @param pattern - Regular expression to match.
16
+ * @template Pattern - The pattern type, defaults to `string`.
17
+ * @returns A new string-struct that matches the given pattern.
18
+ */
19
+ export declare function definePattern<Pattern extends string = string>(name: string, pattern: RegExp): Struct<Pattern, null>;
20
+ //# sourceMappingURL=superstruct.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"superstruct.d.cts","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,8BAA8B;AAGpD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,EAC3D,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAIvB"}
@@ -0,0 +1,20 @@
1
+ import type { Struct } from "@metamask/superstruct";
2
+ /**
3
+ * Defines a new string-struct matching a regular expression.
4
+ *
5
+ * @example
6
+ * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);
7
+ * type EthAddress = Infer<typeof EthAddressStruct>; // string
8
+ *
9
+ * const CaipChainIdStruct = defineTypedPattern<`${string}:${string}`>(
10
+ * 'CaipChainId',
11
+ * /^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}$/u;
12
+ * );
13
+ * type CaipChainId = Infer<typeof CaipChainIdStruct>; // `${string}:${string}`
14
+ * @param name - Type name.
15
+ * @param pattern - Regular expression to match.
16
+ * @template Pattern - The pattern type, defaults to `string`.
17
+ * @returns A new string-struct that matches the given pattern.
18
+ */
19
+ export declare function definePattern<Pattern extends string = string>(name: string, pattern: RegExp): Struct<Pattern, null>;
20
+ //# sourceMappingURL=superstruct.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"superstruct.d.mts","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,8BAA8B;AAGpD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,EAC3D,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAIvB"}
@@ -0,0 +1,24 @@
1
+ import { define } from "@metamask/superstruct";
2
+ /**
3
+ * Defines a new string-struct matching a regular expression.
4
+ *
5
+ * @example
6
+ * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);
7
+ * type EthAddress = Infer<typeof EthAddressStruct>; // string
8
+ *
9
+ * const CaipChainIdStruct = defineTypedPattern<`${string}:${string}`>(
10
+ * 'CaipChainId',
11
+ * /^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}$/u;
12
+ * );
13
+ * type CaipChainId = Infer<typeof CaipChainIdStruct>; // `${string}:${string}`
14
+ * @param name - Type name.
15
+ * @param pattern - Regular expression to match.
16
+ * @template Pattern - The pattern type, defaults to `string`.
17
+ * @returns A new string-struct that matches the given pattern.
18
+ */
19
+ export function definePattern(name, pattern) {
20
+ return define(name, (value) => {
21
+ return typeof value === 'string' && pattern.test(value);
22
+ });
23
+ }
24
+ //# sourceMappingURL=superstruct.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"superstruct.mjs","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,8BAA8B;AAE/C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,aAAa,CAC3B,IAAY,EACZ,OAAe;IAEf,OAAO,MAAM,CAAU,IAAI,EAAE,CAAC,KAAc,EAAoB,EAAE;QAChE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { Struct } from '@metamask/superstruct';\nimport { define } from '@metamask/superstruct';\n\n/**\n * Defines a new string-struct matching a regular expression.\n *\n * @example\n * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);\n * type EthAddress = Infer<typeof EthAddressStruct>; // string\n *\n * const CaipChainIdStruct = defineTypedPattern<`${string}:${string}`>(\n * 'CaipChainId',\n * /^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}$/u;\n * );\n * type CaipChainId = Infer<typeof CaipChainIdStruct>; // `${string}:${string}`\n * @param name - Type name.\n * @param pattern - Regular expression to match.\n * @template Pattern - The pattern type, defaults to `string`.\n * @returns A new string-struct that matches the given pattern.\n */\nexport function definePattern<Pattern extends string = string>(\n name: string,\n pattern: RegExp,\n): Struct<Pattern, null> {\n return define<Pattern>(name, (value: unknown): boolean | string => {\n return typeof value === 'string' && pattern.test(value);\n });\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/utils",
3
- "version": "11.0.1",
3
+ "version": "11.1.0",
4
4
  "description": "Various JavaScript/TypeScript utilities of wide relevance to the MetaMask codebase",
5
5
  "homepage": "https://github.com/MetaMask/utils#readme",
6
6
  "bugs": {