From 78d14cdfea3bb69c35e5e3d7f3123ba5c3e14f2f Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Thu, 12 Jan 2023 13:10:22 +0100 Subject: [PATCH] automatically print synonyms in doc --- packages/core/pattern.mjs | 29 ++++++++++------------------- website/src/docs/JsDoc.jsx | 14 +++++++++++++- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index cfeeeed5..3052a805 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -733,7 +733,7 @@ export class Pattern { } /** - * Appends the given pattern(s) to the current pattern. Synonyms: .sequence .fastcat + * Appends the given pattern(s) to the current pattern. * @name seq * @memberof Pattern * @synonyms sequence, fastcat @@ -747,7 +747,7 @@ export class Pattern { } /** - * Appends the given pattern(s) to the next cycle. Synonym: .slowcat + * Appends the given pattern(s) to the next cycle. * @name cat * @memberof Pattern * @synonyms slowcat @@ -1191,24 +1191,10 @@ export function slowcatPrime(...pats) { return new Pattern(query).splitQueries(); } -/** Concatenation: as with {@link slowcat}, but squashes a cycle from each pattern into one cycle - * - * Synonyms: {@link Pattern.seq}, {@link Pattern.sequence} - * - * @param {...any} items - The items to concatenate - * @return {Pattern} - * @example - * fastcat(e5, b4, [d5, c5]) - * // sequence(e5, b4, [d5, c5]) - * // seq(e5, b4, [d5, c5]) - */ -export function fastcat(...pats) { - return slowcat(...pats)._fast(pats.length); -} - -/** The given items are con**cat**enated, where each one takes one cycle. Synonym: slowcat +/** The given items are con**cat**enated, where each one takes one cycle. * * @param {...any} items - The items to concatenate + * @synonyms slowcat * @return {Pattern} * @example * cat(e5, b4, [d5, c5]).note() // "".note() @@ -1235,12 +1221,17 @@ export function timeCat(...timepats) { return stack(...pats); } +export function fastcat(...pats) { + return slowcat(...pats)._fast(pats.length); +} + /** See {@link fastcat} */ export function sequence(...pats) { return fastcat(...pats); } -/** Like **cat**, but the items are crammed into one cycle. Synonyms: fastcat, sequence +/** Like **cat**, but the items are crammed into one cycle. + * @synonyms fastcat, sequence * @example * seq(e5, b4, [d5, c5]).note() // "e5 b4 [d5 c5]".note() * diff --git a/website/src/docs/JsDoc.jsx b/website/src/docs/JsDoc.jsx index 3c8dd1eb..f0c3b900 100644 --- a/website/src/docs/JsDoc.jsx +++ b/website/src/docs/JsDoc.jsx @@ -2,12 +2,15 @@ import jsdoc from '../../../doc.json'; // doc.json is built with `npm run jsdoc- const docs = jsdoc.docs.reduce((acc, obj) => Object.assign(acc, { [obj.longname]: obj }), {}); import { MiniRepl } from './MiniRepl'; +const getTag = (title, item) => item.tags?.find((t) => t.title === title)?.text; + export function JsDoc({ name, h = 3, hideDescription }) { const item = docs[name]; if (!item) { console.warn('Not found: ' + name); return
; } + const synonyms = getTag('synonyms', item)?.split(', ') || []; const CustomHeading = `h${h}`; const description = item.description.replaceAll(/\{@link ([a-zA-Z\.]+)?#?([a-zA-Z]*)\}/g, (_, a, b) => { // console.log(_, 'a', a, 'b', b); @@ -16,7 +19,16 @@ export function JsDoc({ name, h = 3, hideDescription }) { return ( <> {!!h && {item.longname}} - {!hideDescription &&
} + {!hideDescription && ( + <> + {!!synonyms.length && ( + + Synonyms: {synonyms.join(', ')} + + )} +
+ + )}
    {item.params?.map((param, i) => (