myst-frontmatter
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.unnestKernelSpec = exports.fillPageFrontmatter = exports.validatePageFrontmatter = exports.validateProjectFrontmatter = exports.validatePageFrontmatterKeys = exports.validateProjectFrontmatterKeys = exports.validateSiteFrontmatterKeys = exports.validateGithubUrl = exports.validateExport = exports.validateJupytext = exports.validateKernelSpec = exports.validateNumbering = exports.validateBiblio = exports.validateAuthor = exports.validateVenue = exports.RESERVED_EXPORT_KEYS = exports.USE_PROJECT_FALLBACK = exports.PAGE_FRONTMATTER_KEYS = exports.PROJECT_FRONTMATTER_KEYS = exports.SITE_FRONTMATTER_KEYS = void 0; | ||
exports.unnestKernelSpec = exports.fillPageFrontmatter = exports.validatePageFrontmatter = exports.validateProjectFrontmatter = exports.validatePageFrontmatterKeys = exports.validateProjectFrontmatterKeys = exports.validateSiteFrontmatterKeys = exports.validateGithubUrl = exports.validateExport = exports.validateExportsList = exports.validateJupytext = exports.validateKernelSpec = exports.validateNumbering = exports.validateBiblio = exports.validateAuthor = exports.validateVenue = exports.RESERVED_EXPORT_KEYS = exports.USE_PROJECT_FALLBACK = exports.PAGE_FRONTMATTER_KEYS = exports.PROJECT_FRONTMATTER_KEYS = exports.SITE_FRONTMATTER_KEYS = void 0; | ||
const doi_utils_1 = __importDefault(require("doi-utils")); | ||
@@ -80,2 +80,3 @@ const credit_roles_1 = __importDefault(require("credit-roles")); | ||
role: 'roles', | ||
affiliation: 'affiliations', | ||
}; | ||
@@ -103,2 +104,3 @@ const BIBLIO_KEYS = ['volume', 'issue', 'first_page', 'last_page']; | ||
affiliation: 'affiliations', | ||
export: 'exports', | ||
}; | ||
@@ -159,3 +161,3 @@ const GITHUB_USERNAME_REPO_REGEX = '^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$'; | ||
else { | ||
(0, simple_validators_1.validationError)(`OCRID "${value.orcid}" is not valid, try an ID of the form "0000-0000-0000-0000"`, orcidOpts); | ||
(0, simple_validators_1.validationError)(`ORCID "${value.orcid}" is not valid, try an ID of the form "0000-0000-0000-0000"`, orcidOpts); | ||
} | ||
@@ -194,4 +196,9 @@ } | ||
const affiliationsOpts = (0, simple_validators_1.incrementOptions)('affiliations', opts); | ||
output.affiliations = (0, simple_validators_1.validateList)(value.affiliations, affiliationsOpts, (aff) => { | ||
return (0, simple_validators_1.validateString)(aff, affiliationsOpts); | ||
let affiliations = value.affiliations; | ||
if (typeof affiliations === 'string') { | ||
affiliations = affiliations.split(';'); | ||
} | ||
output.affiliations = (0, simple_validators_1.validateList)(affiliations, affiliationsOpts, (aff) => { | ||
var _a; | ||
return (_a = (0, simple_validators_1.validateString)(aff, affiliationsOpts)) === null || _a === void 0 ? void 0 : _a.trim(); | ||
}); | ||
@@ -319,3 +326,3 @@ } | ||
if ((0, simple_validators_1.defined)(value.format_version)) { | ||
// The format version ocassionally comes as a number in YAML, treat it as a string | ||
// The format version occasionally comes as a number in YAML, treat it as a string | ||
const format_version = typeof value.format_version === 'number' | ||
@@ -350,2 +357,35 @@ ? String(value.format_version) | ||
exports.validateJupytext = validateJupytext; | ||
function validateExportsList(input, opts) { | ||
// Allow a single export to be defined as a dict | ||
if (input === undefined) | ||
return undefined; | ||
let exports; | ||
if (Array.isArray(input)) { | ||
exports = input; | ||
} | ||
else if (typeof input === 'string') { | ||
const format = validateExportFormat(input, opts); | ||
if (!format) | ||
return undefined; | ||
exports = [{ format }]; | ||
} | ||
else { | ||
exports = [input]; | ||
} | ||
const output = (0, simple_validators_1.validateList)(exports, (0, simple_validators_1.incrementOptions)('exports', opts), (exp, ind) => { | ||
return validateExport(exp, (0, simple_validators_1.incrementOptions)(`exports.${ind}`, opts)); | ||
}); | ||
if (!output || output.length === 0) | ||
return undefined; | ||
return output; | ||
} | ||
exports.validateExportsList = validateExportsList; | ||
function validateExportFormat(input, opts) { | ||
if (input === undefined) | ||
return undefined; | ||
if (input === 'tex+pdf') | ||
input = 'pdf+tex'; | ||
const format = (0, simple_validators_1.validateEnum)(input, Object.assign(Object.assign({}, opts), { enum: types_1.ExportFormats })); | ||
return format; | ||
} | ||
function validateExport(input, opts) { | ||
@@ -356,7 +396,3 @@ const value = (0, simple_validators_1.validateObject)(input, opts); | ||
(0, simple_validators_1.validateKeys)(value, { required: ['format'], optional: exports.RESERVED_EXPORT_KEYS }, Object.assign(Object.assign({}, opts), { suppressWarnings: true })); | ||
if (value.format === undefined) | ||
return undefined; | ||
if (value.format === 'tex+pdf') | ||
value.format = 'pdf+tex'; | ||
const format = (0, simple_validators_1.validateEnum)(value.format, Object.assign(Object.assign({}, (0, simple_validators_1.incrementOptions)('format', opts)), { enum: types_1.ExportFormats })); | ||
const format = validateExportFormat(value.format, (0, simple_validators_1.incrementOptions)('format', opts)); | ||
if (format === undefined) | ||
@@ -391,2 +427,3 @@ return undefined; | ||
function validateSiteFrontmatterKeys(value, opts) { | ||
var _a, _b; | ||
const output = {}; | ||
@@ -402,3 +439,3 @@ if ((0, simple_validators_1.defined)(value.title)) { | ||
// Turn a string into a list of strings, this will be transformed later | ||
if (typeof value.authors === 'string') { | ||
if (!Array.isArray(value.authors)) { | ||
authors = [authors]; | ||
@@ -409,2 +446,8 @@ } | ||
}); | ||
// Ensure there is a corresponding author if an email is provided | ||
const corresponding = (_a = output.authors) === null || _a === void 0 ? void 0 : _a.find((a) => a.corresponding !== undefined); | ||
const email = (_b = output.authors) === null || _b === void 0 ? void 0 : _b.find((a) => a.email); | ||
if (!corresponding && email) { | ||
email.corresponding = true; | ||
} | ||
} | ||
@@ -418,3 +461,7 @@ if ((0, simple_validators_1.defined)(value.venue)) { | ||
if ((0, simple_validators_1.defined)(value.keywords)) { | ||
output.keywords = (0, simple_validators_1.validateList)(value.keywords, (0, simple_validators_1.incrementOptions)('keywords', opts), (word, ind) => { | ||
let keywords = value.keywords; | ||
if (typeof keywords === 'string') { | ||
keywords = keywords.split(/[,;]/).map((k) => k.trim()); | ||
} | ||
output.keywords = (0, simple_validators_1.validateList)(keywords, (0, simple_validators_1.incrementOptions)('keywords', opts), (word, ind) => { | ||
return (0, simple_validators_1.validateString)(word, (0, simple_validators_1.incrementOptions)(`keywords.${ind}`, opts)); | ||
@@ -497,5 +544,5 @@ }); | ||
if ((0, simple_validators_1.defined)(value.exports)) { | ||
output.exports = (0, simple_validators_1.validateList)(value.exports, (0, simple_validators_1.incrementOptions)('exports', opts), (exp, ind) => { | ||
return validateExport(exp, (0, simple_validators_1.incrementOptions)(`exports.${ind}`, opts)); | ||
}); | ||
const exports = validateExportsList(value.exports, opts); | ||
if (exports) | ||
output.exports = exports; | ||
} | ||
@@ -548,3 +595,3 @@ // This is only for the project, and is not defined on pages | ||
if ((0, simple_validators_1.defined)(value.thumbnailOptimized)) { | ||
// No validation, this is expected to be set programatically | ||
// No validation, this is expected to be set programmatically | ||
output.thumbnailOptimized = value.thumbnailOptimized; | ||
@@ -551,0 +598,0 @@ } |
@@ -10,2 +10,12 @@ "use strict"; | ||
const licenses_1 = __importDefault(require("./licenses")); | ||
function correctLicense(license) { | ||
if (!license) | ||
return undefined; | ||
const value = (0, spdx_correct_1.default)(license); | ||
if (value) | ||
return value; | ||
if (license.toUpperCase() === 'CC-BY') | ||
return 'CC-BY-4.0'; | ||
return undefined; | ||
} | ||
function createURL(license) { | ||
@@ -83,3 +93,3 @@ var _a, _b; | ||
// Correct expects a non-empty string | ||
const value = valueUnvalidated ? (0, spdx_correct_1.default)(valueUnvalidated) : valueUnvalidated; | ||
const value = correctLicense(valueUnvalidated); | ||
if (!value) { | ||
@@ -86,0 +96,0 @@ return (0, simple_validators_1.validationError)(`invalid value "${valueUnvalidated}" - must be a valid license ID, see https://spdx.org/licenses/`, opts); |
@@ -73,2 +73,3 @@ import doi from 'doi-utils'; | ||
role: 'roles', | ||
affiliation: 'affiliations', | ||
}; | ||
@@ -96,2 +97,3 @@ const BIBLIO_KEYS = ['volume', 'issue', 'first_page', 'last_page']; | ||
affiliation: 'affiliations', | ||
export: 'exports', | ||
}; | ||
@@ -151,3 +153,3 @@ const GITHUB_USERNAME_REPO_REGEX = '^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$'; | ||
else { | ||
validationError(`OCRID "${value.orcid}" is not valid, try an ID of the form "0000-0000-0000-0000"`, orcidOpts); | ||
validationError(`ORCID "${value.orcid}" is not valid, try an ID of the form "0000-0000-0000-0000"`, orcidOpts); | ||
} | ||
@@ -186,4 +188,9 @@ } | ||
const affiliationsOpts = incrementOptions('affiliations', opts); | ||
output.affiliations = validateList(value.affiliations, affiliationsOpts, (aff) => { | ||
return validateString(aff, affiliationsOpts); | ||
let affiliations = value.affiliations; | ||
if (typeof affiliations === 'string') { | ||
affiliations = affiliations.split(';'); | ||
} | ||
output.affiliations = validateList(affiliations, affiliationsOpts, (aff) => { | ||
var _a; | ||
return (_a = validateString(aff, affiliationsOpts)) === null || _a === void 0 ? void 0 : _a.trim(); | ||
}); | ||
@@ -307,3 +314,3 @@ } | ||
if (defined(value.format_version)) { | ||
// The format version ocassionally comes as a number in YAML, treat it as a string | ||
// The format version occasionally comes as a number in YAML, treat it as a string | ||
const format_version = typeof value.format_version === 'number' | ||
@@ -337,2 +344,34 @@ ? String(value.format_version) | ||
} | ||
export function validateExportsList(input, opts) { | ||
// Allow a single export to be defined as a dict | ||
if (input === undefined) | ||
return undefined; | ||
let exports; | ||
if (Array.isArray(input)) { | ||
exports = input; | ||
} | ||
else if (typeof input === 'string') { | ||
const format = validateExportFormat(input, opts); | ||
if (!format) | ||
return undefined; | ||
exports = [{ format }]; | ||
} | ||
else { | ||
exports = [input]; | ||
} | ||
const output = validateList(exports, incrementOptions('exports', opts), (exp, ind) => { | ||
return validateExport(exp, incrementOptions(`exports.${ind}`, opts)); | ||
}); | ||
if (!output || output.length === 0) | ||
return undefined; | ||
return output; | ||
} | ||
function validateExportFormat(input, opts) { | ||
if (input === undefined) | ||
return undefined; | ||
if (input === 'tex+pdf') | ||
input = 'pdf+tex'; | ||
const format = validateEnum(input, Object.assign(Object.assign({}, opts), { enum: ExportFormats })); | ||
return format; | ||
} | ||
export function validateExport(input, opts) { | ||
@@ -343,7 +382,3 @@ const value = validateObject(input, opts); | ||
validateKeys(value, { required: ['format'], optional: RESERVED_EXPORT_KEYS }, Object.assign(Object.assign({}, opts), { suppressWarnings: true })); | ||
if (value.format === undefined) | ||
return undefined; | ||
if (value.format === 'tex+pdf') | ||
value.format = 'pdf+tex'; | ||
const format = validateEnum(value.format, Object.assign(Object.assign({}, incrementOptions('format', opts)), { enum: ExportFormats })); | ||
const format = validateExportFormat(value.format, incrementOptions('format', opts)); | ||
if (format === undefined) | ||
@@ -376,2 +411,3 @@ return undefined; | ||
export function validateSiteFrontmatterKeys(value, opts) { | ||
var _a, _b; | ||
const output = {}; | ||
@@ -387,3 +423,3 @@ if (defined(value.title)) { | ||
// Turn a string into a list of strings, this will be transformed later | ||
if (typeof value.authors === 'string') { | ||
if (!Array.isArray(value.authors)) { | ||
authors = [authors]; | ||
@@ -394,2 +430,8 @@ } | ||
}); | ||
// Ensure there is a corresponding author if an email is provided | ||
const corresponding = (_a = output.authors) === null || _a === void 0 ? void 0 : _a.find((a) => a.corresponding !== undefined); | ||
const email = (_b = output.authors) === null || _b === void 0 ? void 0 : _b.find((a) => a.email); | ||
if (!corresponding && email) { | ||
email.corresponding = true; | ||
} | ||
} | ||
@@ -403,3 +445,7 @@ if (defined(value.venue)) { | ||
if (defined(value.keywords)) { | ||
output.keywords = validateList(value.keywords, incrementOptions('keywords', opts), (word, ind) => { | ||
let keywords = value.keywords; | ||
if (typeof keywords === 'string') { | ||
keywords = keywords.split(/[,;]/).map((k) => k.trim()); | ||
} | ||
output.keywords = validateList(keywords, incrementOptions('keywords', opts), (word, ind) => { | ||
return validateString(word, incrementOptions(`keywords.${ind}`, opts)); | ||
@@ -481,5 +527,5 @@ }); | ||
if (defined(value.exports)) { | ||
output.exports = validateList(value.exports, incrementOptions('exports', opts), (exp, ind) => { | ||
return validateExport(exp, incrementOptions(`exports.${ind}`, opts)); | ||
}); | ||
const exports = validateExportsList(value.exports, opts); | ||
if (exports) | ||
output.exports = exports; | ||
} | ||
@@ -531,3 +577,3 @@ // This is only for the project, and is not defined on pages | ||
if (defined(value.thumbnailOptimized)) { | ||
// No validation, this is expected to be set programatically | ||
// No validation, this is expected to be set programmatically | ||
output.thumbnailOptimized = value.thumbnailOptimized; | ||
@@ -534,0 +580,0 @@ } |
import { validationWarning, defined, incrementOptions, validateObjectKeys, validateString, validationError, } from 'simple-validators'; | ||
import correct from 'spdx-correct'; | ||
import spdxCorrect from 'spdx-correct'; | ||
import LICENSES from './licenses'; | ||
function correctLicense(license) { | ||
if (!license) | ||
return undefined; | ||
const value = spdxCorrect(license); | ||
if (value) | ||
return value; | ||
if (license.toUpperCase() === 'CC-BY') | ||
return 'CC-BY-4.0'; | ||
return undefined; | ||
} | ||
function createURL(license) { | ||
@@ -76,3 +86,3 @@ var _a, _b; | ||
// Correct expects a non-empty string | ||
const value = valueUnvalidated ? correct(valueUnvalidated) : valueUnvalidated; | ||
const value = correctLicense(valueUnvalidated); | ||
if (!value) { | ||
@@ -79,0 +89,0 @@ return validationError(`invalid value "${valueUnvalidated}" - must be a valid license ID, see https://spdx.org/licenses/`, opts); |
@@ -69,2 +69,4 @@ import type { CreditRole } from 'credit-roles'; | ||
title?: string; | ||
subtitle?: string; | ||
short_title?: string; | ||
description?: string; | ||
@@ -100,4 +102,2 @@ authors?: Author[]; | ||
export declare type PageFrontmatter = Omit<ProjectFrontmatter, 'references'> & { | ||
subtitle?: string; | ||
short_title?: string; | ||
kernelspec?: KernelSpec; | ||
@@ -104,0 +104,0 @@ jupytext?: Jupytext; |
@@ -38,2 +38,3 @@ import type { ValidationOptions } from 'simple-validators'; | ||
export declare function validateJupytext(input: any, opts: ValidationOptions): Jupytext | undefined; | ||
export declare function validateExportsList(input: any, opts: ValidationOptions): Export[] | undefined; | ||
export declare function validateExport(input: any, opts: ValidationOptions): Export | undefined; | ||
@@ -40,0 +41,0 @@ export declare function validateGithubUrl(value: any, opts: ValidationOptions): string | undefined; |
{ | ||
"name": "myst-frontmatter", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"sideEffects": false, | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
154651
3124
0