@zag-js/stringify-state 0.0.0-dev-20240627164007

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Chakra UI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # @zag-js/stringify-state
2
+
3
+ Helper to stringify state of Zag machines
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ yarn add @zag-js/stringify-state
9
+ # or
10
+ npm i @zag-js/stringify-state
11
+ ```
12
+
13
+ ## Contribution
14
+
15
+ Yes please! See the [contributing guidelines](https://github.com/chakra-ui/zag/blob/main/CONTRIBUTING.md) for details.
16
+
17
+ ## Licence
18
+
19
+ This project is licensed under the terms of the [MIT license](https://github.com/chakra-ui/zag/blob/main/LICENSE).
@@ -0,0 +1,7 @@
1
+ interface Dict {
2
+ [key: string]: any;
3
+ }
4
+ declare function stringifyState(state: Dict, omit?: string[]): string;
5
+ declare function highlightState(state: Dict, omit?: string[]): string;
6
+
7
+ export { highlightState, stringifyState };
@@ -0,0 +1,7 @@
1
+ interface Dict {
2
+ [key: string]: any;
3
+ }
4
+ declare function stringifyState(state: Dict, omit?: string[]): string;
5
+ declare function highlightState(state: Dict, omit?: string[]): string;
6
+
7
+ export { highlightState, stringifyState };
package/dist/index.js ADDED
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ highlightState: () => highlightState,
34
+ stringifyState: () => stringifyState
35
+ });
36
+ module.exports = __toCommonJS(src_exports);
37
+ var import_json_format_highlight = __toESM(require("json-format-highlight"));
38
+ var pick = (obj, keys) => Object.fromEntries(keys.filter((key) => key in obj).map((key) => [key, obj[key]]));
39
+ var hasProp = (v, prop) => Object.prototype.hasOwnProperty.call(v, prop);
40
+ var isTimeObject = (v) => hasProp(v, "hour") && hasProp(v, "minute") && hasProp(v, "second");
41
+ function stringifyState(state, omit) {
42
+ const code = JSON.stringify(
43
+ state,
44
+ (key, value) => {
45
+ try {
46
+ if (hasProp(value, "target") && hasProp(value, "timeStamp"))
47
+ return pick(value, ["type", "target", "currentTarget", "relatedTarget"]);
48
+ if (omit?.includes(key)) {
49
+ return void 0;
50
+ }
51
+ if (hasProp(value, "calendar") || isTimeObject(value)) {
52
+ return value.toString();
53
+ }
54
+ if (value?.toJSON) {
55
+ return value.toJSON();
56
+ }
57
+ if (Number.isNaN(value)) {
58
+ return "NaN";
59
+ }
60
+ if (value instanceof File) {
61
+ return value.name;
62
+ }
63
+ if (value instanceof Set) {
64
+ return Array.from(value);
65
+ }
66
+ switch (value?.toString()) {
67
+ case "[object Machine]":
68
+ const id = value.state.context.id ?? value.id;
69
+ return `Machine: ${id}`;
70
+ case "[object ShadowRoot]":
71
+ return "#shadow-root";
72
+ case "[object HTMLDocument]":
73
+ return "#document";
74
+ case "[object Window]":
75
+ return "#window";
76
+ case "[object AbortController]":
77
+ return "#abort-controller";
78
+ default:
79
+ return value !== null && typeof value === "object" && value.nodeType === 1 ? value.tagName : value;
80
+ }
81
+ } catch {
82
+ return value;
83
+ }
84
+ },
85
+ 4
86
+ );
87
+ return code;
88
+ }
89
+ function highlightState(state, omit) {
90
+ return (0, import_json_format_highlight.default)(stringifyState(state, omit));
91
+ }
92
+ // Annotate the CommonJS export names for ESM import in node:
93
+ 0 && (module.exports = {
94
+ highlightState,
95
+ stringifyState
96
+ });
97
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import formatHighlight from \"json-format-highlight\"\n\ninterface Dict {\n [key: string]: any\n}\n\nconst pick = (obj: Dict, keys: string[]) =>\n Object.fromEntries(keys.filter((key) => key in obj).map((key) => [key, obj[key]]))\n\nconst hasProp = (v: any, prop: string) => Object.prototype.hasOwnProperty.call(v, prop)\n\nconst isTimeObject = (v: any) => hasProp(v, \"hour\") && hasProp(v, \"minute\") && hasProp(v, \"second\")\n\nexport function stringifyState(state: Dict, omit?: string[]) {\n const code = JSON.stringify(\n state,\n (key, value) => {\n try {\n if (hasProp(value, \"target\") && hasProp(value, \"timeStamp\"))\n return pick(value, [\"type\", \"target\", \"currentTarget\", \"relatedTarget\"])\n\n if (omit?.includes(key)) {\n return undefined\n }\n\n if (hasProp(value, \"calendar\") || isTimeObject(value)) {\n return value.toString()\n }\n\n if (value?.toJSON) {\n return value.toJSON()\n }\n\n if (Number.isNaN(value)) {\n return \"NaN\"\n }\n\n if (value instanceof File) {\n return value.name\n }\n\n if (value instanceof Set) {\n return Array.from(value)\n }\n\n switch (value?.toString()) {\n case \"[object Machine]\":\n const id = value.state.context.id ?? value.id\n return `Machine: ${id}`\n\n case \"[object ShadowRoot]\":\n return \"#shadow-root\"\n\n case \"[object HTMLDocument]\":\n return \"#document\"\n\n case \"[object Window]\":\n return \"#window\"\n\n case \"[object AbortController]\":\n return \"#abort-controller\"\n\n default:\n return value !== null && typeof value === \"object\" && value.nodeType === 1 ? value.tagName : value\n }\n } catch {\n return value\n }\n },\n 4,\n )\n\n return code\n}\n\nexport function highlightState(state: Dict, omit?: string[]) {\n return formatHighlight(stringifyState(state, omit))\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mCAA4B;AAM5B,IAAM,OAAO,CAAC,KAAW,SACvB,OAAO,YAAY,KAAK,OAAO,CAAC,QAAQ,OAAO,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC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AAA,IACF;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AACT;AAEO,SAAS,eAAe,OAAa,MAAiB;AAC3D,aAAO,6BAAAA,SAAgB,eAAe,OAAO,IAAI,CAAC;AACpD;","names":["formatHighlight"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,61 @@
1
+ // src/index.ts
2
+ import formatHighlight from "json-format-highlight";
3
+ var pick = (obj, keys) => Object.fromEntries(keys.filter((key) => key in obj).map((key) => [key, obj[key]]));
4
+ var hasProp = (v, prop) => Object.prototype.hasOwnProperty.call(v, prop);
5
+ var isTimeObject = (v) => hasProp(v, "hour") && hasProp(v, "minute") && hasProp(v, "second");
6
+ function stringifyState(state, omit) {
7
+ const code = JSON.stringify(
8
+ state,
9
+ (key, value) => {
10
+ try {
11
+ if (hasProp(value, "target") && hasProp(value, "timeStamp"))
12
+ return pick(value, ["type", "target", "currentTarget", "relatedTarget"]);
13
+ if (omit?.includes(key)) {
14
+ return void 0;
15
+ }
16
+ if (hasProp(value, "calendar") || isTimeObject(value)) {
17
+ return value.toString();
18
+ }
19
+ if (value?.toJSON) {
20
+ return value.toJSON();
21
+ }
22
+ if (Number.isNaN(value)) {
23
+ return "NaN";
24
+ }
25
+ if (value instanceof File) {
26
+ return value.name;
27
+ }
28
+ if (value instanceof Set) {
29
+ return Array.from(value);
30
+ }
31
+ switch (value?.toString()) {
32
+ case "[object Machine]":
33
+ const id = value.state.context.id ?? value.id;
34
+ return `Machine: ${id}`;
35
+ case "[object ShadowRoot]":
36
+ return "#shadow-root";
37
+ case "[object HTMLDocument]":
38
+ return "#document";
39
+ case "[object Window]":
40
+ return "#window";
41
+ case "[object AbortController]":
42
+ return "#abort-controller";
43
+ default:
44
+ return value !== null && typeof value === "object" && value.nodeType === 1 ? value.tagName : value;
45
+ }
46
+ } catch {
47
+ return value;
48
+ }
49
+ },
50
+ 4
51
+ );
52
+ return code;
53
+ }
54
+ function highlightState(state, omit) {
55
+ return formatHighlight(stringifyState(state, omit));
56
+ }
57
+ export {
58
+ highlightState,
59
+ stringifyState
60
+ };
61
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import formatHighlight from \"json-format-highlight\"\n\ninterface Dict {\n [key: string]: any\n}\n\nconst pick = (obj: Dict, keys: string[]) =>\n Object.fromEntries(keys.filter((key) => key in obj).map((key) => [key, obj[key]]))\n\nconst hasProp = (v: any, prop: string) => Object.prototype.hasOwnProperty.call(v, prop)\n\nconst isTimeObject = (v: any) => hasProp(v, \"hour\") && hasProp(v, \"minute\") && hasProp(v, \"second\")\n\nexport function stringifyState(state: Dict, omit?: string[]) {\n const code = JSON.stringify(\n state,\n (key, value) => {\n try {\n if (hasProp(value, \"target\") && hasProp(value, \"timeStamp\"))\n return pick(value, [\"type\", \"target\", \"currentTarget\", \"relatedTarget\"])\n\n if (omit?.includes(key)) {\n return undefined\n }\n\n if (hasProp(value, \"calendar\") || isTimeObject(value)) {\n return value.toString()\n }\n\n if (value?.toJSON) {\n return value.toJSON()\n }\n\n if (Number.isNaN(value)) {\n return \"NaN\"\n }\n\n if (value instanceof File) {\n return value.name\n }\n\n if (value instanceof Set) {\n return Array.from(value)\n }\n\n switch (value?.toString()) {\n case \"[object Machine]\":\n const id = value.state.context.id ?? value.id\n return `Machine: ${id}`\n\n case \"[object ShadowRoot]\":\n return \"#shadow-root\"\n\n case \"[object HTMLDocument]\":\n return \"#document\"\n\n case \"[object Window]\":\n return \"#window\"\n\n case \"[object AbortController]\":\n return \"#abort-controller\"\n\n default:\n return value !== null && typeof value === \"object\" && value.nodeType === 1 ? value.tagName : value\n }\n } catch {\n return value\n }\n },\n 4,\n )\n\n return code\n}\n\nexport function highlightState(state: Dict, omit?: string[]) {\n return formatHighlight(stringifyState(state, omit))\n}\n"],"mappings":";AAAA,OAAO,qBAAqB;AAM5B,IAAM,OAAO,CAAC,KAAW,SACvB,OAAO,YAAY,KAAK,OAAO,CAAC,QAAQ,OAAO,GA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ACF,QAAQ;AACN,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AACT;AAEO,SAAS,eAAe,OAAa,MAAiB;AAC3D,SAAO,gBAAgB,eAAe,OAAO,IAAI,CAAC;AACpD;","names":[]}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@zag-js/stringify-state",
3
+ "version": "0.0.0-dev-20240627164007",
4
+ "description": "Helper to stringify state of Zag machines",
5
+ "keywords": [
6
+ "js",
7
+ "utils",
8
+ "stringify",
9
+ "zag",
10
+ "state"
11
+ ],
12
+ "author": "Segun Adebayo <sage@adebayosegun.com>",
13
+ "homepage": "https://github.com/chakra-ui/zag#readme",
14
+ "license": "MIT",
15
+ "main": "dist/index.js",
16
+ "repository": "https://github.com/chakra-ui/zag/tree/main/packages/utilities/stringify-state",
17
+ "sideEffects": false,
18
+ "files": [
19
+ "dist/**/*"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/chakra-ui/zag/issues"
26
+ },
27
+ "clean-package": "../../../clean-package.config.json",
28
+ "devDependencies": {
29
+ "clean-package": "2.2.0"
30
+ },
31
+ "dependencies": {
32
+ "json-format-highlight": "1.0.4"
33
+ },
34
+ "module": "dist/index.mjs",
35
+ "types": "dist/index.d.ts",
36
+ "exports": {
37
+ ".": {
38
+ "types": "./dist/index.d.ts",
39
+ "import": "./dist/index.mjs",
40
+ "require": "./dist/index.js"
41
+ },
42
+ "./package.json": "./package.json"
43
+ },
44
+ "scripts": {
45
+ "build": "tsup",
46
+ "lint": "eslint src --ext .ts,.tsx",
47
+ "typecheck": "tsc --noEmit"
48
+ }
49
+ }