Claude-skill-registry creating-libraries
This skill should be used when the user asks to "create a library", "scaffold a new lib", "add a local library", "create a namespace module", "set up _.ts and __.ts", or needs to create a new TypeScript library following the _.ts/__.ts namespace pattern. Handles both simple (single file) and complex (barrel) library structures.
install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/creating-libraries" ~/.claude/skills/majiayu000-claude-skill-registry-creating-libraries && rm -rf "$T"
manifest:
skills/data/creating-libraries/SKILL.mdsource content
Creating Libraries
Scaffold new TypeScript libraries following the namespace module conventions.
CRITICAL
Read the Conventions First
Before creating any library, read the appropriate convention documents:
- Core pattern:
— The abstract~/.claude/docs/conventions/namespace-module.md
/_.ts
pattern__.ts - Local libraries (
):/src/lib/*~/.claude/docs/conventions/library-local.md - Package libraries (package IS the library):
~/.claude/docs/conventions/library-package.md
File Naming
— Namespace module (REQUIRED)_.ts
— Barrel module (only if multiple implementation files)__.ts
— Public API tests_.test.ts
— Shared test fixtures (exports_.test.fixture.ts
)namespace Fx
Operations
Create Simple Library (Single Implementation)
Use when library has one implementation file.
Structure:
src/lib/<name>/ ├── _.ts # export * as Name from './<name>.js' ├── <name>.ts # Implementation └── _.test.ts # Tests
Steps:
- Create directory at
(kebab-case)src/lib/<name>/ - Create
with implementation<name>.ts - Create
with:_.tsexport * as <PascalName> from './<name>.js' - Create
importing from_.test.ts./_.js - Add to
imports:package.json"#<name>": "./build/lib/<name>/_.js" - Add to
paths:tsconfig.json"#<name>": ["src/lib/<name>/_.ts"]
Create Complex Library (Multiple Files)
Use when library has multiple implementation files.
Structure:
src/lib/<name>/ ├── _.ts # export * as Name from './__.js' ├── __.ts # Barrel: exports from all implementation files ├── foo.ts # Implementation ├── bar.ts # Implementation └── _.test.ts # Tests
Steps:
- Create directory at
(kebab-case)src/lib/<name>/ - Create implementation files
- Create
with re-exports from all implementation files__.ts - Create
with:_.tsexport * as <PascalName> from './__.js' - Create
importing from_.test.ts./_.js - Add package.json imports and tsconfig.json paths
Examples
Simple Library Example
// src/lib/mask/mask.ts export const create = (pattern: string): Mask => ({ pattern }) export const apply = (mask: Mask, value: string): string => value export interface Mask { pattern: string } // src/lib/mask/_.ts export * as Mask from './mask.js' // src/lib/mask/_.test.ts import { Mask } from './_.js' test('.create', () => {/* ... */})
Complex Library Example
// src/lib/parser/tokenizer.ts export const tokenize = (input: string): Token[] => [] // src/lib/parser/lexer.ts export const lex = (tokens: Token[]): Lexeme[] => [] // src/lib/parser/__.ts export { lex, type Lexeme } from './lexer.js' export { type Token, tokenize } from './tokenizer.js' // src/lib/parser/_.ts export * as Parser from './__.js'
Reference
Naming Conventions
| Element | Case | Example |
|---|---|---|
| Directory | kebab-case | |
| Files | kebab-case | |
| Namespace | PascalCase | |
Package.json Imports Entry
{ "imports": { "#<name>": "./build/lib/<name>/_.js" } }
TSConfig Paths Entry
{ "compilerOptions": { "paths": { "#<name>": ["src/lib/<name>/_.ts"] } } }
Notes
- Always use
extension in imports (ESM requirement).js - Namespace name = PascalCase of directory name
- Tests import ONLY from
, never from implementation files_.ts - Code modules can import siblings via relative paths
- Cross-library imports use
subpath imports#<name>