@dayme/alien-utils 0.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/README.md +98 -0
- package/dist/bimap/bimap.d.ts +44 -0
- package/dist/bimap/bimap.d.ts.map +1 -0
- package/dist/bimap/index.d.ts +4 -0
- package/dist/bimap/index.d.ts.map +1 -0
- package/dist/dispatch/dispatch.d.ts +17 -0
- package/dist/dispatch/dispatch.d.ts.map +1 -0
- package/dist/dispatch/index.d.ts +2 -0
- package/dist/dispatch/index.d.ts.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1068 -0
- package/dist/iterator/index.d.ts +2 -0
- package/dist/iterator/index.d.ts.map +1 -0
- package/dist/iterator/iterator.d.ts +821 -0
- package/dist/iterator/iterator.d.ts.map +1 -0
- package/dist/match/index.d.ts +2 -0
- package/dist/match/index.d.ts.map +1 -0
- package/dist/match/match.d.ts +17 -0
- package/dist/match/match.d.ts.map +1 -0
- package/dist/option/index.d.ts +3 -0
- package/dist/option/index.d.ts.map +1 -0
- package/dist/option/option.d.ts +274 -0
- package/dist/option/option.d.ts.map +1 -0
- package/dist/queue/index.d.ts +2 -0
- package/dist/queue/index.d.ts.map +1 -0
- package/dist/queue/queue.d.ts +18 -0
- package/dist/queue/queue.d.ts.map +1 -0
- package/dist/result/index.d.ts +3 -0
- package/dist/result/index.d.ts.map +1 -0
- package/dist/result/result.d.ts +343 -0
- package/dist/result/result.d.ts.map +1 -0
- package/dist/stack/index.d.ts +2 -0
- package/dist/stack/index.d.ts.map +1 -0
- package/dist/stack/stack.d.ts +13 -0
- package/dist/stack/stack.d.ts.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { Option } from '../option/option';
|
|
2
|
+
/**
|
|
3
|
+
* Result type represents the result of an operation that can be either successful (Ok)
|
|
4
|
+
* or contain an error (Err). This is an alternative to using exceptions for error handling.
|
|
5
|
+
*
|
|
6
|
+
* @template T - Type of the success value
|
|
7
|
+
* @template E - Type of the error
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* function divide(a: number, b: number): Result<number, string> {
|
|
12
|
+
* if (b === 0) {
|
|
13
|
+
* return new Err("Division by zero");
|
|
14
|
+
* }
|
|
15
|
+
* return new Ok(a / b);
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export type Result<T, E> = Ok<T> | Err<E>;
|
|
20
|
+
/**
|
|
21
|
+
* Interface for the Result type, defining all available methods.
|
|
22
|
+
*
|
|
23
|
+
* @template T - Type of the success value
|
|
24
|
+
* @template E - Type of the error
|
|
25
|
+
*/
|
|
26
|
+
interface IResult<T, E> {
|
|
27
|
+
/**
|
|
28
|
+
* Checks if the result is successful (Ok).
|
|
29
|
+
*
|
|
30
|
+
* @returns true if the result is Ok, otherwise false
|
|
31
|
+
*/
|
|
32
|
+
isOk(): this is Ok<T>;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if the result is an error (Err).
|
|
35
|
+
*
|
|
36
|
+
* @returns true if the result is Err, otherwise false
|
|
37
|
+
*/
|
|
38
|
+
isErr(): this is Err<E>;
|
|
39
|
+
/**
|
|
40
|
+
* Extracts the value from Ok. Throws an error if called on Err.
|
|
41
|
+
*
|
|
42
|
+
* @throws {Error} If called on Err
|
|
43
|
+
* @returns Value of type T
|
|
44
|
+
*/
|
|
45
|
+
unwrap(): T;
|
|
46
|
+
/**
|
|
47
|
+
* Extracts the error from Err. Throws an error if called on Ok.
|
|
48
|
+
*
|
|
49
|
+
* @throws {Error} If called on Ok
|
|
50
|
+
* @returns Error of type E
|
|
51
|
+
*/
|
|
52
|
+
unwrapErr(): E;
|
|
53
|
+
/**
|
|
54
|
+
* Extracts the value from Ok or returns the default value for Err.
|
|
55
|
+
*
|
|
56
|
+
* @param defaultValue - Default value
|
|
57
|
+
* @returns Value of type T
|
|
58
|
+
*/
|
|
59
|
+
unwrapOr(defaultValue: T): T;
|
|
60
|
+
/**
|
|
61
|
+
* Extracts the value from Ok or computes a default value from the error for Err.
|
|
62
|
+
*
|
|
63
|
+
* @param fn - Function that takes an error and returns a default value
|
|
64
|
+
* @returns Value of type T
|
|
65
|
+
*/
|
|
66
|
+
unwrapOrElse(fn: (error: E) => T): T;
|
|
67
|
+
/**
|
|
68
|
+
* Applies a function to the Ok value, leaving Err unchanged.
|
|
69
|
+
*
|
|
70
|
+
* @template U - Type of the transformation result
|
|
71
|
+
* @param fn - Transformation function
|
|
72
|
+
* @returns New Result with transformed value
|
|
73
|
+
*/
|
|
74
|
+
map<U>(fn: (value: T) => U): Result<U, E>;
|
|
75
|
+
/**
|
|
76
|
+
* Applies a function to the Err error, leaving Ok unchanged.
|
|
77
|
+
*
|
|
78
|
+
* @template F - Type of the new error
|
|
79
|
+
* @param fn - Error transformation function
|
|
80
|
+
* @returns New Result with transformed error
|
|
81
|
+
*/
|
|
82
|
+
mapErr<F>(fn: (error: E) => F): Result<T, F>;
|
|
83
|
+
/**
|
|
84
|
+
* Applies a function that returns a Result to the Ok value.
|
|
85
|
+
* If the result is Ok, applies the function; if Err, returns Err unchanged.
|
|
86
|
+
*
|
|
87
|
+
* @template U - Type of the new Result value
|
|
88
|
+
* @template F - Type of the new Result error (defaults to E)
|
|
89
|
+
* @param fn - Function that takes a value and returns a Result
|
|
90
|
+
* @returns New Result
|
|
91
|
+
*/
|
|
92
|
+
andThen<U, F = E>(fn: (value: T) => Result<U, F>): Result<U, E | F>;
|
|
93
|
+
/**
|
|
94
|
+
* Matches the Result with handlers for Ok and Err.
|
|
95
|
+
*
|
|
96
|
+
* @template U - Type of the return value
|
|
97
|
+
* @param handlers - Object with handlers for Ok and Err
|
|
98
|
+
* @returns Result of the handling
|
|
99
|
+
*/
|
|
100
|
+
match<U>(handlers: {
|
|
101
|
+
Ok(value: T): U;
|
|
102
|
+
Err(error: E): U;
|
|
103
|
+
}): U;
|
|
104
|
+
/**
|
|
105
|
+
* Executes a function for the Ok value (for side-effects), returning the original Result.
|
|
106
|
+
*
|
|
107
|
+
* @param fn - Function to execute with the value
|
|
108
|
+
* @returns Original Result unchanged
|
|
109
|
+
*/
|
|
110
|
+
inspect(fn: (value: T) => void): Result<T, E>;
|
|
111
|
+
/**
|
|
112
|
+
* Executes a function for the Err error (for side-effects), returning the original Result.
|
|
113
|
+
*
|
|
114
|
+
* @param fn - Function to execute with the error
|
|
115
|
+
* @returns Original Result unchanged
|
|
116
|
+
*/
|
|
117
|
+
inspectErr(fn: (error: E) => void): Result<T, E>;
|
|
118
|
+
/**
|
|
119
|
+
* Extracts the value from Ok or throws an error with the specified message for Err.
|
|
120
|
+
*
|
|
121
|
+
* @param message - Error message
|
|
122
|
+
* @throws {Error} If called on Err
|
|
123
|
+
* @returns Value of type T
|
|
124
|
+
*/
|
|
125
|
+
expect(message: string): T;
|
|
126
|
+
/**
|
|
127
|
+
* Extracts the error from Err or throws an error with the specified message for Ok.
|
|
128
|
+
*
|
|
129
|
+
* @param message - Error message
|
|
130
|
+
* @throws {Error} If called on Ok
|
|
131
|
+
* @returns Error of type E
|
|
132
|
+
*/
|
|
133
|
+
expectErr(message: string): E;
|
|
134
|
+
/**
|
|
135
|
+
* Returns Ok if this is Ok, otherwise returns another Result.
|
|
136
|
+
*
|
|
137
|
+
* @template U - Type of the other Result value
|
|
138
|
+
* @template F - Type of the other Result error
|
|
139
|
+
* @param other - Alternative Result
|
|
140
|
+
* @returns Ok if this is Ok, otherwise other
|
|
141
|
+
*/
|
|
142
|
+
or<U, F>(other: Result<U, F>): Result<T | U, F>;
|
|
143
|
+
/**
|
|
144
|
+
* Returns Ok if this is Ok, otherwise calls a function to get an alternative Result.
|
|
145
|
+
*
|
|
146
|
+
* @template U - Type of the alternative Result value
|
|
147
|
+
* @template F - Type of the alternative Result error
|
|
148
|
+
* @param fn - Function that takes an error and returns a Result
|
|
149
|
+
* @returns Ok if this is Ok, otherwise the result of the function
|
|
150
|
+
*/
|
|
151
|
+
orElse<U, F>(fn: (error: E) => Result<U, F>): Result<T | U, F>;
|
|
152
|
+
/**
|
|
153
|
+
* Converts Result to Option: Ok becomes Some, Err becomes None.
|
|
154
|
+
*
|
|
155
|
+
* @returns Option with value if this is Ok, otherwise None
|
|
156
|
+
*/
|
|
157
|
+
ok(): Option<T>;
|
|
158
|
+
/**
|
|
159
|
+
* Converts Result to Option: Err becomes Some, Ok becomes None.
|
|
160
|
+
*
|
|
161
|
+
* @returns Option with error if this is Err, otherwise None
|
|
162
|
+
*/
|
|
163
|
+
err(): Option<E>;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Class representing a successful operation result.
|
|
167
|
+
*
|
|
168
|
+
* @template T - Type of the success value
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* const result = new Ok(42);
|
|
173
|
+
* if (result.isOk()) {
|
|
174
|
+
* console.log(result.value); // 42
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export declare class Ok<T> implements IResult<T, never> {
|
|
179
|
+
readonly value: T;
|
|
180
|
+
readonly _tag: "Ok";
|
|
181
|
+
/**
|
|
182
|
+
* Creates a new Ok instance with the specified value.
|
|
183
|
+
*
|
|
184
|
+
* @param value - Success value
|
|
185
|
+
*/
|
|
186
|
+
constructor(value: T);
|
|
187
|
+
/**
|
|
188
|
+
* Static constructor for creating Ok.
|
|
189
|
+
*
|
|
190
|
+
* @template T - Type of the value
|
|
191
|
+
* @param value - Success value
|
|
192
|
+
* @returns New Ok instance
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```ts
|
|
196
|
+
* const result = Ok.of(42);
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
static of<T>(value: T): Ok<T>;
|
|
200
|
+
/**
|
|
201
|
+
* Collects an array of Results into a single Result with an array of values.
|
|
202
|
+
* If at least one Result is Err, returns the first Err.
|
|
203
|
+
*
|
|
204
|
+
* @template T - Type of the values
|
|
205
|
+
* @template E - Type of the error
|
|
206
|
+
* @param results - Array of Results to collect
|
|
207
|
+
* @returns Result with array of values or the first Err
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* const results = [Ok.of(1), Ok.of(2), Ok.of(3)];
|
|
212
|
+
* const collected = Ok.collect(results); // Ok([1, 2, 3])
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
static collect<T, E>(results: Result<T, E>[]): Result<T[], E>;
|
|
216
|
+
/**
|
|
217
|
+
* Partitions an array of Results into two arrays: one with Ok, another with Err.
|
|
218
|
+
*
|
|
219
|
+
* @template T - Type of the values
|
|
220
|
+
* @template E - Type of the error
|
|
221
|
+
* @param results - Array of Results to partition
|
|
222
|
+
* @returns Tuple of two arrays: [Ok[], Err[]]
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```ts
|
|
226
|
+
* const results = [Ok.of(1), Err.of("error"), Ok.of(3)];
|
|
227
|
+
* const [oks, errs] = Ok.partition(results);
|
|
228
|
+
* // oks: [Ok(1), Ok(3)]
|
|
229
|
+
* // errs: [Err("error")]
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
static partition<T, E>(results: Result<T, E>[]): [Ok<T>[], Err<E>[]];
|
|
233
|
+
isOk(): this is Ok<T>;
|
|
234
|
+
isErr(): this is Err<never>;
|
|
235
|
+
unwrap(): T;
|
|
236
|
+
unwrapErr(): never;
|
|
237
|
+
unwrapOr(_defaultValue: T): T;
|
|
238
|
+
unwrapOrElse(_fn: (error: never) => T): T;
|
|
239
|
+
map<U>(fn: (value: T) => U): Result<U, never>;
|
|
240
|
+
mapErr<F>(_fn: (error: never) => F): Result<T, F>;
|
|
241
|
+
andThen<U, F = never>(fn: (value: T) => Result<U, F>): Result<U, never | F>;
|
|
242
|
+
match<U>(handlers: {
|
|
243
|
+
Ok(value: T): U;
|
|
244
|
+
Err(error: never): U;
|
|
245
|
+
}): U;
|
|
246
|
+
inspect(fn: (value: T) => void): Result<T, never>;
|
|
247
|
+
inspectErr(_fn: (error: never) => void): Result<T, never>;
|
|
248
|
+
expect(_message: string): T;
|
|
249
|
+
expectErr(message: string): never;
|
|
250
|
+
or<U, F>(_other: Result<U, F>): Result<T | U, F>;
|
|
251
|
+
orElse<U, F>(_fn: (error: never) => Result<U, F>): Result<T | U, F>;
|
|
252
|
+
ok(): Option<T>;
|
|
253
|
+
err(): Option<never>;
|
|
254
|
+
/**
|
|
255
|
+
* Returns a string representation of Ok.
|
|
256
|
+
*
|
|
257
|
+
* @returns String in the format "Ok(value)"
|
|
258
|
+
*/
|
|
259
|
+
toString(): string;
|
|
260
|
+
/**
|
|
261
|
+
* Converts Ok to a JSON-compatible object.
|
|
262
|
+
*
|
|
263
|
+
* @returns Object with fields ok: true and value
|
|
264
|
+
*/
|
|
265
|
+
toJSON(): {
|
|
266
|
+
ok: boolean;
|
|
267
|
+
value: T;
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Class representing an error in an operation result.
|
|
272
|
+
*
|
|
273
|
+
* @template E - Type of the error
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```ts
|
|
277
|
+
* const result = new Err("Something went wrong");
|
|
278
|
+
* if (result.isErr()) {
|
|
279
|
+
* console.log(result.error); // "Something went wrong"
|
|
280
|
+
* }
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
export declare class Err<E> implements IResult<never, E> {
|
|
284
|
+
readonly error: E;
|
|
285
|
+
readonly _tag: "Err";
|
|
286
|
+
/**
|
|
287
|
+
* Creates a new Err instance with the specified error.
|
|
288
|
+
*
|
|
289
|
+
* @param error - Error
|
|
290
|
+
*/
|
|
291
|
+
constructor(error: E);
|
|
292
|
+
/**
|
|
293
|
+
* Static constructor for creating Err.
|
|
294
|
+
*
|
|
295
|
+
* @template E - Type of the error
|
|
296
|
+
* @param error - Error
|
|
297
|
+
* @returns New Err instance
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```ts
|
|
301
|
+
* const result = Err.of("Error message");
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
static of<E>(error: E): Err<E>;
|
|
305
|
+
isOk(): this is Ok<never>;
|
|
306
|
+
isErr(): this is Err<E>;
|
|
307
|
+
unwrap(): never;
|
|
308
|
+
unwrapErr(): E;
|
|
309
|
+
unwrapOr<T>(defaultValue: T): T;
|
|
310
|
+
unwrapOrElse<T>(fn: (error: E) => T): T;
|
|
311
|
+
map<U>(_fn: (value: never) => U): Result<U, E>;
|
|
312
|
+
mapErr<F>(fn: (error: E) => F): Result<never, F>;
|
|
313
|
+
andThen<U, F = E>(_fn: (value: never) => Result<U, F>): Result<U, E | F>;
|
|
314
|
+
match<U>(handlers: {
|
|
315
|
+
Ok(value: never): U;
|
|
316
|
+
Err(error: E): U;
|
|
317
|
+
}): U;
|
|
318
|
+
inspect(_fn: (value: never) => void): Result<never, E>;
|
|
319
|
+
inspectErr(fn: (error: E) => void): Result<never, E>;
|
|
320
|
+
expect(message: string): never;
|
|
321
|
+
expectErr(_message: string): E;
|
|
322
|
+
or<U, F>(other: Result<U, F>): Result<U, F>;
|
|
323
|
+
orElse<U, F>(fn: (error: E) => Result<U, F>): Result<U, F>;
|
|
324
|
+
ok(): Option<never>;
|
|
325
|
+
err(): Option<E>;
|
|
326
|
+
/**
|
|
327
|
+
* Returns a string representation of Err.
|
|
328
|
+
*
|
|
329
|
+
* @returns String in the format "Err(error)"
|
|
330
|
+
*/
|
|
331
|
+
toString(): string;
|
|
332
|
+
/**
|
|
333
|
+
* Converts Err to a JSON-compatible object.
|
|
334
|
+
*
|
|
335
|
+
* @returns Object with fields ok: false and error
|
|
336
|
+
*/
|
|
337
|
+
toJSON(): {
|
|
338
|
+
ok: boolean;
|
|
339
|
+
error: E;
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
export {};
|
|
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EAAE,CAAC,CAAC;IAItD,UAAU,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IAKpD,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK;IAI9B,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC;IAI9B,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;IAI3C,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;IAI1D,EAAE,IAAI,MAAM,CAAC,KAAK,CAAC;IAInB,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC;IAIhB;;;;OAIG;IACH,QAAQ;IAIR;;;;OAIG;IACH,MAAM;;;;CAGP"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/package/stack/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Option } from '../option/option';
|
|
2
|
+
export declare class Stack<T> implements Iterable<T> {
|
|
3
|
+
private items;
|
|
4
|
+
push(value: T): this;
|
|
5
|
+
pop(): Option<T>;
|
|
6
|
+
peek(): Option<T>;
|
|
7
|
+
get size(): number;
|
|
8
|
+
isEmpty(): boolean;
|
|
9
|
+
clear(): void;
|
|
10
|
+
[Symbol.iterator](): Iterator<T>;
|
|
11
|
+
static from<T>(iterable: Iterable<T>): Stack<T>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=stack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stack.d.ts","sourceRoot":"","sources":["../../src/package/stack/stack.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG/C,qBAAa,KAAK,CAAC,CAAC,CAAE,YAAW,QAAQ,CAAC,CAAC,CAAC;IAC1C,OAAO,CAAC,KAAK,CAAW;IAExB,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAKpB,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC;IAOhB,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC;IAOjB,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,OAAO,IAAI,OAAO;IAIlB,KAAK,IAAI,IAAI;IAIb,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC;IAYhC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;CAOhD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dayme/alien-utils",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "TypeScript utility library with functional programming data structures (Option, Result, Iter, Stack, Queue, Bimap, Match, Dispatch)",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"typescript",
|
|
8
|
+
"utilities",
|
|
9
|
+
"functional",
|
|
10
|
+
"option",
|
|
11
|
+
"result",
|
|
12
|
+
"iter",
|
|
13
|
+
"stack",
|
|
14
|
+
"queue",
|
|
15
|
+
"bimap",
|
|
16
|
+
"match",
|
|
17
|
+
"dispatch"
|
|
18
|
+
],
|
|
19
|
+
"author": "LisovskiyIvan",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/LisovskiyIvan/alien-utils"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://lisovskiyivan.github.io/alien-utils",
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"module": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"import": "./dist/index.js",
|
|
32
|
+
"types": "./dist/index.d.ts"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"dev": "concurrently \"tsc --watch\" \"vite build --watch\"",
|
|
43
|
+
"build": "tsc && vite build",
|
|
44
|
+
"prepublishOnly": "bun run build",
|
|
45
|
+
"test": "bun test",
|
|
46
|
+
"test:watch": "bun test --watch",
|
|
47
|
+
"bench": "bun run tests/iterator.bench.ts",
|
|
48
|
+
"playground:dev": "vite dev --config app/playground/vite.config.ts",
|
|
49
|
+
"playground": "concurrently \"bun run dev\" \"bun run playground:dev\"",
|
|
50
|
+
"docs:dev": "cd app/docs && vite",
|
|
51
|
+
"docs:build": "cd app/docs && bun run build",
|
|
52
|
+
"docs:preview": "cd app/docs && vite preview",
|
|
53
|
+
"lint": "oxlint ./src ./tests"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@types/node": "^25.0.3",
|
|
57
|
+
"concurrently": "^9.1.0",
|
|
58
|
+
"oxlint": "^1.34.0",
|
|
59
|
+
"typescript": "~5.9.3",
|
|
60
|
+
"vite": "npm:rolldown-vite@7.2.5",
|
|
61
|
+
"vite-plugin-dts": "^4.3.0",
|
|
62
|
+
"vitepress": "^1.6.3"
|
|
63
|
+
},
|
|
64
|
+
"overrides": {
|
|
65
|
+
"vite": "npm:rolldown-vite@7.2.5"
|
|
66
|
+
},
|
|
67
|
+
"dependencies": {
|
|
68
|
+
"@types/bun": "^1.3.5"
|
|
69
|
+
}
|
|
70
|
+
}
|