@bubblesjs/utils
Utility function collection containing common helper methods and type utilities.
Installation
Quick Usage
API Documentation
Utility Functions
deepMergeObject(target, source)
Deep merge two objects, supporting recursive merging of nested objects.
Parameters:
target:object- Target objectsource:object- Source object
Return Value:
object- New merged object
Example:
Notes:
- Arrays are replaced entirely, not merged at element level
- Special objects like functions, Date, RegExp are assigned directly
- Source object properties override target object properties with the same name
isReadableStream(obj)
Checks if an object is a ReadableStream.
Parameters:
obj:any- Object to check
Return Value:
boolean- Returns true if it's a readable stream, false otherwise
Example:
Use Cases:
- Distinguish different types of response bodies
- Conditionally handle stream data
- Adapter compatibility checks
Use Cases
1. Configuration Object Merging
2. Response Handling Adaptation
3. Component Property Merging
Type Definitions
Best Practices
1. Configuration Management
2. Response Adapter
3. Utility Function Combination
FAQ
Q: Does deepMergeObject modify the original objects?
A: No. deepMergeObject creates a new object and doesn't modify the input objects.
Q: How to handle array merging?
A: The current implementation replaces arrays entirely. If you need element-level array merging, you can customize the handling:
Q: Which environments does isReadableStream support?
A: Supports ReadableStream in modern browsers and Node.js environments. For unsupported environments, it safely returns false.
Summary
@bubblesjs/utils provides practical utility functions, particularly suitable for:
- Configuration Management: Use
deepMergeObjectfor flexible configuration merging - Response Handling: Use
isReadableStreamto adapt different response types - Data Processing: Provide reliable tool support in various data manipulation scenarios
These utility functions are thoroughly tested and can be safely used in production environments.