dart-use-path-package
БесплатноБез исполняемых скриптовНе проверенCross-platform file and directory path manipulation, segment splitting, extension extraction, and context conversion using `package:path` and `package:file`…
от flutter★ 3 224 звезды на GitHubОб этом скилле
Safe Cross-Platform Path Manipulation in Dart
Contents
- 1. Core Principles & Cross-Platform Rules
- 2. Recommended package:path Idioms vs. String Anti-Patterns
- 3. Bridging Native Paths to POSIX, Git, & URL Contexts
- 4. Mockable File Systems (
package:filevs. Globalp.*) - 5. Extensions, Compound Extensions & Stem Extraction
- 6. Workflows & Audit Checklist
- References & Examples
1. Core Principles & Cross-Platform Rules
Avoid Treating File Paths as Raw Strings
- Native file paths on Windows use backslashes (
\), whereas macOS and Linux use forward slashes (/). - String operations like
.contains('foo/'),.startsWith('foo/'), or.split('/')silently fail on Windows native paths. - String interpolation like
'$dir/$file'injects forward slashes on Windows and produces duplicate slashes (//) when$dirends with a trailing slash.
Rule: Always decompose paths into segments using p.split(path) before inspecting directory hierarchy or segment names, and always join path components using p.join(...).
Pragmatic Boundary Joining vs. Multi-Segment Decomposition (p.join)
- Cross-Platform Libraries (Windows + POSIX): Pass individual path segments to
p.join(dir, 'sub', 'file.json')sopackage:pathinserts OS-native separators (\on Windows,/on POSIX) between every component. - POSIX-Only Tools & Static Subpath Greppability: In codebases exclusively targeting Linux/macOS (or when joining a dynamic base path to a known static subpath), decomposing 5–6 static segments into separate arguments (
p.join(home, '.local', 'share', 'app', 'bin', 'config.json')) causesdart formatto wrap across 6–8 vertical lines and destroys substring greppability (grep/code_searchfor.local/share/app/bin). - Rule for POSIX Targets: Prefer 2-argument boundary joining (
p.join(home, '.local/share/app/bin/config.json')). This prevents duplicate-slash bugs (//) at variable boundaries while preserving single-line readability and exact string searchability.
Normalization vs. Canonicalization (p.normalize vs. p.canonicalize)
p.normalize(path)resolves.and..segments purely lexically without consulting the filesystem or standardizing case.- When deduplicating directory paths or comparing physical file identity across symlinks, relative roots, or case-insensitive filesystems, use
p.canonicalize(path).
Strip Location Specifiers & Convert URIs Safely
- Strings formatted as
<path>:<line>-<col>or<path>:<line>are not pure file paths. Passing them directly top.normalizeorUri.parsecauses bugs (on Windows,Uri.parsemistakesC:for a URI scheme and:linefor a port). - Extract the trailing
:line-colsuffix via regular expression (RegExp(r'^(.*?):(\d+(?:-\d+)?)$')) before passing the file path topackage:path. - URI Boundary Conversions: When converting between file paths and
Uriobjects, always usep.toUri(path)andp.fromUri(uri)rather thanUri.parse(path)or manual string concatenation.
2. Recommended package:path Idioms vs. String Anti-Patterns
Path Joining
- Prefer:
p.join(dir, file) - Avoid:
'$dir/$file'or'a/$b' - Why: String interpolation injects
/on Windows and creates duplicate slashes (//) when$dirends with a trailing separator.
Segment Matching
- Prefer:
p.split(path).contains('foo') - Avoid:
path.contains('foo/') - Why: String matching fails on Windows backslashes (
foo\bar) and produces false positives on partial substring names (e.g.barfoo/).
Root and Directory Prefixes
- Prefer:
if (p.split(path) case ['foo', ...])(orcase ['foo', ...final rest]when extracting tail segments), orp.isWithin('foo', path) - Avoid:
path.startsWith('foo/')orp.split(path).first == 'foo' - Why: String prefix matching fails on Windows separators (
foo\bar). Callingp.split(path).firstthrows aStateErroron empty lists and requires separate.skip(1)slicing, whereas list patterns safely check non-emptiness, match multi-segment prefixes, and optionally bind...final restin a single step. When unnormalized relative prefixes like./foo/barmay appear, usep.isWithin('foo', path)(orp.split(p.normalize(path))).
File Extensions
- Prefer:
p.extension(path) == '.wasm' - Avoid:
path.endsWith('.wasm') - Why: Substring suffix matching falsely matches directories (
foo.wasm/) or non-extension suffixes.
Extension Slicing and Compound Extensions
- Prefer:
p.withoutExtension(path)andp.extension(path, 2) - Avoid: `path.lastIndexOf
Установить dart-use-path-package в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл dart-use-path-package?
Cross-platform file and directory path manipulation, segment splitting, extension extraction, and context conversion using `package:path` and `package:file`. Use when writing, inspecting, joining, splitting, or refactoring file paths, directory names, or extensions, or replacing raw string path operations (`.split('/')`, `'$dir/$file'`, `.endsWith('.ext')`, `.replaceAll('\\', '/')`). Don't use for HTTP network URI routing, database query strings, or non-path string processing.
Как установить скилл dart-use-path-package?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл dart-use-path-package запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic