mirror of
https://github.com/ritz078/transform.git
synced 2026-11-20 16:22:53 +03:00
feat(jsonld): added flatten, compact, n-quads, expanded and framed (#110)
* fixes * feat(jsonld): added flatten, compact, n-quads, expanded and framed closes #109
This commit is contained in:
1 parent
9d368bcc44
commit
0003d2faa8
12 files changed
+270
-38
No files matched your search
@@ -281,3 +281,17 @@ export const jsonSchema = `{
|
||||
},
|
||||
"required": ["firstName", "lastName"]
|
||||
}`;
|
||||
|
||||
export const jsonLd = `{
|
||||
"@context": "https://schema.org/",
|
||||
"@type": "Person",
|
||||
"name": "Jane Doe",
|
||||
"jobTitle": "Professor",
|
||||
"telephone": "(425) 123-4567",
|
||||
"url": "http://www.janedoe.com"
|
||||
}
|
||||
`;
|
||||
|
||||
export const jsonLdContext = `{
|
||||
"@context": "https://schema.org/"
|
||||
}`;
|
||||
+1
-1
@@ -66,7 +66,7 @@ const config = {
|
||||
return config;
|
||||
},
|
||||
|
||||
target: "server"
|
||||
target: "serverless"
|
||||
};
|
||||
|
||||
module.exports = withCSS(withTypescript(config));
|
||||
@@ -3,6 +3,7 @@
|
||||
"name": "transform",
|
||||
"alias": "transform.tools",
|
||||
"builds": [{ "src": "next.config.js", "use": "@now/next" }],
|
||||
|
||||
"routes": [
|
||||
{
|
||||
"src": "/svg-to-jsx",
|
||||
@@ -19,14 +20,6 @@
|
||||
{
|
||||
"src": "/json-schema-to-ts",
|
||||
"dest": "/json-schema-to-typescript"
|
||||
},
|
||||
{
|
||||
"src": "^/service-worker.js$",
|
||||
"dest": "/_next/static/service-worker.js",
|
||||
"headers": {
|
||||
"cache-control": "public, max-age=43200, immutable",
|
||||
"Service-Worker-Allowed": "/"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -37,6 +37,7 @@
|
||||
"@graphql-codegen/typescript-urql": "^1.4.0",
|
||||
"@svgr/core": "^4.3.2",
|
||||
"@svgr/plugin-jsx": "^4.3.2",
|
||||
"@types/jsonld": "^1.5.0",
|
||||
"babel-plugin-flow-to-typescript": "^0.4.0",
|
||||
"babel-plugin-json-to-proptypes": "^0.1.0",
|
||||
"babel-plugin-object-styles-to-template": "^0.2.2",
|
||||
@@ -55,6 +56,7 @@
|
||||
"json-schema-to-typescript": "^6.1.3",
|
||||
"json-to-go": "gist:0d0b8324131c80eeb7e1df20001be32f",
|
||||
"json-ts": "^1.6.4",
|
||||
"jsonld": "^1.6.2",
|
||||
"lodash": "^4.17.14",
|
||||
"markdown": "^0.5.0",
|
||||
"monaco-editor": "^0.17.1",
|
||||
@@ -75,6 +77,7 @@
|
||||
"yaml": "^1.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@now/node": "^0.12.0",
|
||||
"@types/lodash": "^4.14.135",
|
||||
"@types/next": "^8.0.5",
|
||||
"@types/prettier": "^1.16.4",
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import ConversionPanel, { Transformer } from "@components/ConversionPanel";
|
||||
import { useCallback } from "react";
|
||||
import * as React from "react";
|
||||
import { compact } from "jsonld";
|
||||
|
||||
export default function() {
|
||||
const transformer = useCallback<Transformer>(
|
||||
async ({ value, splitEditorValue }) => {
|
||||
const jsonLd = await compact(
|
||||
JSON.parse(value),
|
||||
JSON.parse(splitEditorValue)
|
||||
);
|
||||
|
||||
return JSON.stringify(jsonLd, null, 2);
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
<ConversionPanel
|
||||
transformer={transformer}
|
||||
editorTitle="JSON-LD"
|
||||
editorDefaultValue="jsonLd"
|
||||
splitTitle={"Context"}
|
||||
splitLanguage="json"
|
||||
splitEditorDefaultValue="jsonLdContext"
|
||||
editorLanguage="json"
|
||||
resultTitle="Compacted"
|
||||
resultLanguage={"json"}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import ConversionPanel from "@components/ConversionPanel";
|
||||
import { useCallback } from "react";
|
||||
import * as React from "react";
|
||||
import { expand } from "jsonld";
|
||||
|
||||
export default function() {
|
||||
const transformer = useCallback(async ({ value }) => {
|
||||
const jsonLd = await expand(JSON.parse(value));
|
||||
|
||||
return JSON.stringify(jsonLd, null, 2);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<ConversionPanel
|
||||
transformer={transformer}
|
||||
editorTitle="JSON-LD"
|
||||
editorDefaultValue="jsonLd"
|
||||
editorLanguage="json"
|
||||
resultTitle="Expanded"
|
||||
resultLanguage={"json"}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import ConversionPanel, { Transformer } from "@components/ConversionPanel";
|
||||
import { useCallback } from "react";
|
||||
import * as React from "react";
|
||||
import { flatten } from "jsonld";
|
||||
|
||||
export default function() {
|
||||
const transformer = useCallback<Transformer>(
|
||||
async ({ value, splitEditorValue }) => {
|
||||
const jsonLd = await flatten(
|
||||
JSON.parse(value),
|
||||
JSON.parse(splitEditorValue)
|
||||
);
|
||||
|
||||
return JSON.stringify(jsonLd, null, 2);
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
<ConversionPanel
|
||||
transformer={transformer}
|
||||
editorTitle="JSON-LD"
|
||||
editorDefaultValue="jsonLd"
|
||||
splitTitle={"Context"}
|
||||
splitLanguage="json"
|
||||
splitEditorDefaultValue="jsonLdContext"
|
||||
editorLanguage="json"
|
||||
resultTitle="Flattened"
|
||||
resultLanguage={"json"}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import ConversionPanel, { Transformer } from "@components/ConversionPanel";
|
||||
import { useCallback } from "react";
|
||||
import * as React from "react";
|
||||
import { frame } from "jsonld";
|
||||
|
||||
export default function() {
|
||||
const transformer = useCallback<Transformer>(
|
||||
async ({ value, splitEditorValue }) => {
|
||||
const jsonLd = await frame(
|
||||
JSON.parse(value),
|
||||
JSON.parse(splitEditorValue)
|
||||
);
|
||||
|
||||
return JSON.stringify(jsonLd, null, 2);
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
<ConversionPanel
|
||||
transformer={transformer}
|
||||
editorTitle="JSON-LD"
|
||||
editorDefaultValue="jsonLd"
|
||||
splitTitle={"Frame"}
|
||||
splitLanguage="json"
|
||||
splitEditorDefaultValue="jsonLdContext"
|
||||
editorLanguage="json"
|
||||
resultTitle="Framed"
|
||||
resultLanguage={"json"}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import ConversionPanel from "@components/ConversionPanel";
|
||||
import { useCallback } from "react";
|
||||
import * as React from "react";
|
||||
import { normalize } from "jsonld";
|
||||
|
||||
export default function() {
|
||||
const transformer = useCallback(async ({ value }) => {
|
||||
return (await normalize(JSON.parse(value))) as Promise<string>;
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<ConversionPanel
|
||||
transformer={transformer}
|
||||
editorTitle="JSON-LD"
|
||||
editorDefaultValue="jsonLd"
|
||||
editorLanguage="json"
|
||||
resultTitle="Normalized"
|
||||
resultLanguage={"plaintext"}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import ConversionPanel from "@components/ConversionPanel";
|
||||
import { useCallback } from "react";
|
||||
import * as React from "react";
|
||||
import { toRDF } from "jsonld";
|
||||
|
||||
export default function() {
|
||||
const transformer = useCallback(async ({ value }) => {
|
||||
return toRDF(JSON.parse(value), {
|
||||
format: "application/n-quads"
|
||||
}) as Promise<string>;
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<ConversionPanel
|
||||
transformer={transformer}
|
||||
editorTitle="JSON-LD"
|
||||
editorDefaultValue="jsonLd"
|
||||
editorLanguage="json"
|
||||
resultTitle="N-Quads"
|
||||
resultLanguage={"plaintext"}
|
||||
/>
|
||||
);
|
||||
}
|
||||
+47
-28
@@ -153,61 +153,80 @@ export const categorizedRoutes = [
|
||||
content: [
|
||||
{
|
||||
label: "to TypeScript",
|
||||
path: "/graphql-to-typescript",
|
||||
packageUrl: "https://github.com/dotansimha/graphql-code-generator",
|
||||
packageName: "graphql-code-generator"
|
||||
path: "/graphql-to-typescript"
|
||||
},
|
||||
{
|
||||
label: "to Flow",
|
||||
path: "/graphql-to-flow",
|
||||
packageUrl: "https://github.com/dotansimha/graphql-code-generator",
|
||||
packageName: "graphql-code-generator"
|
||||
path: "/graphql-to-flow"
|
||||
},
|
||||
{
|
||||
label: "to JAVA",
|
||||
path: "/graphql-to-java",
|
||||
packageUrl: "https://github.com/dotansimha/graphql-code-generator",
|
||||
packageName: "graphql-code-generator"
|
||||
path: "/graphql-to-java"
|
||||
},
|
||||
{
|
||||
label: "to Resolvers Signature",
|
||||
path: "/graphql-to-resolvers-signature",
|
||||
packageUrl: "https://github.com/dotansimha/graphql-code-generator",
|
||||
packageName: "graphql-code-generator"
|
||||
path: "/graphql-to-resolvers-signature"
|
||||
},
|
||||
|
||||
{
|
||||
label: "to Introspection JSON",
|
||||
path: "/graphql-to-introspection-json",
|
||||
packageUrl: "https://github.com/dotansimha/graphql-code-generator",
|
||||
packageName: "graphql-code-generator"
|
||||
path: "/graphql-to-introspection-json"
|
||||
},
|
||||
|
||||
{
|
||||
label: "to Schema AST",
|
||||
path: "/graphql-to-schema-ast",
|
||||
packageUrl: "https://github.com/dotansimha/graphql-code-generator",
|
||||
packageName: "graphql-code-generator"
|
||||
path: "/graphql-to-schema-ast"
|
||||
},
|
||||
{
|
||||
label: "to Fragment Matcher",
|
||||
path: "/graphql-to-fragment-matcher",
|
||||
packageUrl: "https://github.com/dotansimha/graphql-code-generator",
|
||||
packageName: "graphql-code-generator"
|
||||
path: "/graphql-to-fragment-matcher"
|
||||
},
|
||||
{
|
||||
label: "to Components",
|
||||
path: "/graphql-to-components",
|
||||
packageUrl: "https://github.com/dotansimha/graphql-code-generator",
|
||||
packageName: "graphql-code-generator"
|
||||
path: "/graphql-to-components"
|
||||
},
|
||||
{
|
||||
label: "to TypeScript MongoDB",
|
||||
path: "/graphql-to-typescript-mongodb",
|
||||
packageUrl: "https://github.com/dotansimha/graphql-code-generator",
|
||||
packageName: "graphql-code-generator"
|
||||
path: "/graphql-to-typescript-mongodb"
|
||||
}
|
||||
]
|
||||
].map(x => ({
|
||||
...x,
|
||||
packageUrl: "https://github.com/dotansimha/graphql-code-generator",
|
||||
packageName: "graphql-code-generator"
|
||||
}))
|
||||
},
|
||||
{
|
||||
category: "JSON-LD",
|
||||
content: [
|
||||
{
|
||||
label: "to N-Quads",
|
||||
path: "jsonld-to-nquads"
|
||||
},
|
||||
{
|
||||
label: "to Expanded",
|
||||
path: "jsonld-to-expanded"
|
||||
},
|
||||
{
|
||||
label: "to Compacted",
|
||||
path: "jsonld-to-compacted"
|
||||
},
|
||||
{
|
||||
label: "to Flattened",
|
||||
path: "jsonld-to-flattened"
|
||||
},
|
||||
{
|
||||
label: "to Framed",
|
||||
path: "jsonld-to-framed"
|
||||
},
|
||||
{
|
||||
label: "to Normalized",
|
||||
path: "jsonld-to-normalized"
|
||||
}
|
||||
].map(x => ({
|
||||
...x,
|
||||
packageName: "jsonld",
|
||||
packageUrl: "https://github.com/digitalbazaar/jsonld.js"
|
||||
}))
|
||||
},
|
||||
{
|
||||
category: "Others",
|
||||
|
||||
@@ -1049,6 +1049,13 @@
|
||||
iterall "^1.1.3"
|
||||
uuid "^3.1.0"
|
||||
|
||||
"@now/node@^0.12.0":
|
||||
version "0.12.0"
|
||||
resolved "https://registry.yarnpkg.com/@now/node/-/node-0.12.0.tgz#ebd4a2494153062b63d2d2f7922ff15e8403883c"
|
||||
integrity sha512-uYdwC2DY035bJuoxLMdBKTAAumcCxY7MN2iWqa3gzssAlJbP7sa6nRz86ONSQ8X+dNEFyoyBUHHyiS7hHzn0Ww==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@samverschueren/stream-to-observable@^0.3.0":
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/@samverschueren/stream-to-observable/-/stream-to-observable-0.3.0.tgz#ecdf48d532c58ea477acfcab80348424f8d0662f"
|
||||
@@ -1170,6 +1177,11 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636"
|
||||
integrity sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A==
|
||||
|
||||
"@types/jsonld@^1.5.0":
|
||||
version "1.5.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/jsonld/-/jsonld-1.5.0.tgz#cd5cb660dcbeffd391290f820efebab571af65d9"
|
||||
integrity sha512-EG2N8JLQ1xDfO6Z/1QRdiUcYX3428CqVRqmY7LyK5or5J1RQ16dpKH6qQ4umVD0vBHU47xHlMeyMbQ6o+6tiYg==
|
||||
|
||||
"@types/lodash@^4.14.121", "@types/lodash@^4.14.135":
|
||||
version "4.14.136"
|
||||
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.136.tgz#413e85089046b865d960c9ff1d400e04c31ab60f"
|
||||
@@ -5773,6 +5785,16 @@ jsonify@~0.0.0:
|
||||
resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73"
|
||||
integrity sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM=
|
||||
|
||||
jsonld@^1.6.2:
|
||||
version "1.6.2"
|
||||
resolved "https://registry.yarnpkg.com/jsonld/-/jsonld-1.6.2.tgz#d81620dccf75fd7bc7501709eeec5da77ecc45e9"
|
||||
integrity sha512-eMzFHqhF2kPMrMUjw8+Lz9IF1QkrxTOIfVndkP/OpuoZs31VdDtfDs8mLa5EOC/ROdemFTQGLdYPZbRtmMe2Yw==
|
||||
dependencies:
|
||||
rdf-canonize "^1.0.2"
|
||||
request "^2.88.0"
|
||||
semver "^5.6.0"
|
||||
xmldom "0.1.19"
|
||||
|
||||
jsprim@^1.2.2:
|
||||
version "1.4.1"
|
||||
resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.1.tgz#313e66bc1e5cc06e438bc1b7499c2e5c56acb6a2"
|
||||
@@ -6627,6 +6649,11 @@ node-fetch@^1.0.1:
|
||||
encoding "^0.1.11"
|
||||
is-stream "^1.0.1"
|
||||
|
||||
node-forge@^0.8.1:
|
||||
version "0.8.5"
|
||||
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.8.5.tgz#57906f07614dc72762c84cef442f427c0e1b86ee"
|
||||
integrity sha512-vFMQIWt+J/7FLNyKouZ9TazT74PRV3wgv9UT4cRjC8BffxFbKXkgIWR42URCPSnHm/QDz6BOlb2Q0U4+VQT67Q==
|
||||
|
||||
node-libs-browser@^2.0.0:
|
||||
version "2.2.1"
|
||||
resolved "https://registry.yarnpkg.com/node-libs-browser/-/node-libs-browser-2.2.1.tgz#b64f513d18338625f90346d27b0d235e631f6425"
|
||||
@@ -7771,6 +7798,14 @@ rc@^1.0.1, rc@^1.1.6, rc@^1.2.7:
|
||||
minimist "^1.2.0"
|
||||
strip-json-comments "~2.0.1"
|
||||
|
||||
rdf-canonize@^1.0.2:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/rdf-canonize/-/rdf-canonize-1.0.3.tgz#71dc56bb808a39d12e3ca17674c15f881cad648a"
|
||||
integrity sha512-piLMOB5Q6LJSVx2XzmdpHktYVb8TmVTy8coXJBFtdkcMC96DknZOuzpAYqCWx2ERZX7xEW+mMi8/wDuMJS/95w==
|
||||
dependencies:
|
||||
node-forge "^0.8.1"
|
||||
semver "^5.6.0"
|
||||
|
||||
react-dom@^16.8.6:
|
||||
version "16.8.6"
|
||||
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.8.6.tgz#71d6303f631e8b0097f56165ef608f051ff6e10f"
|
||||
@@ -8119,7 +8154,7 @@ repeating@^2.0.0:
|
||||
dependencies:
|
||||
is-finite "^1.0.0"
|
||||
|
||||
"request@>= 2.44.0 < 3.0.0":
|
||||
"request@>= 2.44.0 < 3.0.0", request@^2.88.0:
|
||||
version "2.88.0"
|
||||
resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef"
|
||||
integrity sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg==
|
||||
@@ -9823,6 +9858,11 @@ xml-name-validator@^1.0.0:
|
||||
resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-1.0.0.tgz#dcf82ee092322951ef8cc1ba596c9cbfd14a83f1"
|
||||
integrity sha1-3Pgu4JIyKVHvjMG6WWycv9FKg/E=
|
||||
|
||||
xmldom@0.1.19:
|
||||
version "0.1.19"
|
||||
resolved "https://registry.yarnpkg.com/xmldom/-/xmldom-0.1.19.tgz#631fc07776efd84118bf25171b37ed4d075a0abc"
|
||||
integrity sha1-Yx/Ad3bv2EEYvyUXGzftTQdaCrw=
|
||||
|
||||
"xmlhttprequest@>= 1.6.0 < 2.0.0":
|
||||
version "1.8.0"
|
||||
resolved "https://registry.yarnpkg.com/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz#67fe075c5c24fef39f9d65f5f7b7fe75171968fc"
|
||||
|
||||
Reference in new issue
Block a user