Skip to main content

localstorage-patterns

Standardized patterns for localStorage utilities, including key naming conventions, error handling, and testing strategies. Use when creating or modifying localStorage utilities, when localStorage key mismatches occur, or when testing storage functionality. This codebase uses camelCase keys (e.g., pixelGameSettings, not pixel-game-settings).

来源信息

仓库
pmarashian/cursor-agent-skills
最近来源活动
2026年2月13日 19:51
检测到的 SKILL.md 语言
英语
星标
2
分支
1

安装方式

默认使用会先检查来源的 Prompt;你也可以切换为直接命令,或下载本地副本。

检查来源文件

决定是否安装前,请先阅读 SKILL.md,以及 SkillsMP 当前展示的配套文件。

文件资源管理器
4 个文件

正在显示 SKILL.md

SKILL.md
来源说明 · 只读预览
name
localStorage-patterns
description
Standardized patterns for localStorage utilities, including key naming conventions, error handling, and testing strategies. Use when creating or modifying localStorage utilities, when localStorage key mismatches occur, or when testing storage functionality. This codebase uses camelCase keys (e.g., pixelGameSettings, not pixel-game-settings).
# localStorage Patterns ## Overview Standardize localStorage utility creation with consistent key naming, error handling, and testing patterns. ## Key Naming Conventions **This codebase uses camelCase**: `pixelGameSettings` (not `pixel-game-settings`) **Before using localStorage**: 1. Read the storage utility file to find the correct key name 2. Check for constants file with exported storage keys 3. Verify key format matches codebase (camelCase) 4. Don't assume naming conventions - check actual implementation See `references/key-naming.md` for detailed naming patterns. ## Error Handling Pattern Always include error handling: 1. **Check localStorage availability**: `typeof Storage !== 'undefined'` 2. **Wrap JSON.parse in try-catch** 3. **Validate parsed data structure** 4. **Fallback to defaults on any error** 5. **Log warnings for debugging** See `references/error-handling.md` for complete error handling pattern. ## Testing Strategies - Use test seam commands to manipulate localStorage - Test both empty state and populated state - Verify persistence across page reloads - Test quota exceeded scenarios (if applicable) ## Code Structure - Separate storage utilities by domain (settings, highScores) - Export storage keys as constants - Use consistent API: `load*()`, `save*()`, `get*()` - Include JSDoc comments ## Template See `assets/template.ts` for localStorage utility template. ## Resources - `references/key-naming.md` - camelCase vs kebab-case patterns - `references/error-handling.md` - Availability checks, JSON parsing, validation - `assets/template.ts` - Template for localStorage utilities
在 GitHub 查看