test pass

This commit is contained in:
wangkechun 2024-01-29 17:28:50 +08:00
parent 5c4f8e5d87
commit 7f2355b782
5 changed files with 78 additions and 11 deletions

View file

@ -3,12 +3,6 @@
"name": "Favourites",
"ops": []
},
{
"name": "Wangkechun",
"ops": [
"JSON To Go Struct"
]
},
{
"name": "Data format",
"ops": [
@ -420,6 +414,7 @@
"JavaScript Minify",
"JSON Beautify",
"JSON Minify",
"JSON to Go Struct",
"XML Beautify",
"XML Minify",
"SQL Beautify",

View file

@ -5,12 +5,12 @@
*/
import Operation from "../Operation.mjs";
import { jsonToGo } from "../lib/JSONToGoStruct.mjs";
import { jsonToGo } from "../vendor/JSONToGoStruct.mjs";
import JSON5 from "json5";
import OperationError from "../errors/OperationError.mjs";
/**
* JSON To Go Struct operation
* JSON to Go Struct operation
*/
class JSONToGoStruct extends Operation {
/**
@ -19,7 +19,7 @@ class JSONToGoStruct extends Operation {
constructor() {
super();
this.name = "JSON To Go Struct";
this.name = "JSON to Go Struct";
this.module = "Default";
this.description = "converts JSON into a Go type definition.";
this.infoURL = "https://mholt.github.io/json-to-go/";
@ -34,7 +34,7 @@ class JSONToGoStruct extends Operation {
{
name: "Flatten",
type: "boolean",
value: false,
value: true,
},
{
name: "All Omit Empty",
@ -59,7 +59,7 @@ class JSONToGoStruct extends Operation {
throw new OperationError("Unable to parse input as JSON.\n" + err);
}
const result = jsonToGo(code, typename, flatten, false, allOmitempty);
return result["go"];
return result.go;
}
}

View file

@ -171,6 +171,9 @@ export function jsonToGo(
++innerTabs;
const keys = Object.keys(scope);
for (let i in keys) {
if (!Object.prototype.hasOwnProperty.call(keys, i)) {
continue;
}
const keyname = getOriginalName(keys[i]);
indenter(innerTabs);
const typename = uniqueTypeName(format(keyname), seenTypeNames);
@ -195,6 +198,9 @@ export function jsonToGo(
++tabs;
const keys = Object.keys(scope);
for (let i in keys) {
if (!Object.prototype.hasOwnProperty.call(keys, i)) {
continue;
}
const keyname = getOriginalName(keys[i]);
indent(tabs);
const typename = uniqueTypeName(format(keyname), seenTypeNames);
@ -450,6 +456,9 @@ export function jsonToGo(
function formatScopeKeys(keys) {
for (let i in keys) {
if (!Object.prototype.hasOwnProperty.call(keys, i)) {
continue;
}
keys[i] = format(keys[i]);
}
return keys;