mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-07 23:15:14 -04:00
adding prettier
This commit is contained in:
parent
c5a1b69c30
commit
ab0bc52d3c
717 changed files with 29324 additions and 18602 deletions
|
@ -14,14 +14,12 @@ import Utils from "../Utils.mjs";
|
|||
*/
|
||||
export const RECORD_DELIMITER_OPTIONS = ["Line feed", "CRLF"];
|
||||
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
export const FIELD_DELIMITER_OPTIONS = ["Space", "Comma", "Semi-colon", "Colon", "Tab"];
|
||||
|
||||
|
||||
/**
|
||||
* Default from colour
|
||||
*
|
||||
|
@ -33,7 +31,6 @@ export const COLOURS = {
|
|||
max: "black"
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Gets values from input for a plot.
|
||||
*
|
||||
|
@ -48,22 +45,19 @@ export function getValues(input, recordDelimiter, fieldDelimiter, columnHeadings
|
|||
let headings;
|
||||
const values = [];
|
||||
|
||||
input
|
||||
.split(recordDelimiter)
|
||||
.forEach((row, rowIndex) => {
|
||||
const split = row.split(fieldDelimiter);
|
||||
if (split.length !== length) throw new OperationError(`Each row must have length ${length}.`);
|
||||
input.split(recordDelimiter).forEach((row, rowIndex) => {
|
||||
const split = row.split(fieldDelimiter);
|
||||
if (split.length !== length) throw new OperationError(`Each row must have length ${length}.`);
|
||||
|
||||
if (columnHeadingsAreIncluded && rowIndex === 0) {
|
||||
headings = split;
|
||||
} else {
|
||||
values.push(split);
|
||||
}
|
||||
});
|
||||
if (columnHeadingsAreIncluded && rowIndex === 0) {
|
||||
headings = split;
|
||||
} else {
|
||||
values.push(split);
|
||||
}
|
||||
});
|
||||
return { headings, values };
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets values from input for a scatter plot.
|
||||
*
|
||||
|
@ -74,19 +68,13 @@ export function getValues(input, recordDelimiter, fieldDelimiter, columnHeadings
|
|||
* @returns {Object[]}
|
||||
*/
|
||||
export function getScatterValues(input, recordDelimiter, fieldDelimiter, columnHeadingsAreIncluded) {
|
||||
let { headings, values } = getValues(
|
||||
input,
|
||||
recordDelimiter,
|
||||
fieldDelimiter,
|
||||
columnHeadingsAreIncluded,
|
||||
2
|
||||
);
|
||||
let { headings, values } = getValues(input, recordDelimiter, fieldDelimiter, columnHeadingsAreIncluded, 2);
|
||||
|
||||
if (headings) {
|
||||
headings = {x: headings[0], y: headings[1]};
|
||||
headings = { x: headings[0], y: headings[1] };
|
||||
}
|
||||
|
||||
values = values.map(row => {
|
||||
values = values.map((row) => {
|
||||
const x = parseFloat(row[0]),
|
||||
y = parseFloat(row[1]);
|
||||
|
||||
|
@ -99,7 +87,6 @@ export function getScatterValues(input, recordDelimiter, fieldDelimiter, columnH
|
|||
return { headings, values };
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets values from input for a scatter plot with colour from the third column.
|
||||
*
|
||||
|
@ -110,18 +97,13 @@ export function getScatterValues(input, recordDelimiter, fieldDelimiter, columnH
|
|||
* @returns {Object[]}
|
||||
*/
|
||||
export function getScatterValuesWithColour(input, recordDelimiter, fieldDelimiter, columnHeadingsAreIncluded) {
|
||||
let { headings, values } = getValues(
|
||||
input,
|
||||
recordDelimiter, fieldDelimiter,
|
||||
columnHeadingsAreIncluded,
|
||||
3
|
||||
);
|
||||
let { headings, values } = getValues(input, recordDelimiter, fieldDelimiter, columnHeadingsAreIncluded, 3);
|
||||
|
||||
if (headings) {
|
||||
headings = {x: headings[0], y: headings[1]};
|
||||
headings = { x: headings[0], y: headings[1] };
|
||||
}
|
||||
|
||||
values = values.map(row => {
|
||||
values = values.map((row) => {
|
||||
const x = parseFloat(row[0]),
|
||||
y = parseFloat(row[1]),
|
||||
colour = row[2];
|
||||
|
@ -145,17 +127,12 @@ export function getScatterValuesWithColour(input, recordDelimiter, fieldDelimite
|
|||
* @returns {Object[]}
|
||||
*/
|
||||
export function getSeriesValues(input, recordDelimiter, fieldDelimiter, columnHeadingsAreIncluded) {
|
||||
const { values } = getValues(
|
||||
input,
|
||||
recordDelimiter, fieldDelimiter,
|
||||
false,
|
||||
3
|
||||
);
|
||||
const { values } = getValues(input, recordDelimiter, fieldDelimiter, false, 3);
|
||||
|
||||
let xValues = new Set();
|
||||
const series = {};
|
||||
|
||||
values.forEach(row => {
|
||||
values.forEach((row) => {
|
||||
const serie = row[0],
|
||||
xVal = row[1],
|
||||
val = parseFloat(row[2]);
|
||||
|
@ -172,7 +149,7 @@ export function getSeriesValues(input, recordDelimiter, fieldDelimiter, columnHe
|
|||
const seriesList = [];
|
||||
for (const seriesName in series) {
|
||||
const serie = series[seriesName];
|
||||
seriesList.push({name: seriesName, data: serie});
|
||||
seriesList.push({ name: seriesName, data: serie });
|
||||
}
|
||||
|
||||
return { xValues, series: seriesList };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue