@wrikka/create-docs 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +137 -0
- package/bin/cli.js +408 -0
- package/dist/index.cjs +20 -0
- package/dist/index.d.cts +475 -0
- package/dist/index.d.ts +475 -0
- package/dist/index.js +20 -0
- package/docs/_dir.yml +2 -0
- package/docs/config.md +75 -0
- package/docs/data-sources.md +88 -0
- package/docs/deploy.md +38 -0
- package/docs/features.md +51 -0
- package/docs/getting-started.md +42 -0
- package/docs/index.md +34 -0
- package/docs/markdown.md +154 -0
- package/docs/theming.md +53 -0
- package/package.json +142 -0
- package/scripts/generate-docs-index.ts +111 -0
- package/scripts/github-pull.ts +124 -0
- package/src/adapters/config/index.ts +1 -0
- package/src/adapters/config/node-config-loader.ts +36 -0
- package/src/adapters/fs/fs-docs-loader.ts +31 -0
- package/src/adapters/fs/index.ts +12 -0
- package/src/adapters/fs/memory-fs.ts +60 -0
- package/src/adapters/fs/node-fs.ts +116 -0
- package/src/adapters/git/index.ts +164 -0
- package/src/adapters/github/github-pull.ts +340 -0
- package/src/adapters/index.ts +6 -0
- package/src/adapters/velite.ts +112 -0
- package/src/adapters/vite/docs-watcher.ts +36 -0
- package/src/adapters/vite/index.ts +2 -0
- package/src/adapters/vite/polling-watcher.ts +89 -0
- package/src/code-block-enhancements/index.ts +3 -0
- package/src/config/index.ts +15 -0
- package/src/content/index.ts +11 -0
- package/src/content-validation/index.ts +5 -0
- package/src/index.ts +174 -0
- package/src/live-editor/index.ts +7 -0
- package/src/modules/analytics/application/plausible-adapter.ts +103 -0
- package/src/modules/analytics/application/umami-adapter.ts +109 -0
- package/src/modules/analytics/domain/events/index.ts +37 -0
- package/src/modules/analytics/domain/models/index.ts +35 -0
- package/src/modules/analytics/domain/operations/analytics-operations.ts +67 -0
- package/src/modules/analytics/domain/validators/index.ts +50 -0
- package/src/modules/analytics/index.ts +9 -0
- package/src/modules/analytics/ports/analytics-port.ts +17 -0
- package/src/modules/analytics/types/analytics.ts +16 -0
- package/src/modules/api-docs/application/type-docs-adapter.ts +34 -0
- package/src/modules/api-docs/domain/events/index.ts +42 -0
- package/src/modules/api-docs/domain/models/index.ts +40 -0
- package/src/modules/api-docs/domain/operations/api-docs-operations.ts +59 -0
- package/src/modules/api-docs/domain/validators/index.ts +56 -0
- package/src/modules/api-docs/index.ts +8 -0
- package/src/modules/api-docs/ports/api-docs-port.ts +21 -0
- package/src/modules/api-docs/types/api-docs.ts +15 -0
- package/src/modules/api-reference/openapi.ts +166 -0
- package/src/modules/api-reference/orpc.ts +94 -0
- package/src/modules/code-block-enhancements/application/usecases/index.ts +39 -0
- package/src/modules/code-block-enhancements/domain/code-operations.ts +72 -0
- package/src/modules/code-block-enhancements/domain/events/index.ts +58 -0
- package/src/modules/code-block-enhancements/domain/index.ts +11 -0
- package/src/modules/code-block-enhancements/domain/models/index.ts +36 -0
- package/src/modules/code-block-enhancements/domain/validators/index.ts +50 -0
- package/src/modules/code-block-enhancements/index.ts +10 -0
- package/src/modules/code-block-enhancements/ports/index.ts +18 -0
- package/src/modules/code-block-enhancements/types/index.ts +37 -0
- package/src/modules/code-execution/application/sandbox-adapter.ts +44 -0
- package/src/modules/code-execution/domain/events/index.ts +58 -0
- package/src/modules/code-execution/domain/models/index.ts +33 -0
- package/src/modules/code-execution/domain/operations/execution-operations.ts +60 -0
- package/src/modules/code-execution/domain/validators/index.ts +50 -0
- package/src/modules/code-execution/index.ts +8 -0
- package/src/modules/code-execution/ports/execution-port.ts +15 -0
- package/src/modules/code-execution/types/execution.ts +15 -0
- package/src/modules/comments/application/giscus-adapter.ts +55 -0
- package/src/modules/comments/domain/events/index.ts +55 -0
- package/src/modules/comments/domain/models/index.ts +30 -0
- package/src/modules/comments/domain/operations/comment-operations.ts +46 -0
- package/src/modules/comments/domain/validators/index.ts +50 -0
- package/src/modules/comments/index.ts +8 -0
- package/src/modules/comments/ports/comment-port.ts +18 -0
- package/src/modules/comments/types/comments.ts +19 -0
- package/src/modules/config/application/usecases/index.ts +1 -0
- package/src/modules/config/application/usecases/loadConfig.ts +38 -0
- package/src/modules/config/application/workflows/index.ts +1 -0
- package/src/modules/config/application/workflows/validateConfig.ts +14 -0
- package/src/modules/config/domain/events/index.ts +50 -0
- package/src/modules/config/domain/models/index.ts +9 -0
- package/src/modules/config/domain/operations/defaults.ts +74 -0
- package/src/modules/config/domain/operations/index.ts +2 -0
- package/src/modules/config/domain/operations/resolve.ts +40 -0
- package/src/modules/config/domain/validators/index.ts +152 -0
- package/src/modules/config/index.ts +23 -0
- package/src/modules/config/ports/index.ts +15 -0
- package/src/modules/config/types/index.ts +113 -0
- package/src/modules/config/types/public.ts +19 -0
- package/src/modules/content/application/cache/index.ts +6 -0
- package/src/modules/content/application/cache/parse-cache.ts +6 -0
- package/src/modules/content/application/cache/parseCache.ts +56 -0
- package/src/modules/content/application/usecases/index.ts +2 -0
- package/src/modules/content/application/usecases/load-doc-page.ts +1 -0
- package/src/modules/content/application/usecases/loadDocPage.ts +111 -0
- package/src/modules/content/application/usecases/scanDocsDir.ts +105 -0
- package/src/modules/content/application/workflows/index.ts +1 -0
- package/src/modules/content/application/workflows/processDocs.ts +51 -0
- package/src/modules/content/domain/events/index.ts +61 -0
- package/src/modules/content/domain/models/index.ts +13 -0
- package/src/modules/content/domain/operations/build-page.ts +146 -0
- package/src/modules/content/domain/operations/buildPage.ts +93 -0
- package/src/modules/content/domain/operations/index.ts +17 -0
- package/src/modules/content/domain/operations/parse.ts +241 -0
- package/src/modules/content/domain/validators/frontmatter.ts +82 -0
- package/src/modules/content/domain/validators/index.ts +6 -0
- package/src/modules/content/index.ts +27 -0
- package/src/modules/content/ports/index.ts +45 -0
- package/src/modules/content/ports/velite.ts +134 -0
- package/src/modules/content/types/index.ts +76 -0
- package/src/modules/content/types/public.ts +1 -0
- package/src/modules/content-linting/application/builtin-linting-adapter.ts +82 -0
- package/src/modules/content-linting/domain/events/index.ts +58 -0
- package/src/modules/content-linting/domain/models/index.ts +46 -0
- package/src/modules/content-linting/domain/operations/linting-operations.ts +82 -0
- package/src/modules/content-linting/domain/validators/index.ts +50 -0
- package/src/modules/content-linting/index.ts +8 -0
- package/src/modules/content-linting/ports/linting-port.ts +21 -0
- package/src/modules/content-linting/types/linting.ts +18 -0
- package/src/modules/content-validation/application/usecases/index.ts +18 -0
- package/src/modules/content-validation/domain/events/index.ts +7 -0
- package/src/modules/content-validation/domain/index.ts +16 -0
- package/src/modules/content-validation/domain/models/index.ts +33 -0
- package/src/modules/content-validation/domain/operations/index.ts +157 -0
- package/src/modules/content-validation/domain/types/index.ts +17 -0
- package/src/modules/content-validation/domain/validators/index.ts +8 -0
- package/src/modules/content-validation/index.ts +9 -0
- package/src/modules/content-validation/ports/index.ts +15 -0
- package/src/modules/content-validation/types/index.ts +5 -0
- package/src/modules/export/application/puppeteer-export-adapter.ts +63 -0
- package/src/modules/export/domain/events/index.ts +55 -0
- package/src/modules/export/domain/models/index.ts +38 -0
- package/src/modules/export/domain/operations/export-operations.ts +56 -0
- package/src/modules/export/domain/validators/index.ts +52 -0
- package/src/modules/export/index.ts +8 -0
- package/src/modules/export/ports/export-port.ts +15 -0
- package/src/modules/export/types/export.ts +15 -0
- package/src/modules/external-search/application/algolia-adapter.ts +182 -0
- package/src/modules/external-search/application/meilisearch-adapter.ts +161 -0
- package/src/modules/external-search/domain/events/index.ts +42 -0
- package/src/modules/external-search/domain/models/index.ts +42 -0
- package/src/modules/external-search/domain/operations/search-operations.ts +53 -0
- package/src/modules/external-search/domain/validators/index.ts +55 -0
- package/src/modules/external-search/index.ts +9 -0
- package/src/modules/external-search/ports/external-search-port.ts +23 -0
- package/src/modules/external-search/types/search.ts +19 -0
- package/src/modules/git-history/application/simple-git-adapter.ts +46 -0
- package/src/modules/git-history/domain/events/index.ts +34 -0
- package/src/modules/git-history/domain/models/index.ts +25 -0
- package/src/modules/git-history/domain/operations/git-history-operations.ts +56 -0
- package/src/modules/git-history/domain/validators/index.ts +52 -0
- package/src/modules/git-history/index.ts +8 -0
- package/src/modules/git-history/ports/git-history-port.ts +21 -0
- package/src/modules/git-history/types/git-history.ts +15 -0
- package/src/modules/i18n/application/fs-locale-loader.ts +39 -0
- package/src/modules/i18n/domain/events/index.ts +34 -0
- package/src/modules/i18n/domain/models/index.ts +34 -0
- package/src/modules/i18n/domain/operations/locale-operations.ts +74 -0
- package/src/modules/i18n/domain/validators/index.ts +52 -0
- package/src/modules/i18n/index.ts +8 -0
- package/src/modules/i18n/ports/locale-loader-port.ts +18 -0
- package/src/modules/i18n/types/locale.ts +17 -0
- package/src/modules/image-optimization/application/sharp-adapter.ts +58 -0
- package/src/modules/image-optimization/domain/events/index.ts +39 -0
- package/src/modules/image-optimization/domain/models/index.ts +27 -0
- package/src/modules/image-optimization/domain/operations/image-operations.ts +65 -0
- package/src/modules/image-optimization/domain/validators/index.ts +52 -0
- package/src/modules/image-optimization/index.ts +8 -0
- package/src/modules/image-optimization/ports/image-optimizer-port.ts +15 -0
- package/src/modules/image-optimization/types/image.ts +17 -0
- package/src/modules/live-editor/application/usecases/index.ts +60 -0
- package/src/modules/live-editor/domain/events/index.ts +37 -0
- package/src/modules/live-editor/domain/gitOperations.ts +110 -0
- package/src/modules/live-editor/domain/index.ts +15 -0
- package/src/modules/live-editor/domain/models/index.ts +21 -0
- package/src/modules/live-editor/domain/validators/index.ts +55 -0
- package/src/modules/live-editor/index.ts +14 -0
- package/src/modules/live-editor/ports/index.ts +49 -0
- package/src/modules/live-editor/types/index.ts +80 -0
- package/src/modules/live-preview/application/vite-preview-adapter.ts +20 -0
- package/src/modules/live-preview/domain/operations/preview-operations.ts +56 -0
- package/src/modules/live-preview/index.ts +8 -0
- package/src/modules/live-preview/ports/preview-port.ts +20 -0
- package/src/modules/live-preview/types/preview.ts +16 -0
- package/src/modules/mdx/application/mdx-js-adapter.ts +38 -0
- package/src/modules/mdx/domain/operations/parse-mdx.ts +43 -0
- package/src/modules/mdx/index.ts +8 -0
- package/src/modules/mdx/ports/mdx-parser-port.ts +15 -0
- package/src/modules/mdx/types/mdx.ts +14 -0
- package/src/modules/navigation/application/usecases/buildNav.ts +15 -0
- package/src/modules/navigation/application/usecases/buildSidebar.ts +45 -0
- package/src/modules/navigation/application/usecases/index.ts +2 -0
- package/src/modules/navigation/domain/events/index.ts +30 -0
- package/src/modules/navigation/domain/models/index.ts +7 -0
- package/src/modules/navigation/domain/operations/group.ts +79 -0
- package/src/modules/navigation/domain/operations/index.ts +10 -0
- package/src/modules/navigation/domain/operations/sort.ts +27 -0
- package/src/modules/navigation/domain/shared/utils/array.ts +39 -0
- package/src/modules/navigation/domain/validators/index.ts +88 -0
- package/src/modules/navigation/index.ts +15 -0
- package/src/modules/navigation/ports/index.ts +9 -0
- package/src/modules/navigation/types/index.ts +38 -0
- package/src/modules/navigation/types/public.ts +9 -0
- package/src/modules/openapi/application/swagger-parser-adapter.ts +178 -0
- package/src/modules/openapi/domain/operations/parse-openapi.ts +46 -0
- package/src/modules/openapi/index.ts +8 -0
- package/src/modules/openapi/ports/openapi-parser-port.ts +15 -0
- package/src/modules/openapi/types/openapi.ts +37 -0
- package/src/modules/plugin/application/usecases/build-virtual-modules.ts +53 -0
- package/src/modules/plugin/application/usecases/index.ts +1 -0
- package/src/modules/plugin/application/workflows/build-docs.ts +79 -0
- package/src/modules/plugin/application/workflows/index.ts +1 -0
- package/src/modules/plugin/domain/events/index.ts +62 -0
- package/src/modules/plugin/domain/models/index.ts +1 -0
- package/src/modules/plugin/domain/operations/build-virtual.ts +76 -0
- package/src/modules/plugin/domain/operations/index.ts +11 -0
- package/src/modules/plugin/domain/validators/index.ts +30 -0
- package/src/modules/plugin/index.ts +14 -0
- package/src/modules/plugin/ports/index.ts +21 -0
- package/src/modules/plugin/types/index.ts +27 -0
- package/src/modules/plugin/types/public.ts +1 -0
- package/src/modules/search/application/usecases/index.ts +1 -0
- package/src/modules/search/application/usecases/indexPages.ts +15 -0
- package/src/modules/search/domain/events/index.ts +32 -0
- package/src/modules/search/domain/models/index.ts +1 -0
- package/src/modules/search/domain/operations/build-index.ts +6 -0
- package/src/modules/search/domain/operations/buildIndex.ts +70 -0
- package/src/modules/search/domain/operations/index.ts +7 -0
- package/src/modules/search/domain/operations/query.ts +186 -0
- package/src/modules/search/domain/validators/index.ts +32 -0
- package/src/modules/search/index.ts +9 -0
- package/src/modules/search/types/index.ts +22 -0
- package/src/modules/search/types/public.ts +1 -0
- package/src/modules/search-analytics/application/local-storage-adapter.ts +68 -0
- package/src/modules/search-analytics/domain/operations/search-analytics-operations.ts +74 -0
- package/src/modules/search-analytics/index.ts +8 -0
- package/src/modules/search-analytics/ports/search-analytics-port.ts +20 -0
- package/src/modules/search-analytics/types/search-analytics.ts +16 -0
- package/src/modules/search-highlighting/application/dom-highlighting-adapter.ts +36 -0
- package/src/modules/search-highlighting/domain/operations/highlighting-operations.ts +72 -0
- package/src/modules/search-highlighting/index.ts +8 -0
- package/src/modules/search-highlighting/ports/highlighting-port.ts +14 -0
- package/src/modules/search-highlighting/types/highlighting.ts +15 -0
- package/src/modules/seo-optimization/application/usecases/index.ts +18 -0
- package/src/modules/seo-optimization/domain/index.ts +12 -0
- package/src/modules/seo-optimization/domain/seoOperations.ts +92 -0
- package/src/modules/seo-optimization/index.ts +8 -0
- package/src/modules/seo-optimization/ports/index.ts +18 -0
- package/src/modules/seo-optimization/types/index.ts +41 -0
- package/src/modules/theme/application/css-theme-adapter.ts +50 -0
- package/src/modules/theme/domain/operations/theme-operations.ts +68 -0
- package/src/modules/theme/index.ts +8 -0
- package/src/modules/theme/ports/theme-port.ts +8 -0
- package/src/modules/theme/types/theme.ts +12 -0
- package/src/modules/toc/application/markdown-toc-adapter.ts +106 -0
- package/src/modules/toc/domain/operations/toc-operations.ts +92 -0
- package/src/modules/toc/index.ts +8 -0
- package/src/modules/toc/ports/toc-port.ts +21 -0
- package/src/modules/toc/types/toc.ts +17 -0
- package/src/modules/toc-generator/application/usecases/index.ts +30 -0
- package/src/modules/toc-generator/domain/index.ts +12 -0
- package/src/modules/toc-generator/domain/tocOperations.ts +104 -0
- package/src/modules/toc-generator/index.ts +9 -0
- package/src/modules/toc-generator/ports/index.ts +20 -0
- package/src/modules/toc-generator/types/index.ts +50 -0
- package/src/modules/version-control/domain/events/index.ts +39 -0
- package/src/modules/version-control/domain/models/index.ts +25 -0
- package/src/modules/version-control/domain/validators/index.ts +50 -0
- package/src/modules/versioning/application/fs-version-loader.ts +44 -0
- package/src/modules/versioning/domain/operations/versioning-operations.ts +80 -0
- package/src/modules/versioning/index.ts +8 -0
- package/src/modules/versioning/ports/version-loader-port.ts +18 -0
- package/src/modules/versioning/types/versioning.ts +17 -0
- package/src/modules/workflow/domain/events/index.ts +55 -0
- package/src/modules/workflow/domain/models/index.ts +40 -0
- package/src/modules/workflow/domain/validators/index.ts +50 -0
- package/src/modules/yaml-parser/application/js-yaml-adapter.ts +34 -0
- package/src/modules/yaml-parser/domain/operations/parse-yaml.ts +58 -0
- package/src/modules/yaml-parser/index.ts +7 -0
- package/src/modules/yaml-parser/ports/yaml-parser-port.ts +18 -0
- package/src/navigation/index.ts +9 -0
- package/src/plugin/index.ts +4 -0
- package/src/presentation/index.ts +1 -0
- package/src/presentation/live-editor/index.ts +22 -0
- package/src/presentation/live-editor/live-editor-component.ts +219 -0
- package/src/presentation/live-editor/virtual-module.ts +16 -0
- package/src/presentation/solid/CodeBlock.tsx +120 -0
- package/src/presentation/solid/Toc.tsx +58 -0
- package/src/presentation/solid/index.ts +11 -0
- package/src/presentation/vite-plugin/docs-plugin.ts +212 -0
- package/src/presentation/vite-plugin/index.ts +9 -0
- package/src/presentation/vite-plugin/transform-markdown.ts +26 -0
- package/src/runtime/analytics.ts +59 -0
- package/src/runtime/api-diff.ts +115 -0
- package/src/runtime/app.tsx +32 -0
- package/src/runtime/components/AccentPicker.tsx +114 -0
- package/src/runtime/components/ApiPlayground.tsx +332 -0
- package/src/runtime/components/AskAiDialog.tsx +127 -0
- package/src/runtime/components/BackToTop.tsx +38 -0
- package/src/runtime/components/Banner.tsx +75 -0
- package/src/runtime/components/Breadcrumbs.tsx +42 -0
- package/src/runtime/components/CollectionDropdown.tsx +85 -0
- package/src/runtime/components/CustomizeDrawer.tsx +195 -0
- package/src/runtime/components/DocMarkdown.tsx +579 -0
- package/src/runtime/components/DocPrevNext.tsx +54 -0
- package/src/runtime/components/DocToc.tsx +147 -0
- package/src/runtime/components/DocsDropdown.tsx +184 -0
- package/src/runtime/components/Footer.tsx +52 -0
- package/src/runtime/components/GitHubAuth.tsx +82 -0
- package/src/runtime/components/GitHubStats.tsx +73 -0
- package/src/runtime/components/Head.tsx +225 -0
- package/src/runtime/components/LocaleDropdown.tsx +75 -0
- package/src/runtime/components/MobileBottomNav.tsx +111 -0
- package/src/runtime/components/NotFound.tsx +139 -0
- package/src/runtime/components/PageActions.tsx +144 -0
- package/src/runtime/components/RelatedDocs.tsx +50 -0
- package/src/runtime/components/ScrollProgress.tsx +32 -0
- package/src/runtime/components/SearchPalette.tsx +333 -0
- package/src/runtime/components/ShowcaseCard.tsx +87 -0
- package/src/runtime/components/SidebarNav.tsx +237 -0
- package/src/runtime/components/Skeleton.tsx +39 -0
- package/src/runtime/components/ThemeToggle.tsx +26 -0
- package/src/runtime/components/TopNav.tsx +270 -0
- package/src/runtime/components/VersionDropdown.tsx +189 -0
- package/src/runtime/components/markdown/components.ts +280 -0
- package/src/runtime/config.ts +225 -0
- package/src/runtime/content.ts +451 -0
- package/src/runtime/context.tsx +30 -0
- package/src/runtime/data.ts +93 -0
- package/src/runtime/github.ts +226 -0
- package/src/runtime/icons.ts +32 -0
- package/src/runtime/index.ts +153 -0
- package/src/runtime/layouts/DocsLayout.tsx +144 -0
- package/src/runtime/markdown-content.css +996 -0
- package/src/runtime/pages/AbTestPage.tsx +88 -0
- package/src/runtime/pages/AnalyticsPage.tsx +90 -0
- package/src/runtime/pages/ApiDiffPage.tsx +86 -0
- package/src/runtime/pages/ApiEndpointPage.tsx +248 -0
- package/src/runtime/pages/BuilderPage.tsx +150 -0
- package/src/runtime/pages/ChangelogPage.tsx +210 -0
- package/src/runtime/pages/CollectionPage.tsx +140 -0
- package/src/runtime/pages/CommunityPage.tsx +384 -0
- package/src/runtime/pages/CreatePage.tsx +448 -0
- package/src/runtime/pages/DocPage.tsx +193 -0
- package/src/runtime/pages/EditPage.tsx +201 -0
- package/src/runtime/pages/HomePage.tsx +187 -0
- package/src/runtime/pages/IssuesPage.tsx +140 -0
- package/src/runtime/pages/OAuthCallbackPage.tsx +80 -0
- package/src/runtime/pages/PluginsPage.tsx +249 -0
- package/src/runtime/pages/ShowcasePage.tsx +202 -0
- package/src/runtime/pwa.ts +39 -0
- package/src/runtime/router.tsx +192 -0
- package/src/runtime/seo.ts +192 -0
- package/src/runtime/theme.css +175 -0
- package/src/runtime/theme.ts +224 -0
- package/src/runtime/types.ts +217 -0
- package/src/search/index.ts +6 -0
- package/src/seo-optimization/index.ts +4 -0
- package/src/shared/constants/index.ts +26 -0
- package/src/shared/errors/index.ts +195 -0
- package/src/shared/index.ts +27 -0
- package/src/shared/types/brand.ts +14 -0
- package/src/shared/types/client.d.ts +45 -0
- package/src/shared/types/either.ts +38 -0
- package/src/shared/types/index.ts +42 -0
- package/src/shared/types/option.ts +52 -0
- package/src/shared/types/result.ts +81 -0
- package/src/shared/utils/array.ts +97 -0
- package/src/shared/utils/index.ts +46 -0
- package/src/shared/utils/object.ts +47 -0
- package/src/shared/utils/string.ts +74 -0
- package/src/toc-generator/index.ts +1 -0
- package/src/types/js-yaml.d.ts +42 -0
- package/src/worker.ts +462 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result<T, E> — A pure algebraic data type for synchronous operations
|
|
3
|
+
* that can fail with a typed error.
|
|
4
|
+
*
|
|
5
|
+
* Use this over throwing exceptions at the boundaries (domain, application).
|
|
6
|
+
* Domain must never throw — only return Result.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const divide = (a: number, b: number): Result<number, string> =>
|
|
10
|
+
* b === 0 ? err('Division by zero') : ok(a / b);
|
|
11
|
+
*/
|
|
12
|
+
export type Result<T, E> =
|
|
13
|
+
| { readonly ok: true; readonly value: T }
|
|
14
|
+
| { readonly ok: false; readonly error: E };
|
|
15
|
+
|
|
16
|
+
export const ok = <T>(value: T): Result<T, never> => ({ ok: true, value });
|
|
17
|
+
|
|
18
|
+
export const err = <E>(error: E): Result<never, E> => ({ ok: false, error });
|
|
19
|
+
|
|
20
|
+
export const isOk = <T, E>(r: Result<T, E>): r is { ok: true; value: T } =>
|
|
21
|
+
r.ok;
|
|
22
|
+
|
|
23
|
+
export const isErr = <T, E>(r: Result<T, E>): r is { ok: false; error: E } =>
|
|
24
|
+
!r.ok;
|
|
25
|
+
|
|
26
|
+
export const map = <T, U, E>(
|
|
27
|
+
r: Result<T, E>,
|
|
28
|
+
fn: (value: T) => U,
|
|
29
|
+
): Result<U, E> => (r.ok ? ok(fn(r.value)) : r);
|
|
30
|
+
|
|
31
|
+
export const mapErr = <T, E, F>(
|
|
32
|
+
r: Result<T, E>,
|
|
33
|
+
fn: (error: E) => F,
|
|
34
|
+
): Result<T, F> => (r.ok ? r : err(fn(r.error)));
|
|
35
|
+
|
|
36
|
+
export const flatMap = <T, U, E>(
|
|
37
|
+
r: Result<T, E>,
|
|
38
|
+
fn: (value: T) => Result<U, E>,
|
|
39
|
+
): Result<U, E> => (r.ok ? fn(r.value) : r);
|
|
40
|
+
|
|
41
|
+
export const unwrap = <T, E>(r: Result<T, E>): T => {
|
|
42
|
+
if (r.ok) return r.value;
|
|
43
|
+
throw new Error(`unwrap on Err: ${String(r.error)}`);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const unwrapOr = <T, E>(r: Result<T, E>, fallback: T): T =>
|
|
47
|
+
r.ok ? r.value : fallback;
|
|
48
|
+
|
|
49
|
+
export const fromThrowable = <T, E = Error>(
|
|
50
|
+
fn: () => T,
|
|
51
|
+
onError: (e: unknown) => E,
|
|
52
|
+
): Result<T, E> => {
|
|
53
|
+
try {
|
|
54
|
+
return ok(fn());
|
|
55
|
+
} catch (e) {
|
|
56
|
+
return err(onError(e));
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const all = <T, E>(
|
|
61
|
+
results: readonly Result<T, E>[],
|
|
62
|
+
): Result<readonly T[], E> => {
|
|
63
|
+
const values: T[] = [];
|
|
64
|
+
for (const r of results) {
|
|
65
|
+
if (!r.ok) return r;
|
|
66
|
+
values.push(r.value);
|
|
67
|
+
}
|
|
68
|
+
return ok(values);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const partition = <T, E>(
|
|
72
|
+
results: readonly Result<T, E>[],
|
|
73
|
+
): { ok: readonly T[]; err: readonly E[] } => {
|
|
74
|
+
const okValues: T[] = [];
|
|
75
|
+
const errValues: E[] = [];
|
|
76
|
+
for (const r of results) {
|
|
77
|
+
if (r.ok) okValues.push(r.value);
|
|
78
|
+
else errValues.push(r.error);
|
|
79
|
+
}
|
|
80
|
+
return { ok: okValues, err: errValues };
|
|
81
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure array utility functions. No mutation, no side effects.
|
|
3
|
+
* All functions are total — they handle empty arrays gracefully.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const isEmpty = <T>(arr: readonly T[]): boolean => arr.length === 0;
|
|
7
|
+
|
|
8
|
+
export const first = <T>(arr: readonly T[]): T | undefined => arr[0];
|
|
9
|
+
|
|
10
|
+
export const last = <T>(arr: readonly T[]): T | undefined =>
|
|
11
|
+
arr[arr.length - 1];
|
|
12
|
+
|
|
13
|
+
export const unique = <T>(arr: readonly T[]): T[] => Array.from(new Set(arr));
|
|
14
|
+
|
|
15
|
+
export const uniqueBy = <T, K>(
|
|
16
|
+
arr: readonly T[],
|
|
17
|
+
keyFn: (item: T) => K,
|
|
18
|
+
): T[] => {
|
|
19
|
+
const seen = new Set<K>();
|
|
20
|
+
const out: T[] = [];
|
|
21
|
+
for (const item of arr) {
|
|
22
|
+
const k = keyFn(item);
|
|
23
|
+
if (!seen.has(k)) {
|
|
24
|
+
seen.add(k);
|
|
25
|
+
out.push(item);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const groupBy = <T, K extends string>(
|
|
32
|
+
arr: readonly T[],
|
|
33
|
+
keyFn: (item: T) => K,
|
|
34
|
+
): Record<K, T[]> => {
|
|
35
|
+
const out = {} as Record<K, T[]>;
|
|
36
|
+
for (const item of arr) {
|
|
37
|
+
const k = keyFn(item);
|
|
38
|
+
if (!out[k]) out[k] = [];
|
|
39
|
+
out[k].push(item);
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const sortBy = <T>(arr: readonly T[], keyFn: (item: T) => number): T[] =>
|
|
45
|
+
[...arr].sort((a, b) => keyFn(a) - keyFn(b));
|
|
46
|
+
|
|
47
|
+
export const sortByString = <T>(
|
|
48
|
+
arr: readonly T[],
|
|
49
|
+
keyFn: (item: T) => string,
|
|
50
|
+
): T[] => [...arr].sort((a, b) => keyFn(a).localeCompare(keyFn(b)));
|
|
51
|
+
|
|
52
|
+
export const partitionBy = <T>(
|
|
53
|
+
arr: readonly T[],
|
|
54
|
+
pred: (item: T) => boolean,
|
|
55
|
+
): { yes: T[]; no: T[] } => {
|
|
56
|
+
const yes: T[] = [];
|
|
57
|
+
const no: T[] = [];
|
|
58
|
+
for (const item of arr) {
|
|
59
|
+
if (pred(item)) yes.push(item);
|
|
60
|
+
else no.push(item);
|
|
61
|
+
}
|
|
62
|
+
return { yes, no };
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const filterMap = <T, U>(
|
|
66
|
+
arr: readonly T[],
|
|
67
|
+
fn: (item: T) => U | undefined,
|
|
68
|
+
): U[] => {
|
|
69
|
+
const out: U[] = [];
|
|
70
|
+
for (const item of arr) {
|
|
71
|
+
const v = fn(item);
|
|
72
|
+
if (v !== undefined) out.push(v);
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const chunk = <T>(arr: readonly T[], size: number): T[][] => {
|
|
78
|
+
if (size <= 0) throw new Error("chunk: size must be > 0");
|
|
79
|
+
const out: T[][] = [];
|
|
80
|
+
for (let i = 0; i < arr.length; i += size) {
|
|
81
|
+
out.push(arr.slice(i, i + size));
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const flatten = <T>(arr: readonly (readonly T[])[]): T[] => arr.flat();
|
|
87
|
+
|
|
88
|
+
export const zip = <A, B>(a: readonly A[], b: readonly B[]): Array<[A, B]> => {
|
|
89
|
+
const len = Math.min(a.length, b.length);
|
|
90
|
+
const out: Array<[A, B]> = [];
|
|
91
|
+
for (let i = 0; i < len; i++) {
|
|
92
|
+
const av = a[i];
|
|
93
|
+
const bv = b[i];
|
|
94
|
+
if (av !== undefined && bv !== undefined) out.push([av, bv]);
|
|
95
|
+
}
|
|
96
|
+
return out;
|
|
97
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export {
|
|
2
|
+
chunk,
|
|
3
|
+
filterMap,
|
|
4
|
+
first,
|
|
5
|
+
flatten,
|
|
6
|
+
groupBy,
|
|
7
|
+
isEmpty,
|
|
8
|
+
last,
|
|
9
|
+
partitionBy,
|
|
10
|
+
sortBy,
|
|
11
|
+
sortByString,
|
|
12
|
+
unique,
|
|
13
|
+
uniqueBy,
|
|
14
|
+
zip,
|
|
15
|
+
} from "./array";
|
|
16
|
+
export {
|
|
17
|
+
isArray,
|
|
18
|
+
isBoolean,
|
|
19
|
+
isNonEmptyArray,
|
|
20
|
+
isNonEmptyString,
|
|
21
|
+
isNumber,
|
|
22
|
+
isPlainObject,
|
|
23
|
+
isString,
|
|
24
|
+
keys,
|
|
25
|
+
omit,
|
|
26
|
+
pick,
|
|
27
|
+
} from "./object";
|
|
28
|
+
export {
|
|
29
|
+
capitalize,
|
|
30
|
+
endsWith,
|
|
31
|
+
isBlank,
|
|
32
|
+
isEmptyString,
|
|
33
|
+
removeExtension,
|
|
34
|
+
slugify,
|
|
35
|
+
splitLines,
|
|
36
|
+
startsWith,
|
|
37
|
+
stripLeadingSlash,
|
|
38
|
+
stripPrefix,
|
|
39
|
+
stripQuotes,
|
|
40
|
+
stripSuffix,
|
|
41
|
+
stripTrailingSlash,
|
|
42
|
+
titleCase,
|
|
43
|
+
toPosixPath,
|
|
44
|
+
trim,
|
|
45
|
+
truncate,
|
|
46
|
+
} from "./string";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure object utility functions. No mutation of inputs.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export const isPlainObject = (v: unknown): v is Record<string, unknown> =>
|
|
6
|
+
typeof v === "object" && v !== null && !Array.isArray(v);
|
|
7
|
+
|
|
8
|
+
export const isString = (v: unknown): v is string => typeof v === "string";
|
|
9
|
+
|
|
10
|
+
export const isNumber = (v: unknown): v is number =>
|
|
11
|
+
typeof v === "number" && !Number.isNaN(v);
|
|
12
|
+
|
|
13
|
+
export const isBoolean = (v: unknown): v is boolean => typeof v === "boolean";
|
|
14
|
+
|
|
15
|
+
export const isArray = Array.isArray as <T>(v: unknown) => v is T[];
|
|
16
|
+
|
|
17
|
+
export const isNonEmptyString = (v: unknown): v is string =>
|
|
18
|
+
isString(v) && v.length > 0;
|
|
19
|
+
|
|
20
|
+
export const isNonEmptyArray = <T>(
|
|
21
|
+
v: readonly T[],
|
|
22
|
+
): v is readonly [T, ...T[]] => v.length > 0;
|
|
23
|
+
|
|
24
|
+
export const keys = <T extends object>(o: T): readonly (keyof T)[] =>
|
|
25
|
+
Object.keys(o) as (keyof T)[];
|
|
26
|
+
|
|
27
|
+
export const pick = <T extends object, K extends keyof T>(
|
|
28
|
+
o: T,
|
|
29
|
+
ks: readonly K[],
|
|
30
|
+
): Pick<T, K> => {
|
|
31
|
+
const out = {} as Pick<T, K>;
|
|
32
|
+
for (const k of ks) {
|
|
33
|
+
if (k in o) out[k] = o[k];
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const omit = <T extends object, K extends keyof T>(
|
|
39
|
+
o: T,
|
|
40
|
+
ks: readonly K[],
|
|
41
|
+
): Omit<T, K> => {
|
|
42
|
+
const out = { ...o };
|
|
43
|
+
for (const k of ks) {
|
|
44
|
+
delete out[k];
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure string utility functions.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export const trim = (s: string): string => s.trim();
|
|
6
|
+
|
|
7
|
+
export const isBlank = (s: string): boolean => s.trim().length === 0;
|
|
8
|
+
|
|
9
|
+
export const isEmptyString = (s: string): boolean => s.length === 0;
|
|
10
|
+
|
|
11
|
+
export const startsWith = (s: string, prefix: string): boolean =>
|
|
12
|
+
s.startsWith(prefix);
|
|
13
|
+
|
|
14
|
+
export const endsWith = (s: string, suffix: string): boolean =>
|
|
15
|
+
s.endsWith(suffix);
|
|
16
|
+
|
|
17
|
+
export const stripPrefix = (s: string, prefix: string): string =>
|
|
18
|
+
s.startsWith(prefix) ? s.slice(prefix.length) : s;
|
|
19
|
+
|
|
20
|
+
export const stripSuffix = (s: string, suffix: string): string =>
|
|
21
|
+
s.endsWith(suffix) ? s.slice(0, -suffix.length) : s;
|
|
22
|
+
|
|
23
|
+
export const removeExtension = (s: string, ext: string): string =>
|
|
24
|
+
stripSuffix(s, ext);
|
|
25
|
+
|
|
26
|
+
/** Replace all forward slashes and backslashes with the platform-agnostic `/`. */
|
|
27
|
+
export const toPosixPath = (s: string): string => s.replace(/\\/g, "/");
|
|
28
|
+
|
|
29
|
+
/** Strip a leading slash. */
|
|
30
|
+
export const stripLeadingSlash = (s: string): string =>
|
|
31
|
+
s.startsWith("/") ? s.slice(1) : s;
|
|
32
|
+
|
|
33
|
+
/** Strip a trailing slash. */
|
|
34
|
+
export const stripTrailingSlash = (s: string): string =>
|
|
35
|
+
s.endsWith("/") && s.length > 1 ? s.slice(0, -1) : s;
|
|
36
|
+
|
|
37
|
+
/** Capitalize the first character. */
|
|
38
|
+
export const capitalize = (s: string): string =>
|
|
39
|
+
s.length === 0 ? s : s.charAt(0).toUpperCase() + s.slice(1);
|
|
40
|
+
|
|
41
|
+
/** Title-case each dash/underscore separated word. */
|
|
42
|
+
export const titleCase = (s: string): string =>
|
|
43
|
+
s
|
|
44
|
+
.split(/[-_\s]+/)
|
|
45
|
+
.filter((w) => w.length > 0)
|
|
46
|
+
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
|
47
|
+
.join(" ");
|
|
48
|
+
|
|
49
|
+
export const slugify = (s: string): string =>
|
|
50
|
+
s
|
|
51
|
+
.toLowerCase()
|
|
52
|
+
.trim()
|
|
53
|
+
.replace(/[^a-z0-9\s-]/g, "")
|
|
54
|
+
.replace(/\s+/g, "-")
|
|
55
|
+
.replace(/-+/g, "-")
|
|
56
|
+
.replace(/^-+|-+$/g, "");
|
|
57
|
+
|
|
58
|
+
export const truncate = (s: string, max: number, suffix = "..."): string =>
|
|
59
|
+
s.length <= max
|
|
60
|
+
? s
|
|
61
|
+
: `${s.slice(0, Math.max(0, max - suffix.length))}${suffix}`;
|
|
62
|
+
|
|
63
|
+
export const splitLines = (s: string): string[] => s.split(/\r?\n/);
|
|
64
|
+
|
|
65
|
+
export const stripQuotes = (s: string): string => {
|
|
66
|
+
const t = s.trim();
|
|
67
|
+
if (
|
|
68
|
+
(t.startsWith('"') && t.endsWith('"')) ||
|
|
69
|
+
(t.startsWith("'") && t.endsWith("'"))
|
|
70
|
+
) {
|
|
71
|
+
return t.slice(1, -1);
|
|
72
|
+
}
|
|
73
|
+
return t;
|
|
74
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../modules/toc-generator";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
declare module "js-yaml" {
|
|
2
|
+
export interface LoadOptions {
|
|
3
|
+
filename?: string;
|
|
4
|
+
json?: boolean;
|
|
5
|
+
onWarning?: (error: unknown) => void;
|
|
6
|
+
schema?: Schema;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface DumpOptions {
|
|
10
|
+
indent?: number;
|
|
11
|
+
lineWidth?: number;
|
|
12
|
+
noRefs?: boolean;
|
|
13
|
+
schema?: Schema;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface Schema {}
|
|
17
|
+
|
|
18
|
+
export const DEFAULT_SCHEMA: Schema;
|
|
19
|
+
export const JSON_SCHEMA: Schema;
|
|
20
|
+
export const YAMLException: new (
|
|
21
|
+
message?: string,
|
|
22
|
+
mark?: { line: number; column: number },
|
|
23
|
+
) => Error & { mark?: { line: number; column: number } };
|
|
24
|
+
|
|
25
|
+
export function load(input: string, options?: LoadOptions): unknown;
|
|
26
|
+
export function loadAll(input: string, options?: LoadOptions): unknown[];
|
|
27
|
+
export function dump(input: unknown, options?: DumpOptions): string;
|
|
28
|
+
export function safeLoad(input: string, options?: LoadOptions): unknown;
|
|
29
|
+
export function safeLoadAll(input: string, options?: LoadOptions): unknown[];
|
|
30
|
+
export function safeDump(input: unknown, options?: DumpOptions): string;
|
|
31
|
+
|
|
32
|
+
const yaml: {
|
|
33
|
+
load: typeof load;
|
|
34
|
+
dump: typeof dump;
|
|
35
|
+
safeLoad: typeof safeLoad;
|
|
36
|
+
safeDump: typeof safeDump;
|
|
37
|
+
DEFAULT_SCHEMA: Schema;
|
|
38
|
+
JSON_SCHEMA: Schema;
|
|
39
|
+
YAMLException: typeof YAMLException;
|
|
40
|
+
};
|
|
41
|
+
export default yaml;
|
|
42
|
+
}
|