Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const bytype = type => flist(pipe(
schemas,
filter(schema => schema[keyword`type`] === type), // remove schemas without matching type
filter(schema => !!schema[s.parent]), // keep only schemas with a parent
mapSort(schema => gentitle(schema[s.titles], schema[keyword`type`])),
map(schema => listItem(paragraph([
link(`./${schema[s.slug]}.md`, gendescription(schema), [text(gentitle(schema[s.titles], schema[keyword`type`]))]),
text(' – '),
inlineCode(`${schema[s.id]}#${schema[s.pointer]}`),
]))),
), Array);
const bytype = type => flist(pipe(
schemas,
filter(schema => schema[keyword`type`] === type), // remove schemas without matching type
filter(schema => !!schema[s.parent]), // keep only schemas with a parent
mapSort(schema => gentitle(schema[s.titles], schema[keyword`type`])),
map(schema => listItem(paragraph([
link(`./${schema[s.slug]}.md`, gendescription(schema), [text(gentitle(schema[s.titles], schema[keyword`type`]))]),
text(' – '),
inlineCode(`${schema[s.id]}#${schema[s.pointer]}`),
]))),
), Array);
map(([idx, nod]) => {
const mat = nodeStr(idx).match(re(`(?<=^|\\n)---${hspace}*\\n?$`));
if (!mat) {
return null;
}
// Offset of the actual separator line (this may deviate from the)
const offStart = mat.index + start(idx);
const offEnd = offStart + size(mat[0]);
// Is there a new line or EOF before/after the separator?
const before = Boolean(str.slice(0, offStart).match(re(`(^|(^|\\n)${hspace}*\\n)$`)));
const after = Boolean(str.slice(offEnd).match(re(`^(${hspace}*(\\n${hspace}*(\\n|$))|$)`)));
return {
idx, nod, offStart, offEnd, before, after,
};
}),
filter(identity),
// Pair up two fences each; we even do this if there is only a single
// fence (even though by definition that could never form a frontmatter
// block) in order to warn about ambiguous nodes
lookahead(1, null),
// Filter out pairs in which both the start and the end is definately
// a settext heading or <hr>
reject(([fst, last]) => toIgnore(fst) && toIgnore(last)),
// Decide which blocks to ignore, which deserve warnings and which
// are actual frontmatter
procwarnigns,
filter(identity),
// Filter out false positive warnings for pseudo frontmatter blocks
// before actual frontmatter (warning gets invalidated by the fact
// that it DIRECTLY PRECEDES an actual frontmatter block)
lookahead(1, null),
reject(([val, next]) => true
}
return {
type: 'frontmatter',
payload: data,
start: fst.idx,
end: last.idx,
};
});
// Preprocessing
return pipe(
enumerate(mdast.children),
// Find any potential frontmatter starts/ends in the mdast
/* eslint-disable-next-line no-unused-vars */
filter(([idx, nod]) => isPotential(nod)),
// Filter out dom nodes based on their actual text content;
// this filters out HRs made from other characters or setext
// headings with more than three dashes...
//
// And: Perform some more sophisticated feature extraction on the nodes
map(([idx, nod]) => {
const mat = nodeStr(idx).match(re(`(?<=^|\\n)---${hspace}*\\n?$`));
if (!mat) {
return null;
}
// Offset of the actual separator line (this may deviate from the)
const offStart = mat.index + start(idx);
const offEnd = offStart + size(mat[0]);
// Is there a new line or EOF before/after the separator?
const before = Boolean(str.slice(0, offStart).match(re(`(^|(^|\\n)${hspace}*\\n)$`)));
const after = Boolean(str.slice(offEnd).match(re(`^(${hspace}*(\\n${hspace}*(\\n|$))|$)`)));
return {
idx, nod, offStart, offEnd, before, after,
};
}),
filter(identity),
// Pair up two fences each; we even do this if there is only a single
// fence (even though by definition that could never form a frontmatter
// block) in order to warn about ambiguous nodes
lookahead(1, null),
// Filter out pairs in which both the start and the end is definately
// a settext heading or <hr>
reject(([fst, last]) => toIgnore(fst) && toIgnore(last)),
// Decide which blocks to ignore, which deserve warnings and which
// are actual frontmatter
procwarnigns,
filter(identity),
// Filter out false positive warnings for pseudo frontmatter blocks
// before actual frontmatter (warning gets invalidated by the fact
// that it DIRECTLY PRECEDES an actual frontmatter block)
lookahead(1, null),
reject(([val, next]) => true
&& val.type === 'warning'
&& val.warning.startsWith('Found ambigous frontmatter')
&& next
&& next.type === 'frontmatter'
&& val.end === next.start),
/* eslint-disable-next-line no-unused-vars */
map(([val, next]) => val),
);
};
function nullable(property) {
const types = Array.isArray(property[keyword`type`]) ? property[keyword`type`] : [property[keyword`type`]];
const nulltypes = flist(filter(types, mytype => mytype === keyword`null`));
if (size(nulltypes)) {
return text(i18n`can be null`);
}
return text(i18n`cannot be null`);
}
function type(property) {
const types = Array.isArray(property[keyword`type`]) ? property[keyword`type`] : [property[keyword`type`]];
const realtypes = flist(filter(types, mytype => mytype !== 'null' && mytype !== undefined));
if (property[keyword`allOf`] || property[keyword`anyOf`] || property[keyword`oneOf`] || property[keyword`not`]) {
return text(i18n`Merged`);
} else if (size(realtypes) === 0) {
return text(i18n`Not specified`);
}
return (size(realtypes) === 1) ? inlineCode(realtypes[0]) : text(i18n`Multiple`);
}