Skip to content

Commit d9aa268

Browse files
committed
Enhance standard library with datetime, crypto, regex modules and improvements to math/str/collections
1 parent 8a446b3 commit d9aa268

8 files changed

Lines changed: 2067 additions & 78 deletions

File tree

std/README.md

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
# ProXPL Standard Library
2+
3+
The ProXPL Standard Library provides a comprehensive set of modules for common programming tasks.
4+
5+
## Available Libraries
6+
7+
### Core Libraries
8+
9+
#### `collections.prox` - Collection Data Structures and Utilities
10+
- **Stack**: LIFO data structure with push, pop, peek operations
11+
- **Queue**: FIFO data structure with enqueue, dequeue operations
12+
- **Set**: Unique value collection
13+
- **Collections utilities**: map, filter, reduce, sort, unique, flatten, reverse, and more
14+
15+
```prox
16+
let stack = Stack();
17+
stack.push(1).push(2).push(3);
18+
print(stack.pop()); // 3
19+
20+
let numbers = [1, 2, 3, 4, 5];
21+
let doubled = Collections.map(numbers, func(x) { return x * 2; });
22+
let evens = Collections.filter(numbers, func(x) { return x % 2 == 0; });
23+
```
24+
25+
#### `str.prox` - String Manipulation
26+
Comprehensive string utilities including:
27+
- Case conversion: `upper`, `lower`, `capitalize`, `title`
28+
- Whitespace: `trim`, `trimStart`, `trimEnd`
29+
- Search: `contains`, `startsWith`, `endsWith`, `indexOf`, `lastIndexOf`
30+
- Manipulation: `split`, `replace`, `replaceAll`, `repeat`, `reverse`
31+
- Padding: `padStart`, `padEnd`
32+
- Analysis: `count`, `isDigit`, `isAlpha`, `isAlphaNumeric`
33+
- Utilities: `join`, `lines`, `words`
34+
35+
```prox
36+
let text = " hello world ";
37+
print(StringUtils.trim(text)); // "hello world"
38+
print(StringUtils.capitalize(text)); // "Hello world"
39+
print(StringUtils.title(text)); // "Hello World"
40+
print(StringUtils.repeat("Ha", 3)); // "HaHaHa"
41+
print(StringUtils.padStart("42", 5, "0")); // "00042"
42+
```
43+
44+
#### `math.prox` - Mathematical Functions
45+
Extended math library with:
46+
- **Constants**: PI, E, TAU, PHI, SQRT2, LN2, etc.
47+
- **Basic**: abs, sign, ceil, floor, round, trunc, min, max, clamp
48+
- **Power/Root**: pow, sqrt, cbrt, hypot
49+
- **Exponential**: exp, log, log2, log10, ln
50+
- **Trigonometric**: sin, cos, tan, asin, acos, atan, atan2
51+
- **Hyperbolic**: sinh, cosh, tanh
52+
- **Statistical**: sum, mean, median, variance, stddev
53+
- **ML Activation**: sigmoid, relu, leakyRelu, softplus
54+
- **Utilities**: factorial, gcd, lcm, isPrime, fibonacci, lerp, normalize, map
55+
56+
```prox
57+
print(Math.PI); // 3.14159...
58+
print(Math.factorial(5)); // 120
59+
print(Math.gcd(48, 18)); // 6
60+
print(Math.isPrime(17)); // true
61+
print(Math.fibonacci(10)); // 55
62+
print(Math.mean([1,2,3,4,5])); // 3
63+
print(Math.clamp(15, 0, 10)); // 10
64+
```
65+
66+
### New Libraries
67+
68+
#### `datetime.prox` - Date and Time Manipulation
69+
Complete date/time handling:
70+
- **DateTime class**: Date and time representation
71+
- **Factory methods**: `now()`, `fromTimestamp()`, `fromDate()`
72+
- **Getters**: year, month, day, hour, minute, second, dayOfWeek
73+
- **Formatting**: Custom format strings (YYYY-MM-DD, etc.)
74+
- **Arithmetic**: addSeconds, addMinutes, addHours, addDays, addWeeks
75+
- **Comparison**: isBefore, isAfter, isSame, diff, diffInDays
76+
- **Time utilities**: measure, formatDuration
77+
78+
```prox
79+
let now = DateTime.now();
80+
print(now.format("YYYY-MM-DD HH:mm:ss"));
81+
print(now.toISOString());
82+
83+
let future = now.addDays(7);
84+
print("Days until: " + to_string(now.diffInDays(future)));
85+
86+
let duration = Time.formatDuration(3665); // "1h 1m 5s"
87+
```
88+
89+
#### `crypto.prox` - Cryptography and Encoding
90+
Hashing, encoding, and random utilities:
91+
- **Crypto**: hashDJB2, hashSDBM, hashFNV1a, checksum, crc32
92+
- **Base64**: encode, decode
93+
- **Hex**: encode, decode
94+
- **UUID**: v4 generation, validation
95+
- **Random**: bytes, hex, alphanumeric, choice, shuffle
96+
97+
```prox
98+
let message = "Hello, World!";
99+
print(Crypto.hashDJB2(message));
100+
print(Crypto.hashFNV1a(message));
101+
102+
let uuid = UUID.v4();
103+
print(uuid); // "550e8400-e29b-41d4-a716-446655440000"
104+
105+
let randomHex = Random.hex(16);
106+
let randomStr = Random.alphanumeric(10);
107+
```
108+
109+
#### `regex.prox` - Pattern Matching and Text Processing
110+
Regular expressions and text utilities:
111+
- **Regex class**: Pattern matching with test, match, replace, split
112+
- **Pattern validation**: isEmail, isURL, isIPv4, isPhone, isCreditCard
113+
- **Character checks**: isAlphanumeric, isNumeric, isAlpha, isLowercase, isUppercase
114+
- **Extraction**: extractNumbers, extractWords
115+
- **TextUtils**: removeWhitespace, normalizeWhitespace, truncate, wordWrap, slugify, levenshtein
116+
117+
```prox
118+
print(Pattern.isEmail("test@example.com")); // true
119+
print(Pattern.isURL("https://example.com")); // true
120+
print(Pattern.isIPv4("192.168.1.1")); // true
121+
122+
let nums = Pattern.extractNumbers("Price: $99.99");
123+
print(nums); // [99.99]
124+
125+
let slug = TextUtils.slugify("Hello World!"); // "hello-world"
126+
let truncated = TextUtils.truncate("Long text...", 10, "...");
127+
```
128+
129+
### Existing Libraries
130+
131+
#### `io.prox` - Input/Output
132+
- print, println, error, readLine, flush
133+
- Color constants and setColor
134+
135+
#### `json.prox` - JSON Parsing
136+
- parse, stringify
137+
138+
#### `time.prox` - Time Functions
139+
- now, sleep, clock, measure
140+
141+
#### `fs.prox` - File System Operations
142+
- File reading, writing, and manipulation
143+
144+
#### `net.prox` - Network Operations
145+
- HTTP requests and network utilities
146+
147+
#### `os.prox` - Operating System
148+
- System information and operations
149+
150+
#### `sys.prox` - System Utilities
151+
- Runtime and system utilities
152+
153+
#### `hash.prox` - Hashing
154+
- Hash functions
155+
156+
#### `reflect.prox` - Reflection
157+
- Runtime type inspection
158+
159+
## Usage
160+
161+
To use a library in your ProXPL code:
162+
163+
```prox
164+
use std.lib.collections;
165+
use std.lib.math;
166+
use std.lib.datetime;
167+
168+
let stack = Stack();
169+
let result = Math.factorial(5);
170+
let now = DateTime.now();
171+
```
172+
173+
## Testing
174+
175+
Run the comprehensive library test:
176+
177+
```bash
178+
proxpl tests/test_libraries.prox
179+
```
180+
181+
## Contributing
182+
183+
When adding new libraries:
184+
1. Place them in `std/lib/`
185+
2. Follow the existing naming conventions
186+
3. Include comprehensive documentation
187+
4. Add tests to verify functionality
188+
5. Update this README
189+
190+
## License
191+
192+
Part of the ProXPL project. See main LICENSE file.

0 commit comments

Comments
 (0)