mirror of
https://github.com/ritz078/transform.git
synced 2026-12-01 21:04:42 +03:00
Transform 2.0 (#101)
* feat(init): added EditorPanel with prettier, copy and settings support * chore(static): ignore static * feat: added navigator * feat: * feat(settings): added sessionStorage support for settings * feat(message): add messaging support in editors * feat(preview): added support for preview panel * fix(settings): use localstorage for settings instead of session storage * feat: * feat(css-to-js): implemented React section * feat(schema): add json to schema conversions * feat(others): implemented xml, yaml and markdown conversions * feat(babel): added flow to typescript converter * feat(graphql): implemented graphql to typescript * feat(graphql): added some transformations * fix: add support for different default value in one language * feat(graphql): added components, resolver signatures and mongodb * feat: * scala case class * fix(memory): worker-loader patch applied to fix memory overflow crash * feat: added json schema to typescript * icon: <GraphQLIcon />, * feat(navigator): shorter naming and new categories * route fixes * navigator * perf(workers): create separate file and remove fallback * fix(navigator): completed * build(snack): * fixes * fixes * fix(safari): * added json-to-mobx-state tree * fix(native): snacksession * fixes * added logo * navigator * fixes * custom header * fixes * refactor(settings): move settings to left side * feat: set up redirects * feat(seo): added title and description * feat(error): added custom error page * ga-script * feat: * fixes * fixe * fixes * fixes * fix:
This commit is contained in:
1 parent
b0826e9486
commit
1bd559514b
150 files changed
+22892
-224910
No files matched your search
@@ -1,109 +0,0 @@
|
||||
import uniqBy from "lodash/uniqBy";
|
||||
import isEmpty from "lodash/isEmpty";
|
||||
|
||||
/**
|
||||
* This is a babel plugin that converts an object to ImmutablePropTypes
|
||||
* @param t
|
||||
* @returns {{visitor: {ArrayExpression: (function(*)), NullLiteral: (function(*)), StringLiteral: (function(*)), NumericLiteral: (function(*)), ArrowFunctionExpression: (function(*)), FunctionExpression: (function(*)), BooleanLiteral: (function(*)), Program: (function(*, *)), ObjectExpression: (function(*))}}}
|
||||
*/
|
||||
export default function({ types: t }) {
|
||||
return {
|
||||
visitor: {
|
||||
ArrayExpression(path) {
|
||||
if (t.isCallExpression(path.parent)) return;
|
||||
let uniqueElements = uniqBy(path.node.elements, "type");
|
||||
|
||||
if (t.isObjectExpression(uniqueElements[0])) {
|
||||
uniqueElements = [
|
||||
t.callExpression(
|
||||
t.memberExpression(
|
||||
t.identifier("ImmutablePropTypes"),
|
||||
t.identifier("mapContains")
|
||||
),
|
||||
uniqueElements
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
if (
|
||||
(!isEmpty(uniqueElements) && uniqueElements.length === 1) ||
|
||||
t.isCallExpression(uniqueElements)
|
||||
) {
|
||||
path.replaceWith(
|
||||
t.callExpression(
|
||||
t.memberExpression(
|
||||
t.identifier("ImmutablePropTypes"),
|
||||
t.identifier("listOf")
|
||||
),
|
||||
uniqueElements
|
||||
)
|
||||
);
|
||||
} else {
|
||||
path.replaceWith(t.identifier("ImmutablePropTypes.list"));
|
||||
}
|
||||
},
|
||||
|
||||
NullLiteral(path) {
|
||||
path.replaceWith(t.identifier("PropTypes.any"));
|
||||
},
|
||||
|
||||
StringLiteral(path) {
|
||||
if (path.parentKey === "key") return;
|
||||
path.replaceWith(t.identifier(`PropTypes.string`));
|
||||
},
|
||||
|
||||
NumericLiteral(path) {
|
||||
path.replaceWith(t.identifier("PropTypes.number"));
|
||||
},
|
||||
|
||||
ArrowFunctionExpression(path) {
|
||||
path.replaceWith(t.identifier("PropTypes.func"));
|
||||
},
|
||||
|
||||
FunctionExpression(path) {
|
||||
path.replaceWith(t.identifier("PropTypes.func"));
|
||||
},
|
||||
|
||||
BooleanLiteral(path) {
|
||||
path.replaceWith(t.identifier("PropTypes.bool"));
|
||||
},
|
||||
|
||||
VariableDeclaration(path) {
|
||||
path.insertBefore(
|
||||
t.identifier(
|
||||
`import ImmutablePropTypes from 'react-immutable-proptypes'`
|
||||
)
|
||||
);
|
||||
},
|
||||
|
||||
Program(path) {
|
||||
path.traverse({
|
||||
enter(path) {
|
||||
t.removeComments(path.node);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
ObjectExpression(path) {
|
||||
if (
|
||||
t.isVariableDeclarator(path.parent) ||
|
||||
t.isCallExpression(path.parent)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const elements = [path.node];
|
||||
|
||||
path.replaceWith(
|
||||
t.callExpression(
|
||||
t.memberExpression(
|
||||
t.identifier("ImmutablePropTypes"),
|
||||
t.identifier("mapContains")
|
||||
),
|
||||
elements
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
import uniqBy from "lodash/uniqBy";
|
||||
import isEmpty from "lodash/isEmpty";
|
||||
|
||||
/**
|
||||
* This is a babel plugin that converts an object to PropTypes
|
||||
* @param t
|
||||
* @returns {{visitor: {ArrayExpression: (function(*)), NullLiteral: (function(*)), StringLiteral: (function(*)), NumericLiteral: (function(*)), ArrowFunctionExpression: (function(*)), FunctionExpression: (function(*)), BooleanLiteral: (function(*)), Program: (function(*, *)), ObjectExpression: (function(*))}}}
|
||||
*/
|
||||
export default function({ types: t }) {
|
||||
return {
|
||||
visitor: {
|
||||
ArrayExpression(path) {
|
||||
// if (t.isCallExpression(path.parent)) return;
|
||||
let uniqueElements = uniqBy(path.node.elements, "type");
|
||||
|
||||
if (t.isObjectExpression(uniqueElements[0])) {
|
||||
uniqueElements = [
|
||||
t.callExpression(
|
||||
t.memberExpression(t.identifier("t"), t.identifier("model")),
|
||||
uniqueElements
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
if (
|
||||
(!isEmpty(uniqueElements) && uniqueElements.length === 1) ||
|
||||
t.isCallExpression(uniqueElements)
|
||||
) {
|
||||
path.replaceWith(
|
||||
t.callExpression(
|
||||
t.memberExpression(t.identifier("t"), t.identifier("array")),
|
||||
uniqueElements
|
||||
)
|
||||
);
|
||||
} else {
|
||||
path.replaceWith(t.identifier("t.array"));
|
||||
}
|
||||
},
|
||||
|
||||
NullLiteral(path) {
|
||||
path.replaceWith(t.identifier("t.null"));
|
||||
},
|
||||
|
||||
StringLiteral(path) {
|
||||
if (path.parentKey === "key") return;
|
||||
path.replaceWith(t.identifier(`t.string`));
|
||||
},
|
||||
|
||||
NumericLiteral(path) {
|
||||
path.replaceWith(t.identifier("t.number"));
|
||||
},
|
||||
|
||||
ArrowFunctionExpression(path) {
|
||||
path.replaceWith(t.identifier("t.frozen"));
|
||||
},
|
||||
|
||||
FunctionExpression(path) {
|
||||
path.replaceWith(t.identifier("t.frozen"));
|
||||
},
|
||||
|
||||
BooleanLiteral(path) {
|
||||
path.replaceWith(t.identifier("t.boolean"));
|
||||
},
|
||||
|
||||
Program(path) {
|
||||
path.traverse({
|
||||
enter(path) {
|
||||
t.removeComments(path.node);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
ObjectProperty(path) {
|
||||
if (t.isStringLiteral(path.node.key)) {
|
||||
path.node.key = t.identifier(path.node.key.value);
|
||||
}
|
||||
},
|
||||
|
||||
ObjectExpression(path) {
|
||||
if (t.isCallExpression(path.parent)) return;
|
||||
|
||||
const elements = [path.node];
|
||||
|
||||
path.replaceWith(
|
||||
t.callExpression(
|
||||
t.memberExpression(t.identifier("t"), t.identifier("model")),
|
||||
elements
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
const json = `{
|
||||
"title": "Example Schema",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"firstName": {
|
||||
"type": "string"
|
||||
},
|
||||
"lastName": {
|
||||
"type": "string"
|
||||
},
|
||||
"age": {
|
||||
"description": "Age in years",
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
},
|
||||
"height": {
|
||||
"type": "number"
|
||||
},
|
||||
"favoriteFoods": {
|
||||
"type": "array",
|
||||
"minItems": 0,
|
||||
"maxItems": 2,
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"likesDogs": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": ["firstName", "lastName"]
|
||||
}`;
|
||||
|
||||
export default json;
|
||||
@@ -1,44 +0,0 @@
|
||||
const x = `{
|
||||
"hello": [
|
||||
{
|
||||
"type": 50.087977,
|
||||
"longitude": 72.167197,
|
||||
"tags": [
|
||||
"nulla",
|
||||
"ullamco"
|
||||
],
|
||||
"friends": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "Robinson Woods"
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Lottie Hogan"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"optionalField": "hello",
|
||||
"type": 47.460772,
|
||||
"longitude": 85.95137,
|
||||
"tags": [
|
||||
"aliqua",
|
||||
"nulla"
|
||||
],
|
||||
"friends": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "Mamie Wyatt"
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Alejandra Mcdaniel"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
`;
|
||||
|
||||
export default x;
|
||||
@@ -1,21 +0,0 @@
|
||||
const y = `{
|
||||
"title": {
|
||||
"type": "String",
|
||||
"trim": true,
|
||||
"index": true,
|
||||
"required": true
|
||||
},
|
||||
"year": {
|
||||
"type": "Number",
|
||||
"max": 2012,
|
||||
"validate": "validateBookYear"
|
||||
},
|
||||
"author": {
|
||||
"type": "ObjectId",
|
||||
"ref": "Author",
|
||||
"index": true,
|
||||
"required": true
|
||||
}
|
||||
}`;
|
||||
|
||||
export default y;
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,233 +0,0 @@
|
||||
/*
|
||||
JSON-to-Go
|
||||
by Matt Holt
|
||||
|
||||
https://github.com/mholt/json-to-go
|
||||
|
||||
A simple utility to translate JSON into a Go type definition.
|
||||
*/
|
||||
|
||||
function jsonToGo(json, typename) {
|
||||
let data;
|
||||
let scope;
|
||||
let go = "";
|
||||
let tabs = 0;
|
||||
|
||||
try {
|
||||
data = JSON.parse(json.replace(/\.0/g, ".1")); // hack that forces floats to stay as floats
|
||||
scope = data;
|
||||
} catch (e) {
|
||||
return {
|
||||
go: "",
|
||||
error: e.message
|
||||
};
|
||||
}
|
||||
|
||||
typename = format(typename || "AutoGenerated");
|
||||
append("type " + typename + " ");
|
||||
|
||||
parseScope(scope);
|
||||
|
||||
return { go: go };
|
||||
|
||||
function parseScope(scope) {
|
||||
let keyname;
|
||||
if (typeof scope === "object" && scope !== null) {
|
||||
if (Array.isArray(scope)) {
|
||||
let i;
|
||||
let sliceType,
|
||||
scopeLength = scope.length;
|
||||
|
||||
for (i = 0; i < scopeLength; i++) {
|
||||
const thisType = goType(scope[i]);
|
||||
if (!sliceType) sliceType = thisType;
|
||||
else if (sliceType !== thisType) {
|
||||
sliceType = mostSpecificPossibleGoType(thisType, sliceType);
|
||||
if (sliceType === "interface{}") break;
|
||||
}
|
||||
}
|
||||
|
||||
append("[]");
|
||||
if (sliceType === "struct") {
|
||||
let k;
|
||||
let keys;
|
||||
const allFields = {};
|
||||
|
||||
// for each field counts how many times appears
|
||||
for (i = 0; i < scopeLength; i++) {
|
||||
keys = Object.keys(scope[i]);
|
||||
for (k in keys) {
|
||||
keyname = keys[k];
|
||||
if (!(keyname in allFields)) {
|
||||
allFields[keyname] = {
|
||||
value: scope[i][keyname],
|
||||
count: 0
|
||||
};
|
||||
}
|
||||
|
||||
allFields[keyname].count++;
|
||||
}
|
||||
}
|
||||
|
||||
// create a common struct with all fields found in the current array
|
||||
// omitempty dict indicates if a field is optional
|
||||
keys = Object.keys(allFields);
|
||||
let struct = {},
|
||||
omitempty = {};
|
||||
for (k in keys) {
|
||||
keyname = keys[k];
|
||||
let elem = allFields[keyname];
|
||||
|
||||
struct[keyname] = elem.value;
|
||||
omitempty[keyname] = elem.count !== scopeLength;
|
||||
}
|
||||
|
||||
parseStruct(struct, omitempty); // finally parse the struct !!
|
||||
} else if (sliceType === "slice") {
|
||||
parseScope(scope[0]);
|
||||
} else append(sliceType || "interface{}");
|
||||
} else {
|
||||
parseStruct(scope);
|
||||
}
|
||||
} else append(goType(scope));
|
||||
}
|
||||
|
||||
function parseStruct(scope, omitempty) {
|
||||
append("struct {\n");
|
||||
++tabs;
|
||||
const keys = Object.keys(scope);
|
||||
for (const i in keys) {
|
||||
const keyname = keys[i];
|
||||
indent(tabs);
|
||||
append(format(keyname) + " ");
|
||||
parseScope(scope[keyname]);
|
||||
|
||||
append(' `json:"' + keyname);
|
||||
if (omitempty && omitempty[keyname] === true) {
|
||||
append(",omitempty");
|
||||
}
|
||||
append('"`\n');
|
||||
}
|
||||
indent(--tabs);
|
||||
append("}");
|
||||
}
|
||||
|
||||
function indent(tabs) {
|
||||
for (let i = 0; i < tabs; i++) go += "\t";
|
||||
}
|
||||
|
||||
function append(str) {
|
||||
go += str;
|
||||
}
|
||||
|
||||
// Sanitizes and formats a string to make an appropriate identifier in Go
|
||||
function format(str) {
|
||||
if (!str) return "";
|
||||
else if (str.match(/^\d+$/)) str = "Num" + str;
|
||||
else if (str.charAt(0).match(/\d/)) {
|
||||
const numbers = {
|
||||
"0": "Zero_",
|
||||
"1": "One_",
|
||||
"2": "Two_",
|
||||
"3": "Three_",
|
||||
"4": "Four_",
|
||||
"5": "Five_",
|
||||
"6": "Six_",
|
||||
"7": "Seven_",
|
||||
"8": "Eight_",
|
||||
"9": "Nine_"
|
||||
};
|
||||
str = numbers[str.charAt(0)] + str.substr(1);
|
||||
}
|
||||
return toProperCase(str).replace(/[^a-z0-9]/gi, "") || "NAMING_FAILED";
|
||||
}
|
||||
|
||||
// Determines the most appropriate Go type
|
||||
function goType(val) {
|
||||
if (val === null) return "interface{}";
|
||||
|
||||
switch (typeof val) {
|
||||
case "string":
|
||||
if (/\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+)?(\+\d\d:\d\d|Z)/.test(val)) {
|
||||
return "time.Time";
|
||||
} else return "string";
|
||||
case "number":
|
||||
if (val % 1 === 0) {
|
||||
if (val > -2147483648 && val < 2147483647) return "int";
|
||||
else return "int64";
|
||||
} else return "float64";
|
||||
case "boolean":
|
||||
return "bool";
|
||||
case "object":
|
||||
if (Array.isArray(val)) return "slice";
|
||||
return "struct";
|
||||
default:
|
||||
return "interface{}";
|
||||
}
|
||||
}
|
||||
|
||||
// Given two types, returns the more specific of the two
|
||||
function mostSpecificPossibleGoType(typ1, typ2) {
|
||||
if (typ1.substr(0, 5) === "float" && typ2.substr(0, 3) === "int") {
|
||||
return typ1;
|
||||
} else if (typ1.substr(0, 3) === "int" && typ2.substr(0, 5) === "float") {
|
||||
return typ1;
|
||||
} else return "interface{}";
|
||||
}
|
||||
|
||||
// Proper cases a string according to Go conventions
|
||||
function toProperCase(str) {
|
||||
// https://github.com/golang/lint/blob/39d15d55e9777df34cdffde4f406ab27fd2e60c0/lint.go#L695-L731
|
||||
const commonInitialisms = [
|
||||
"API",
|
||||
"ASCII",
|
||||
"CPU",
|
||||
"CSS",
|
||||
"DNS",
|
||||
"EOF",
|
||||
"GUID",
|
||||
"HTML",
|
||||
"HTTP",
|
||||
"HTTPS",
|
||||
"ID",
|
||||
"IP",
|
||||
"JSON",
|
||||
"LHS",
|
||||
"QPS",
|
||||
"RAM",
|
||||
"RHS",
|
||||
"RPC",
|
||||
"SLA",
|
||||
"SMTP",
|
||||
"SSH",
|
||||
"TCP",
|
||||
"TLS",
|
||||
"TTL",
|
||||
"UDP",
|
||||
"UI",
|
||||
"UID",
|
||||
"UUID",
|
||||
"URI",
|
||||
"URL",
|
||||
"UTF8",
|
||||
"VM",
|
||||
"XML",
|
||||
"XSRF",
|
||||
"XSS"
|
||||
];
|
||||
|
||||
return str
|
||||
.replace(/(^|[^a-zA-Z])([a-z]+)/g, function(unused, sep, frag) {
|
||||
if (commonInitialisms.indexOf(frag.toUpperCase()) >= 0) {
|
||||
return sep + frag.toUpperCase();
|
||||
} else return sep + frag[0].toUpperCase() + frag.substr(1).toLowerCase();
|
||||
})
|
||||
.replace(/([A-Z])([a-z]+)/g, function(unused, sep, frag) {
|
||||
if (commonInitialisms.indexOf(sep + frag.toUpperCase()) >= 0) {
|
||||
return (sep + frag).toUpperCase();
|
||||
} else return sep + frag;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = jsonToGo;
|
||||
@@ -1,9 +0,0 @@
|
||||
export default function(fileName, self) {
|
||||
if (self && self.promiseWorker) return { promiseWorker: self.promiseWorker };
|
||||
const PromiseWorker = require("promise-worker");
|
||||
const MyWorker = require(`worker-loader?inline!../workers/${fileName}`);
|
||||
const worker = new MyWorker();
|
||||
const promiseWorker = new PromiseWorker(worker);
|
||||
|
||||
return { worker, promiseWorker };
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import prettier from "prettier/standalone";
|
||||
|
||||
const prettierParsers = {
|
||||
css: "postcss",
|
||||
javascript: "babel",
|
||||
jsx: "babel",
|
||||
svg: "html",
|
||||
xml: "html",
|
||||
typescript: "typescript"
|
||||
};
|
||||
|
||||
const plugins = [
|
||||
require("prettier/parser-babylon"),
|
||||
require("prettier/parser-html"),
|
||||
require("prettier/parser-postcss"),
|
||||
require("prettier/parser-graphql"),
|
||||
require("prettier/parser-markdown"),
|
||||
require("prettier/parser-yaml"),
|
||||
require("prettier/parser-flow"),
|
||||
require("prettier/parser-typescript")
|
||||
];
|
||||
|
||||
export async function prettify(language: string, value: string) {
|
||||
let result;
|
||||
|
||||
if (language === "json") {
|
||||
result = JSON.stringify(JSON.parse(value), null, 2);
|
||||
} else {
|
||||
result = prettier.format(value, {
|
||||
parser: prettierParsers[language] || language,
|
||||
plugins
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
-261
@@ -1,261 +0,0 @@
|
||||
import flatten from "lodash/flatten";
|
||||
import find from "lodash/find";
|
||||
|
||||
function GraphQLIcon() {
|
||||
return (
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400">
|
||||
<path
|
||||
fill="#ffffff"
|
||||
d="M57.468 302.66l-14.376-8.3 160.15-277.38 14.376 8.3z"
|
||||
/>
|
||||
<path fill="#ffffff" d="M39.8 272.2h320.3v16.6H39.8z" />
|
||||
<path
|
||||
fill="#ffffff"
|
||||
d="M206.348 374.026l-160.21-92.5 8.3-14.376 160.21 92.5zM345.522 132.947l-160.21-92.5 8.3-14.376 160.21 92.5z"
|
||||
/>
|
||||
<path
|
||||
fill="#ffffff"
|
||||
d="M54.482 132.883l-8.3-14.375 160.21-92.5 8.3 14.376z"
|
||||
/>
|
||||
<path
|
||||
fill="#ffffff"
|
||||
d="M342.568 302.663l-160.15-277.38 14.376-8.3 160.15 277.38zM52.5 107.5h16.6v185H52.5zM330.9 107.5h16.6v185h-16.6z"
|
||||
/>
|
||||
<path
|
||||
fill="#ffffff"
|
||||
d="M203.522 367l-7.25-12.558 139.34-80.45 7.25 12.557z"
|
||||
/>
|
||||
<path
|
||||
fill="#ffffff"
|
||||
d="M369.5 297.9c-9.6 16.7-31 22.4-47.7 12.8-16.7-9.6-22.4-31-12.8-47.7 9.6-16.7 31-22.4 47.7-12.8 16.8 9.7 22.5 31 12.8 47.7M90.9 137c-9.6 16.7-31 22.4-47.7 12.8-16.7-9.6-22.4-31-12.8-47.7 9.6-16.7 31-22.4 47.7-12.8 16.7 9.7 22.4 31 12.8 47.7M30.5 297.9c-9.6-16.7-3.9-38 12.8-47.7 16.7-9.6 38-3.9 47.7 12.8 9.6 16.7 3.9 38-12.8 47.7-16.8 9.6-38.1 3.9-47.7-12.8M309.1 137c-9.6-16.7-3.9-38 12.8-47.7 16.7-9.6 38-3.9 47.7 12.8 9.6 16.7 3.9 38-12.8 47.7-16.7 9.6-38.1 3.9-47.7-12.8M200 395.8c-19.3 0-34.9-15.6-34.9-34.9 0-19.3 15.6-34.9 34.9-34.9 19.3 0 34.9 15.6 34.9 34.9 0 19.2-15.6 34.9-34.9 34.9M200 74c-19.3 0-34.9-15.6-34.9-34.9 0-19.3 15.6-34.9 34.9-34.9 19.3 0 34.9 15.6 34.9 34.9 0 19.3-15.6 34.9-34.9 34.9"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
export const categorizedRoutes = [
|
||||
{
|
||||
category: "React",
|
||||
iconName: "icon-reactjs",
|
||||
content: [
|
||||
{
|
||||
label: "JSON to React PropTypes",
|
||||
path: "/",
|
||||
title: "Transform | All important transforms at one place.",
|
||||
desc:
|
||||
"An online utility to convert a JSON object to prop-types, Typescript Interface, Rust serde or flow types. It also converts your CSS into JS and HTML into JSX."
|
||||
},
|
||||
{
|
||||
label: "HTML/SVG to JSX",
|
||||
path: "/html-to-jsx",
|
||||
desc:
|
||||
"An online REPL for converting HTML to JSX with proper support for SVG."
|
||||
},
|
||||
{
|
||||
label: "SVG to React Native",
|
||||
path: "/svg-to-react-native",
|
||||
desc:
|
||||
"An online REPL for converting SVG to React Native compatible equivalent."
|
||||
},
|
||||
{
|
||||
label: "CSS to JS Objects",
|
||||
path: "/css-to-js",
|
||||
desc:
|
||||
"An online REPL for converting CSS to JS object. It also gives style optimized for React Native.",
|
||||
packageName: "transform-css-to-js",
|
||||
packageUrl: "https://github.com/transform-it/transform-css-to-js"
|
||||
},
|
||||
{
|
||||
label: "CSS to Emotion",
|
||||
path: "/css-to-emotion",
|
||||
desc: "An online REPL for converting CSS to Emotion compatible code.",
|
||||
packageName: "css-in-js-generator",
|
||||
packageUrl: "https://github.com/brikou/CSS-in-JS-generator",
|
||||
beta: true
|
||||
},
|
||||
{
|
||||
label: "Object Styles to template literal",
|
||||
path: "/object-styles-to-template-literal",
|
||||
desc: "An online REPL to convert object styles to template literal.",
|
||||
packageUrl:
|
||||
"https://github.com/satya164/babel-plugin-object-styles-to-template",
|
||||
packageName: "babel-plugin-object-styles-to-template"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "JavaScript",
|
||||
iconName: "icon-javascript",
|
||||
content: [
|
||||
{
|
||||
label: "JSON to Flow Types",
|
||||
path: "/json-to-flow-types",
|
||||
desc: "An online REPL for converting JSON to generate Flow Types."
|
||||
},
|
||||
{
|
||||
label: "JSON to Typescript Interface",
|
||||
path: "/json-to-ts-interface",
|
||||
desc:
|
||||
"An online REPL for converting JSON to generate TypeScript Interface."
|
||||
},
|
||||
{
|
||||
label: "JSON to MobX-State-Tree Model",
|
||||
path: "/json-to-mobx-state-tree",
|
||||
desc: "An online REPL for converting JSON to generate Mobx State Tree."
|
||||
},
|
||||
{
|
||||
label: "JS Object to JSON",
|
||||
path: "/js-object-to-json",
|
||||
desc: "An online REPL for converting JS Object to JSON."
|
||||
},
|
||||
{
|
||||
label: "JSON Schema to TypeScript",
|
||||
path: "/json-schema-to-ts",
|
||||
desc:
|
||||
"An online REPL for converting JSON Schema to TypeScript Interface.",
|
||||
packageName: "json-schema-to-typescript",
|
||||
packageUrl: "https://github.com/bcherny/json-schema-to-typescript"
|
||||
},
|
||||
{
|
||||
label: "JSON to Sarcastic",
|
||||
path: "/json-to-sarcastic",
|
||||
desc: "An online REPL for converting JSON to sarcastic.",
|
||||
packageName: "transform-json-types",
|
||||
packageUrl: "https://github.com/transform-it/transform-json-types"
|
||||
},
|
||||
{
|
||||
label: "JSON to io-ts",
|
||||
path: "/json-to-io-ts",
|
||||
desc: "An online REPL for converting JSON to io-ts.",
|
||||
packageName: "transform-json-types",
|
||||
packageUrl: "https://github.com/transform-it/transform-json-types"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "Rust",
|
||||
iconName: "icon-rust",
|
||||
content: [
|
||||
{
|
||||
label: "JSON to Rust Serde",
|
||||
path: "/json-to-rust-serde",
|
||||
desc: "An online REPL for converting JSON to Rust Serde Structs."
|
||||
},
|
||||
{
|
||||
label: "JSON Schema to Rust Serde",
|
||||
path: "/json-schema-to-rust-serde",
|
||||
desc: "An online REPL for converting JSON Schema to Rust Serde Structs."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "Databases",
|
||||
iconName: "icon-database",
|
||||
content: [
|
||||
{
|
||||
label: "JSON to Mongoose Schema",
|
||||
path: "/json-to-mongoose",
|
||||
desc: "An online REPL to generate Mongoose Schema from JSON.",
|
||||
packageName: "generate-schema",
|
||||
packageUrl: "https://github.com/nijikokun/generate-schema"
|
||||
},
|
||||
{
|
||||
label: "JSON to Big Query Schema",
|
||||
path: "/json-to-big-query",
|
||||
desc: "An online REPL to generate Big Query Schema from JSON.",
|
||||
packageName: "generate-schema",
|
||||
packageUrl: "https://github.com/nijikokun/generate-schema"
|
||||
},
|
||||
{
|
||||
label: "JSON to MySQL",
|
||||
path: "/json-to-mysql",
|
||||
desc:
|
||||
"An online REPL to generate MySQL table generation code from JSON.",
|
||||
packageName: "generate-schema",
|
||||
packageUrl: "https://github.com/nijikokun/generate-schema"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "Scala",
|
||||
iconName: "icon-scala",
|
||||
content: [
|
||||
{
|
||||
label: "JSON to Scala Case Class",
|
||||
path: "/json-to-scala-case-class",
|
||||
desc: "An online REPL to generate Scala Case Class from JSON."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "GraphQL",
|
||||
icon: <GraphQLIcon />,
|
||||
content: [
|
||||
{
|
||||
label: "GraphQL to TypeScript",
|
||||
path: "/graphql-to-typescript",
|
||||
desc:
|
||||
"An online REPL to generate TypeScript type annotations based on a GraphQL schema and query documents."
|
||||
},
|
||||
{
|
||||
label: "GraphQL to Flow",
|
||||
path: "/graphql-to-flow",
|
||||
desc:
|
||||
"An online REPL to generate Flow type annotations based on a GraphQL schema and query documents."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "Go",
|
||||
iconName: "icon-go",
|
||||
content: [
|
||||
{
|
||||
label: "JSON to Go Struct",
|
||||
path: "/json-to-go",
|
||||
desc: "An online REPL to generate Go Struct from JSON.",
|
||||
packageName: "json-to-go",
|
||||
packageUrl: "https://github.com/mholt/json-to-go"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "Others",
|
||||
iconName: "",
|
||||
content: [
|
||||
{
|
||||
label: "XML to JSON",
|
||||
path: "/xml-to-json",
|
||||
desc: "An online REPL to generate basic JSON from a XML.",
|
||||
packageName: "xml-js",
|
||||
packageUrl: "https://github.com/nashwaan/xml-js"
|
||||
},
|
||||
{
|
||||
label: "JSON to YAML",
|
||||
path: "/json-to-yaml",
|
||||
desc: "An online REPL to convert JSON to YAML.",
|
||||
packageName: "json2yaml",
|
||||
packageUrl: "https://github.com/jeffsu/json2yaml"
|
||||
},
|
||||
{
|
||||
label: "YAML to JSON",
|
||||
path: "/yaml-to-json",
|
||||
desc: "An online REPL to convert YAML to JSON.",
|
||||
packageName: "yaml",
|
||||
packageUrl: "https://github.com/tj/js-yaml"
|
||||
},
|
||||
{
|
||||
label: "Markdown to HTML",
|
||||
path: "/markdown-to-html",
|
||||
desc: "An online REPL to convert Markdown to HTML.",
|
||||
packageName: "markdown",
|
||||
packageUrl: "https://github.com/evilstreak/markdown-js"
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
export const routes = flatten(categorizedRoutes.map(a => a.content));
|
||||
|
||||
export function activeRouteData(pathname) {
|
||||
return find(routes, o => o.path === pathname);
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
import React from "react";
|
||||
import flatten from "lodash/flatten";
|
||||
import find from "lodash/find";
|
||||
|
||||
export const categorizedRoutes = [
|
||||
{
|
||||
category: "SVG",
|
||||
content: [
|
||||
{
|
||||
label: "to JSX",
|
||||
path: "/",
|
||||
packageName: "@svgr/core",
|
||||
packageUrl: "https://github.com/smooth-code/svgr"
|
||||
},
|
||||
{
|
||||
label: "to React Native",
|
||||
path: "/svg-to-react-native",
|
||||
packageName: "@svgr/core",
|
||||
packageUrl: "https://github.com/smooth-code/svgr"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "HTML",
|
||||
content: [
|
||||
{
|
||||
label: "to JSX",
|
||||
path: "/html-to-jsx"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "JSON",
|
||||
content: [
|
||||
{
|
||||
label: "to React PropTypes",
|
||||
path: "/json-to-proptypes",
|
||||
title: "Transform | All important transforms at one place."
|
||||
},
|
||||
{
|
||||
label: "to Flow",
|
||||
path: "/json-to-flow"
|
||||
},
|
||||
{
|
||||
label: "to TypeScript",
|
||||
path: "/json-to-typescript"
|
||||
},
|
||||
{
|
||||
label: "to MobX-State-Tree Model",
|
||||
path: "/json-to-mobx-state-tree"
|
||||
},
|
||||
{
|
||||
label: "to Sarcastic",
|
||||
path: "/json-to-sarcastic",
|
||||
packageName: "transform-json-types",
|
||||
packageUrl: "https://github.com/transform-it/transform-json-types"
|
||||
},
|
||||
{
|
||||
label: "to io-ts",
|
||||
path: "/json-to-io-ts",
|
||||
packageName: "transform-json-types",
|
||||
packageUrl: "https://github.com/transform-it/transform-json-types"
|
||||
},
|
||||
{
|
||||
label: "to Rust Serde",
|
||||
path: "/json-to-rust-serde",
|
||||
desc: "An online REPL for converting JSON to Rust Serde Structs."
|
||||
},
|
||||
{
|
||||
label: "to Mongoose Schema",
|
||||
path: "/json-to-mongoose",
|
||||
packageName: "generate-schema",
|
||||
packageUrl: "https://github.com/nijikokun/generate-schema"
|
||||
},
|
||||
{
|
||||
label: "to Big Query Schema",
|
||||
path: "/json-to-big-query",
|
||||
packageName: "generate-schema",
|
||||
packageUrl: "https://github.com/nijikokun/generate-schema"
|
||||
},
|
||||
{
|
||||
label: "to MySQL",
|
||||
path: "/json-to-mysql",
|
||||
packageName: "generate-schema",
|
||||
packageUrl: "https://github.com/nijikokun/generate-schema"
|
||||
},
|
||||
{
|
||||
label: "to Scala Case Class",
|
||||
path: "/json-to-scala-case-class"
|
||||
},
|
||||
{
|
||||
label: "to Go Struct",
|
||||
path: "/json-to-go",
|
||||
packageName: "json-to-go",
|
||||
packageUrl: "https://github.com/mholt/json-to-go"
|
||||
},
|
||||
{
|
||||
label: "to YAML",
|
||||
path: "/json-to-yaml",
|
||||
packageName: "json2yaml",
|
||||
packageUrl: "https://github.com/jeffsu/json2yaml"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "JSON Schema",
|
||||
content: [
|
||||
{
|
||||
label: "to TypeScript",
|
||||
path: "/json-schema-to-typescript",
|
||||
packageName: "json-schema-to-typescript",
|
||||
packageUrl: "https://github.com/bcherny/json-schema-to-typescript"
|
||||
},
|
||||
{
|
||||
label: "to OpenAPI Schema",
|
||||
path: "json-schema-to-openapi-schema",
|
||||
packageName: "json-schema-to-openapi-schema",
|
||||
packageUrl: "https://github.com/wework/json-schema-to-openapi-schema"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "CSS",
|
||||
content: [
|
||||
{
|
||||
label: "to JS Objects",
|
||||
path: "/css-to-js",
|
||||
packageName: "transform-css-to-js",
|
||||
packageUrl: "https://github.com/transform-it/transform-css-to-js"
|
||||
},
|
||||
{
|
||||
label: "to template literal",
|
||||
path: "/object-styles-to-template-literal",
|
||||
packageUrl:
|
||||
"https://github.com/satya164/babel-plugin-object-styles-to-template",
|
||||
packageName: "babel-plugin-object-styles-to-template"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "JavaScript",
|
||||
content: [
|
||||
{
|
||||
label: "to JSON",
|
||||
path: "/js-object-to-json",
|
||||
desc: "An online REPL for converting JS Object to JSON."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "GraphQL",
|
||||
content: [
|
||||
{
|
||||
label: "to TypeScript",
|
||||
path: "/graphql-to-typescript",
|
||||
packageUrl: "https://github.com/dotansimha/graphql-code-generator",
|
||||
packageName: "graphql-code-generator"
|
||||
},
|
||||
{
|
||||
label: "to Flow",
|
||||
path: "/graphql-to-flow",
|
||||
packageUrl: "https://github.com/dotansimha/graphql-code-generator",
|
||||
packageName: "graphql-code-generator"
|
||||
},
|
||||
{
|
||||
label: "to JAVA",
|
||||
path: "/graphql-to-java",
|
||||
packageUrl: "https://github.com/dotansimha/graphql-code-generator",
|
||||
packageName: "graphql-code-generator"
|
||||
},
|
||||
{
|
||||
label: "to Resolvers Signature",
|
||||
path: "/graphql-to-resolvers-signature",
|
||||
packageUrl: "https://github.com/dotansimha/graphql-code-generator",
|
||||
packageName: "graphql-code-generator"
|
||||
},
|
||||
|
||||
{
|
||||
label: "to Introspection JSON",
|
||||
path: "/graphql-to-introspection-json",
|
||||
packageUrl: "https://github.com/dotansimha/graphql-code-generator",
|
||||
packageName: "graphql-code-generator"
|
||||
},
|
||||
|
||||
{
|
||||
label: "to Schema AST",
|
||||
path: "/graphql-to-schema-ast",
|
||||
packageUrl: "https://github.com/dotansimha/graphql-code-generator",
|
||||
packageName: "graphql-code-generator"
|
||||
},
|
||||
{
|
||||
label: "to Fragment Matcher",
|
||||
path: "/graphql-to-fragment-matcher",
|
||||
packageUrl: "https://github.com/dotansimha/graphql-code-generator",
|
||||
packageName: "graphql-code-generator"
|
||||
},
|
||||
{
|
||||
label: "to Components",
|
||||
path: "/graphql-to-components",
|
||||
packageUrl: "https://github.com/dotansimha/graphql-code-generator",
|
||||
packageName: "graphql-code-generator"
|
||||
},
|
||||
{
|
||||
label: "to TypeScript MongoDB",
|
||||
path: "/graphql-to-typescript-mongodb",
|
||||
packageUrl: "https://github.com/dotansimha/graphql-code-generator",
|
||||
packageName: "graphql-code-generator"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "Others",
|
||||
iconName: "",
|
||||
content: [
|
||||
{
|
||||
label: "Flow to Typescript",
|
||||
path: "/flow-to-typescript"
|
||||
},
|
||||
{
|
||||
label: "XML to JSON",
|
||||
path: "/xml-to-json",
|
||||
packageName: "xml-js",
|
||||
packageUrl: "https://github.com/nashwaan/xml-js"
|
||||
},
|
||||
|
||||
{
|
||||
label: "YAML to JSON",
|
||||
path: "/yaml-to-json",
|
||||
packageName: "yaml",
|
||||
packageUrl: "https://github.com/tj/js-yaml"
|
||||
},
|
||||
{
|
||||
label: "Markdown to HTML",
|
||||
path: "/markdown-to-html",
|
||||
packageName: "markdown",
|
||||
packageUrl: "https://github.com/evilstreak/markdown-js"
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
export interface Route {
|
||||
path: string;
|
||||
label: string;
|
||||
desc: string;
|
||||
}
|
||||
|
||||
export const routes = flatten(
|
||||
categorizedRoutes.map(a =>
|
||||
// @ts-ignore
|
||||
a.content.map(x => {
|
||||
const _label =
|
||||
a.category.toLowerCase() !== "others"
|
||||
? `${a.category} ${x.label}`
|
||||
: x.label;
|
||||
return {
|
||||
...x,
|
||||
category: a.category,
|
||||
searchTerm: _label,
|
||||
desc: x.desc || `An online Repl to convert ${_label}`
|
||||
};
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
export function activeRouteData(pathname) {
|
||||
return find(routes, o => o.path === pathname);
|
||||
}
|
||||
+315
@@ -0,0 +1,315 @@
|
||||
import React from "react";
|
||||
import { editor } from "monaco-editor";
|
||||
|
||||
export const ThemeContext = React.createContext({
|
||||
theme: "light",
|
||||
toggleTheme: () => {}
|
||||
});
|
||||
|
||||
export const lightEditor: editor.IStandaloneThemeData = {
|
||||
base: "vs",
|
||||
inherit: true,
|
||||
rules: [
|
||||
{
|
||||
foreground: "940494",
|
||||
background: "444494",
|
||||
token: "punctuation.definition.list"
|
||||
},
|
||||
{
|
||||
foreground: "404f50",
|
||||
background: "5f0fff",
|
||||
fontStyle: "italic",
|
||||
token: "comment"
|
||||
},
|
||||
{
|
||||
foreground: "5a5f9b",
|
||||
background: "aaafdb",
|
||||
token: "string"
|
||||
},
|
||||
{
|
||||
foreground: "4f827b",
|
||||
background: "77c2bb",
|
||||
token: "constant.numeric"
|
||||
},
|
||||
{
|
||||
foreground: "025f69",
|
||||
background: "7f2299",
|
||||
token: "constant.character"
|
||||
},
|
||||
{
|
||||
foreground: "025f69",
|
||||
background: "7f2299",
|
||||
token: "constant.other"
|
||||
},
|
||||
{
|
||||
foreground: "7d7e52",
|
||||
background: "bdbe82",
|
||||
token: "constant.language"
|
||||
},
|
||||
{
|
||||
foreground: "7b5d8f",
|
||||
background: "9b9ffd",
|
||||
fontStyle: "bold",
|
||||
token: "storage.modifier"
|
||||
},
|
||||
{
|
||||
foreground: "7b5cbf",
|
||||
background: "8b5ddf",
|
||||
fontStyle: "bold",
|
||||
token: "storage"
|
||||
},
|
||||
{
|
||||
foreground: "025f49",
|
||||
background: "22ff49",
|
||||
token: "entity.name.function"
|
||||
},
|
||||
{
|
||||
foreground: "9d7e62",
|
||||
background: "bdbe82",
|
||||
token: "support.function"
|
||||
},
|
||||
{
|
||||
foreground: "939469",
|
||||
background: "e3e4a9",
|
||||
token: "entity.name.function.misc"
|
||||
},
|
||||
{
|
||||
foreground: "856f63",
|
||||
background: "a5df93",
|
||||
token: "entity.name.function.predicate"
|
||||
},
|
||||
{
|
||||
foreground: "af938c",
|
||||
background: "dfb3ac",
|
||||
token: "entity.name.function.io"
|
||||
},
|
||||
{
|
||||
foreground: "7bafad",
|
||||
background: "bbdfdd",
|
||||
token: "variable.other.external-symbol"
|
||||
},
|
||||
{
|
||||
foreground: "316fcf",
|
||||
background: "3aafff",
|
||||
token: "variable.language"
|
||||
},
|
||||
{
|
||||
foreground: "316fcf",
|
||||
background: "3aafff",
|
||||
token: "variable.other"
|
||||
},
|
||||
{
|
||||
foreground: "33969f",
|
||||
background: "05d6f9",
|
||||
fontStyle: "italic",
|
||||
token: "variable.parameter"
|
||||
},
|
||||
{
|
||||
foreground: "674aa8",
|
||||
background: "a3aad8",
|
||||
token: "keyword"
|
||||
},
|
||||
{
|
||||
foreground: "b9986f",
|
||||
background: "b998df",
|
||||
fontStyle: "bold",
|
||||
token: "entity.name.class"
|
||||
},
|
||||
{
|
||||
foreground: "22af9d",
|
||||
background: "b998df",
|
||||
token: "entity.name.structure"
|
||||
},
|
||||
{
|
||||
foreground: "af47a9",
|
||||
background: "af77a9",
|
||||
token: "entity.name.type"
|
||||
},
|
||||
{
|
||||
foreground: "cc4357",
|
||||
background: "ffddff",
|
||||
token: "entity.name.class"
|
||||
},
|
||||
{
|
||||
foreground: "cc4357",
|
||||
background: "ffddff",
|
||||
token: "entity.name.type.class"
|
||||
},
|
||||
{
|
||||
foreground: "ef6aa7",
|
||||
background: "ef6aa7",
|
||||
token: "support.class"
|
||||
},
|
||||
{
|
||||
foreground: "dfdfd5",
|
||||
background: "cc1b27",
|
||||
token: "invalid"
|
||||
},
|
||||
{
|
||||
foreground: "13499f",
|
||||
background: "0099ff",
|
||||
fontStyle: "italic",
|
||||
token: "string source"
|
||||
},
|
||||
{
|
||||
foreground: "3976a2",
|
||||
background: "49a6d2",
|
||||
token: "entity.name.tag"
|
||||
},
|
||||
{
|
||||
foreground: "4946c2",
|
||||
background: "4986c2",
|
||||
token: "entity.other.attribute-name"
|
||||
}
|
||||
],
|
||||
colors: {
|
||||
"editor.foreground": "#0f0009",
|
||||
"editor.background": "#f9f8f9",
|
||||
"editor.selectionBackground": "#BAD6FD",
|
||||
"editor.lineHighlightBackground": "#ffffff",
|
||||
"editorCursor.foreground": "#100011",
|
||||
"editorWhitespace.foreground": "#000000",
|
||||
"editor.selectionHighlightBorder": "#B3B3B3"
|
||||
}
|
||||
};
|
||||
|
||||
export const darkEditor: editor.IStandaloneThemeData = {
|
||||
base: "vs-dark",
|
||||
inherit: true,
|
||||
rules: [
|
||||
{
|
||||
foreground: "75715e",
|
||||
token: "comment"
|
||||
},
|
||||
{
|
||||
foreground: "e6db74",
|
||||
token: "string"
|
||||
},
|
||||
{
|
||||
foreground: "ae81ff",
|
||||
token: "constant.numeric"
|
||||
},
|
||||
{
|
||||
foreground: "ae81ff",
|
||||
token: "constant.language"
|
||||
},
|
||||
{
|
||||
foreground: "ae81ff",
|
||||
token: "constant.character"
|
||||
},
|
||||
{
|
||||
foreground: "ae81ff",
|
||||
token: "constant.other"
|
||||
},
|
||||
{
|
||||
foreground: "f92672",
|
||||
token: "keyword"
|
||||
},
|
||||
{
|
||||
foreground: "f92672",
|
||||
token: "storage"
|
||||
},
|
||||
{
|
||||
foreground: "66d9ef",
|
||||
fontStyle: "italic",
|
||||
token: "storage.type"
|
||||
},
|
||||
{
|
||||
foreground: "a6e22e",
|
||||
fontStyle: "underline",
|
||||
token: "entity.name.class"
|
||||
},
|
||||
{
|
||||
foreground: "a6e22e",
|
||||
fontStyle: "italic underline",
|
||||
token: "entity.other.inherited-class"
|
||||
},
|
||||
{
|
||||
foreground: "a6e22e",
|
||||
token: "entity.name.function"
|
||||
},
|
||||
{
|
||||
foreground: "fd971f",
|
||||
fontStyle: "italic",
|
||||
token: "variable.parameter"
|
||||
},
|
||||
{
|
||||
foreground: "f92672",
|
||||
token: "entity.name.tag"
|
||||
},
|
||||
{
|
||||
foreground: "a6e22e",
|
||||
token: "entity.other.attribute-name"
|
||||
},
|
||||
{
|
||||
foreground: "66d9ef",
|
||||
token: "support.function"
|
||||
},
|
||||
{
|
||||
foreground: "66d9ef",
|
||||
token: "support.constant"
|
||||
},
|
||||
{
|
||||
foreground: "66d9ef",
|
||||
fontStyle: "italic",
|
||||
token: "support.type"
|
||||
},
|
||||
{
|
||||
foreground: "66d9ef",
|
||||
fontStyle: "italic",
|
||||
token: "support.class"
|
||||
},
|
||||
{
|
||||
foreground: "f8f8f0",
|
||||
background: "f92672",
|
||||
token: "invalid"
|
||||
},
|
||||
{
|
||||
foreground: "f8f8f0",
|
||||
background: "ae81ff",
|
||||
token: "invalid.deprecated"
|
||||
},
|
||||
{
|
||||
foreground: "cfcfc2",
|
||||
token: "meta.structure.dictionary.json string.quoted.double.json"
|
||||
},
|
||||
{
|
||||
foreground: "75715e",
|
||||
token: "meta.diff"
|
||||
},
|
||||
{
|
||||
foreground: "75715e",
|
||||
token: "meta.diff.header"
|
||||
},
|
||||
{
|
||||
foreground: "f92672",
|
||||
token: "markup.deleted"
|
||||
},
|
||||
{
|
||||
foreground: "a6e22e",
|
||||
token: "markup.inserted"
|
||||
},
|
||||
{
|
||||
foreground: "e6db74",
|
||||
token: "markup.changed"
|
||||
},
|
||||
{
|
||||
foreground: "ae81ff",
|
||||
token: "constant.numeric.line-number.find-in-files - match"
|
||||
},
|
||||
{
|
||||
foreground: "e6db74",
|
||||
token: "entity.name.filename.find-in-files"
|
||||
}
|
||||
],
|
||||
colors: {
|
||||
"editor.foreground": "#F8F8F2",
|
||||
"editor.background": "#272822",
|
||||
"editor.selectionBackground": "#49483E",
|
||||
"editor.lineHighlightBackground": "#3E3D32",
|
||||
"editorCursor.foreground": "#F8F8F0",
|
||||
"editorWhitespace.foreground": "#3B3A32",
|
||||
"editorIndentGuide.activeBackground": "#9D550F",
|
||||
"editor.selectionHighlightBorder": "#222218"
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,63 @@
|
||||
import { Module } from "webpack";
|
||||
|
||||
const resolves = {};
|
||||
const rejects = {};
|
||||
let globalMsgId = 0;
|
||||
|
||||
// Activate calculation in the worker, returning a promise
|
||||
function sendMsg(payload, worker: Worker) {
|
||||
const msgId = globalMsgId++;
|
||||
const msg = {
|
||||
id: msgId,
|
||||
payload
|
||||
};
|
||||
return new Promise(function(resolve, reject) {
|
||||
// save callbacks for later
|
||||
resolves[msgId] = resolve;
|
||||
rejects[msgId] = reject;
|
||||
worker.postMessage(msg);
|
||||
|
||||
// TODO: CHECK FOR MEMORY LEAK
|
||||
});
|
||||
}
|
||||
// Handle incoming calculation result
|
||||
function handleMsg(msg) {
|
||||
const { id, err, payload } = msg.data;
|
||||
if (payload) {
|
||||
const resolve = resolves[id];
|
||||
if (resolve) {
|
||||
resolve(payload);
|
||||
}
|
||||
} else {
|
||||
// error condition
|
||||
const reject = rejects[id];
|
||||
if (reject) {
|
||||
if (err) {
|
||||
reject(new Error(err));
|
||||
} else {
|
||||
reject("Got nothing");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// purge used callbacks
|
||||
delete resolves[id];
|
||||
delete rejects[id];
|
||||
}
|
||||
|
||||
export class Wrapper {
|
||||
worker: Worker;
|
||||
|
||||
constructor(worker: Worker) {
|
||||
this.worker = worker;
|
||||
this.worker.onmessage = handleMsg;
|
||||
}
|
||||
|
||||
send(str): Promise<any> {
|
||||
return sendMsg(str, this.worker);
|
||||
}
|
||||
}
|
||||
|
||||
export function getWorker(Worker) {
|
||||
return new Wrapper(new Worker());
|
||||
}
|
||||
Reference in new issue
Block a user