Skip to content

Commit

Permalink
Restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Mar 15, 2024
1 parent 2d9f06f commit 798731f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
27 changes: 1 addition & 26 deletions src/nodeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const klaw = require('klaw');
const fs = require('fs-extra');
const path = require('path');

const { isUrl, isObject } = require('./utils');
const { isUrl, makeAjvErrorMessage } = require('./utils');

const SCHEMA_CHOICE = ['anyOf', 'oneOf'];

Expand Down Expand Up @@ -173,31 +173,6 @@ function isSchemaChoice(schemaPath) {
return typeof schemaPath === 'string' && schemaPath.match(/\/(one|any)Of\/\d+\//);
}

function makeAjvErrorMessage(error) {
let message = error.message;
if (isObject(error.params) && Object.keys(error.params).length > 0) {
let params = Object.entries(error.params)
.map(([key, value]) => {
let label = key.replace(/([^A-Z]+)([A-Z])/g, "$1 $2").toLowerCase();
return `${label}: ${value}`;
})
.join(', ')
message += ` (${params})`;
}
if (error.instancePath) {
return `${error.instancePath} ${message}`;
}
else if (error.schemaPath) {
return `${message}, for schema ${error.schemaPath}`;
}
else if (message) {
return message;
}
else {
return String(error);
}
}

async function resolveFiles(files, depth = -1) {
const resolved = [];
const extensions = [".geojson", ".json"];
Expand Down
26 changes: 26 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,37 @@ function getSummary(result, config) {
return summary;
}

function makeAjvErrorMessage(error) {
let message = error.message;
if (isObject(error.params) && Object.keys(error.params).length > 0) {
let params = Object.entries(error.params)
.map(([key, value]) => {
let label = key.replace(/([^A-Z]+)([A-Z])/g, "$1 $2").toLowerCase();
return `${label}: ${value}`;
})
.join(', ')
message += ` (${params})`;
}
if (error.instancePath) {
return `${error.instancePath} ${message}`;
}
else if (error.schemaPath) {
return `${message}, for schema ${error.schemaPath}`;
}
else if (message) {
return message;
}
else {
return String(error);
}
}

module.exports = {
createAjv,
getSummary,
isObject,
isUrl,
loadSchemaFromUri,
makeAjvErrorMessage,
normalizePath
};

0 comments on commit 798731f

Please sign in to comment.