Skip to content

Commit

Permalink
internal tool to decode submitted JSON files
Browse files Browse the repository at this point in the history
  • Loading branch information
phfaist committed Dec 6, 2021
1 parent 0d88efd commit d25105a
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 1,026 deletions.
123 changes: 2 additions & 121 deletions jscomponents/dist/eczsearch.js

Large diffs are not rendered by default.

900 changes: 2 additions & 898 deletions jscomponents/dist/ecztooldecodesubmittedjson.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions jscomponents/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"lunr": "^2.3.9",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"sass": "^1.44.0",
"style-loader": "^3.3.1",
"yaml": "^2.0.0-9"
},
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import React from 'react';
import YAML from 'yaml';


import "./EczToolDecodeSubmittedJsonCode_style.scss";


export default class EczToolDecodeSubmittedJsonCode extends React.Component
{
render()
Expand Down Expand Up @@ -35,33 +38,66 @@ export default class EczToolDecodeSubmittedJsonCode extends React.Component
}
set_json_content(json)
{
console.log("Got JSON = ", json);
console.log("Got JSON = ", {data: json});

const d = JSON.parse( json );

const yamldoc = new YAML.Document(d);
const yamldoc = new YAML.Document( d );

yamldoc.commentBefore =
'######################################################\n'
+'# This is a code entry in the error correction zoo. ##\n'
+'# https://github.com/errorcorrectionzoo ##\n'
+'######################################################\n';

YAML.visit(
yamldoc,
{
Pair(_, pair, path) {
console.log('pair =', pair, '; path =', path);
if (path.length <= 6) { // [document, map object] for root map
pair.key.spaceBefore = true;
} else {
pair.key.spaceBefore = false;
}
},
Seq(key, node, path) {
console.log('seq; node =', node, '; path =', path);
node.items.forEach( (child, index) => {
if (index > 0) {
child.spaceBefore = true;
}
} );
},
Map(key, node, path) {
console.log('map; node =', node, '; path =', path);
node.items.forEach( (child, index) => {
if (index > 0) {
child.spaceBefore = true;
}
} );
},
Scalar(key, node) {
console.log('string; key =', key, ' node =', node);
if (key == 'key') {
node.type = 'PLAIN';
} else if (typeof node.value === 'string') {
if (node.value.indexOf('\n') == -1) {
let value = node.value;
if (value.indexOf('\n') == -1) {
node.type = 'QUOTE_SINGLE';
} else {
node.type = 'BLOCK_LITERAL';
}
}
}
},
}
);

const yamlcode = yamldoc.toString();
const yamlcode = yamldoc.toString({
lineWidth: 0, // inhibit folding of single-quoted strings for Victor
});

console.log("Got YaML = ", yamlcode);
console.log("Got YaML = ", {data: yamlcode});

this.setState({ output_yaml_code: yamlcode });
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

.EczToolDecodeSubmittedJsonCode {

input[type="file"]
{
display: block;
width: 100%;
box-sizing: border-box;

border: solid 1px #aaa;
background-color: #ddd;

padding: 1em;
}

textarea {
display: block;

box-sizing: border-box;

width: 100%;
min-width: 100%;
max-width: 100%;
height: 20em;

padding: 1em;
}
}
20 changes: 19 additions & 1 deletion jscomponents/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ chalk@^4.1.0:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

[email protected], chokidar@^3.4.0:
[email protected], "chokidar@>=3.0.0 <4.0.0", chokidar@^3.4.0:
version "3.5.2"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.2.tgz#dba3976fcadb016f66fd365021d91600d01c1e75"
integrity sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ==
Expand Down Expand Up @@ -1803,6 +1803,11 @@ icss-utils@^5.0.0, icss-utils@^5.1.0:
resolved "https://registry.yarnpkg.com/icss-utils/-/icss-utils-5.1.0.tgz#c6be6858abd013d768e98366ae47e25d5887b1ae"
integrity sha512-soFhflCVWLfRNOPU3iv5Z9VUdT44xFRbzjLsEzSr5AQmgqPMTHdU3PMT1Cf1ssx8fLNJDA1juftYl+PUcv3MqA==

immutable@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.0.0.tgz#b86f78de6adef3608395efb269a91462797e2c23"
integrity sha512-zIE9hX70qew5qTUjSS7wi1iwj/l7+m54KWU247nhM3v806UdGj1yDndXj+IOYxxtW9zyLI+xqFNZjTuDaLUqFw==

import-local@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/import-local/-/import-local-3.0.3.tgz#4d51c2c495ca9393da259ec66b62e022920211e0"
Expand Down Expand Up @@ -2450,6 +2455,14 @@ sass-loader@^12.3.0:
klona "^2.0.4"
neo-async "^2.6.2"

sass@^1.44.0:
version "1.44.0"
resolved "https://registry.yarnpkg.com/sass/-/sass-1.44.0.tgz#619aa0a2275c097f9af5e6b8fe8a95e3056430fb"
integrity sha512-0hLREbHFXGQqls/K8X+koeP+ogFRPF4ZqetVB19b7Cst9Er8cOR0rc6RU7MaI4W1JmUShd1BPgPoeqmmgMMYFw==
dependencies:
chokidar ">=3.0.0 <4.0.0"
immutable "^4.0.0"

scheduler@^0.20.2:
version "0.20.2"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.20.2.tgz#4baee39436e34aa93b4874bddcbf0fe8b8b50e91"
Expand Down Expand Up @@ -2588,6 +2601,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006"
integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==

style-loader@^3.3.1:
version "3.3.1"
resolved "https://registry.yarnpkg.com/style-loader/-/style-loader-3.3.1.tgz#057dfa6b3d4d7c7064462830f9113ed417d38575"
integrity sha512-GPcQ+LDJbrcxHORTRes6Jy2sfvK2kS6hpSfI/fXhPt+spVzxF6LJ1dHLN9zIGmVaaP044YKaIatFaufENRiDoQ==

[email protected], supports-color@^8.0.0:
version "8.1.1"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-8.1.1.tgz#cd6fc17e28500cff56c1b86c0a7fd4a54a73005c"
Expand Down

0 comments on commit d25105a

Please sign in to comment.