diff --git a/pages/json-to-go-bson.tsx b/pages/json-to-go-bson.tsx new file mode 100644 index 0000000..4597e95 --- /dev/null +++ b/pages/json-to-go-bson.tsx @@ -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(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 ( + + ); +} diff --git a/utils/routes.tsx b/utils/routes.tsx index 78c113c..68a054f 100644 --- a/utils/routes.tsx +++ b/utils/routes.tsx @@ -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",