Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

24 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Custom Methods

A TypeScript project that implements custom versions of JavaScript's built-in array and object methods. This project provides educational implementations and alternative versions of native methods with identical functionality.

🎯 Purpose

This project serves as:

  • Educational resource for understanding how JavaScript built-in methods work internally
  • Custom implementations with identical behavior to native methods
  • TypeScript practice with generics, type safety, and prototype extensions
  • Testing ground for exploring JavaScript array and object manipulation

πŸ“ Project Structure

CUSTOM-METHODS/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ array/
β”‚   β”‚   β”œβ”€β”€ filter/          # Custom Array.prototype.filter implementation
β”‚   β”‚   β”œβ”€β”€ find/            # Custom Array.prototype.find implementation
β”‚   β”‚   β”œβ”€β”€ map/             # Custom Array.prototype.map implementation
β”‚   β”‚   └── push/            # Custom Array.prototype.push implementation
β”‚   └── object/              # Custom object methods (future implementations)
β”œβ”€β”€ public/                  # Static assets
β”œβ”€β”€ node_modules/           # Dependencies
β”œβ”€β”€ main.ts                 # Main entry point
β”œβ”€β”€ style.css              # Styling
β”œβ”€β”€ index.html             # HTML entry point
β”œβ”€β”€ vite-env.d.ts          # Vite environment types
β”œβ”€β”€ tsconfig.json          # TypeScript configuration
β”œβ”€β”€ package.json           # Project dependencies and scripts
└── README.md              # This file

πŸš€ Getting Started

Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn
  • TypeScript knowledge

Installation

  1. Clone the repository:
git clone <repository-url>
cd CUSTOM-METHODS
  1. Install dependencies:
npm install
  1. Start the development server:
npm run dev

πŸ“š Implemented Methods

Array Methods

βœ… customPush(...args)

Custom implementation of Array.prototype.push().

const arr = [1, 2, 3];
const newLength = arr.customPush(4, 5); // Returns 5
console.log(arr); // [1, 2, 3, 4, 5]

βœ… customMap(callback, thisArg?)

Custom implementation of Array.prototype.map().

const numbers = [1, 2, 3];
const doubled = numbers.customMap(x => x * 2); // [2, 4, 6]

βœ… customFilter(callback, thisArg?)

Custom implementation of Array.prototype.filter().

const numbers = [1, 2, 3, 4, 5];
const evens = numbers.customFilter(x => x % 2 === 0); // [2, 4]

βœ… customFind(callback, thisArg?)

Custom implementation of Array.prototype.find().

const users = [{id: 1, name: 'John'}, {id: 2, name: 'Jane'}];
const user = users.customFind(u => u.id === 2); // {id: 2, name: 'Jane'}

Object Methods (Planned)

  • customKeys()
  • customValues()
  • customEntries()
  • customHasOwnProperty()

πŸ§ͺ Testing

The project includes comprehensive unit test suites using Vitest:

# Run all tests
npm test

Test Coverage

  • βœ… Unit Tests: Individual method functionality and behavior verification
  • βœ… Behavior Comparison: Direct comparison with native methods
  • βœ… Edge Cases: Empty arrays, sparse arrays, null/undefined handling
  • βœ… Type Safety: TypeScript generic constraints verification
  • βœ… Performance Benchmarks: Speed comparison with native implementations
  • βœ… Error Handling: Proper error throwing and handling

πŸ”§ Development

Adding New Methods

  1. Create a new folder in the appropriate category (src/array/ or src/object/)
  2. Implement the method with proper TypeScript types
  3. Add comprehensive JSDoc documentation
  4. Create test files comparing with native behavior
  5. Update this README

Code Style

  • Use TypeScript for all implementations
  • Follow JSDoc documentation standards
  • Maintain identical behavior to native methods
  • Include comprehensive examples
  • Write tests for all edge cases

πŸ“– Documentation Standards

Each method follows this documentation pattern:

/**
 * customMethodName - A custom implementation of the native method
 *
 * Brief description of what the method does and its behavior.
 *
 * @template T - Generic type descriptions
 * @param {type} paramName - Parameter descriptions
 * @returns {type} Return value description
 *
 * @example
 * // Usage examples
 * [1, 2, 3].customMethod(); // Expected output
 */

πŸŽ“ Educational Value

This project demonstrates:

  • Prototype Extensions: How to safely extend built-in prototypes
  • Generic Types: Advanced TypeScript generics usage
  • Algorithm Implementation: Understanding of built-in method algorithms
  • Testing Strategies: Comprehensive testing approaches
  • Documentation: Professional code documentation practices

πŸ” Features

  • Type Safety: Full TypeScript support with proper generics
  • Identical Behavior: Methods behave exactly like native implementations
  • Comprehensive Testing: Extensive test suites with edge cases
  • Educational Comments: Detailed inline documentation
  • Modern Tooling: Vite, TypeScript, Vitest setup

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/new-method
  3. Implement the method with tests and documentation
  4. Commit your changes: git commit -m 'Add customMethodName'
  5. Push to the branch: git push origin feature/new-method
  6. Submit a pull request

Contribution Guidelines

  • Ensure identical behavior to native methods
  • Include comprehensive tests
  • Follow the established documentation format
  • Add examples and edge cases
  • Update the README with new methods

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ”— Resources


Note: This project is for educational purposes. In production code, always use the native JavaScript methods unless you have specific requirements that necessitate custom implementations.

About

Custom builtin Javascript methods

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages