@ruaruababa/vibe-kit 1.0.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/CATALOG.md +317 -0
- package/README.md +121 -0
- package/aliases.json +65 -0
- package/bin/vibe.js +2 -0
- package/bundles.json +265 -0
- package/catalog.json +1560 -0
- package/dist/antigravity-skills/bin/cli.js +438 -0
- package/dist/antigravity-skills/lib/skill-utils.js +158 -0
- package/dist/antigravity-skills/scripts/build-catalog.js +305 -0
- package/dist/antigravity-skills/scripts/normalize-frontmatter.js +144 -0
- package/dist/antigravity-skills/scripts/validate-skills.js +230 -0
- package/dist/bin/vibe.js +2 -0
- package/dist/dist/src/cli/index.js +26 -0
- package/dist/lib/skill-utils.js +158 -0
- package/dist/scripts/build-catalog.js +50 -0
- package/dist/scripts/normalize-frontmatter.js +144 -0
- package/dist/scripts/validate-skills.js +56 -0
- package/dist/src/cli/index.js +146 -0
- package/dist/src/types/index.js +13 -0
- package/dist/src/utils/fs.js +1 -0
- package/package.json +43 -0
- package/skills/accessibility-compliance-accessibility-audit/SKILL.md +42 -0
- package/skills/accessibility-compliance-accessibility-audit/resources/implementation-playbook.md +502 -0
- package/skills/agent-orchestration-improve-agent/SKILL.md +349 -0
- package/skills/agent-orchestration-multi-agent-optimize/SKILL.md +239 -0
- package/skills/agent-orchestrator/SKILL.md +24 -0
- package/skills/ai-engineer/SKILL.md +171 -0
- package/skills/airflow-dag-patterns/SKILL.md +41 -0
- package/skills/airflow-dag-patterns/resources/implementation-playbook.md +509 -0
- package/skills/angular-migration/SKILL.md +428 -0
- package/skills/anti-reversing-techniques/SKILL.md +42 -0
- package/skills/anti-reversing-techniques/resources/implementation-playbook.md +539 -0
- package/skills/api-design-principles/SKILL.md +37 -0
- package/skills/api-design-principles/assets/api-design-checklist.md +155 -0
- package/skills/api-design-principles/assets/rest-api-template.py +182 -0
- package/skills/api-design-principles/references/graphql-schema-design.md +583 -0
- package/skills/api-design-principles/references/rest-best-practices.md +408 -0
- package/skills/api-design-principles/resources/implementation-playbook.md +513 -0
- package/skills/api-documenter/SKILL.md +184 -0
- package/skills/api-testing-observability-api-mock/SKILL.md +46 -0
- package/skills/api-testing-observability-api-mock/resources/implementation-playbook.md +1327 -0
- package/skills/application-performance-performance-optimization/SKILL.md +154 -0
- package/skills/architect-review/SKILL.md +174 -0
- package/skills/architecture-decision-records/SKILL.md +441 -0
- package/skills/architecture-patterns/SKILL.md +37 -0
- package/skills/architecture-patterns/resources/implementation-playbook.md +479 -0
- package/skills/arm-cortex-expert/SKILL.md +306 -0
- package/skills/async-python-patterns/SKILL.md +39 -0
- package/skills/async-python-patterns/resources/implementation-playbook.md +678 -0
- package/skills/attack-tree-construction/SKILL.md +38 -0
- package/skills/attack-tree-construction/resources/implementation-playbook.md +671 -0
- package/skills/auth-implementation-patterns/SKILL.md +39 -0
- package/skills/auth-implementation-patterns/resources/implementation-playbook.md +618 -0
- package/skills/backend-architect/SKILL.md +333 -0
- package/skills/backend-development-feature-development/SKILL.md +180 -0
- package/skills/backend-security-coder/SKILL.md +156 -0
- package/skills/backtesting-frameworks/SKILL.md +39 -0
- package/skills/backtesting-frameworks/resources/implementation-playbook.md +647 -0
- package/skills/bash-defensive-patterns/SKILL.md +43 -0
- package/skills/bash-defensive-patterns/resources/implementation-playbook.md +517 -0
- package/skills/bash-pro/SKILL.md +310 -0
- package/skills/bats-testing-patterns/SKILL.md +34 -0
- package/skills/bats-testing-patterns/resources/implementation-playbook.md +614 -0
- package/skills/bazel-build-optimization/SKILL.md +397 -0
- package/skills/billing-automation/SKILL.md +42 -0
- package/skills/billing-automation/resources/implementation-playbook.md +544 -0
- package/skills/binary-analysis-patterns/SKILL.md +450 -0
- package/skills/blockchain-developer/SKILL.md +208 -0
- package/skills/business-analyst/SKILL.md +182 -0
- package/skills/c-pro/SKILL.md +56 -0
- package/skills/c4-architecture-c4-architecture/SKILL.md +389 -0
- package/skills/c4-code/SKILL.md +244 -0
- package/skills/c4-component/SKILL.md +153 -0
- package/skills/c4-container/SKILL.md +171 -0
- package/skills/c4-context/SKILL.md +150 -0
- package/skills/changelog-automation/SKILL.md +38 -0
- package/skills/changelog-automation/resources/implementation-playbook.md +538 -0
- package/skills/cicd-automation-workflow-automate/SKILL.md +51 -0
- package/skills/cicd-automation-workflow-automate/resources/implementation-playbook.md +1333 -0
- package/skills/clean-markdown/SKILL.md +23 -0
- package/skills/cloud-architect/SKILL.md +135 -0
- package/skills/code-documentation-code-explain/SKILL.md +46 -0
- package/skills/code-documentation-code-explain/resources/implementation-playbook.md +802 -0
- package/skills/code-documentation-doc-generate/SKILL.md +48 -0
- package/skills/code-documentation-doc-generate/resources/implementation-playbook.md +640 -0
- package/skills/code-refactoring-context-restore/SKILL.md +179 -0
- package/skills/code-refactoring-refactor-clean/SKILL.md +51 -0
- package/skills/code-refactoring-refactor-clean/resources/implementation-playbook.md +879 -0
- package/skills/code-refactoring-tech-debt/SKILL.md +386 -0
- package/skills/code-review-ai-ai-review/SKILL.md +450 -0
- package/skills/code-review-excellence/SKILL.md +40 -0
- package/skills/code-review-excellence/resources/implementation-playbook.md +515 -0
- package/skills/code-reviewer/SKILL.md +178 -0
- package/skills/codebase-cleanup-deps-audit/SKILL.md +51 -0
- package/skills/codebase-cleanup-deps-audit/resources/implementation-playbook.md +766 -0
- package/skills/codebase-cleanup-refactor-clean/SKILL.md +51 -0
- package/skills/codebase-cleanup-refactor-clean/resources/implementation-playbook.md +879 -0
- package/skills/codebase-cleanup-tech-debt/SKILL.md +386 -0
- package/skills/competitive-landscape/SKILL.md +34 -0
- package/skills/competitive-landscape/resources/implementation-playbook.md +494 -0
- package/skills/comprehensive-review-full-review/SKILL.md +146 -0
- package/skills/comprehensive-review-pr-enhance/SKILL.md +46 -0
- package/skills/comprehensive-review-pr-enhance/resources/implementation-playbook.md +691 -0
- package/skills/conductor-implement/SKILL.md +388 -0
- package/skills/conductor-manage/SKILL.md +39 -0
- package/skills/conductor-manage/resources/implementation-playbook.md +1120 -0
- package/skills/conductor-new-track/SKILL.md +433 -0
- package/skills/conductor-revert/SKILL.md +372 -0
- package/skills/conductor-setup/SKILL.md +426 -0
- package/skills/conductor-status/SKILL.md +338 -0
- package/skills/conductor-validator/SKILL.md +62 -0
- package/skills/content-marketer/SKILL.md +170 -0
- package/skills/context-driven-development/SKILL.md +400 -0
- package/skills/context-management-context-restore/SKILL.md +179 -0
- package/skills/context-management-context-save/SKILL.md +177 -0
- package/skills/context-manager/SKILL.md +185 -0
- package/skills/cost-optimization/SKILL.md +286 -0
- package/skills/cpp-pro/SKILL.md +59 -0
- package/skills/cqrs-implementation/SKILL.md +35 -0
- package/skills/cqrs-implementation/resources/implementation-playbook.md +540 -0
- package/skills/csharp-pro/SKILL.md +59 -0
- package/skills/customer-support/SKILL.md +170 -0
- package/skills/data-engineer/SKILL.md +224 -0
- package/skills/data-engineering-data-driven-feature/SKILL.md +182 -0
- package/skills/data-engineering-data-pipeline/SKILL.md +201 -0
- package/skills/data-quality-frameworks/SKILL.md +40 -0
- package/skills/data-quality-frameworks/resources/implementation-playbook.md +573 -0
- package/skills/data-scientist/SKILL.md +199 -0
- package/skills/data-storytelling/SKILL.md +465 -0
- package/skills/database-admin/SKILL.md +165 -0
- package/skills/database-architect/SKILL.md +268 -0
- package/skills/database-cloud-optimization-cost-optimize/SKILL.md +44 -0
- package/skills/database-cloud-optimization-cost-optimize/resources/implementation-playbook.md +1441 -0
- package/skills/database-migration/SKILL.md +436 -0
- package/skills/database-migrations-migration-observability/SKILL.md +420 -0
- package/skills/database-migrations-sql-migrations/SKILL.md +53 -0
- package/skills/database-migrations-sql-migrations/resources/implementation-playbook.md +499 -0
- package/skills/database-optimizer/SKILL.md +167 -0
- package/skills/dbt-transformation-patterns/SKILL.md +34 -0
- package/skills/dbt-transformation-patterns/resources/implementation-playbook.md +547 -0
- package/skills/debugger/SKILL.md +49 -0
- package/skills/debugging-strategies/SKILL.md +34 -0
- package/skills/debugging-strategies/resources/implementation-playbook.md +511 -0
- package/skills/debugging-toolkit-smart-debug/SKILL.md +197 -0
- package/skills/defi-protocol-templates/SKILL.md +466 -0
- package/skills/dependency-management-deps-audit/SKILL.md +44 -0
- package/skills/dependency-management-deps-audit/resources/implementation-playbook.md +766 -0
- package/skills/dependency-upgrade/SKILL.md +421 -0
- package/skills/deployment-engineer/SKILL.md +170 -0
- package/skills/deployment-pipeline-design/SKILL.md +371 -0
- package/skills/deployment-validation-config-validate/SKILL.md +496 -0
- package/skills/devops-troubleshooter/SKILL.md +161 -0
- package/skills/distributed-debugging-debug-trace/SKILL.md +44 -0
- package/skills/distributed-debugging-debug-trace/resources/implementation-playbook.md +1307 -0
- package/skills/distributed-tracing/SKILL.md +450 -0
- package/skills/django-pro/SKILL.md +180 -0
- package/skills/docs-architect/SKILL.md +98 -0
- package/skills/documentation-generation-doc-generate/SKILL.md +48 -0
- package/skills/documentation-generation-doc-generate/resources/implementation-playbook.md +640 -0
- package/skills/dotnet-architect/SKILL.md +197 -0
- package/skills/dotnet-backend-patterns/SKILL.md +37 -0
- package/skills/dotnet-backend-patterns/assets/repository-template.cs +523 -0
- package/skills/dotnet-backend-patterns/assets/service-template.cs +336 -0
- package/skills/dotnet-backend-patterns/references/dapper-patterns.md +544 -0
- package/skills/dotnet-backend-patterns/references/ef-core-best-practices.md +355 -0
- package/skills/dotnet-backend-patterns/resources/implementation-playbook.md +799 -0
- package/skills/dummy-skill/SKILL.md +5 -0
- package/skills/dx-optimizer/SKILL.md +83 -0
- package/skills/e2e-testing-patterns/SKILL.md +41 -0
- package/skills/e2e-testing-patterns/resources/implementation-playbook.md +531 -0
- package/skills/elixir-pro/SKILL.md +59 -0
- package/skills/embedding-strategies/SKILL.md +491 -0
- package/skills/employment-contract-templates/SKILL.md +39 -0
- package/skills/employment-contract-templates/resources/implementation-playbook.md +493 -0
- package/skills/error-debugging-error-analysis/SKILL.md +47 -0
- package/skills/error-debugging-error-analysis/resources/implementation-playbook.md +1143 -0
- package/skills/error-debugging-error-trace/SKILL.md +43 -0
- package/skills/error-debugging-error-trace/resources/implementation-playbook.md +1361 -0
- package/skills/error-debugging-multi-agent-review/SKILL.md +216 -0
- package/skills/error-detective/SKILL.md +53 -0
- package/skills/error-diagnostics-error-analysis/SKILL.md +47 -0
- package/skills/error-diagnostics-error-analysis/resources/implementation-playbook.md +1143 -0
- package/skills/error-diagnostics-error-trace/SKILL.md +48 -0
- package/skills/error-diagnostics-error-trace/resources/implementation-playbook.md +1371 -0
- package/skills/error-diagnostics-smart-debug/SKILL.md +197 -0
- package/skills/error-handling-patterns/SKILL.md +35 -0
- package/skills/error-handling-patterns/resources/implementation-playbook.md +635 -0
- package/skills/event-sourcing-architect/SKILL.md +58 -0
- package/skills/event-store-design/SKILL.md +449 -0
- package/skills/fastapi-pro/SKILL.md +192 -0
- package/skills/fastapi-templates/SKILL.md +32 -0
- package/skills/fastapi-templates/resources/implementation-playbook.md +566 -0
- package/skills/final-test/SKILL.md +5 -0
- package/skills/firmware-analyst/SKILL.md +320 -0
- package/skills/flutter-expert/SKILL.md +200 -0
- package/skills/framework-migration-code-migrate/SKILL.md +48 -0
- package/skills/framework-migration-code-migrate/resources/implementation-playbook.md +1052 -0
- package/skills/framework-migration-deps-upgrade/SKILL.md +48 -0
- package/skills/framework-migration-deps-upgrade/resources/implementation-playbook.md +755 -0
- package/skills/framework-migration-legacy-modernize/SKILL.md +132 -0
- package/skills/frontend-developer/SKILL.md +171 -0
- package/skills/frontend-mobile-development-component-scaffold/SKILL.md +403 -0
- package/skills/frontend-mobile-security-xss-scan/SKILL.md +322 -0
- package/skills/frontend-security-coder/SKILL.md +170 -0
- package/skills/full-stack-orchestration-full-stack-feature/SKILL.md +135 -0
- package/skills/gdpr-data-handling/SKILL.md +33 -0
- package/skills/gdpr-data-handling/resources/implementation-playbook.md +615 -0
- package/skills/git-advanced-workflows/SKILL.md +412 -0
- package/skills/git-pr-workflows-git-workflow/SKILL.md +140 -0
- package/skills/git-pr-workflows-onboard/SKILL.md +416 -0
- package/skills/git-pr-workflows-pr-enhance/SKILL.md +48 -0
- package/skills/git-pr-workflows-pr-enhance/resources/implementation-playbook.md +701 -0
- package/skills/github-actions-templates/SKILL.md +345 -0
- package/skills/gitlab-ci-patterns/SKILL.md +283 -0
- package/skills/gitops-workflow/SKILL.md +303 -0
- package/skills/gitops-workflow/references/argocd-setup.md +134 -0
- package/skills/gitops-workflow/references/sync-policies.md +131 -0
- package/skills/go-concurrency-patterns/SKILL.md +33 -0
- package/skills/go-concurrency-patterns/resources/implementation-playbook.md +654 -0
- package/skills/godot-gdscript-patterns/SKILL.md +33 -0
- package/skills/godot-gdscript-patterns/resources/implementation-playbook.md +804 -0
- package/skills/golang-pro/SKILL.md +179 -0
- package/skills/grafana-dashboards/SKILL.md +381 -0
- package/skills/graphql-architect/SKILL.md +182 -0
- package/skills/haskell-pro/SKILL.md +56 -0
- package/skills/helm-chart-scaffolding/SKILL.md +34 -0
- package/skills/helm-chart-scaffolding/assets/Chart.yaml.template +42 -0
- package/skills/helm-chart-scaffolding/assets/values.yaml.template +185 -0
- package/skills/helm-chart-scaffolding/references/chart-structure.md +500 -0
- package/skills/helm-chart-scaffolding/resources/implementation-playbook.md +543 -0
- package/skills/helm-chart-scaffolding/scripts/validate-chart.sh +244 -0
- package/skills/hr-pro/SKILL.md +126 -0
- package/skills/hybrid-cloud-architect/SKILL.md +168 -0
- package/skills/hybrid-cloud-networking/SKILL.md +238 -0
- package/skills/hybrid-search-implementation/SKILL.md +32 -0
- package/skills/hybrid-search-implementation/resources/implementation-playbook.md +567 -0
- package/skills/incident-responder/SKILL.md +213 -0
- package/skills/incident-response-incident-response/SKILL.md +168 -0
- package/skills/incident-response-smart-fix/SKILL.md +29 -0
- package/skills/incident-response-smart-fix/resources/implementation-playbook.md +838 -0
- package/skills/incident-runbook-templates/SKILL.md +395 -0
- package/skills/ios-developer/SKILL.md +219 -0
- package/skills/istio-traffic-management/SKILL.md +337 -0
- package/skills/java-pro/SKILL.md +177 -0
- package/skills/javascript-pro/SKILL.md +57 -0
- package/skills/javascript-testing-patterns/SKILL.md +35 -0
- package/skills/javascript-testing-patterns/resources/implementation-playbook.md +1024 -0
- package/skills/javascript-typescript-typescript-scaffold/SKILL.md +361 -0
- package/skills/julia-pro/SKILL.md +209 -0
- package/skills/k8s-manifest-generator/SKILL.md +35 -0
- package/skills/k8s-manifest-generator/assets/configmap-template.yaml +296 -0
- package/skills/k8s-manifest-generator/assets/deployment-template.yaml +203 -0
- package/skills/k8s-manifest-generator/assets/service-template.yaml +171 -0
- package/skills/k8s-manifest-generator/references/deployment-spec.md +753 -0
- package/skills/k8s-manifest-generator/references/service-spec.md +724 -0
- package/skills/k8s-manifest-generator/resources/implementation-playbook.md +510 -0
- package/skills/k8s-security-policies/SKILL.md +346 -0
- package/skills/k8s-security-policies/assets/network-policy-template.yaml +177 -0
- package/skills/k8s-security-policies/references/rbac-patterns.md +187 -0
- package/skills/kpi-dashboard-design/SKILL.md +440 -0
- package/skills/kubernetes-architect/SKILL.md +170 -0
- package/skills/langchain-architecture/SKILL.md +350 -0
- package/skills/legacy-modernizer/SKILL.md +53 -0
- package/skills/legal-advisor/SKILL.md +70 -0
- package/skills/linkerd-patterns/SKILL.md +321 -0
- package/skills/llm-application-dev-ai-assistant/SKILL.md +35 -0
- package/skills/llm-application-dev-ai-assistant/resources/implementation-playbook.md +1236 -0
- package/skills/llm-application-dev-langchain-agent/SKILL.md +246 -0
- package/skills/llm-application-dev-prompt-optimize/SKILL.md +37 -0
- package/skills/llm-application-dev-prompt-optimize/resources/implementation-playbook.md +591 -0
- package/skills/llm-evaluation/SKILL.md +483 -0
- package/skills/machine-learning-ops-ml-pipeline/SKILL.md +314 -0
- package/skills/malware-analyst/SKILL.md +247 -0
- package/skills/market-sizing-analysis/SKILL.md +425 -0
- package/skills/market-sizing-analysis/examples/saas-market-sizing.md +349 -0
- package/skills/market-sizing-analysis/references/data-sources.md +360 -0
- package/skills/memory-forensics/SKILL.md +491 -0
- package/skills/memory-safety-patterns/SKILL.md +33 -0
- package/skills/memory-safety-patterns/resources/implementation-playbook.md +603 -0
- package/skills/mermaid-expert/SKILL.md +59 -0
- package/skills/microservices-patterns/SKILL.md +35 -0
- package/skills/microservices-patterns/resources/implementation-playbook.md +607 -0
- package/skills/minecraft-bukkit-pro/SKILL.md +126 -0
- package/skills/ml-engineer/SKILL.md +168 -0
- package/skills/ml-pipeline-workflow/SKILL.md +257 -0
- package/skills/mlops-engineer/SKILL.md +219 -0
- package/skills/mobile-developer/SKILL.md +205 -0
- package/skills/mobile-security-coder/SKILL.md +184 -0
- package/skills/modern-javascript-patterns/SKILL.md +35 -0
- package/skills/modern-javascript-patterns/resources/implementation-playbook.md +910 -0
- package/skills/monorepo-architect/SKILL.md +61 -0
- package/skills/monorepo-management/SKILL.md +35 -0
- package/skills/monorepo-management/resources/implementation-playbook.md +621 -0
- package/skills/mtls-configuration/SKILL.md +359 -0
- package/skills/multi-cloud-architecture/SKILL.md +189 -0
- package/skills/multi-platform-apps-multi-platform/SKILL.md +203 -0
- package/skills/network-engineer/SKILL.md +169 -0
- package/skills/nextjs-app-router-patterns/SKILL.md +33 -0
- package/skills/nextjs-app-router-patterns/resources/implementation-playbook.md +543 -0
- package/skills/nft-standards/SKILL.md +395 -0
- package/skills/node-expert/SKILL.md +23 -0
- package/skills/nodejs-backend-patterns/SKILL.md +35 -0
- package/skills/nodejs-backend-patterns/resources/implementation-playbook.md +1019 -0
- package/skills/nx-workspace-patterns/SKILL.md +464 -0
- package/skills/observability-engineer/SKILL.md +237 -0
- package/skills/observability-monitoring-monitor-setup/SKILL.md +48 -0
- package/skills/observability-monitoring-monitor-setup/resources/implementation-playbook.md +505 -0
- package/skills/observability-monitoring-slo-implement/SKILL.md +43 -0
- package/skills/observability-monitoring-slo-implement/resources/implementation-playbook.md +1077 -0
- package/skills/on-call-handoff-patterns/SKILL.md +453 -0
- package/skills/openapi-spec-generation/SKILL.md +33 -0
- package/skills/openapi-spec-generation/resources/implementation-playbook.md +1027 -0
- package/skills/payment-integration/SKILL.md +77 -0
- package/skills/paypal-integration/SKILL.md +479 -0
- package/skills/pci-compliance/SKILL.md +478 -0
- package/skills/performance-engineer/SKILL.md +180 -0
- package/skills/performance-testing-review-ai-review/SKILL.md +450 -0
- package/skills/performance-testing-review-multi-agent-review/SKILL.md +216 -0
- package/skills/php-pro/SKILL.md +63 -0
- package/skills/posix-shell-pro/SKILL.md +304 -0
- package/skills/postgresql/SKILL.md +230 -0
- package/skills/postmortem-writing/SKILL.md +386 -0
- package/skills/projection-patterns/SKILL.md +33 -0
- package/skills/projection-patterns/resources/implementation-playbook.md +501 -0
- package/skills/prometheus-configuration/SKILL.md +404 -0
- package/skills/prompt-engineer/SKILL.md +272 -0
- package/skills/prompt-engineering-patterns/SKILL.md +213 -0
- package/skills/prompt-engineering-patterns/assets/few-shot-examples.json +106 -0
- package/skills/prompt-engineering-patterns/assets/prompt-template-library.md +246 -0
- package/skills/prompt-engineering-patterns/references/chain-of-thought.md +399 -0
- package/skills/prompt-engineering-patterns/references/few-shot-learning.md +369 -0
- package/skills/prompt-engineering-patterns/references/prompt-optimization.md +414 -0
- package/skills/prompt-engineering-patterns/references/prompt-templates.md +470 -0
- package/skills/prompt-engineering-patterns/references/system-prompts.md +189 -0
- package/skills/prompt-engineering-patterns/scripts/optimize-prompt.py +279 -0
- package/skills/protocol-reverse-engineering/SKILL.md +29 -0
- package/skills/protocol-reverse-engineering/resources/implementation-playbook.md +509 -0
- package/skills/python-development-python-scaffold/SKILL.md +331 -0
- package/skills/python-packaging/SKILL.md +36 -0
- package/skills/python-packaging/resources/implementation-playbook.md +869 -0
- package/skills/python-performance-optimization/SKILL.md +36 -0
- package/skills/python-performance-optimization/resources/implementation-playbook.md +868 -0
- package/skills/python-pro/SKILL.md +158 -0
- package/skills/python-testing-patterns/SKILL.md +37 -0
- package/skills/python-testing-patterns/resources/implementation-playbook.md +906 -0
- package/skills/quant-analyst/SKILL.md +53 -0
- package/skills/rag-implementation/SKILL.md +421 -0
- package/skills/react-modernization/SKILL.md +34 -0
- package/skills/react-modernization/resources/implementation-playbook.md +512 -0
- package/skills/react-native-architecture/SKILL.md +33 -0
- package/skills/react-native-architecture/resources/implementation-playbook.md +670 -0
- package/skills/react-state-management/SKILL.md +441 -0
- package/skills/reference-builder/SKILL.md +188 -0
- package/skills/reverse-engineer/SKILL.md +173 -0
- package/skills/risk-manager/SKILL.md +61 -0
- package/skills/risk-metrics-calculation/SKILL.md +33 -0
- package/skills/risk-metrics-calculation/resources/implementation-playbook.md +554 -0
- package/skills/ruby-pro/SKILL.md +56 -0
- package/skills/rust-async-patterns/SKILL.md +33 -0
- package/skills/rust-async-patterns/resources/implementation-playbook.md +516 -0
- package/skills/rust-pro/SKILL.md +178 -0
- package/skills/saga-orchestration/SKILL.md +496 -0
- package/skills/sales-automator/SKILL.md +55 -0
- package/skills/sast-configuration/SKILL.md +212 -0
- package/skills/scala-pro/SKILL.md +82 -0
- package/skills/screen-reader-testing/SKILL.md +33 -0
- package/skills/screen-reader-testing/resources/implementation-playbook.md +544 -0
- package/skills/search-specialist/SKILL.md +80 -0
- package/skills/secrets-management/SKILL.md +364 -0
- package/skills/security-auditor/SKILL.md +169 -0
- package/skills/security-compliance-compliance-check/SKILL.md +55 -0
- package/skills/security-compliance-compliance-check/resources/implementation-playbook.md +963 -0
- package/skills/security-requirement-extraction/SKILL.md +33 -0
- package/skills/security-requirement-extraction/resources/implementation-playbook.md +676 -0
- package/skills/security-scanning-security-dependencies/SKILL.md +43 -0
- package/skills/security-scanning-security-dependencies/resources/implementation-playbook.md +544 -0
- package/skills/security-scanning-security-hardening/SKILL.md +147 -0
- package/skills/security-scanning-security-sast/SKILL.md +495 -0
- package/skills/seo-authority-builder/SKILL.md +136 -0
- package/skills/seo-cannibalization-detector/SKILL.md +123 -0
- package/skills/seo-content-auditor/SKILL.md +83 -0
- package/skills/seo-content-planner/SKILL.md +108 -0
- package/skills/seo-content-refresher/SKILL.md +118 -0
- package/skills/seo-content-writer/SKILL.md +96 -0
- package/skills/seo-keyword-strategist/SKILL.md +95 -0
- package/skills/seo-meta-optimizer/SKILL.md +92 -0
- package/skills/seo-snippet-hunter/SKILL.md +114 -0
- package/skills/seo-structure-architect/SKILL.md +108 -0
- package/skills/service-mesh-expert/SKILL.md +58 -0
- package/skills/service-mesh-observability/SKILL.md +395 -0
- package/skills/shellcheck-configuration/SKILL.md +466 -0
- package/skills/similarity-search-patterns/SKILL.md +33 -0
- package/skills/similarity-search-patterns/resources/implementation-playbook.md +557 -0
- package/skills/slo-implementation/SKILL.md +341 -0
- package/skills/solidity-security/SKILL.md +34 -0
- package/skills/solidity-security/resources/implementation-playbook.md +524 -0
- package/skills/spark-optimization/SKILL.md +427 -0
- package/skills/sql-optimization-patterns/SKILL.md +35 -0
- package/skills/sql-optimization-patterns/resources/implementation-playbook.md +504 -0
- package/skills/sql-pro/SKILL.md +173 -0
- package/skills/startup-analyst/SKILL.md +328 -0
- package/skills/startup-business-analyst-business-case/SKILL.md +487 -0
- package/skills/startup-business-analyst-financial-projections/SKILL.md +353 -0
- package/skills/startup-business-analyst-market-opportunity/SKILL.md +240 -0
- package/skills/startup-financial-modeling/SKILL.md +467 -0
- package/skills/startup-metrics-framework/SKILL.md +34 -0
- package/skills/startup-metrics-framework/resources/implementation-playbook.md +500 -0
- package/skills/stride-analysis-patterns/SKILL.md +33 -0
- package/skills/stride-analysis-patterns/resources/implementation-playbook.md +655 -0
- package/skills/stripe-integration/SKILL.md +454 -0
- package/skills/systems-programming-rust-project/SKILL.md +440 -0
- package/skills/tailwind-design-system/SKILL.md +33 -0
- package/skills/tailwind-design-system/resources/implementation-playbook.md +665 -0
- package/skills/tdd-orchestrator/SKILL.md +205 -0
- package/skills/tdd-workflows-tdd-cycle/SKILL.md +221 -0
- package/skills/tdd-workflows-tdd-green/SKILL.md +73 -0
- package/skills/tdd-workflows-tdd-green/resources/implementation-playbook.md +870 -0
- package/skills/tdd-workflows-tdd-red/SKILL.md +164 -0
- package/skills/tdd-workflows-tdd-refactor/SKILL.md +187 -0
- package/skills/team-collaboration-issue/SKILL.md +37 -0
- package/skills/team-collaboration-issue/resources/implementation-playbook.md +640 -0
- package/skills/team-collaboration-standup-notes/SKILL.md +44 -0
- package/skills/team-collaboration-standup-notes/resources/implementation-playbook.md +768 -0
- package/skills/team-composition-analysis/SKILL.md +413 -0
- package/skills/temporal-python-pro/SKILL.md +370 -0
- package/skills/temporal-python-testing/SKILL.md +170 -0
- package/skills/temporal-python-testing/resources/integration-testing.md +455 -0
- package/skills/temporal-python-testing/resources/local-setup.md +553 -0
- package/skills/temporal-python-testing/resources/replay-testing.md +462 -0
- package/skills/temporal-python-testing/resources/unit-testing.md +328 -0
- package/skills/terraform-module-library/SKILL.md +261 -0
- package/skills/terraform-module-library/references/aws-modules.md +63 -0
- package/skills/terraform-specialist/SKILL.md +166 -0
- package/skills/test-automator/SKILL.md +224 -0
- package/skills/threat-mitigation-mapping/SKILL.md +33 -0
- package/skills/threat-mitigation-mapping/resources/implementation-playbook.md +744 -0
- package/skills/threat-modeling-expert/SKILL.md +60 -0
- package/skills/track-management/SKILL.md +38 -0
- package/skills/track-management/resources/implementation-playbook.md +591 -0
- package/skills/turborepo-caching/SKILL.md +419 -0
- package/skills/tutorial-engineer/SKILL.md +139 -0
- package/skills/typescript-advanced-types/SKILL.md +35 -0
- package/skills/typescript-advanced-types/resources/implementation-playbook.md +716 -0
- package/skills/typescript-pro/SKILL.md +55 -0
- package/skills/ui-minimal/SKILL.md +23 -0
- package/skills/ui-ux-designer/SKILL.md +209 -0
- package/skills/ui-visual-validator/SKILL.md +214 -0
- package/skills/unit-testing-test-generate/SKILL.md +319 -0
- package/skills/unity-developer/SKILL.md +230 -0
- package/skills/unity-ecs-patterns/SKILL.md +33 -0
- package/skills/unity-ecs-patterns/resources/implementation-playbook.md +625 -0
- package/skills/uv-package-manager/SKILL.md +37 -0
- package/skills/uv-package-manager/resources/implementation-playbook.md +830 -0
- package/skills/vector-database-engineer/SKILL.md +60 -0
- package/skills/vector-index-tuning/SKILL.md +42 -0
- package/skills/vector-index-tuning/resources/implementation-playbook.md +507 -0
- package/skills/wcag-audit-patterns/SKILL.md +41 -0
- package/skills/wcag-audit-patterns/resources/implementation-playbook.md +541 -0
- package/skills/web3-testing/SKILL.md +427 -0
- package/skills/workflow-orchestration-patterns/SKILL.md +333 -0
- package/skills/workflow-patterns/SKILL.md +38 -0
- package/skills/workflow-patterns/resources/implementation-playbook.md +621 -0
|
@@ -0,0 +1,910 @@
|
|
|
1
|
+
# Modern JavaScript Patterns Implementation Playbook
|
|
2
|
+
|
|
3
|
+
This file contains detailed patterns, checklists, and code samples referenced by the skill.
|
|
4
|
+
|
|
5
|
+
# Modern JavaScript Patterns
|
|
6
|
+
|
|
7
|
+
Comprehensive guide for mastering modern JavaScript (ES6+) features, functional programming patterns, and best practices for writing clean, maintainable, and performant code.
|
|
8
|
+
|
|
9
|
+
## When to Use This Skill
|
|
10
|
+
|
|
11
|
+
- Refactoring legacy JavaScript to modern syntax
|
|
12
|
+
- Implementing functional programming patterns
|
|
13
|
+
- Optimizing JavaScript performance
|
|
14
|
+
- Writing maintainable and readable code
|
|
15
|
+
- Working with asynchronous operations
|
|
16
|
+
- Building modern web applications
|
|
17
|
+
- Migrating from callbacks to Promises/async-await
|
|
18
|
+
- Implementing data transformation pipelines
|
|
19
|
+
|
|
20
|
+
## ES6+ Core Features
|
|
21
|
+
|
|
22
|
+
### 1. Arrow Functions
|
|
23
|
+
|
|
24
|
+
**Syntax and Use Cases:**
|
|
25
|
+
```javascript
|
|
26
|
+
// Traditional function
|
|
27
|
+
function add(a, b) {
|
|
28
|
+
return a + b;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Arrow function
|
|
32
|
+
const add = (a, b) => a + b;
|
|
33
|
+
|
|
34
|
+
// Single parameter (parentheses optional)
|
|
35
|
+
const double = x => x * 2;
|
|
36
|
+
|
|
37
|
+
// No parameters
|
|
38
|
+
const getRandom = () => Math.random();
|
|
39
|
+
|
|
40
|
+
// Multiple statements (need curly braces)
|
|
41
|
+
const processUser = user => {
|
|
42
|
+
const normalized = user.name.toLowerCase();
|
|
43
|
+
return { ...user, name: normalized };
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// Returning objects (wrap in parentheses)
|
|
47
|
+
const createUser = (name, age) => ({ name, age });
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**Lexical 'this' Binding:**
|
|
51
|
+
```javascript
|
|
52
|
+
class Counter {
|
|
53
|
+
constructor() {
|
|
54
|
+
this.count = 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Arrow function preserves 'this' context
|
|
58
|
+
increment = () => {
|
|
59
|
+
this.count++;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// Traditional function loses 'this' in callbacks
|
|
63
|
+
incrementTraditional() {
|
|
64
|
+
setTimeout(function() {
|
|
65
|
+
this.count++; // 'this' is undefined
|
|
66
|
+
}, 1000);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Arrow function maintains 'this'
|
|
70
|
+
incrementArrow() {
|
|
71
|
+
setTimeout(() => {
|
|
72
|
+
this.count++; // 'this' refers to Counter instance
|
|
73
|
+
}, 1000);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 2. Destructuring
|
|
79
|
+
|
|
80
|
+
**Object Destructuring:**
|
|
81
|
+
```javascript
|
|
82
|
+
const user = {
|
|
83
|
+
id: 1,
|
|
84
|
+
name: 'John Doe',
|
|
85
|
+
email: 'john@example.com',
|
|
86
|
+
address: {
|
|
87
|
+
city: 'New York',
|
|
88
|
+
country: 'USA'
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// Basic destructuring
|
|
93
|
+
const { name, email } = user;
|
|
94
|
+
|
|
95
|
+
// Rename variables
|
|
96
|
+
const { name: userName, email: userEmail } = user;
|
|
97
|
+
|
|
98
|
+
// Default values
|
|
99
|
+
const { age = 25 } = user;
|
|
100
|
+
|
|
101
|
+
// Nested destructuring
|
|
102
|
+
const { address: { city, country } } = user;
|
|
103
|
+
|
|
104
|
+
// Rest operator
|
|
105
|
+
const { id, ...userWithoutId } = user;
|
|
106
|
+
|
|
107
|
+
// Function parameters
|
|
108
|
+
function greet({ name, age = 18 }) {
|
|
109
|
+
console.log(`Hello ${name}, you are ${age}`);
|
|
110
|
+
}
|
|
111
|
+
greet(user);
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Array Destructuring:**
|
|
115
|
+
```javascript
|
|
116
|
+
const numbers = [1, 2, 3, 4, 5];
|
|
117
|
+
|
|
118
|
+
// Basic destructuring
|
|
119
|
+
const [first, second] = numbers;
|
|
120
|
+
|
|
121
|
+
// Skip elements
|
|
122
|
+
const [, , third] = numbers;
|
|
123
|
+
|
|
124
|
+
// Rest operator
|
|
125
|
+
const [head, ...tail] = numbers;
|
|
126
|
+
|
|
127
|
+
// Swapping variables
|
|
128
|
+
let a = 1, b = 2;
|
|
129
|
+
[a, b] = [b, a];
|
|
130
|
+
|
|
131
|
+
// Function return values
|
|
132
|
+
function getCoordinates() {
|
|
133
|
+
return [10, 20];
|
|
134
|
+
}
|
|
135
|
+
const [x, y] = getCoordinates();
|
|
136
|
+
|
|
137
|
+
// Default values
|
|
138
|
+
const [one, two, three = 0] = [1, 2];
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### 3. Spread and Rest Operators
|
|
142
|
+
|
|
143
|
+
**Spread Operator:**
|
|
144
|
+
```javascript
|
|
145
|
+
// Array spreading
|
|
146
|
+
const arr1 = [1, 2, 3];
|
|
147
|
+
const arr2 = [4, 5, 6];
|
|
148
|
+
const combined = [...arr1, ...arr2];
|
|
149
|
+
|
|
150
|
+
// Object spreading
|
|
151
|
+
const defaults = { theme: 'dark', lang: 'en' };
|
|
152
|
+
const userPrefs = { theme: 'light' };
|
|
153
|
+
const settings = { ...defaults, ...userPrefs };
|
|
154
|
+
|
|
155
|
+
// Function arguments
|
|
156
|
+
const numbers = [1, 2, 3];
|
|
157
|
+
Math.max(...numbers);
|
|
158
|
+
|
|
159
|
+
// Copying arrays/objects (shallow copy)
|
|
160
|
+
const copy = [...arr1];
|
|
161
|
+
const objCopy = { ...user };
|
|
162
|
+
|
|
163
|
+
// Adding items immutably
|
|
164
|
+
const newArr = [...arr1, 4, 5];
|
|
165
|
+
const newObj = { ...user, age: 30 };
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**Rest Parameters:**
|
|
169
|
+
```javascript
|
|
170
|
+
// Collect function arguments
|
|
171
|
+
function sum(...numbers) {
|
|
172
|
+
return numbers.reduce((total, num) => total + num, 0);
|
|
173
|
+
}
|
|
174
|
+
sum(1, 2, 3, 4, 5);
|
|
175
|
+
|
|
176
|
+
// With regular parameters
|
|
177
|
+
function greet(greeting, ...names) {
|
|
178
|
+
return `${greeting} ${names.join(', ')}`;
|
|
179
|
+
}
|
|
180
|
+
greet('Hello', 'John', 'Jane', 'Bob');
|
|
181
|
+
|
|
182
|
+
// Object rest
|
|
183
|
+
const { id, ...userData } = user;
|
|
184
|
+
|
|
185
|
+
// Array rest
|
|
186
|
+
const [first, ...rest] = [1, 2, 3, 4, 5];
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### 4. Template Literals
|
|
190
|
+
|
|
191
|
+
```javascript
|
|
192
|
+
// Basic usage
|
|
193
|
+
const name = 'John';
|
|
194
|
+
const greeting = `Hello, ${name}!`;
|
|
195
|
+
|
|
196
|
+
// Multi-line strings
|
|
197
|
+
const html = `
|
|
198
|
+
<div>
|
|
199
|
+
<h1>${title}</h1>
|
|
200
|
+
<p>${content}</p>
|
|
201
|
+
</div>
|
|
202
|
+
`;
|
|
203
|
+
|
|
204
|
+
// Expression evaluation
|
|
205
|
+
const price = 19.99;
|
|
206
|
+
const total = `Total: $${(price * 1.2).toFixed(2)}`;
|
|
207
|
+
|
|
208
|
+
// Tagged template literals
|
|
209
|
+
function highlight(strings, ...values) {
|
|
210
|
+
return strings.reduce((result, str, i) => {
|
|
211
|
+
const value = values[i] || '';
|
|
212
|
+
return result + str + `<mark>${value}</mark>`;
|
|
213
|
+
}, '');
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const name = 'John';
|
|
217
|
+
const age = 30;
|
|
218
|
+
const html = highlight`Name: ${name}, Age: ${age}`;
|
|
219
|
+
// Output: "Name: <mark>John</mark>, Age: <mark>30</mark>"
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### 5. Enhanced Object Literals
|
|
223
|
+
|
|
224
|
+
```javascript
|
|
225
|
+
const name = 'John';
|
|
226
|
+
const age = 30;
|
|
227
|
+
|
|
228
|
+
// Shorthand property names
|
|
229
|
+
const user = { name, age };
|
|
230
|
+
|
|
231
|
+
// Shorthand method names
|
|
232
|
+
const calculator = {
|
|
233
|
+
add(a, b) {
|
|
234
|
+
return a + b;
|
|
235
|
+
},
|
|
236
|
+
subtract(a, b) {
|
|
237
|
+
return a - b;
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
// Computed property names
|
|
242
|
+
const field = 'email';
|
|
243
|
+
const user = {
|
|
244
|
+
name: 'John',
|
|
245
|
+
[field]: 'john@example.com',
|
|
246
|
+
[`get${field.charAt(0).toUpperCase()}${field.slice(1)}`]() {
|
|
247
|
+
return this[field];
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
// Dynamic property creation
|
|
252
|
+
const createUser = (name, ...props) => {
|
|
253
|
+
return props.reduce((user, [key, value]) => ({
|
|
254
|
+
...user,
|
|
255
|
+
[key]: value
|
|
256
|
+
}), { name });
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
const user = createUser('John', ['age', 30], ['email', 'john@example.com']);
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## Asynchronous Patterns
|
|
263
|
+
|
|
264
|
+
### 1. Promises
|
|
265
|
+
|
|
266
|
+
**Creating and Using Promises:**
|
|
267
|
+
```javascript
|
|
268
|
+
// Creating a promise
|
|
269
|
+
const fetchUser = (id) => {
|
|
270
|
+
return new Promise((resolve, reject) => {
|
|
271
|
+
setTimeout(() => {
|
|
272
|
+
if (id > 0) {
|
|
273
|
+
resolve({ id, name: 'John' });
|
|
274
|
+
} else {
|
|
275
|
+
reject(new Error('Invalid ID'));
|
|
276
|
+
}
|
|
277
|
+
}, 1000);
|
|
278
|
+
});
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
// Using promises
|
|
282
|
+
fetchUser(1)
|
|
283
|
+
.then(user => console.log(user))
|
|
284
|
+
.catch(error => console.error(error))
|
|
285
|
+
.finally(() => console.log('Done'));
|
|
286
|
+
|
|
287
|
+
// Chaining promises
|
|
288
|
+
fetchUser(1)
|
|
289
|
+
.then(user => fetchUserPosts(user.id))
|
|
290
|
+
.then(posts => processPosts(posts))
|
|
291
|
+
.then(result => console.log(result))
|
|
292
|
+
.catch(error => console.error(error));
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
**Promise Combinators:**
|
|
296
|
+
```javascript
|
|
297
|
+
// Promise.all - Wait for all promises
|
|
298
|
+
const promises = [
|
|
299
|
+
fetchUser(1),
|
|
300
|
+
fetchUser(2),
|
|
301
|
+
fetchUser(3)
|
|
302
|
+
];
|
|
303
|
+
|
|
304
|
+
Promise.all(promises)
|
|
305
|
+
.then(users => console.log(users))
|
|
306
|
+
.catch(error => console.error('At least one failed:', error));
|
|
307
|
+
|
|
308
|
+
// Promise.allSettled - Wait for all, regardless of outcome
|
|
309
|
+
Promise.allSettled(promises)
|
|
310
|
+
.then(results => {
|
|
311
|
+
results.forEach(result => {
|
|
312
|
+
if (result.status === 'fulfilled') {
|
|
313
|
+
console.log('Success:', result.value);
|
|
314
|
+
} else {
|
|
315
|
+
console.log('Error:', result.reason);
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
// Promise.race - First to complete
|
|
321
|
+
Promise.race(promises)
|
|
322
|
+
.then(winner => console.log('First:', winner))
|
|
323
|
+
.catch(error => console.error(error));
|
|
324
|
+
|
|
325
|
+
// Promise.any - First to succeed
|
|
326
|
+
Promise.any(promises)
|
|
327
|
+
.then(first => console.log('First success:', first))
|
|
328
|
+
.catch(error => console.error('All failed:', error));
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### 2. Async/Await
|
|
332
|
+
|
|
333
|
+
**Basic Usage:**
|
|
334
|
+
```javascript
|
|
335
|
+
// Async function always returns a Promise
|
|
336
|
+
async function fetchUser(id) {
|
|
337
|
+
const response = await fetch(`/api/users/${id}`);
|
|
338
|
+
const user = await response.json();
|
|
339
|
+
return user;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// Error handling with try/catch
|
|
343
|
+
async function getUserData(id) {
|
|
344
|
+
try {
|
|
345
|
+
const user = await fetchUser(id);
|
|
346
|
+
const posts = await fetchUserPosts(user.id);
|
|
347
|
+
return { user, posts };
|
|
348
|
+
} catch (error) {
|
|
349
|
+
console.error('Error fetching data:', error);
|
|
350
|
+
throw error;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// Sequential vs Parallel execution
|
|
355
|
+
async function sequential() {
|
|
356
|
+
const user1 = await fetchUser(1); // Wait
|
|
357
|
+
const user2 = await fetchUser(2); // Then wait
|
|
358
|
+
return [user1, user2];
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
async function parallel() {
|
|
362
|
+
const [user1, user2] = await Promise.all([
|
|
363
|
+
fetchUser(1),
|
|
364
|
+
fetchUser(2)
|
|
365
|
+
]);
|
|
366
|
+
return [user1, user2];
|
|
367
|
+
}
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
**Advanced Patterns:**
|
|
371
|
+
```javascript
|
|
372
|
+
// Async IIFE
|
|
373
|
+
(async () => {
|
|
374
|
+
const result = await someAsyncOperation();
|
|
375
|
+
console.log(result);
|
|
376
|
+
})();
|
|
377
|
+
|
|
378
|
+
// Async iteration
|
|
379
|
+
async function processUsers(userIds) {
|
|
380
|
+
for (const id of userIds) {
|
|
381
|
+
const user = await fetchUser(id);
|
|
382
|
+
await processUser(user);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// Top-level await (ES2022)
|
|
387
|
+
const config = await fetch('/config.json').then(r => r.json());
|
|
388
|
+
|
|
389
|
+
// Retry logic
|
|
390
|
+
async function fetchWithRetry(url, retries = 3) {
|
|
391
|
+
for (let i = 0; i < retries; i++) {
|
|
392
|
+
try {
|
|
393
|
+
return await fetch(url);
|
|
394
|
+
} catch (error) {
|
|
395
|
+
if (i === retries - 1) throw error;
|
|
396
|
+
await new Promise(resolve => setTimeout(resolve, 1000 * (i + 1)));
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// Timeout wrapper
|
|
402
|
+
async function withTimeout(promise, ms) {
|
|
403
|
+
const timeout = new Promise((_, reject) =>
|
|
404
|
+
setTimeout(() => reject(new Error('Timeout')), ms)
|
|
405
|
+
);
|
|
406
|
+
return Promise.race([promise, timeout]);
|
|
407
|
+
}
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
## Functional Programming Patterns
|
|
411
|
+
|
|
412
|
+
### 1. Array Methods
|
|
413
|
+
|
|
414
|
+
**Map, Filter, Reduce:**
|
|
415
|
+
```javascript
|
|
416
|
+
const users = [
|
|
417
|
+
{ id: 1, name: 'John', age: 30, active: true },
|
|
418
|
+
{ id: 2, name: 'Jane', age: 25, active: false },
|
|
419
|
+
{ id: 3, name: 'Bob', age: 35, active: true }
|
|
420
|
+
];
|
|
421
|
+
|
|
422
|
+
// Map - Transform array
|
|
423
|
+
const names = users.map(user => user.name);
|
|
424
|
+
const upperNames = users.map(user => user.name.toUpperCase());
|
|
425
|
+
|
|
426
|
+
// Filter - Select elements
|
|
427
|
+
const activeUsers = users.filter(user => user.active);
|
|
428
|
+
const adults = users.filter(user => user.age >= 18);
|
|
429
|
+
|
|
430
|
+
// Reduce - Aggregate data
|
|
431
|
+
const totalAge = users.reduce((sum, user) => sum + user.age, 0);
|
|
432
|
+
const avgAge = totalAge / users.length;
|
|
433
|
+
|
|
434
|
+
// Group by property
|
|
435
|
+
const byActive = users.reduce((groups, user) => {
|
|
436
|
+
const key = user.active ? 'active' : 'inactive';
|
|
437
|
+
return {
|
|
438
|
+
...groups,
|
|
439
|
+
[key]: [...(groups[key] || []), user]
|
|
440
|
+
};
|
|
441
|
+
}, {});
|
|
442
|
+
|
|
443
|
+
// Chaining methods
|
|
444
|
+
const result = users
|
|
445
|
+
.filter(user => user.active)
|
|
446
|
+
.map(user => user.name)
|
|
447
|
+
.sort()
|
|
448
|
+
.join(', ');
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
**Advanced Array Methods:**
|
|
452
|
+
```javascript
|
|
453
|
+
// Find - First matching element
|
|
454
|
+
const user = users.find(u => u.id === 2);
|
|
455
|
+
|
|
456
|
+
// FindIndex - Index of first match
|
|
457
|
+
const index = users.findIndex(u => u.name === 'Jane');
|
|
458
|
+
|
|
459
|
+
// Some - At least one matches
|
|
460
|
+
const hasActive = users.some(u => u.active);
|
|
461
|
+
|
|
462
|
+
// Every - All match
|
|
463
|
+
const allAdults = users.every(u => u.age >= 18);
|
|
464
|
+
|
|
465
|
+
// FlatMap - Map and flatten
|
|
466
|
+
const userTags = [
|
|
467
|
+
{ name: 'John', tags: ['admin', 'user'] },
|
|
468
|
+
{ name: 'Jane', tags: ['user'] }
|
|
469
|
+
];
|
|
470
|
+
const allTags = userTags.flatMap(u => u.tags);
|
|
471
|
+
|
|
472
|
+
// From - Create array from iterable
|
|
473
|
+
const str = 'hello';
|
|
474
|
+
const chars = Array.from(str);
|
|
475
|
+
const numbers = Array.from({ length: 5 }, (_, i) => i + 1);
|
|
476
|
+
|
|
477
|
+
// Of - Create array from arguments
|
|
478
|
+
const arr = Array.of(1, 2, 3);
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
### 2. Higher-Order Functions
|
|
482
|
+
|
|
483
|
+
**Functions as Arguments:**
|
|
484
|
+
```javascript
|
|
485
|
+
// Custom forEach
|
|
486
|
+
function forEach(array, callback) {
|
|
487
|
+
for (let i = 0; i < array.length; i++) {
|
|
488
|
+
callback(array[i], i, array);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// Custom map
|
|
493
|
+
function map(array, transform) {
|
|
494
|
+
const result = [];
|
|
495
|
+
for (const item of array) {
|
|
496
|
+
result.push(transform(item));
|
|
497
|
+
}
|
|
498
|
+
return result;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// Custom filter
|
|
502
|
+
function filter(array, predicate) {
|
|
503
|
+
const result = [];
|
|
504
|
+
for (const item of array) {
|
|
505
|
+
if (predicate(item)) {
|
|
506
|
+
result.push(item);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return result;
|
|
510
|
+
}
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
**Functions Returning Functions:**
|
|
514
|
+
```javascript
|
|
515
|
+
// Currying
|
|
516
|
+
const multiply = a => b => a * b;
|
|
517
|
+
const double = multiply(2);
|
|
518
|
+
const triple = multiply(3);
|
|
519
|
+
|
|
520
|
+
console.log(double(5)); // 10
|
|
521
|
+
console.log(triple(5)); // 15
|
|
522
|
+
|
|
523
|
+
// Partial application
|
|
524
|
+
function partial(fn, ...args) {
|
|
525
|
+
return (...moreArgs) => fn(...args, ...moreArgs);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
const add = (a, b, c) => a + b + c;
|
|
529
|
+
const add5 = partial(add, 5);
|
|
530
|
+
console.log(add5(3, 2)); // 10
|
|
531
|
+
|
|
532
|
+
// Memoization
|
|
533
|
+
function memoize(fn) {
|
|
534
|
+
const cache = new Map();
|
|
535
|
+
return (...args) => {
|
|
536
|
+
const key = JSON.stringify(args);
|
|
537
|
+
if (cache.has(key)) {
|
|
538
|
+
return cache.get(key);
|
|
539
|
+
}
|
|
540
|
+
const result = fn(...args);
|
|
541
|
+
cache.set(key, result);
|
|
542
|
+
return result;
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
const fibonacci = memoize((n) => {
|
|
547
|
+
if (n <= 1) return n;
|
|
548
|
+
return fibonacci(n - 1) + fibonacci(n - 2);
|
|
549
|
+
});
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
### 3. Composition and Piping
|
|
553
|
+
|
|
554
|
+
```javascript
|
|
555
|
+
// Function composition
|
|
556
|
+
const compose = (...fns) => x =>
|
|
557
|
+
fns.reduceRight((acc, fn) => fn(acc), x);
|
|
558
|
+
|
|
559
|
+
const pipe = (...fns) => x =>
|
|
560
|
+
fns.reduce((acc, fn) => fn(acc), x);
|
|
561
|
+
|
|
562
|
+
// Example usage
|
|
563
|
+
const addOne = x => x + 1;
|
|
564
|
+
const double = x => x * 2;
|
|
565
|
+
const square = x => x * x;
|
|
566
|
+
|
|
567
|
+
const composed = compose(square, double, addOne);
|
|
568
|
+
console.log(composed(3)); // ((3 + 1) * 2)^2 = 64
|
|
569
|
+
|
|
570
|
+
const piped = pipe(addOne, double, square);
|
|
571
|
+
console.log(piped(3)); // ((3 + 1) * 2)^2 = 64
|
|
572
|
+
|
|
573
|
+
// Practical example
|
|
574
|
+
const processUser = pipe(
|
|
575
|
+
user => ({ ...user, name: user.name.trim() }),
|
|
576
|
+
user => ({ ...user, email: user.email.toLowerCase() }),
|
|
577
|
+
user => ({ ...user, age: parseInt(user.age) })
|
|
578
|
+
);
|
|
579
|
+
|
|
580
|
+
const user = processUser({
|
|
581
|
+
name: ' John ',
|
|
582
|
+
email: 'JOHN@EXAMPLE.COM',
|
|
583
|
+
age: '30'
|
|
584
|
+
});
|
|
585
|
+
```
|
|
586
|
+
|
|
587
|
+
### 4. Pure Functions and Immutability
|
|
588
|
+
|
|
589
|
+
```javascript
|
|
590
|
+
// Impure function (modifies input)
|
|
591
|
+
function addItemImpure(cart, item) {
|
|
592
|
+
cart.items.push(item);
|
|
593
|
+
cart.total += item.price;
|
|
594
|
+
return cart;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// Pure function (no side effects)
|
|
598
|
+
function addItemPure(cart, item) {
|
|
599
|
+
return {
|
|
600
|
+
...cart,
|
|
601
|
+
items: [...cart.items, item],
|
|
602
|
+
total: cart.total + item.price
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// Immutable array operations
|
|
607
|
+
const numbers = [1, 2, 3, 4, 5];
|
|
608
|
+
|
|
609
|
+
// Add to array
|
|
610
|
+
const withSix = [...numbers, 6];
|
|
611
|
+
|
|
612
|
+
// Remove from array
|
|
613
|
+
const withoutThree = numbers.filter(n => n !== 3);
|
|
614
|
+
|
|
615
|
+
// Update array element
|
|
616
|
+
const doubled = numbers.map(n => n === 3 ? n * 2 : n);
|
|
617
|
+
|
|
618
|
+
// Immutable object operations
|
|
619
|
+
const user = { name: 'John', age: 30 };
|
|
620
|
+
|
|
621
|
+
// Update property
|
|
622
|
+
const olderUser = { ...user, age: 31 };
|
|
623
|
+
|
|
624
|
+
// Add property
|
|
625
|
+
const withEmail = { ...user, email: 'john@example.com' };
|
|
626
|
+
|
|
627
|
+
// Remove property
|
|
628
|
+
const { age, ...withoutAge } = user;
|
|
629
|
+
|
|
630
|
+
// Deep cloning (simple approach)
|
|
631
|
+
const deepClone = obj => JSON.parse(JSON.stringify(obj));
|
|
632
|
+
|
|
633
|
+
// Better deep cloning
|
|
634
|
+
const structuredClone = obj => globalThis.structuredClone(obj);
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
## Modern Class Features
|
|
638
|
+
|
|
639
|
+
```javascript
|
|
640
|
+
// Class syntax
|
|
641
|
+
class User {
|
|
642
|
+
// Private fields
|
|
643
|
+
#password;
|
|
644
|
+
|
|
645
|
+
// Public fields
|
|
646
|
+
id;
|
|
647
|
+
name;
|
|
648
|
+
|
|
649
|
+
// Static field
|
|
650
|
+
static count = 0;
|
|
651
|
+
|
|
652
|
+
constructor(id, name, password) {
|
|
653
|
+
this.id = id;
|
|
654
|
+
this.name = name;
|
|
655
|
+
this.#password = password;
|
|
656
|
+
User.count++;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// Public method
|
|
660
|
+
greet() {
|
|
661
|
+
return `Hello, ${this.name}`;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// Private method
|
|
665
|
+
#hashPassword(password) {
|
|
666
|
+
return `hashed_${password}`;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
// Getter
|
|
670
|
+
get displayName() {
|
|
671
|
+
return this.name.toUpperCase();
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
// Setter
|
|
675
|
+
set password(newPassword) {
|
|
676
|
+
this.#password = this.#hashPassword(newPassword);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
// Static method
|
|
680
|
+
static create(id, name, password) {
|
|
681
|
+
return new User(id, name, password);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// Inheritance
|
|
686
|
+
class Admin extends User {
|
|
687
|
+
constructor(id, name, password, role) {
|
|
688
|
+
super(id, name, password);
|
|
689
|
+
this.role = role;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
greet() {
|
|
693
|
+
return `${super.greet()}, I'm an admin`;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
```
|
|
697
|
+
|
|
698
|
+
## Modules (ES6)
|
|
699
|
+
|
|
700
|
+
```javascript
|
|
701
|
+
// Exporting
|
|
702
|
+
// math.js
|
|
703
|
+
export const PI = 3.14159;
|
|
704
|
+
export function add(a, b) {
|
|
705
|
+
return a + b;
|
|
706
|
+
}
|
|
707
|
+
export class Calculator {
|
|
708
|
+
// ...
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// Default export
|
|
712
|
+
export default function multiply(a, b) {
|
|
713
|
+
return a * b;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
// Importing
|
|
717
|
+
// app.js
|
|
718
|
+
import multiply, { PI, add, Calculator } from './math.js';
|
|
719
|
+
|
|
720
|
+
// Rename imports
|
|
721
|
+
import { add as sum } from './math.js';
|
|
722
|
+
|
|
723
|
+
// Import all
|
|
724
|
+
import * as Math from './math.js';
|
|
725
|
+
|
|
726
|
+
// Dynamic imports
|
|
727
|
+
const module = await import('./math.js');
|
|
728
|
+
const { add } = await import('./math.js');
|
|
729
|
+
|
|
730
|
+
// Conditional loading
|
|
731
|
+
if (condition) {
|
|
732
|
+
const module = await import('./feature.js');
|
|
733
|
+
module.init();
|
|
734
|
+
}
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
## Iterators and Generators
|
|
738
|
+
|
|
739
|
+
```javascript
|
|
740
|
+
// Custom iterator
|
|
741
|
+
const range = {
|
|
742
|
+
from: 1,
|
|
743
|
+
to: 5,
|
|
744
|
+
|
|
745
|
+
[Symbol.iterator]() {
|
|
746
|
+
return {
|
|
747
|
+
current: this.from,
|
|
748
|
+
last: this.to,
|
|
749
|
+
|
|
750
|
+
next() {
|
|
751
|
+
if (this.current <= this.last) {
|
|
752
|
+
return { done: false, value: this.current++ };
|
|
753
|
+
} else {
|
|
754
|
+
return { done: true };
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
|
|
761
|
+
for (const num of range) {
|
|
762
|
+
console.log(num); // 1, 2, 3, 4, 5
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
// Generator function
|
|
766
|
+
function* rangeGenerator(from, to) {
|
|
767
|
+
for (let i = from; i <= to; i++) {
|
|
768
|
+
yield i;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
for (const num of rangeGenerator(1, 5)) {
|
|
773
|
+
console.log(num);
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
// Infinite generator
|
|
777
|
+
function* fibonacci() {
|
|
778
|
+
let [prev, curr] = [0, 1];
|
|
779
|
+
while (true) {
|
|
780
|
+
yield curr;
|
|
781
|
+
[prev, curr] = [curr, prev + curr];
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// Async generator
|
|
786
|
+
async function* fetchPages(url) {
|
|
787
|
+
let page = 1;
|
|
788
|
+
while (true) {
|
|
789
|
+
const response = await fetch(`${url}?page=${page}`);
|
|
790
|
+
const data = await response.json();
|
|
791
|
+
if (data.length === 0) break;
|
|
792
|
+
yield data;
|
|
793
|
+
page++;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
for await (const page of fetchPages('/api/users')) {
|
|
798
|
+
console.log(page);
|
|
799
|
+
}
|
|
800
|
+
```
|
|
801
|
+
|
|
802
|
+
## Modern Operators
|
|
803
|
+
|
|
804
|
+
```javascript
|
|
805
|
+
// Optional chaining
|
|
806
|
+
const user = { name: 'John', address: { city: 'NYC' } };
|
|
807
|
+
const city = user?.address?.city;
|
|
808
|
+
const zipCode = user?.address?.zipCode; // undefined
|
|
809
|
+
|
|
810
|
+
// Function call
|
|
811
|
+
const result = obj.method?.();
|
|
812
|
+
|
|
813
|
+
// Array access
|
|
814
|
+
const first = arr?.[0];
|
|
815
|
+
|
|
816
|
+
// Nullish coalescing
|
|
817
|
+
const value = null ?? 'default'; // 'default'
|
|
818
|
+
const value = undefined ?? 'default'; // 'default'
|
|
819
|
+
const value = 0 ?? 'default'; // 0 (not 'default')
|
|
820
|
+
const value = '' ?? 'default'; // '' (not 'default')
|
|
821
|
+
|
|
822
|
+
// Logical assignment
|
|
823
|
+
let a = null;
|
|
824
|
+
a ??= 'default'; // a = 'default'
|
|
825
|
+
|
|
826
|
+
let b = 5;
|
|
827
|
+
b ??= 10; // b = 5 (unchanged)
|
|
828
|
+
|
|
829
|
+
let obj = { count: 0 };
|
|
830
|
+
obj.count ||= 1; // obj.count = 1
|
|
831
|
+
obj.count &&= 2; // obj.count = 2
|
|
832
|
+
```
|
|
833
|
+
|
|
834
|
+
## Performance Optimization
|
|
835
|
+
|
|
836
|
+
```javascript
|
|
837
|
+
// Debounce
|
|
838
|
+
function debounce(fn, delay) {
|
|
839
|
+
let timeoutId;
|
|
840
|
+
return (...args) => {
|
|
841
|
+
clearTimeout(timeoutId);
|
|
842
|
+
timeoutId = setTimeout(() => fn(...args), delay);
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
const searchDebounced = debounce(search, 300);
|
|
847
|
+
|
|
848
|
+
// Throttle
|
|
849
|
+
function throttle(fn, limit) {
|
|
850
|
+
let inThrottle;
|
|
851
|
+
return (...args) => {
|
|
852
|
+
if (!inThrottle) {
|
|
853
|
+
fn(...args);
|
|
854
|
+
inThrottle = true;
|
|
855
|
+
setTimeout(() => inThrottle = false, limit);
|
|
856
|
+
}
|
|
857
|
+
};
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
const scrollThrottled = throttle(handleScroll, 100);
|
|
861
|
+
|
|
862
|
+
// Lazy evaluation
|
|
863
|
+
function* lazyMap(iterable, transform) {
|
|
864
|
+
for (const item of iterable) {
|
|
865
|
+
yield transform(item);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
// Use only what you need
|
|
870
|
+
const numbers = [1, 2, 3, 4, 5];
|
|
871
|
+
const doubled = lazyMap(numbers, x => x * 2);
|
|
872
|
+
const first = doubled.next().value; // Only computes first value
|
|
873
|
+
```
|
|
874
|
+
|
|
875
|
+
## Best Practices
|
|
876
|
+
|
|
877
|
+
1. **Use const by default**: Only use let when reassignment is needed
|
|
878
|
+
2. **Prefer arrow functions**: Especially for callbacks
|
|
879
|
+
3. **Use template literals**: Instead of string concatenation
|
|
880
|
+
4. **Destructure objects and arrays**: For cleaner code
|
|
881
|
+
5. **Use async/await**: Instead of Promise chains
|
|
882
|
+
6. **Avoid mutating data**: Use spread operator and array methods
|
|
883
|
+
7. **Use optional chaining**: Prevent "Cannot read property of undefined"
|
|
884
|
+
8. **Use nullish coalescing**: For default values
|
|
885
|
+
9. **Prefer array methods**: Over traditional loops
|
|
886
|
+
10. **Use modules**: For better code organization
|
|
887
|
+
11. **Write pure functions**: Easier to test and reason about
|
|
888
|
+
12. **Use meaningful variable names**: Self-documenting code
|
|
889
|
+
13. **Keep functions small**: Single responsibility principle
|
|
890
|
+
14. **Handle errors properly**: Use try/catch with async/await
|
|
891
|
+
15. **Use strict mode**: `'use strict'` for better error catching
|
|
892
|
+
|
|
893
|
+
## Common Pitfalls
|
|
894
|
+
|
|
895
|
+
1. **this binding confusion**: Use arrow functions or bind()
|
|
896
|
+
2. **Async/await without error handling**: Always use try/catch
|
|
897
|
+
3. **Promise creation unnecessary**: Don't wrap already async functions
|
|
898
|
+
4. **Mutation of objects**: Use spread operator or Object.assign()
|
|
899
|
+
5. **Forgetting await**: Async functions return promises
|
|
900
|
+
6. **Blocking event loop**: Avoid synchronous operations
|
|
901
|
+
7. **Memory leaks**: Clean up event listeners and timers
|
|
902
|
+
8. **Not handling promise rejections**: Use catch() or try/catch
|
|
903
|
+
|
|
904
|
+
## Resources
|
|
905
|
+
|
|
906
|
+
- **MDN Web Docs**: https://developer.mozilla.org/en-US/docs/Web/JavaScript
|
|
907
|
+
- **JavaScript.info**: https://javascript.info/
|
|
908
|
+
- **You Don't Know JS**: https://github.com/getify/You-Dont-Know-JS
|
|
909
|
+
- **Eloquent JavaScript**: https://eloquentjavascript.net/
|
|
910
|
+
- **ES6 Features**: http://es6-features.org/
|