mirror of
https://github.com/ritz078/transform.git
synced 2026-11-23 01:12:07 +03:00
add json to go bson (works for mongo-driver) (#145)
This commit is contained in:
1 parent
521a050c4e
commit
69cf8c183a
2 files changed
+28
No files matched your search
@@ -0,0 +1,24 @@
|
||||
import ConversionPanel, { Transformer } from "@components/ConversionPanel";
|
||||
import * as React from "react";
|
||||
import { useCallback } from "react";
|
||||
|
||||
export default function() {
|
||||
const transformer = useCallback<Transformer>(async ({ value }) => {
|
||||
return JSON.stringify(JSON.parse(value || "{}"), null, 2)
|
||||
.replace(/\{/gm, "bson.M{")
|
||||
.replace(/\[/gm, "bson.A{")
|
||||
.replace(/\]/gm, "}")
|
||||
.replace(/(\d|\w|")$/gm, "$1,")
|
||||
.replace(/(\}$)(\n)/gm, "$1,$2");
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<ConversionPanel
|
||||
transformer={transformer}
|
||||
editorTitle="JSON"
|
||||
editorLanguage="json"
|
||||
resultTitle="Go Bson"
|
||||
resultLanguage={"go"}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -110,6 +110,10 @@ export const categorizedRoutes = [
|
||||
packageName: "json-to-go",
|
||||
packageUrl: "https://github.com/mholt/json-to-go"
|
||||
},
|
||||
{
|
||||
label: "to Go Bson",
|
||||
path: "/json-to-go-bson"
|
||||
},
|
||||
{
|
||||
label: "to YAML",
|
||||
path: "/json-to-yaml",
|
||||
|
||||
Reference in new issue
Block a user