npm package: @maksym.seniordev25/js-common-utils
Description: A collection of useful JavaScript utility functions for URL parsing, theme management, and mathematical interpolation
Author: Maksy
Latest version: 1.0.0

# JavaScript Common Utils

A collection of useful JavaScript utility functions for URL parsing, theme management, and mathematical interpolation.

## Installation

```bash
npm install js-common-utils
```

## Usage

```javascript
const utils = require('js-common-utils');

// URL parsing
const result = utils.parse_url_in_line("Product description https://example.com/image.jpg");

// Theme colors
const theme = utils.get_theme_colors("NeonGlow");

// Interpolation
const x = utils.interpolate_x(0, 0, 10, 10, 5);
```

## API Reference

### URL Parsing

#### `parse_url_in_line(line)`

Parses a line string to extract text label and URL/image.

**Parameters:**
- `line` (string): The input line containing text and a URL

**Returns:**
- `{txt: string, url: string|null, img: string|null}|null`: Object with parsed text, URL, and image, or null if no URL found

**Example:**
```javascript
const result = parse_url_in_line("大苹果 19.9kg! 🚀https://images.photowall.com/products/45025/beer.jpg?h=699&q=85");
// Returns: {
//   txt: "大苹果 19.9kg! 🚀",
//   url: null,
//   img: "https://images.photowall.com/products/45025/beer.jpg?h=699&q=85"
// }
```

### Theme Management

#### `get_theme_colors(themeName)`

Returns theme colors based on name.

**Parameters:**
- `themeName` (string): Name of the theme

**Returns:**
- `{palette: string[], fontcolor: string}|null`: Theme object with color palette and font color, or null if theme not found

**Available Themes:**
- NeonGlow
- SunsetBlush
- Midnight
- PastelPop
- Cyberpunk
- MinimalWhite
- TropicalVibe
- Monochrome
- GoldLux
- RetroWave
- EarthTone
- Bubblegum
- DeepOcean
- LavenderDream
- CrimsonNight
- CorporateBlue
- ExecutiveGrey
- ModernSlate
- OceanTrust
- NeutralEdge
- InsightDark

**Example:**
```javascript
const theme = get_theme_colors("NeonGlow");
// Returns: {
//   palette: ["#0F0F0F", "#1F0033", "#390099", ...],
//   fontcolor: "#FFFFFF"
// }
```

### Mathematical Interpolation

#### `interpolate_x(x1, y1, x2, y2, y)`

Interpolates X coordinate given Y value along a line.

**Parameters:**
- `x1` (number): First point X coordinate
- `y1` (number): First point Y coordinate
- `x2` (number): Second point X coordinate
- `y2` (number): Second point Y coordinate
- `y` (number): Target Y coordinate

**Returns:**
- `number`: Interpolated X coordinate

**Example:**
```javascript
const x = interpolate_x(0, 0, 10, 10, 5);
// Returns: 5
```

#### `interpolate_y(x1, y1, x2, y2, x)`

Interpolates Y coordinate given X value along a line.

**Parameters:**
- `x1` (number): First point X coordinate
- `y1` (number): First point Y coordinate
- `x2` (number): Second point X coordinate
- `y2` (number): Second point Y coordinate
- `x` (number): Target X coordinate

**Returns:**
- `number`: Interpolated Y coordinate

**Example:**
```javascript
const y = interpolate_y(0, 0, 10, 10, 5);
// Returns: 5
```

#### `interpolate_points_in_arc(x, y, angleStart, angleEnd, n, jitter = 0)`

Interpolates points along an arc.

**Parameters:**
- `x` (number): Center X coordinate
- `y` (number): Center Y coordinate
- `angleStart` (number): Starting angle in radians
- `angleEnd` (number): Ending angle in radians
- `n` (number): Number of points to generate
- `jitter` (number, optional): Amount of random jitter to add (default: 0)

**Returns:**
- `Array<{x: number, y: number}>`: Array of interpolated points

**Example:**
```javascript
const points = interpolate_points_in_arc(0, 0, 0, Math.PI/2, 5);
// Returns: [
//   {x: 80, y: 0},
//   {x: 56.57, y: 56.57},
//   {x: 0, y: 80},
//   ...
// ]
```

#### `interpolate_points_in_line(x1, y1, x2, y2, n, jitter = 0)`

Interpolates points along a line.

**Parameters:**
- `x1` (number): First point X coordinate
- `y1` (number): First point Y coordinate
- `x2` (number): Second point X coordinate
- `y2` (number): Second point Y coordinate
- `n` (number): Number of points to generate
- `jitter` (number, optional): Amount of random jitter to add (default: 0)

**Returns:**
- `Array<{x: number, y: number}>`: Array of interpolated points

**Example:**
```javascript
const points = interpolate_points_in_line(0, 0, 100, 50, 5);
// Returns: [
//   {x: 0, y: 0},
//   {x: 25, y: 12.5},
//   {x: 50, y: 25},
//   {x: 75, y: 37.5},
//   {x: 100, y: 50}
// ]
```

## Features

- **URL Parsing**: Extract text and URLs from strings, with automatic image detection
- **Theme Management**: 21 pre-defined color themes for consistent styling
- **Mathematical Interpolation**: Linear and arc interpolation with optional jitter for natural-looking results
- **TypeScript Support**: Full JSDoc documentation for better IDE support

## License

MIT License