@kurokeita/add-skill 2.6.1 → 3.0.1

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.
Files changed (140) hide show
  1. package/README.md +43 -64
  2. package/dist/bin/cli.js +270 -478
  3. package/dist/skills/statusline-setup/.claude-plugin/plugin.json +1 -1
  4. package/dist/skills/statusline-setup/SKILL.md +48 -448
  5. package/dist/skills/statusline-setup/mod/hooks/register.tsx +93 -103
  6. package/dist/skills/statusline-setup/mod/tests/work.test.ts +28 -10
  7. package/dist/skills/statusline-setup/mod/types/index.d.ts +2 -1
  8. package/dist/skills/universalize-agents/reference/mapping.md +3 -2
  9. package/package.json +3 -3
  10. package/dist/agents/backend-specialist.md +0 -277
  11. package/dist/agents/code-archaeologist.md +0 -114
  12. package/dist/agents/database-architect.md +0 -238
  13. package/dist/agents/debugger.md +0 -231
  14. package/dist/agents/devops-engineer.md +0 -242
  15. package/dist/agents/documentation-writer.md +0 -104
  16. package/dist/agents/explorer-agent.md +0 -79
  17. package/dist/agents/frontend-specialist.md +0 -594
  18. package/dist/agents/game-developer.md +0 -162
  19. package/dist/agents/mobile-developer.md +0 -383
  20. package/dist/agents/orchestrator.md +0 -435
  21. package/dist/agents/penetration-tester.md +0 -188
  22. package/dist/agents/performance-optimizer.md +0 -191
  23. package/dist/agents/product-manager.md +0 -122
  24. package/dist/agents/product-owner.md +0 -106
  25. package/dist/agents/project-planner.md +0 -408
  26. package/dist/agents/qa-automation-engineer.md +0 -109
  27. package/dist/agents/security-auditor.md +0 -171
  28. package/dist/agents/test-engineer.md +0 -158
  29. package/dist/skills/agent-identifier/SKILL.md +0 -431
  30. package/dist/skills/agent-identifier/examples/agent-creation-prompt.md +0 -247
  31. package/dist/skills/agent-identifier/examples/complete-agent-examples.md +0 -432
  32. package/dist/skills/agent-identifier/references/agent-creation-system-prompt.md +0 -215
  33. package/dist/skills/agent-identifier/references/system-prompt-design.md +0 -419
  34. package/dist/skills/agent-identifier/references/triggering-examples.md +0 -508
  35. package/dist/skills/agent-identifier/scripts/validate-agent.sh +0 -217
  36. package/dist/skills/code-review-excellence/SKILL.md +0 -525
  37. package/dist/skills/component-refactoring/SKILL.md +0 -492
  38. package/dist/skills/component-refactoring/references/complexity-patterns.md +0 -493
  39. package/dist/skills/component-refactoring/references/component-splitting.md +0 -477
  40. package/dist/skills/component-refactoring/references/hook-extraction.md +0 -317
  41. package/dist/skills/context7-guidelines/SKILL.md +0 -31
  42. package/dist/skills/feature-design-assistant/SKILL.md +0 -371
  43. package/dist/skills/find-bugs/SKILL.md +0 -75
  44. package/dist/skills/frontend-design/SKILL.md +0 -45
  45. package/dist/skills/go-concurrency-patterns/SKILL.md +0 -657
  46. package/dist/skills/grill-me/SKILL.md +0 -9
  47. package/dist/skills/handoff/SKILL.md +0 -16
  48. package/dist/skills/koreader-plugin-development/SKILL.md +0 -141
  49. package/dist/skills/koreader-plugin-development/examples/2-example-patch.lua +0 -17
  50. package/dist/skills/koreader-plugin-development/examples/_meta.lua +0 -6
  51. package/dist/skills/koreader-plugin-development/examples/helloworld.lua +0 -36
  52. package/dist/skills/koreader-plugin-development/references/debugging.md +0 -92
  53. package/dist/skills/koreader-plugin-development/references/events-and-widgets.md +0 -102
  54. package/dist/skills/koreader-plugin-development/references/patches.md +0 -118
  55. package/dist/skills/koreader-plugin-development/references/plugin-anatomy.md +0 -97
  56. package/dist/skills/make-instruction/SKILL.md +0 -68
  57. package/dist/skills/make-prompt/SKILL.md +0 -70
  58. package/dist/skills/make-skill/SKILL.md +0 -147
  59. package/dist/skills/prd-to-tasks/SKILL.md +0 -164
  60. package/dist/skills/react-native-async-patterns/SKILL.md +0 -256
  61. package/dist/skills/react-native-performance/SKILL.md +0 -425
  62. package/dist/skills/react-native-testing/SKILL.md +0 -458
  63. package/dist/skills/react-native-zustand-patterns/SKILL.md +0 -343
  64. package/dist/skills/skill-creator/SKILL.md +0 -385
  65. package/dist/skills/skill-creator/scripts/init_skill.cjs +0 -235
  66. package/dist/skills/skill-creator/scripts/package_skill.cjs +0 -84
  67. package/dist/skills/skill-creator/scripts/validate_skill.cjs +0 -127
  68. package/dist/skills/skill-development/SKILL.md +0 -676
  69. package/dist/skills/skill-development/references/skill-creator-original.md +0 -210
  70. package/dist/skills/sql-optimization-patterns/SKILL.md +0 -509
  71. package/dist/skills/test-driven-development/SKILL.md +0 -114
  72. package/dist/skills/test-driven-development/deep-modules.md +0 -33
  73. package/dist/skills/test-driven-development/interface-design.md +0 -35
  74. package/dist/skills/test-driven-development/mocking.md +0 -68
  75. package/dist/skills/test-driven-development/refactoring.md +0 -10
  76. package/dist/skills/test-driven-development/tests.md +0 -61
  77. package/dist/skills/vercel-react-best-practices/AGENTS.md +0 -2410
  78. package/dist/skills/vercel-react-best-practices/SKILL.md +0 -127
  79. package/dist/skills/vercel-react-best-practices/rules/advanced-event-handler-refs.md +0 -55
  80. package/dist/skills/vercel-react-best-practices/rules/advanced-use-latest.md +0 -49
  81. package/dist/skills/vercel-react-best-practices/rules/async-api-routes.md +0 -38
  82. package/dist/skills/vercel-react-best-practices/rules/async-defer-await.md +0 -80
  83. package/dist/skills/vercel-react-best-practices/rules/async-dependencies.md +0 -36
  84. package/dist/skills/vercel-react-best-practices/rules/async-parallel.md +0 -28
  85. package/dist/skills/vercel-react-best-practices/rules/async-suspense-boundaries.md +0 -99
  86. package/dist/skills/vercel-react-best-practices/rules/bundle-barrel-imports.md +0 -59
  87. package/dist/skills/vercel-react-best-practices/rules/bundle-conditional.md +0 -31
  88. package/dist/skills/vercel-react-best-practices/rules/bundle-defer-third-party.md +0 -49
  89. package/dist/skills/vercel-react-best-practices/rules/bundle-dynamic-imports.md +0 -35
  90. package/dist/skills/vercel-react-best-practices/rules/bundle-preload.md +0 -50
  91. package/dist/skills/vercel-react-best-practices/rules/client-event-listeners.md +0 -74
  92. package/dist/skills/vercel-react-best-practices/rules/client-localstorage-schema.md +0 -71
  93. package/dist/skills/vercel-react-best-practices/rules/client-passive-event-listeners.md +0 -48
  94. package/dist/skills/vercel-react-best-practices/rules/client-swr-dedup.md +0 -56
  95. package/dist/skills/vercel-react-best-practices/rules/js-batch-dom-css.md +0 -82
  96. package/dist/skills/vercel-react-best-practices/rules/js-cache-function-results.md +0 -80
  97. package/dist/skills/vercel-react-best-practices/rules/js-cache-property-access.md +0 -28
  98. package/dist/skills/vercel-react-best-practices/rules/js-cache-storage.md +0 -70
  99. package/dist/skills/vercel-react-best-practices/rules/js-combine-iterations.md +0 -32
  100. package/dist/skills/vercel-react-best-practices/rules/js-early-exit.md +0 -50
  101. package/dist/skills/vercel-react-best-practices/rules/js-hoist-regexp.md +0 -45
  102. package/dist/skills/vercel-react-best-practices/rules/js-index-maps.md +0 -37
  103. package/dist/skills/vercel-react-best-practices/rules/js-length-check-first.md +0 -50
  104. package/dist/skills/vercel-react-best-practices/rules/js-min-max-loop.md +0 -82
  105. package/dist/skills/vercel-react-best-practices/rules/js-set-map-lookups.md +0 -24
  106. package/dist/skills/vercel-react-best-practices/rules/js-tosorted-immutable.md +0 -57
  107. package/dist/skills/vercel-react-best-practices/rules/rendering-activity.md +0 -26
  108. package/dist/skills/vercel-react-best-practices/rules/rendering-animate-svg-wrapper.md +0 -47
  109. package/dist/skills/vercel-react-best-practices/rules/rendering-conditional-render.md +0 -40
  110. package/dist/skills/vercel-react-best-practices/rules/rendering-content-visibility.md +0 -38
  111. package/dist/skills/vercel-react-best-practices/rules/rendering-hoist-jsx.md +0 -46
  112. package/dist/skills/vercel-react-best-practices/rules/rendering-hydration-no-flicker.md +0 -82
  113. package/dist/skills/vercel-react-best-practices/rules/rendering-svg-precision.md +0 -28
  114. package/dist/skills/vercel-react-best-practices/rules/rerender-defer-reads.md +0 -39
  115. package/dist/skills/vercel-react-best-practices/rules/rerender-dependencies.md +0 -45
  116. package/dist/skills/vercel-react-best-practices/rules/rerender-derived-state.md +0 -29
  117. package/dist/skills/vercel-react-best-practices/rules/rerender-functional-setstate.md +0 -74
  118. package/dist/skills/vercel-react-best-practices/rules/rerender-lazy-state-init.md +0 -58
  119. package/dist/skills/vercel-react-best-practices/rules/rerender-memo.md +0 -44
  120. package/dist/skills/vercel-react-best-practices/rules/rerender-transitions.md +0 -40
  121. package/dist/skills/vercel-react-best-practices/rules/server-after-nonblocking.md +0 -73
  122. package/dist/skills/vercel-react-best-practices/rules/server-cache-lru.md +0 -41
  123. package/dist/skills/vercel-react-best-practices/rules/server-cache-react.md +0 -76
  124. package/dist/skills/vercel-react-best-practices/rules/server-parallel-fetching.md +0 -83
  125. package/dist/skills/vercel-react-best-practices/rules/server-serialization.md +0 -38
  126. package/dist/skills/web-design-guidelines/SKILL.md +0 -40
  127. package/dist/skills/workflow-patterns/SKILL.md +0 -623
  128. package/dist/skills/write-prd/SKILL.md +0 -162
  129. package/dist/workflows/brainstorm.md +0 -113
  130. package/dist/workflows/create.md +0 -60
  131. package/dist/workflows/debug.md +0 -107
  132. package/dist/workflows/deploy.md +0 -178
  133. package/dist/workflows/enhance.md +0 -64
  134. package/dist/workflows/github-pull-request-create.md +0 -134
  135. package/dist/workflows/orchestrate.md +0 -246
  136. package/dist/workflows/plan.md +0 -90
  137. package/dist/workflows/preview.md +0 -83
  138. package/dist/workflows/status.md +0 -87
  139. package/dist/workflows/test.md +0 -144
  140. package/dist/workflows/ui-ux-pro-max.md +0 -315
@@ -1,50 +0,0 @@
1
- ---
2
- title: Preload Based on User Intent
3
- impact: MEDIUM
4
- impactDescription: reduces perceived latency
5
- tags: bundle, preload, user-intent, hover
6
- ---
7
-
8
- ## Preload Based on User Intent
9
-
10
- Preload heavy bundles before they're needed to reduce perceived latency.
11
-
12
- **Example (preload on hover/focus):**
13
-
14
- ```tsx
15
- function EditorButton({ onClick }: { onClick: () => void }) {
16
- const preload = () => {
17
- if (typeof window !== 'undefined') {
18
- void import('./monaco-editor')
19
- }
20
- }
21
-
22
- return (
23
- <button
24
- onMouseEnter={preload}
25
- onFocus={preload}
26
- onClick={onClick}
27
- >
28
- Open Editor
29
- </button>
30
- )
31
- }
32
- ```
33
-
34
- **Example (preload when feature flag is enabled):**
35
-
36
- ```tsx
37
- function FlagsProvider({ children, flags }: Props) {
38
- useEffect(() => {
39
- if (flags.editorEnabled && typeof window !== 'undefined') {
40
- void import('./monaco-editor').then(mod => mod.init())
41
- }
42
- }, [flags.editorEnabled])
43
-
44
- return <FlagsContext.Provider value={flags}>
45
- {children}
46
- </FlagsContext.Provider>
47
- }
48
- ```
49
-
50
- The `typeof window !== 'undefined'` check prevents bundling preloaded modules for SSR, optimizing server bundle size and build speed.
@@ -1,74 +0,0 @@
1
- ---
2
- title: Deduplicate Global Event Listeners
3
- impact: LOW
4
- impactDescription: single listener for N components
5
- tags: client, swr, event-listeners, subscription
6
- ---
7
-
8
- ## Deduplicate Global Event Listeners
9
-
10
- Use `useSWRSubscription()` to share global event listeners across component instances.
11
-
12
- **Incorrect (N instances = N listeners):**
13
-
14
- ```tsx
15
- function useKeyboardShortcut(key: string, callback: () => void) {
16
- useEffect(() => {
17
- const handler = (e: KeyboardEvent) => {
18
- if (e.metaKey && e.key === key) {
19
- callback()
20
- }
21
- }
22
- window.addEventListener('keydown', handler)
23
- return () => window.removeEventListener('keydown', handler)
24
- }, [key, callback])
25
- }
26
- ```
27
-
28
- When using the `useKeyboardShortcut` hook multiple times, each instance will register a new listener.
29
-
30
- **Correct (N instances = 1 listener):**
31
-
32
- ```tsx
33
- import useSWRSubscription from 'swr/subscription'
34
-
35
- // Module-level Map to track callbacks per key
36
- const keyCallbacks = new Map<string, Set<() => void>>()
37
-
38
- function useKeyboardShortcut(key: string, callback: () => void) {
39
- // Register this callback in the Map
40
- useEffect(() => {
41
- if (!keyCallbacks.has(key)) {
42
- keyCallbacks.set(key, new Set())
43
- }
44
- keyCallbacks.get(key)!.add(callback)
45
-
46
- return () => {
47
- const set = keyCallbacks.get(key)
48
- if (set) {
49
- set.delete(callback)
50
- if (set.size === 0) {
51
- keyCallbacks.delete(key)
52
- }
53
- }
54
- }
55
- }, [key, callback])
56
-
57
- useSWRSubscription('global-keydown', () => {
58
- const handler = (e: KeyboardEvent) => {
59
- if (e.metaKey && keyCallbacks.has(e.key)) {
60
- keyCallbacks.get(e.key)!.forEach(cb => cb())
61
- }
62
- }
63
- window.addEventListener('keydown', handler)
64
- return () => window.removeEventListener('keydown', handler)
65
- })
66
- }
67
-
68
- function Profile() {
69
- // Multiple shortcuts will share the same listener
70
- useKeyboardShortcut('p', () => { /* ... */ })
71
- useKeyboardShortcut('k', () => { /* ... */ })
72
- // ...
73
- }
74
- ```
@@ -1,71 +0,0 @@
1
- ---
2
- title: Version and Minimize localStorage Data
3
- impact: MEDIUM
4
- impactDescription: prevents schema conflicts, reduces storage size
5
- tags: client, localStorage, storage, versioning, data-minimization
6
- ---
7
-
8
- ## Version and Minimize localStorage Data
9
-
10
- Add version prefix to keys and store only needed fields. Prevents schema conflicts and accidental storage of sensitive data.
11
-
12
- **Incorrect:**
13
-
14
- ```typescript
15
- // No version, stores everything, no error handling
16
- localStorage.setItem('userConfig', JSON.stringify(fullUserObject))
17
- const data = localStorage.getItem('userConfig')
18
- ```
19
-
20
- **Correct:**
21
-
22
- ```typescript
23
- const VERSION = 'v2'
24
-
25
- function saveConfig(config: { theme: string; language: string }) {
26
- try {
27
- localStorage.setItem(`userConfig:${VERSION}`, JSON.stringify(config))
28
- } catch {
29
- // Throws in incognito/private browsing, quota exceeded, or disabled
30
- }
31
- }
32
-
33
- function loadConfig() {
34
- try {
35
- const data = localStorage.getItem(`userConfig:${VERSION}`)
36
- return data ? JSON.parse(data) : null
37
- } catch {
38
- return null
39
- }
40
- }
41
-
42
- // Migration from v1 to v2
43
- function migrate() {
44
- try {
45
- const v1 = localStorage.getItem('userConfig:v1')
46
- if (v1) {
47
- const old = JSON.parse(v1)
48
- saveConfig({ theme: old.darkMode ? 'dark' : 'light', language: old.lang })
49
- localStorage.removeItem('userConfig:v1')
50
- }
51
- } catch {}
52
- }
53
- ```
54
-
55
- **Store minimal fields from server responses:**
56
-
57
- ```typescript
58
- // User object has 20+ fields, only store what UI needs
59
- function cachePrefs(user: FullUser) {
60
- try {
61
- localStorage.setItem('prefs:v1', JSON.stringify({
62
- theme: user.preferences.theme,
63
- notifications: user.preferences.notifications
64
- }))
65
- } catch {}
66
- }
67
- ```
68
-
69
- **Always wrap in try-catch:** `getItem()` and `setItem()` throw in incognito/private browsing (Safari, Firefox), when quota exceeded, or when disabled.
70
-
71
- **Benefits:** Schema evolution via versioning, reduced storage size, prevents storing tokens/PII/internal flags.
@@ -1,48 +0,0 @@
1
- ---
2
- title: Use Passive Event Listeners for Scrolling Performance
3
- impact: MEDIUM
4
- impactDescription: eliminates scroll delay caused by event listeners
5
- tags: client, event-listeners, scrolling, performance, touch, wheel
6
- ---
7
-
8
- ## Use Passive Event Listeners for Scrolling Performance
9
-
10
- Add `{ passive: true }` to touch and wheel event listeners to enable immediate scrolling. Browsers normally wait for listeners to finish to check if `preventDefault()` is called, causing scroll delay.
11
-
12
- **Incorrect:**
13
-
14
- ```typescript
15
- useEffect(() => {
16
- const handleTouch = (e: TouchEvent) => console.log(e.touches[0].clientX)
17
- const handleWheel = (e: WheelEvent) => console.log(e.deltaY)
18
-
19
- document.addEventListener('touchstart', handleTouch)
20
- document.addEventListener('wheel', handleWheel)
21
-
22
- return () => {
23
- document.removeEventListener('touchstart', handleTouch)
24
- document.removeEventListener('wheel', handleWheel)
25
- }
26
- }, [])
27
- ```
28
-
29
- **Correct:**
30
-
31
- ```typescript
32
- useEffect(() => {
33
- const handleTouch = (e: TouchEvent) => console.log(e.touches[0].clientX)
34
- const handleWheel = (e: WheelEvent) => console.log(e.deltaY)
35
-
36
- document.addEventListener('touchstart', handleTouch, { passive: true })
37
- document.addEventListener('wheel', handleWheel, { passive: true })
38
-
39
- return () => {
40
- document.removeEventListener('touchstart', handleTouch)
41
- document.removeEventListener('wheel', handleWheel)
42
- }
43
- }, [])
44
- ```
45
-
46
- **Use passive when:** tracking/analytics, logging, any listener that doesn't call `preventDefault()`.
47
-
48
- **Don't use passive when:** implementing custom swipe gestures, custom zoom controls, or any listener that needs `preventDefault()`.
@@ -1,56 +0,0 @@
1
- ---
2
- title: Use SWR for Automatic Deduplication
3
- impact: MEDIUM-HIGH
4
- impactDescription: automatic deduplication
5
- tags: client, swr, deduplication, data-fetching
6
- ---
7
-
8
- ## Use SWR for Automatic Deduplication
9
-
10
- SWR enables request deduplication, caching, and revalidation across component instances.
11
-
12
- **Incorrect (no deduplication, each instance fetches):**
13
-
14
- ```tsx
15
- function UserList() {
16
- const [users, setUsers] = useState([])
17
- useEffect(() => {
18
- fetch('/api/users')
19
- .then(r => r.json())
20
- .then(setUsers)
21
- }, [])
22
- }
23
- ```
24
-
25
- **Correct (multiple instances share one request):**
26
-
27
- ```tsx
28
- import useSWR from 'swr'
29
-
30
- function UserList() {
31
- const { data: users } = useSWR('/api/users', fetcher)
32
- }
33
- ```
34
-
35
- **For immutable data:**
36
-
37
- ```tsx
38
- import { useImmutableSWR } from '@/lib/swr'
39
-
40
- function StaticContent() {
41
- const { data } = useImmutableSWR('/api/config', fetcher)
42
- }
43
- ```
44
-
45
- **For mutations:**
46
-
47
- ```tsx
48
- import { useSWRMutation } from 'swr/mutation'
49
-
50
- function UpdateButton() {
51
- const { trigger } = useSWRMutation('/api/user', updateUser)
52
- return <button onClick={() => trigger()}>Update</button>
53
- }
54
- ```
55
-
56
- Reference: [https://swr.vercel.app](https://swr.vercel.app)
@@ -1,82 +0,0 @@
1
- ---
2
- title: Batch DOM CSS Changes
3
- impact: MEDIUM
4
- impactDescription: reduces reflows/repaints
5
- tags: javascript, dom, css, performance, reflow
6
- ---
7
-
8
- ## Batch DOM CSS Changes
9
-
10
- Avoid changing styles one property at a time. Group multiple CSS changes together via classes or `cssText` to minimize browser reflows.
11
-
12
- **Incorrect (multiple reflows):**
13
-
14
- ```typescript
15
- function updateElementStyles(element: HTMLElement) {
16
- // Each line triggers a reflow
17
- element.style.width = '100px'
18
- element.style.height = '200px'
19
- element.style.backgroundColor = 'blue'
20
- element.style.border = '1px solid black'
21
- }
22
- ```
23
-
24
- **Correct (add class - single reflow):**
25
-
26
- ```typescript
27
- // CSS file
28
- .highlighted-box {
29
- width: 100px;
30
- height: 200px;
31
- background-color: blue;
32
- border: 1px solid black;
33
- }
34
-
35
- // JavaScript
36
- function updateElementStyles(element: HTMLElement) {
37
- element.classList.add('highlighted-box')
38
- }
39
- ```
40
-
41
- **Correct (change cssText - single reflow):**
42
-
43
- ```typescript
44
- function updateElementStyles(element: HTMLElement) {
45
- element.style.cssText = `
46
- width: 100px;
47
- height: 200px;
48
- background-color: blue;
49
- border: 1px solid black;
50
- `
51
- }
52
- ```
53
-
54
- **React example:**
55
-
56
- ```tsx
57
- // Incorrect: changing styles one by one
58
- function Box({ isHighlighted }: { isHighlighted: boolean }) {
59
- const ref = useRef<HTMLDivElement>(null)
60
-
61
- useEffect(() => {
62
- if (ref.current && isHighlighted) {
63
- ref.current.style.width = '100px'
64
- ref.current.style.height = '200px'
65
- ref.current.style.backgroundColor = 'blue'
66
- }
67
- }, [isHighlighted])
68
-
69
- return <div ref={ref}>Content</div>
70
- }
71
-
72
- // Correct: toggle class
73
- function Box({ isHighlighted }: { isHighlighted: boolean }) {
74
- return (
75
- <div className={isHighlighted ? 'highlighted-box' : ''}>
76
- Content
77
- </div>
78
- )
79
- }
80
- ```
81
-
82
- Prefer CSS classes over inline styles when possible. Classes are cached by the browser and provide better separation of concerns.
@@ -1,80 +0,0 @@
1
- ---
2
- title: Cache Repeated Function Calls
3
- impact: MEDIUM
4
- impactDescription: avoid redundant computation
5
- tags: javascript, cache, memoization, performance
6
- ---
7
-
8
- ## Cache Repeated Function Calls
9
-
10
- Use a module-level Map to cache function results when the same function is called repeatedly with the same inputs during render.
11
-
12
- **Incorrect (redundant computation):**
13
-
14
- ```typescript
15
- function ProjectList({ projects }: { projects: Project[] }) {
16
- return (
17
- <div>
18
- {projects.map(project => {
19
- // slugify() called 100+ times for same project names
20
- const slug = slugify(project.name)
21
-
22
- return <ProjectCard key={project.id} slug={slug} />
23
- })}
24
- </div>
25
- )
26
- }
27
- ```
28
-
29
- **Correct (cached results):**
30
-
31
- ```typescript
32
- // Module-level cache
33
- const slugifyCache = new Map<string, string>()
34
-
35
- function cachedSlugify(text: string): string {
36
- if (slugifyCache.has(text)) {
37
- return slugifyCache.get(text)!
38
- }
39
- const result = slugify(text)
40
- slugifyCache.set(text, result)
41
- return result
42
- }
43
-
44
- function ProjectList({ projects }: { projects: Project[] }) {
45
- return (
46
- <div>
47
- {projects.map(project => {
48
- // Computed only once per unique project name
49
- const slug = cachedSlugify(project.name)
50
-
51
- return <ProjectCard key={project.id} slug={slug} />
52
- })}
53
- </div>
54
- )
55
- }
56
- ```
57
-
58
- **Simpler pattern for single-value functions:**
59
-
60
- ```typescript
61
- let isLoggedInCache: boolean | null = null
62
-
63
- function isLoggedIn(): boolean {
64
- if (isLoggedInCache !== null) {
65
- return isLoggedInCache
66
- }
67
-
68
- isLoggedInCache = document.cookie.includes('auth=')
69
- return isLoggedInCache
70
- }
71
-
72
- // Clear cache when auth changes
73
- function onAuthChange() {
74
- isLoggedInCache = null
75
- }
76
- ```
77
-
78
- Use a Map (not a hook) so it works everywhere: utilities, event handlers, not just React components.
79
-
80
- Reference: [How we made the Vercel Dashboard twice as fast](https://vercel.com/blog/how-we-made-the-vercel-dashboard-twice-as-fast)
@@ -1,28 +0,0 @@
1
- ---
2
- title: Cache Property Access in Loops
3
- impact: LOW-MEDIUM
4
- impactDescription: reduces lookups
5
- tags: javascript, loops, optimization, caching
6
- ---
7
-
8
- ## Cache Property Access in Loops
9
-
10
- Cache object property lookups in hot paths.
11
-
12
- **Incorrect (3 lookups × N iterations):**
13
-
14
- ```typescript
15
- for (let i = 0; i < arr.length; i++) {
16
- process(obj.config.settings.value)
17
- }
18
- ```
19
-
20
- **Correct (1 lookup total):**
21
-
22
- ```typescript
23
- const value = obj.config.settings.value
24
- const len = arr.length
25
- for (let i = 0; i < len; i++) {
26
- process(value)
27
- }
28
- ```
@@ -1,70 +0,0 @@
1
- ---
2
- title: Cache Storage API Calls
3
- impact: LOW-MEDIUM
4
- impactDescription: reduces expensive I/O
5
- tags: javascript, localStorage, storage, caching, performance
6
- ---
7
-
8
- ## Cache Storage API Calls
9
-
10
- `localStorage`, `sessionStorage`, and `document.cookie` are synchronous and expensive. Cache reads in memory.
11
-
12
- **Incorrect (reads storage on every call):**
13
-
14
- ```typescript
15
- function getTheme() {
16
- return localStorage.getItem('theme') ?? 'light'
17
- }
18
- // Called 10 times = 10 storage reads
19
- ```
20
-
21
- **Correct (Map cache):**
22
-
23
- ```typescript
24
- const storageCache = new Map<string, string | null>()
25
-
26
- function getLocalStorage(key: string) {
27
- if (!storageCache.has(key)) {
28
- storageCache.set(key, localStorage.getItem(key))
29
- }
30
- return storageCache.get(key)
31
- }
32
-
33
- function setLocalStorage(key: string, value: string) {
34
- localStorage.setItem(key, value)
35
- storageCache.set(key, value) // keep cache in sync
36
- }
37
- ```
38
-
39
- Use a Map (not a hook) so it works everywhere: utilities, event handlers, not just React components.
40
-
41
- **Cookie caching:**
42
-
43
- ```typescript
44
- let cookieCache: Record<string, string> | null = null
45
-
46
- function getCookie(name: string) {
47
- if (!cookieCache) {
48
- cookieCache = Object.fromEntries(
49
- document.cookie.split('; ').map(c => c.split('='))
50
- )
51
- }
52
- return cookieCache[name]
53
- }
54
- ```
55
-
56
- **Important (invalidate on external changes):**
57
-
58
- If storage can change externally (another tab, server-set cookies), invalidate cache:
59
-
60
- ```typescript
61
- window.addEventListener('storage', (e) => {
62
- if (e.key) storageCache.delete(e.key)
63
- })
64
-
65
- document.addEventListener('visibilitychange', () => {
66
- if (document.visibilityState === 'visible') {
67
- storageCache.clear()
68
- }
69
- })
70
- ```
@@ -1,32 +0,0 @@
1
- ---
2
- title: Combine Multiple Array Iterations
3
- impact: LOW-MEDIUM
4
- impactDescription: reduces iterations
5
- tags: javascript, arrays, loops, performance
6
- ---
7
-
8
- ## Combine Multiple Array Iterations
9
-
10
- Multiple `.filter()` or `.map()` calls iterate the array multiple times. Combine into one loop.
11
-
12
- **Incorrect (3 iterations):**
13
-
14
- ```typescript
15
- const admins = users.filter(u => u.isAdmin)
16
- const testers = users.filter(u => u.isTester)
17
- const inactive = users.filter(u => !u.isActive)
18
- ```
19
-
20
- **Correct (1 iteration):**
21
-
22
- ```typescript
23
- const admins: User[] = []
24
- const testers: User[] = []
25
- const inactive: User[] = []
26
-
27
- for (const user of users) {
28
- if (user.isAdmin) admins.push(user)
29
- if (user.isTester) testers.push(user)
30
- if (!user.isActive) inactive.push(user)
31
- }
32
- ```
@@ -1,50 +0,0 @@
1
- ---
2
- title: Early Return from Functions
3
- impact: LOW-MEDIUM
4
- impactDescription: avoids unnecessary computation
5
- tags: javascript, functions, optimization, early-return
6
- ---
7
-
8
- ## Early Return from Functions
9
-
10
- Return early when result is determined to skip unnecessary processing.
11
-
12
- **Incorrect (processes all items even after finding answer):**
13
-
14
- ```typescript
15
- function validateUsers(users: User[]) {
16
- let hasError = false
17
- let errorMessage = ''
18
-
19
- for (const user of users) {
20
- if (!user.email) {
21
- hasError = true
22
- errorMessage = 'Email required'
23
- }
24
- if (!user.name) {
25
- hasError = true
26
- errorMessage = 'Name required'
27
- }
28
- // Continues checking all users even after error found
29
- }
30
-
31
- return hasError ? { valid: false, error: errorMessage } : { valid: true }
32
- }
33
- ```
34
-
35
- **Correct (returns immediately on first error):**
36
-
37
- ```typescript
38
- function validateUsers(users: User[]) {
39
- for (const user of users) {
40
- if (!user.email) {
41
- return { valid: false, error: 'Email required' }
42
- }
43
- if (!user.name) {
44
- return { valid: false, error: 'Name required' }
45
- }
46
- }
47
-
48
- return { valid: true }
49
- }
50
- ```
@@ -1,45 +0,0 @@
1
- ---
2
- title: Hoist RegExp Creation
3
- impact: LOW-MEDIUM
4
- impactDescription: avoids recreation
5
- tags: javascript, regexp, optimization, memoization
6
- ---
7
-
8
- ## Hoist RegExp Creation
9
-
10
- Don't create RegExp inside render. Hoist to module scope or memoize with `useMemo()`.
11
-
12
- **Incorrect (new RegExp every render):**
13
-
14
- ```tsx
15
- function Highlighter({ text, query }: Props) {
16
- const regex = new RegExp(`(${query})`, 'gi')
17
- const parts = text.split(regex)
18
- return <>{parts.map((part, i) => ...)}</>
19
- }
20
- ```
21
-
22
- **Correct (memoize or hoist):**
23
-
24
- ```tsx
25
- const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
26
-
27
- function Highlighter({ text, query }: Props) {
28
- const regex = useMemo(
29
- () => new RegExp(`(${escapeRegex(query)})`, 'gi'),
30
- [query]
31
- )
32
- const parts = text.split(regex)
33
- return <>{parts.map((part, i) => ...)}</>
34
- }
35
- ```
36
-
37
- **Warning (global regex has mutable state):**
38
-
39
- Global regex (`/g`) has mutable `lastIndex` state:
40
-
41
- ```typescript
42
- const regex = /foo/g
43
- regex.test('foo') // true, lastIndex = 3
44
- regex.test('foo') // false, lastIndex = 0
45
- ```