### Getting Started: Clone and Install Dependencies Source: https://github.com/mateuszperlak/better-builder-pattern/blob/main/CONTRIBUTING.md Instructions for setting up your local development environment. This involves forking and cloning the repository, creating a new feature branch, and installing project dependencies using npm or yarn. ```Shell git clone https://github.com/your-username/better-builder-pattern.git git checkout -b feature/your-feature-name npm install # OR yarn install ``` -------------------------------- ### Install better-builder-pattern with npm or Yarn Source: https://github.com/mateuszperlak/better-builder-pattern/blob/main/README.md This snippet demonstrates how to install the `better-builder-pattern` library using popular package managers. Choose either npm or Yarn to add the library to your project dependencies. ```bash npm install better-builder-pattern # or yarn add better-builder-pattern ``` -------------------------------- ### Implement TypeScript Builder Pattern with Custom Methods Source: https://github.com/mateuszperlak/better-builder-pattern/blob/main/README.md This comprehensive example illustrates how to define an interface, create a builder instance with custom methods, and chain calls to build a complex object. It showcases automatic method generation, nested property handling, and custom logic integration. ```typescript import { Builder } from 'better-builder-pattern'; // Define your interface interface Foo { id: string; name: string; item: { foo: { bar: { nested: { baz: string; }; }; }; }; relation: { id: string; value: string; }[]; metadata: { id: string; key: string; }; } // Define custom methods type (optional) type FooCustomMethods = { withValidation: (this: Foo, isValid: boolean) => Foo; } // Create a builder instance with custom methods const FooBuilder = Builder({ withValidation(this: Foo, isValid: boolean): Foo { this.id = isValid ? 'valid-id' : 'invalid-id'; return this; }, }); // Use the builder const data = FooBuilder() .withId('123') .withName('test') .withValidation(true) .withItem({ foo: { bar: { nested: { baz: 'value' } } } }) .withRelation([ { id: '1', value: 'value1' }, { id: '2', value: 'value2' } ]) .withMetadata({ id: 'meta1', key: 'key1' }) .build(); ``` -------------------------------- ### Integrate Custom Methods into TypeScript Builder Source: https://github.com/mateuszperlak/better-builder-pattern/blob/main/README.md This example shows how to define and integrate custom methods into your builder, ensuring type safety. Custom methods allow you to encapsulate specific logic or validations directly within the builder's chainable API. ```typescript type CustomMethods = { withValidation: (this: YourType, isValid: boolean) => YourType; } const YourBuilder = Builder({ withValidation(this: YourType, isValid: boolean): YourType { // Your custom logic here return this; }, }); ``` -------------------------------- ### Development Workflow: Test and Build Commands Source: https://github.com/mateuszperlak/better-builder-pattern/blob/main/CONTRIBUTING.md Essential commands for the development workflow, including running tests to ensure code quality and building the project. It's crucial to pass all tests before submitting a pull request. ```Shell npm test # OR yarn test npm run build # OR yarn build ``` -------------------------------- ### Conventional Commit Message Format Source: https://github.com/mateuszperlak/better-builder-pattern/blob/main/CONTRIBUTING.md Adherence to the Conventional Commits specification is required for all commit messages. This format helps in generating changelogs and understanding the nature of changes at a glance. It includes a type, an optional scope, and a description. ```Text (): [optional body] [optional footer(s)] ``` -------------------------------- ### Manage Array Properties with TypeScript Builder Source: https://github.com/mateuszperlak/better-builder-pattern/blob/main/README.md This snippet illustrates the builder's built-in support for array properties. It demonstrates how to set an array of objects, ensuring proper type handling for collections within your data model. ```typescript .withRelation([ { id: '1', value: 'value1' }, { id: '2', value: 'value2' } ]) ``` -------------------------------- ### Configure Default Data for TypeScript Builder Instances Source: https://github.com/mateuszperlak/better-builder-pattern/blob/main/README.md This snippet demonstrates how to provide default values to a builder, which act as fallbacks for properties not explicitly set. It shows how to initialize a builder with a base data structure and then optionally override specific fields. ```typescript // Define default data const defaultUser = { id: 'default-id', name: 'Default User', address: { street: 'Default Street', city: 'Default City', zipCode: '00000', country: 'Default Country' } }; // Create a builder with default data const UserBuilder = Builder({}, defaultUser); // Use default values const user1 = UserBuilder().build(); // Result: { id: 'default-id', name: 'Default User', address: {...} } // Override specific values const user2 = UserBuilder() .withName('Custom User') .withAddress({ street: 'Custom Street', city: 'Custom City', zipCode: '11111', country: 'Custom Country' }) .build(); // Result: { id: 'default-id', name: 'Custom User', address: {...} } ``` -------------------------------- ### Handle Nested TypeScript Object Properties with Builder Source: https://github.com/mateuszperlak/better-builder-pattern/blob/main/README.md This snippet demonstrates how the builder pattern supports deeply nested object properties while maintaining full type safety. It shows how to set values for complex, multi-level structures within your data model. ```typescript .withItem({ foo: { bar: { nested: { baz: 'value' } } } }) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.