Explorar el Código

typescriptize and change exporting way

Yuki Takei hace 3 años
padre
commit
c1112f3332

+ 3 - 0
packages/remark-growi-plugin/src/index.ts

@@ -0,0 +1,3 @@
+import { remarkGrowiPlugin } from './remark-growi-plugin';
+
+export default remarkGrowiPlugin;

+ 13 - 24
packages/remark-growi-plugin/src/remark-growi-plugin.ts

@@ -1,35 +1,24 @@
-/**
- * @typedef {import('mdast').Root} Root
- *
- * @typedef {import('mdast-util-directive')} DoNotTouchAsThisImportIncludesDirectivesInTree
- */
+import { Plugin } from 'unified';
 
 import { directiveFromMarkdown, directiveToMarkdown } from './mdast-util-growi-plugin';
 import { directive } from './micromark-extension-growi-plugin/dev';
 
-/**
-  * Plugin to support GROWI plugin (`$lsx(/path, depth=2)`).
-  *
-  * @type {import('unified').Plugin<void[], Root>}
-  */
-export default function remarkGrowiPlugin() {
+export const remarkGrowiPlugin: Plugin = function() {
   const data = this.data();
 
-  /**
-    * @param {string} field
-    * @param {unknown} value
-    */
-  function add(field, value) {
-    const list = /** @type {unknown[]} */ (
-      // Other extensions
-      /* c8 ignore next 2 */
-      data[field] ? data[field] : (data[field] = [])
-    );
-
-    list.push(value);
+  function add(field: string, value) {
+    if (data[field] != null) {
+      const array = data[field];
+      if (Array.isArray(array)) {
+        array.push(value);
+      }
+    }
+    else {
+      data[field] = [value];
+    }
   }
 
   add('micromarkExtensions', directive());
   add('fromMarkdownExtensions', directiveFromMarkdown);
   add('toMarkdownExtensions', directiveToMarkdown);
-}
+};