@abdokouta/react-support 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/LICENSE +21 -0
- package/README.md +178 -0
- package/dist/index.d.cts +1749 -0
- package/dist/index.d.ts +1749 -0
- package/dist/index.js +2418 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2385 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +84 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [1.0.0] - 2024-03-31
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Initial release
|
|
10
|
+
- `Str` class with 100+ Laravel-style string manipulation methods
|
|
11
|
+
- `Collection` class for array collections (powered by collect.js)
|
|
12
|
+
- `MapCollection` class for Map data structures
|
|
13
|
+
- `SetCollection` class for Set data structures
|
|
14
|
+
- `BaseRegistry` class for building extensible registry patterns
|
|
15
|
+
- Full TypeScript support with comprehensive type definitions
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Refine
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# @abdokouta/support
|
|
2
|
+
|
|
3
|
+
Laravel-style utilities for JavaScript/TypeScript. Provides powerful string manipulation, collection handling, and registry patterns inspired by Laravel's support package.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- π― **Str Class**: 100+ string manipulation methods matching Laravel's API
|
|
8
|
+
- π¦ **Collection**: Array collection with 50+ chainable methods (powered by collect.js)
|
|
9
|
+
- πΊοΈ **MapCollection**: Map data structure with collection methods
|
|
10
|
+
- π² **SetCollection**: Set data structure with collection methods
|
|
11
|
+
- ποΈ **BaseRegistry**: Generic registry pattern for building extensible systems
|
|
12
|
+
- πͺ **TypeScript**: Full type safety with comprehensive type definitions
|
|
13
|
+
- π **Chainable**: Fluent, chainable API for elegant code
|
|
14
|
+
- π **Zero Config**: Works out of the box
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @abdokouta/support
|
|
20
|
+
# or
|
|
21
|
+
pnpm add @abdokouta/support
|
|
22
|
+
# or
|
|
23
|
+
yarn add @abdokouta/support
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
### Str Class
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { Str } from '@abdokouta/support';
|
|
32
|
+
|
|
33
|
+
// String manipulation
|
|
34
|
+
Str.camel('foo_bar'); // 'fooBar'
|
|
35
|
+
Str.snake('fooBar'); // 'foo_bar'
|
|
36
|
+
Str.kebab('fooBar'); // 'foo-bar'
|
|
37
|
+
Str.studly('foo_bar'); // 'FooBar'
|
|
38
|
+
Str.title('a nice title'); // 'A Nice Title'
|
|
39
|
+
|
|
40
|
+
// String inspection
|
|
41
|
+
Str.contains('This is my name', 'my'); // true
|
|
42
|
+
Str.startsWith('Hello World', 'Hello'); // true
|
|
43
|
+
Str.endsWith('Hello World', 'World'); // true
|
|
44
|
+
Str.isJson('{"key": "value"}'); // true
|
|
45
|
+
Str.isUrl('https://example.com'); // true
|
|
46
|
+
Str.isUuid('a0a2a2d2-0b87-4a18-83f2-2529882be2de'); // true
|
|
47
|
+
|
|
48
|
+
// String extraction
|
|
49
|
+
Str.after('This is my name', 'This is'); // ' my name'
|
|
50
|
+
Str.before('This is my name', 'my'); // 'This is '
|
|
51
|
+
Str.between('This is my name', 'This', 'name'); // ' is my '
|
|
52
|
+
|
|
53
|
+
// String modification
|
|
54
|
+
Str.limit('The quick brown fox', 10); // 'The quick...'
|
|
55
|
+
Str.slug('Laravel 5 Framework', '-'); // 'laravel-5-framework'
|
|
56
|
+
|
|
57
|
+
// And 80+ more methods!
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Collection (Array)
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { collect } from '@abdokouta/support';
|
|
64
|
+
|
|
65
|
+
// Create a collection
|
|
66
|
+
const collection = collect([1, 2, 3, 4, 5]);
|
|
67
|
+
|
|
68
|
+
// Chainable methods
|
|
69
|
+
collection
|
|
70
|
+
.filter(item => item > 2)
|
|
71
|
+
.map(item => item * 2)
|
|
72
|
+
.sum(); // 24
|
|
73
|
+
|
|
74
|
+
// Working with objects
|
|
75
|
+
const users = collect([
|
|
76
|
+
{ name: 'John', age: 30 },
|
|
77
|
+
{ name: 'Jane', age: 25 },
|
|
78
|
+
{ name: 'Bob', age: 35 }
|
|
79
|
+
]);
|
|
80
|
+
|
|
81
|
+
users.where('age', '>', 25).pluck('name').all();
|
|
82
|
+
// ['John', 'Bob']
|
|
83
|
+
|
|
84
|
+
// Aggregation
|
|
85
|
+
collect([1, 2, 3, 4, 5]).sum(); // 15
|
|
86
|
+
collect([1, 2, 3, 4, 5]).avg(); // 3
|
|
87
|
+
collect([1, 2, 3, 4, 5]).max(); // 5
|
|
88
|
+
collect([1, 2, 3, 4, 5]).min(); // 1
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### MapCollection
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { collectMap } from '@abdokouta/support';
|
|
95
|
+
|
|
96
|
+
const map = collectMap({ name: 'John', age: 30 });
|
|
97
|
+
|
|
98
|
+
map.set('city', 'New York');
|
|
99
|
+
map.get('name'); // 'John'
|
|
100
|
+
map.has('age'); // true
|
|
101
|
+
map.keys(); // ['name', 'age', 'city']
|
|
102
|
+
map.values(); // ['John', 30, 'New York']
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### SetCollection
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { collectSet } from '@abdokouta/support';
|
|
109
|
+
|
|
110
|
+
const set1 = collectSet([1, 2, 3]);
|
|
111
|
+
const set2 = collectSet([2, 3, 4]);
|
|
112
|
+
|
|
113
|
+
set1.union(set2).all(); // [1, 2, 3, 4]
|
|
114
|
+
set1.intersect(set2).all(); // [2, 3]
|
|
115
|
+
set1.diff(set2).all(); // [1]
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### BaseRegistry
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
import { BaseRegistry } from '@abdokouta/support';
|
|
122
|
+
|
|
123
|
+
// Create a typed registry
|
|
124
|
+
interface Theme {
|
|
125
|
+
name: string;
|
|
126
|
+
colors: Record<string, string>;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const themeRegistry = new BaseRegistry<Theme>({
|
|
130
|
+
validateBeforeAdd: (key, theme) => {
|
|
131
|
+
if (!theme.name) {
|
|
132
|
+
return { valid: false, error: 'Theme must have a name' };
|
|
133
|
+
}
|
|
134
|
+
return { valid: true };
|
|
135
|
+
},
|
|
136
|
+
afterAdd: (key, theme) => {
|
|
137
|
+
console.log(`Registered theme: ${theme.name}`);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// Register items
|
|
142
|
+
themeRegistry.register('dark', { name: 'Dark', colors: { bg: '#000' } });
|
|
143
|
+
themeRegistry.register('light', { name: 'Light', colors: { bg: '#fff' } });
|
|
144
|
+
|
|
145
|
+
// Retrieve items
|
|
146
|
+
const theme = themeRegistry.get('dark');
|
|
147
|
+
const allThemes = themeRegistry.getAll();
|
|
148
|
+
const hasTheme = themeRegistry.has('dark');
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## TypeScript Support
|
|
152
|
+
|
|
153
|
+
Full TypeScript support with comprehensive type definitions:
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { Str, Collection, MapCollection, SetCollection, BaseRegistry } from '@abdokouta/support';
|
|
157
|
+
|
|
158
|
+
// Type-safe collections
|
|
159
|
+
const numbers: Collection<number> = collect([1, 2, 3]);
|
|
160
|
+
|
|
161
|
+
// Type-safe maps
|
|
162
|
+
const userMap: MapCollection<string, User> = collectMap();
|
|
163
|
+
|
|
164
|
+
// Type-safe sets
|
|
165
|
+
const tags: SetCollection<string> = collectSet(['tag1', 'tag2']);
|
|
166
|
+
|
|
167
|
+
// Type-safe registries
|
|
168
|
+
const registry = new BaseRegistry<MyType>();
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
MIT
|
|
174
|
+
|
|
175
|
+
## Credits
|
|
176
|
+
|
|
177
|
+
- Inspired by [Laravel](https://laravel.com)'s support package
|
|
178
|
+
- Array collections powered by [collect.js](https://collect.js.org/)
|