Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

:wastebasket: Deletes Json to Yaml script (#482)

Alicia Sykes45edc9731add
diff --git a/src/utils/JsonToYaml.js b/src/utils/JsonToYaml.js
deleted file mode 100644
index c855f5d0..00000000
--- a/src/utils/JsonToYaml.js
+++ /dev/null
@@ -1,87 +0,0 @@
-import { typeOf } from 'remedial';
-
-const trimWhitespace = (input) => input.split('\n').map(x => x.trimRight()).join('\n');
-
-const throwError = (msg) => {
- throw new Error(`Error in Json to YAML conversion: ${msg}`);
-};
-
-/* A function that converts valid JSON into valid YAML */
-const stringify = (data) => {
- let indentLevel = '';
- const handlers = {
- undefined() {
- return 'null';
- },
- null() {
- return 'null';
- },
- number(x) {
- return x;
- },
- boolean(x) {
- return x ? 'true' : 'false';
- },
- string(x) {
- return JSON.stringify(x);
- },
- array(x) {
- let output = '';
- if (x.length === 0) {
- output += '[]';
- return output;
- }
-
- indentLevel = indentLevel.replace(/$/, ' ');
- x.forEach((y) => {
- const handler = handlers[typeOf(y)];
-
- if (!handler) throwError(typeOf(y));
-
- output += `\n${indentLevel}- ${handler(y, true)}`;
- });
- indentLevel = indentLevel.replace(/ {2}/, '');
-
- return output;
- },
- object(x, inArray, rootNode) {
- let output = '';
-
- if (Object.keys(x).length === 0) {
- output += '{}';
- return output;
- }
-
- if (!rootNode) {
- indentLevel = indentLevel.replace(/$/, ' ');
- }
-
- Object.keys(x).forEach((k, i) => {
- const val = x[k];
- const handler = handlers[typeOf(val)];
-
- if (typeof val === 'undefined') {
- return;
- }
-
- if (!handler) throwError(typeOf(val));
-
- if (!(inArray && i === 0)) {
- output += `\n${indentLevel}`;
- }
-
- output += `${k}: ${handler(val)}`;
- });
- indentLevel = indentLevel.replace(/ {2}/, '');
-
- return output;
- },
- function() {
- return '[object Function]';
- },
- };
-
- return trimWhitespace(`${handlers[typeOf(data)](data, true, true)}\n`);
-};
-
-export default stringify;