@figma-vars/hooks 3.0.0-beta.1 → 3.0.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.
Files changed (58) hide show
  1. package/README.md +371 -177
  2. package/dist/api/fetcher.d.ts.map +1 -1
  3. package/dist/api/index.d.ts.map +1 -1
  4. package/dist/api/mutator.d.ts +10 -9
  5. package/dist/api/mutator.d.ts.map +1 -1
  6. package/dist/constants/index.d.ts +2 -28
  7. package/dist/constants/index.d.ts.map +1 -1
  8. package/dist/contexts/FigmaTokenContext.d.ts.map +1 -1
  9. package/dist/contexts/FigmaVarsProvider.d.ts +1 -1
  10. package/dist/contexts/FigmaVarsProvider.d.ts.map +1 -1
  11. package/dist/contexts/index.d.ts +1 -1
  12. package/dist/contexts/index.d.ts.map +1 -1
  13. package/dist/contexts/useFigmaTokenContext.d.ts.map +1 -1
  14. package/dist/core/index.d.cts +8 -0
  15. package/dist/core/index.d.ts +8 -0
  16. package/dist/core/index.d.ts.map +1 -0
  17. package/dist/core.cjs +1 -0
  18. package/dist/core.d.cts +2 -0
  19. package/dist/core.d.ts +2 -0
  20. package/dist/core.mjs +20 -0
  21. package/dist/hooks/index.d.ts +19 -0
  22. package/dist/hooks/index.d.ts.map +1 -1
  23. package/dist/hooks/useBulkUpdateVariables.d.ts.map +1 -1
  24. package/dist/hooks/useCreateVariable.d.ts.map +1 -1
  25. package/dist/hooks/useDeleteVariable.d.ts.map +1 -1
  26. package/dist/hooks/useFigmaToken.d.ts.map +1 -1
  27. package/dist/hooks/useInvalidateVariables.d.ts +31 -0
  28. package/dist/hooks/useInvalidateVariables.d.ts.map +1 -0
  29. package/dist/hooks/usePublishedVariables.d.ts +42 -0
  30. package/dist/hooks/usePublishedVariables.d.ts.map +1 -0
  31. package/dist/hooks/useUpdateVariable.d.ts.map +1 -1
  32. package/dist/hooks/useVariableCollections.d.ts.map +1 -1
  33. package/dist/hooks/useVariableModes.d.ts.map +1 -1
  34. package/dist/hooks/useVariables.d.ts +3 -1
  35. package/dist/hooks/useVariables.d.ts.map +1 -1
  36. package/dist/index-BIUpDTdr.cjs +1 -0
  37. package/dist/index-Cd4HQQHO.js +94 -0
  38. package/dist/index.cjs +1 -1
  39. package/dist/index.d.cts +9 -4
  40. package/dist/index.d.ts +9 -4
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.mjs +235 -162
  43. package/dist/types/contexts.d.ts +29 -3
  44. package/dist/types/contexts.d.ts.map +1 -1
  45. package/dist/types/figma.d.ts +56 -3
  46. package/dist/types/figma.d.ts.map +1 -1
  47. package/dist/types/hooks.d.ts.map +1 -1
  48. package/dist/types/index.d.ts.map +1 -1
  49. package/dist/types/mutations.d.ts +4 -4
  50. package/dist/types/mutations.d.ts.map +1 -1
  51. package/dist/utils/errorHelpers.d.ts +96 -0
  52. package/dist/utils/errorHelpers.d.ts.map +1 -0
  53. package/dist/utils/filterVariables.d.ts.map +1 -1
  54. package/dist/utils/index.d.ts +2 -1
  55. package/dist/utils/index.d.ts.map +1 -1
  56. package/package.json +75 -31
  57. package/scripts/export-variables.mjs +101 -0
  58. package/dist/index.d.mts +0 -2
@@ -1 +1 @@
1
- {"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/types/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB,EAAE,MAAM,CAAC;IAC7B,YAAY,EAAE,YAAY,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,MAAM,CAAC,EAAE,aAAa,EAAE,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;C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,MAAM,EAAE,MAAM,CAAC,CAAA;KACvC,CAAA;CACF;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,aAAa,CAAC,KAAK;IAClC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAA;IAChD,IAAI,EAAE,KAAK,GAAG,IAAI,CAAA;IAClB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;CACpB;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,cAAc,CAAC,KAAK,EAAE,QAAQ;IAC7C,MAAM,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC,CAAA;IACzD,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAA;IAChD,IAAI,EAAE,KAAK,GAAG,IAAI,CAAA;IAClB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;IACnB,SAAS,EAAE,OAAO,CAAA;IAClB,SAAS,EAAE,OAAO,CAAA;IAClB,OAAO,EAAE,OAAO,CAAA;CACjB"}
@@ -0,0 +1,96 @@
1
+ import { FigmaApiError } from '../types/figma';
2
+ /**
3
+ * Type guard to check if an error is a FigmaApiError instance.
4
+ *
5
+ * @remarks
6
+ * Use this to safely check if an error has HTTP status code information before accessing `statusCode`.
7
+ *
8
+ * @param error - The error to check.
9
+ * @returns `true` if the error is a FigmaApiError, `false` otherwise.
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * import { isFigmaApiError } from '@figma-vars/hooks';
14
+ *
15
+ * try {
16
+ * await mutate(payload);
17
+ * } catch (error) {
18
+ * if (isFigmaApiError(error)) {
19
+ * if (error.statusCode === 401) {
20
+ * // Handle authentication error
21
+ * } else if (error.statusCode === 429) {
22
+ * // Handle rate limit
23
+ * }
24
+ * }
25
+ * }
26
+ * ```
27
+ *
28
+ * @public
29
+ */
30
+ export declare function isFigmaApiError(error: unknown): error is FigmaApiError;
31
+ /**
32
+ * Extracts the HTTP status code from an error, if available.
33
+ *
34
+ * @remarks
35
+ * Returns the status code from FigmaApiError, or `null` if the error doesn't have status information.
36
+ *
37
+ * @param error - The error to extract status code from.
38
+ * @returns The HTTP status code, or `null` if not available.
39
+ *
40
+ * @example
41
+ * ```tsx
42
+ * import { getErrorStatus } from '@figma-vars/hooks';
43
+ *
44
+ * const status = getErrorStatus(error);
45
+ * if (status === 401) {
46
+ * // Handle unauthorized
47
+ * }
48
+ * ```
49
+ *
50
+ * @public
51
+ */
52
+ export declare function getErrorStatus(error: unknown): number | null;
53
+ /**
54
+ * Extracts a human-readable error message from an error.
55
+ *
56
+ * @remarks
57
+ * Returns the error message, falling back to a default message if the error doesn't have one.
58
+ *
59
+ * @param error - The error to extract message from.
60
+ * @param defaultMessage - Optional default message if error has no message. Defaults to "An error occurred".
61
+ * @returns The error message string.
62
+ *
63
+ * @example
64
+ * ```tsx
65
+ * import { getErrorMessage } from '@figma-vars/hooks';
66
+ *
67
+ * const message = getErrorMessage(error);
68
+ * toast.error(message);
69
+ * ```
70
+ *
71
+ * @public
72
+ */
73
+ export declare function getErrorMessage(error: unknown, defaultMessage?: string): string;
74
+ /**
75
+ * Checks if an error represents a specific HTTP status code.
76
+ *
77
+ * @remarks
78
+ * Convenience function to check if an error has a specific status code.
79
+ *
80
+ * @param error - The error to check.
81
+ * @param statusCode - The HTTP status code to check for.
82
+ * @returns `true` if the error has the specified status code, `false` otherwise.
83
+ *
84
+ * @example
85
+ * ```tsx
86
+ * import { hasErrorStatus } from '@figma-vars/hooks';
87
+ *
88
+ * if (hasErrorStatus(error, 401)) {
89
+ * // Handle unauthorized
90
+ * }
91
+ * ```
92
+ *
93
+ * @public
94
+ */
95
+ export declare function hasErrorStatus(error: unknown, statusCode: number): boolean;
96
+ //# sourceMappingURL=errorHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errorHelpers.d.ts","sourceRoot":"","sources":["../../src/utils/errorHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEtE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAK5D;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,OAAO,EACd,cAAc,SAAsB,GACnC,MAAM,CAQR;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAE1E"}
@@ -1 +1 @@
1
- {"version":3,"file":"filterVariables.d.ts","sourceRoot":"","sources":["../../src/utils/filterVariables.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,aAAa,EAAE,EAC1B,QAAQ,EAAE;IAAE,YAAY,CAAC,EAAE,YAAY,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GACvD,aAAa,EAAE,CAOjB"}
1
+ {"version":3,"file":"filterVariables.d.ts","sourceRoot":"","sources":["../../src/utils/filterVariables.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,aAAa,EAAE,EAC1B,QAAQ,EAAE;IAAE,YAAY,CAAC,EAAE,YAAY,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GACvD,aAAa,EAAE,CAQjB"}
@@ -11,7 +11,7 @@
11
11
  *
12
12
  * @example
13
13
  * ```ts
14
- * import { filterVariables } from '@figma-vars/hooks/utils';
14
+ * import { filterVariables, isFigmaApiError } from '@figma-vars/hooks/utils';
15
15
  *
16
16
  * const filtered = filterVariables(allVariables, { resolvedType: 'COLOR' });
17
17
  * ```
@@ -19,4 +19,5 @@
19
19
  * @public
20
20
  */
21
21
  export { filterVariables } from './filterVariables';
22
+ export { isFigmaApiError, getErrorStatus, getErrorMessage, hasErrorStatus, } from './errorHelpers';
22
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EACL,eAAe,EACf,cAAc,EACd,eAAe,EACf,cAAc,GACf,MAAM,oBAAoB,CAAA"}
package/package.json CHANGED
@@ -1,15 +1,27 @@
1
1
  {
2
2
  "name": "@figma-vars/hooks",
3
- "version": "3.0.0-beta.1",
3
+ "version": "3.0.0",
4
4
  "description": "Typed React hooks for managing Figma Variables, modes, tokens, and bindings via API.",
5
5
  "author": "Mark Learst",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "main": "dist/index.cjs",
9
9
  "module": "dist/index.mjs",
10
+ "types": "dist/index.d.ts",
11
+ "typesVersions": {
12
+ "*": {
13
+ "core": [
14
+ "dist/core.d.ts"
15
+ ]
16
+ }
17
+ },
10
18
  "files": [
11
- "dist"
19
+ "dist",
20
+ "scripts"
12
21
  ],
22
+ "bin": {
23
+ "figma-vars-export": "./scripts/export-variables.mjs"
24
+ },
13
25
  "keywords": [
14
26
  "figma",
15
27
  "figma variables",
@@ -34,9 +46,36 @@
34
46
  "engines": {
35
47
  "node": ">=20.0.0"
36
48
  },
49
+ "scripts": {
50
+ "dev": "vite",
51
+ "build": "tsc && vite build",
52
+ "postbuild": "cp dist/index.d.ts dist/index.d.cts || copy dist/index.d.ts dist/index.d.cts && cp dist/core.d.ts dist/core.d.cts || copy dist/core.d.ts dist/core.d.cts && cp dist/core/index.d.ts dist/core/index.d.cts || copy dist/core\\index.d.ts dist/core\\index.d.cts",
53
+ "prepublishOnly": "pnpm build",
54
+ "lint": "biome format --write .",
55
+ "format": "prettier --write .",
56
+ "format:check": "prettier --check .",
57
+ "preview": "vite preview",
58
+ "test": "vitest",
59
+ "test:ui": "vitest --ui",
60
+ "test:coverage": "vitest run --coverage",
61
+ "test:watch": "vitest watch",
62
+ "postversion": "git push && git push --tags",
63
+ "create:docs": "npx typedoc src/index.ts --out docs-site/api",
64
+ "check:publint": "publint",
65
+ "check:attw": "attw --pack .",
66
+ "check:size": "size-limit",
67
+ "check:release": "pnpm run build && pnpm run check:publint && pnpm run check:attw && pnpm run check:size",
68
+ "prepare": "husky"
69
+ },
70
+ "lint-staged": {
71
+ "*.{js,jsx,ts,tsx,json,md}": [
72
+ "prettier --write"
73
+ ]
74
+ },
37
75
  "peerDependencies": {
38
- "react": "^18.3.1 || ^19.0.0",
39
- "react-dom": "^18.3.1 || ^19.0.0"
76
+ "react": "^19.2.3",
77
+ "react-dom": "^19.2.3",
78
+ "swr": "^2.3.7"
40
79
  },
41
80
  "sideEffects": false,
42
81
  "exports": {
@@ -50,6 +89,17 @@
50
89
  "default": "./dist/index.cjs"
51
90
  },
52
91
  "default": "./dist/index.mjs"
92
+ },
93
+ "./core": {
94
+ "import": {
95
+ "types": "./dist/core/index.d.ts",
96
+ "default": "./dist/core.mjs"
97
+ },
98
+ "require": {
99
+ "types": "./dist/core/index.d.cts",
100
+ "default": "./dist/core.cjs"
101
+ },
102
+ "default": "./dist/core.mjs"
53
103
  }
54
104
  },
55
105
  "publishConfig": {
@@ -60,6 +110,16 @@
60
110
  "type": "github",
61
111
  "url": "https://github.com/sponsors/marklearst"
62
112
  },
113
+ "pnpm": {
114
+ "overrides": {
115
+ "vite": "^6.3.5"
116
+ },
117
+ "onlyBuiltDependencies": [
118
+ "@biomejs/biome",
119
+ "esbuild"
120
+ ]
121
+ },
122
+ "packageManager": "pnpm@10.15.0",
63
123
  "devDependencies": {
64
124
  "@arethetypeswrong/cli": "^0.17.0",
65
125
  "@biomejs/biome": "^1.9.4",
@@ -67,17 +127,21 @@
67
127
  "@testing-library/jest-dom": "^6.6.3",
68
128
  "@testing-library/react": "^16.3.0",
69
129
  "@types/node": "^24.0.3",
70
- "@types/react": "^19.0.0",
71
- "@types/react-dom": "^19.0.0",
130
+ "@types/react": "^19.2.7",
131
+ "@types/react-dom": "^19.2.3",
72
132
  "@vitejs/plugin-react": "^4.5.2",
73
133
  "@vitest/coverage-v8": "^2.0.5",
74
134
  "@vitest/ui": "2.1.9",
75
135
  "dotenv": "^16.5.0",
136
+ "husky": "^9.1.7",
76
137
  "jsdom": "^26.1.0",
138
+ "lint-staged": "^16.1.5",
139
+ "prettier": "^3.6.2",
77
140
  "publint": "^0.3.1",
78
- "react": "^19.0.0",
79
- "react-dom": "^19.0.0",
141
+ "react": "^19.2.3",
142
+ "react-dom": "^19.2.3",
80
143
  "size-limit": "^11.1.5",
144
+ "swr": "^2.3.7",
81
145
  "typescript": "~5.8.3",
82
146
  "vite": "^6.3.5",
83
147
  "vite-plugin-dts": "^4.5.4",
@@ -87,9 +151,7 @@
87
151
  "directories": {
88
152
  "doc": "docs"
89
153
  },
90
- "dependencies": {
91
- "swr": "^2.3.3"
92
- },
154
+ "dependencies": {},
93
155
  "size-limit": [
94
156
  {
95
157
  "name": "modern ESM entry",
@@ -97,23 +159,5 @@
97
159
  "import": "{ useVariables }",
98
160
  "limit": "10 kB"
99
161
  }
100
- ],
101
- "scripts": {
102
- "dev": "vite",
103
- "build": "tsc && vite build",
104
- "postbuild": "cp dist/index.d.ts dist/index.d.cts || copy dist/index.d.ts dist/index.d.cts",
105
- "lint": "biome format --write .",
106
- "format": "biome format --write .",
107
- "preview": "vite preview",
108
- "test": "vitest",
109
- "test:ui": "vitest --ui",
110
- "test:coverage": "vitest run --coverage",
111
- "test:watch": "vitest watch",
112
- "postversion": "git push && git push --tags",
113
- "create:docs": "npx typedoc src/index.ts --out docs-site/api",
114
- "check:publint": "publint",
115
- "check:attw": "attw --pack .",
116
- "check:size": "size-limit",
117
- "check:release": "pnpm run build && pnpm run check:publint && pnpm run check:attw && pnpm run check:size"
118
- }
119
- }
162
+ ]
163
+ }
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'fs/promises'
3
+ import path from 'path'
4
+
5
+ const FIGMA_TOKEN = process.env.FIGMA_TOKEN || process.env.FIGMA_PAT
6
+
7
+ function parseArgs() {
8
+ const args = process.argv.slice(2)
9
+ const opts = {
10
+ fileKey: process.env.FIGMA_FILE_KEY,
11
+ out: 'data/figma-variables.json',
12
+ }
13
+
14
+ // Show help
15
+ if (args.includes('--help') || args.includes('-h')) {
16
+ console.log(`
17
+ Export Figma Variables to JSON
18
+
19
+ Usage:
20
+ figma-vars-export --file-key <FILE_KEY> --out <OUTPUT_PATH>
21
+ figma-vars-export --file-key <FILE_KEY> [--out <OUTPUT_PATH>]
22
+
23
+ Options:
24
+ --file-key, --fileKey Figma file key (required, or set FIGMA_FILE_KEY env var)
25
+ --out Output file path (default: data/figma-variables.json)
26
+ --help, -h Show this help message
27
+
28
+ Environment Variables:
29
+ FIGMA_TOKEN or FIGMA_PAT Figma Personal Access Token (required)
30
+ FIGMA_FILE_KEY Figma file key (optional, can use --file-key instead)
31
+
32
+ Examples:
33
+ # Using npx (no install needed)
34
+ FIGMA_TOKEN=xxx npx figma-vars-export --file-key abc123 --out ./variables.json
35
+
36
+ # After installing the package
37
+ FIGMA_TOKEN=xxx figma-vars-export --file-key abc123 --out ./variables.json
38
+
39
+ # Using environment variables
40
+ export FIGMA_TOKEN=xxx
41
+ export FIGMA_FILE_KEY=abc123
42
+ figma-vars-export --out ./variables.json
43
+
44
+ Note: Requires Figma Enterprise account for live API access.
45
+ `)
46
+ process.exit(0)
47
+ }
48
+
49
+ for (let i = 0; i < args.length; i += 1) {
50
+ const arg = args[i]
51
+ if (arg === '--file-key' || arg === '--fileKey') {
52
+ opts.fileKey = args[i + 1]
53
+ i += 1
54
+ } else if (arg === '--out') {
55
+ opts.out = args[i + 1]
56
+ i += 1
57
+ }
58
+ }
59
+ return opts
60
+ }
61
+
62
+ async function main() {
63
+ const { fileKey, out } = parseArgs()
64
+ if (!FIGMA_TOKEN) {
65
+ console.error('FIGMA_TOKEN (or FIGMA_PAT) is required')
66
+ process.exit(1)
67
+ }
68
+ if (!fileKey) {
69
+ console.error('--file-key or FIGMA_FILE_KEY is required')
70
+ process.exit(1)
71
+ }
72
+
73
+ const url = `https://api.figma.com/v1/files/${fileKey}/variables/local`
74
+ const res = await fetch(url, {
75
+ headers: {
76
+ 'Content-Type': 'application/json',
77
+ 'X-Figma-Token': FIGMA_TOKEN,
78
+ },
79
+ })
80
+
81
+ if (!res.ok) {
82
+ const text = await res.text()
83
+ console.error(`Request failed: ${res.status} ${res.statusText}`)
84
+ console.error(text)
85
+ process.exit(1)
86
+ }
87
+
88
+ const json = await res.json()
89
+ const outputPath = path.resolve(out)
90
+ await fs.mkdir(path.dirname(outputPath), { recursive: true })
91
+ await fs.writeFile(outputPath, JSON.stringify(json, null, 2), 'utf8')
92
+ console.log(`Saved variables to ${outputPath}`)
93
+ if (json?.meta?.variables) {
94
+ console.log(`Variables count: ${Object.keys(json.meta.variables).length}`)
95
+ }
96
+ }
97
+
98
+ main().catch(err => {
99
+ console.error(err)
100
+ process.exit(1)
101
+ })
package/dist/index.d.mts DELETED
@@ -1,2 +0,0 @@
1
- export * from './index'
2
- export {}