oop-to-fp-refactor

Convert OOP TypeScript classes and factories into pure functions and interfaces.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/linzb93/cli-tools --skill oop-to-fp-refactor
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: oop-to-fp-refactor
Source: https://github.com/linzb93/cli-tools/tree/main/.trae/skills/oop-to-fp-refactor
Command: npx skills add https://github.com/linzb93/cli-tools --skill oop-to-fp-refactor

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

将面向对象编程 (OOP) 代码(类、继承、工厂模式)重构为函数式编程 (FP) 风格(纯函数、接口)。当需要重构旧的 OOP 代码或用户要求“函数式重构xx命令”时调用。

Core Features & Use Cases

  • 识别并定位 OOP 代码中的类、继承和工厂模式,映射到等效的 FP 结构(函数、接口、模块导出)。
  • 在不改变核心行为的前提下,移除类、构造函数并将公共方法转换为导出的常量函数,私有方法转为文件作用域函数。
  • 提供系统化的迁移策略,支持将状态从实例成员转换为纯参数传递,并更新依赖注入模式以使用单例工具。
  • Use Case: 将含有大量实例化和多态行为的 CLI 子命令重写为纯函数风格,提升可测试性与组合性。

Quick Start

Follow the refactor guide to convert a sample OOP CLI command into a pure function module, ensuring exported API matches the original usage and updating imports accordingly.

Frequently Asked Questions about oop-to-fp-refactor

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor TypeScript OOP code to functional programming?

Refactor TypeScript OOP code to functional programming by replacing classes and constructors with pure functions, converting public methods to exported constant functions, and moving private methods to file scope.

What is the best way to convert class instance state to pure function arguments?

Converting class instance state to pure function arguments requires replacing internal instance members with explicit parameter passing, ensuring stateless execution while preserving the original runtime behavior.

How do I update dependency injection when rewriting OOP TypeScript to FP?

Update dependency injection when rewriting OOP TypeScript to FP by replacing instantiated class factories with singleton tools and adjusting imports to consume pure functional equivalents.

How to rewrite CLI command implementations from classes to pure functions?

Rewrite CLI command implementations from classes to pure functions by discovering explicit entry points, removing inheritance, and mapping factory patterns to modular function exports.

Does functional refactoring change the exported API of the original TypeScript code?

Functional refactoring preserves the exported API of the original TypeScript code by matching the original usage signatures while replacing the underlying class constructs with trimmed functional equivalents.

When should I not use functional programming to refactor TypeScript code?

Avoid functional programming refactoring for TypeScript code heavily reliant on complex inheritance hierarchies or polymorphic behaviors where mapping to pure functions would obscure logic and reduce clarity.