@raclettejs/workbench 0.1.18 → 0.1.19

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,81 @@
1
+ /**
2
+ * Downloads a JSON object as a .json file
3
+ * @param {Object|Array} data - The data to be downloaded as JSON
4
+ * @param {string} filename - The name of the file (without .json extension)
5
+ * @throws {Error} If data cannot be serialized to JSON
6
+ */
7
+ export function downloadJson(data, filename = "download") {
8
+ try {
9
+ // Convert data to JSON string with pretty formatting
10
+ const jsonString = JSON.stringify(data, null, 2)
11
+
12
+ // Create blob from JSON string
13
+ const blob = new Blob([jsonString], { type: "application/json" })
14
+
15
+ // Create download link
16
+ const url = URL.createObjectURL(blob)
17
+ const link = document.createElement("a")
18
+
19
+ // Ensure filename has .json extension
20
+ const normalizedFilename = filename.endsWith(".json")
21
+ ? filename
22
+ : `${filename}.json`
23
+
24
+ link.href = url
25
+ link.download = normalizedFilename
26
+
27
+ // Trigger download
28
+ document.body.appendChild(link)
29
+ link.click()
30
+
31
+ // Cleanup
32
+ document.body.removeChild(link)
33
+ URL.revokeObjectURL(url)
34
+ } catch (error) {
35
+ console.error("Failed to download JSON:", error)
36
+ throw new Error(`Unable to download JSON file: ${error.message}`)
37
+ }
38
+ }
39
+ /**
40
+ * Recursively maps values in a JSON object based on a mapping configuration
41
+ * @param {Object|Array} data - The source JSON data to transform
42
+ * @param {Object} mapping - Mapping object where keys are attribute names and values are replacement values
43
+ * @returns {Object|Array} New object with mapped values
44
+ * @throws {Error} If data cannot be processed
45
+ *
46
+ * @example
47
+ * const data = { owner: 'user123', name: 'Project A', lastEditor: 'user123' };
48
+ * const mapping = { owner: 'user456', lastEditor: 'user789' };
49
+ * const result = mapJsonValues(data, mapping);
50
+ * // Result: { owner: 'user456', name: 'Project A', lastEditor: 'user789' }
51
+ */
52
+ export function mapJsonValues(data, mapping = {}) {
53
+ if (!data || typeof data !== "object") {
54
+ return data
55
+ }
56
+
57
+ // Handle arrays
58
+ if (Array.isArray(data)) {
59
+ return data.map((item) => mapJsonValues(item, mapping))
60
+ }
61
+
62
+ // Handle objects
63
+ const result = {}
64
+
65
+ for (const [key, value] of Object.entries(data)) {
66
+ // If this key exists in mapping, use the mapped value
67
+ if (key in mapping) {
68
+ result[key] = mapping[key]
69
+ }
70
+ // If value is an object or array, recursively process it
71
+ else if (value && typeof value === "object") {
72
+ result[key] = mapJsonValues(value, mapping)
73
+ }
74
+ // Otherwise keep the original value
75
+ else {
76
+ result[key] = value
77
+ }
78
+ }
79
+
80
+ return result
81
+ }
package/yarn.lock CHANGED
@@ -476,10 +476,10 @@
476
476
  resolved "https://registry.yarnpkg.com/@pkgr/core/-/core-0.2.9.tgz#d229a7b7f9dac167a156992ef23c7f023653f53b"
477
477
  integrity sha512-QNqXyfVS2wm9hweSYD2O7F0G06uurj9kZ96TRQE5Y9hU7+tgdZwIkbAKc5Ocy1HxEY2kuDQa6cQ1WRs/O5LFKA==
478
478
 
479
- "@raclettejs/core@^0.1.18":
480
- version "0.1.18"
481
- resolved "https://registry.yarnpkg.com/@raclettejs/core/-/core-0.1.18.tgz#6bf2a7de62996b3e2bc038b35e572467d2871130"
482
- integrity sha512-jftqZLGoUm3CxG8UZ8nsF0vrQiZ+mhFdOglu+AdECEqi0Jr+2MbStEkHsz5RRKau6TXiT4Prmtv9/x1ZS8aGbQ==
479
+ "@raclettejs/core@^0.1.19":
480
+ version "0.1.19"
481
+ resolved "https://registry.yarnpkg.com/@raclettejs/core/-/core-0.1.19.tgz#a95b033cc297d2f9d6f6f9e7251e8aa71c58bf42"
482
+ integrity sha512-hScs5MuRiUUUuEcdd/DTrUUX5ohlHTnMTMuMZnxXwvLOciWbkxob++CQn/FOmdjzmC1PEoS+pEalVKor5FHVAA==
483
483
  dependencies:
484
484
  chalk "5.6.2"
485
485
  chokidar "3.6.0"
@@ -492,10 +492,10 @@
492
492
  ramda "0.31.3"
493
493
  tsc-alias "1.8.16"
494
494
 
495
- "@raclettejs/types@^0.1.18":
496
- version "0.1.18"
497
- resolved "https://registry.yarnpkg.com/@raclettejs/types/-/types-0.1.18.tgz#7df0eb1b86db015694fabfafa089a277e654b350"
498
- integrity sha512-mvQI2sO48z6+QKj/s5A5JMBKnY8piE+8D8N0soctfsU7tAKg8nEwlxOiQHZiqJyR1k+gX2p+VBMRGbxHCYAGFw==
495
+ "@raclettejs/types@^0.1.19":
496
+ version "0.1.19"
497
+ resolved "https://registry.yarnpkg.com/@raclettejs/types/-/types-0.1.19.tgz#5f17afcc3b8f2d4849c828648711c426fdb2f74d"
498
+ integrity sha512-EdIMglaM+ivsvkVaXZKVKBoyXsLivulloveYPEV70Lm1iLeja6l7IywyM82dMdEgNMmpEMlG8r2TjHyXu9MPkg==
499
499
  dependencies:
500
500
  "@types/node" "24.5.2"
501
501
  fastify "5.6.0"