promise-logic 1.3.1 β†’ 2.3.3

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.
Files changed (60) hide show
  1. package/README.md +211 -259
  2. package/dist/factory.cjs.js +15 -1
  3. package/dist/factory.cjs.js.map +1 -1
  4. package/dist/factory.esm.js +15 -1
  5. package/dist/factory.esm.js.map +1 -1
  6. package/dist/index.cjs.js +15 -1
  7. package/dist/index.cjs.js.map +1 -1
  8. package/dist/index.esm.js +15 -1
  9. package/dist/index.esm.js.map +1 -1
  10. package/dist/v2/factory.cjs.js +287 -0
  11. package/dist/v2/factory.cjs.js.map +1 -0
  12. package/dist/v2/factory.esm.js +285 -0
  13. package/dist/v2/factory.esm.js.map +1 -0
  14. package/dist/v2/gates/BaseGate.d.ts +6 -0
  15. package/dist/v2/gates/BaseGate.d.ts.map +1 -0
  16. package/dist/v2/gates/and.d.ts +5 -0
  17. package/dist/v2/gates/and.d.ts.map +1 -0
  18. package/dist/v2/gates/majority.d.ts +5 -0
  19. package/dist/v2/gates/majority.d.ts.map +1 -0
  20. package/dist/v2/gates/nand.d.ts +5 -0
  21. package/dist/v2/gates/nand.d.ts.map +1 -0
  22. package/dist/v2/gates/nor.d.ts +5 -0
  23. package/dist/v2/gates/nor.d.ts.map +1 -0
  24. package/dist/v2/gates/or.d.ts +5 -0
  25. package/dist/v2/gates/or.d.ts.map +1 -0
  26. package/dist/v2/gates/xnor.d.ts +5 -0
  27. package/dist/v2/gates/xnor.d.ts.map +1 -0
  28. package/dist/v2/gates/xor.d.ts +5 -0
  29. package/dist/v2/gates/xor.d.ts.map +1 -0
  30. package/dist/v2/index.cjs.js +289 -0
  31. package/dist/v2/index.cjs.js.map +1 -0
  32. package/dist/v2/index.esm.js +285 -0
  33. package/dist/v2/index.esm.js.map +1 -0
  34. package/dist/v2/ts/gates/BaseGate.d.ts +6 -0
  35. package/dist/v2/ts/gates/BaseGate.d.ts.map +1 -0
  36. package/dist/v2/ts/gates/and.d.ts +5 -0
  37. package/dist/v2/ts/gates/and.d.ts.map +1 -0
  38. package/dist/v2/ts/gates/majority.d.ts +5 -0
  39. package/dist/v2/ts/gates/majority.d.ts.map +1 -0
  40. package/dist/v2/ts/gates/nand.d.ts +5 -0
  41. package/dist/v2/ts/gates/nand.d.ts.map +1 -0
  42. package/dist/v2/ts/gates/nor.d.ts +5 -0
  43. package/dist/v2/ts/gates/nor.d.ts.map +1 -0
  44. package/dist/v2/ts/gates/or.d.ts +5 -0
  45. package/dist/v2/ts/gates/or.d.ts.map +1 -0
  46. package/dist/v2/ts/gates/xnor.d.ts +5 -0
  47. package/dist/v2/ts/gates/xnor.d.ts.map +1 -0
  48. package/dist/v2/ts/gates/xor.d.ts +5 -0
  49. package/dist/v2/ts/gates/xor.d.ts.map +1 -0
  50. package/dist/v2/types/factory.d.ts +10 -0
  51. package/dist/v2/types/index.d.ts +85 -0
  52. package/dist/v2/utils/v2/errors.d.ts +7 -0
  53. package/dist/v2/utils/v2/errors.d.ts.map +1 -0
  54. package/dist/v2/v2/PromiseLogic.d.ts +29 -0
  55. package/dist/v2/v2/PromiseLogic.d.ts.map +1 -0
  56. package/dist/v2/v2/factory.d.ts +7 -0
  57. package/dist/v2/v2/factory.d.ts.map +1 -0
  58. package/dist/v2/v2/index.d.ts +6 -0
  59. package/dist/v2/v2/index.d.ts.map +1 -0
  60. package/package.json +14 -10
package/README.md CHANGED
@@ -1,21 +1,48 @@
1
- # PromiseLogic
2
1
 
3
- > Compose promises with logic gate semantics - Forget APIs, remember logic.
2
+ # Promise Logic - Advanced Promise Logic Gates for Async Programming
4
3
 
5
- PromiseLogic is a comprehensive utility library that provides intuitive logical gate semantics for Promise composition. It extends the standard Promise API with logical operations that mirror digital circuit design, making asynchronous programming more intuitive and expressive.
4
+ Compose promises with logic gate semantics (AND, OR, NOT, XOR, NAND, NOR, XNOR, Majority). Forget APIs, remember logic.
6
5
 
7
- ## Philosophy
6
+ ## Features
8
7
 
9
- **"Forget APIs, remember logic."** - Replace fragmented API knowledge with fundamental logic concepts that work consistently across all asynchronous operations.
8
+ - **Logic Gate Semantics**: Extend Promise API with AND, OR, NOT, XOR, NAND, NOR, XNOR, Majority operations
9
+ - **Dual Entry Points**: Choose between JavaScript or enhanced TypeScript experience
10
+ - **Type Safety**: Complete TypeScript definitions with strict type checking
11
+ - **Promise Utilities**: Additional utilities like Flip-Flop state management
12
+ - **Zero Dependencies**: Pure JavaScript/TypeScript implementation
13
+ - **Tree Shakeable**: Optimized for modern bundlers
10
14
 
11
- ## Features
15
+ ## Recent Updates
16
+
17
+ ### Version 2.3.2 Highlights
18
+
19
+ **πŸš€ NOT Gate Implementation**
20
+ Introduced the NOT logic gate for promise inversion, enabling flexible negation patterns in asynchronous workflows:
21
+
22
+ ```javascript
23
+ // Success -> Failure transformation
24
+ await PromiseLogic.not(Promise.resolve('success')); // Rejects with 'success'
12
25
 
13
- - **Complete Logic Gate Semantics**: AND, OR, XOR, NAND, NOR, XNOR, Majority
14
- - **Extended Promise Operations**: All fulfilled/rejected results, complete settlement analysis
15
- - **Dual API Pattern**: Static class methods + Configurable factory function
16
- - **Production Ready**: Zero dependencies, complete TypeScript support
17
- - **Test Driven**: 100% test coverage with comprehensive edge cases
18
- - **Tree Shaking**: Optimized bundle output for modern build systems
26
+ // Failure -> Success transformation
27
+ const result = await PromiseLogic.not(Promise.reject('error')); // Resolves with 'error'
28
+ ```
29
+
30
+ **πŸ“¦ Enhanced TypeScript System**
31
+ Completely revamped TypeScript architecture with:
32
+ - Full generic type propagation
33
+ - Strict type checking with zero `any` types
34
+ - Advanced type inference for all operations
35
+ - Seamless IDE integration with IntelliSense
36
+
37
+ **⚑ Performance Optimizations**
38
+ - Optimized internal logic for better efficiency
39
+ - Reduced memory overhead in gate operations
40
+ - Improved error handling and edge case management
41
+
42
+ **πŸ“š Documentation Enhancements**
43
+ - Comprehensive API reference with TypeScript examples
44
+ - Better usage guidelines and best practices
45
+ - Clear entry point documentation for different environments
19
46
 
20
47
  ## Installation
21
48
 
@@ -25,324 +52,249 @@ npm install promise-logic
25
52
 
26
53
  ## Quick Start
27
54
 
28
- ### Basic Logic Gates
55
+ ### JavaScript (Default)
29
56
 
30
57
  ```javascript
58
+ // ES Modules
31
59
  import { PromiseLogic } from 'promise-logic';
32
60
 
33
- // AND logic - All promises must succeed (equivalent to Promise.all)
61
+ // CommonJS
62
+ const { PromiseLogic } = require('promise-logic');
63
+
64
+ // Use logic gates
34
65
  const results = await PromiseLogic.and([
35
- fetch('/api/users'),
36
- fetch('/api/posts'),
37
- fetch('/api/comments')
66
+ Promise.resolve('data1'),
67
+ Promise.resolve('data2')
38
68
  ]);
69
+ // results = ['data1', 'data2']
70
+ ```
39
71
 
40
- // OR logic - Any promise succeeds (short-circuits on first success)
41
- const data = await PromiseLogic.or([
42
- fetchPrimaryService(),
43
- fetchBackupService()
44
- ]);
72
+ ### TypeScript (Enhanced)
45
73
 
46
- // XOR logic - Exactly one promise must succeed
47
- const uniqueResult = await PromiseLogic.xor([
48
- cacheLookup(),
49
- databaseQuery()
50
- ]);
74
+ ```typescript
75
+ // TypeScript version with full type inference
76
+ import { PromiseLogic } from 'promise-logic/typescript';
77
+
78
+ // Type-safe operations with automatic inference
79
+ const numbers = await PromiseLogic.and<number>([
80
+ Promise.resolve(1),
81
+ Promise.resolve(2)
82
+ ]);
83
+
84
+ const strings = await PromiseLogic.or<string>([
85
+ Promise.resolve('hello'),
86
+ Promise.resolve('world')
87
+ ]);
51
88
  ```
52
89
 
53
- ### Advanced Logic Operations
90
+ ## Core Logic Gates
91
+
92
+ ### `and(promises)`
93
+ Resolves with all values when all promises fulfill. Equivalent to `Promise.all()`.
54
94
 
55
95
  ```javascript
56
- // NAND logic - Not all promises succeed (at least one failure)
57
- const hasFailures = await PromiseLogic.nand([
58
- validateInput(),
59
- checkPermissions(),
60
- verifyResources()
96
+ const results = await PromiseLogic.and([
97
+ Promise.resolve(1),
98
+ Promise.resolve(2),
99
+ Promise.resolve(3)
61
100
  ]);
101
+ // results = [1, 2, 3]
102
+ ```
62
103
 
63
- // NOR logic - All promises must fail
64
- const allFailed = await PromiseLogic.nor([
65
- experimentalFeature(),
66
- deprecatedAPI()
67
- ]);
104
+ ### `or(promises)`
105
+ Resolves with the first fulfilled promise. Equivalent to `Promise.any()`.
68
106
 
69
- // Majority logic - More than half succeed
70
- const consensus = await PromiseLogic.majority([
71
- server1.query(),
72
- server2.query(),
73
- server3.query()
107
+ ```javascript
108
+ const result = await PromiseLogic.or([
109
+ Promise.reject('error'),
110
+ Promise.resolve('success')
74
111
  ]);
112
+ // result = 'success'
75
113
  ```
76
114
 
77
- ### Extended Result Analysis
115
+ ### `xor(promises)`
116
+ Exclusive OR - resolves only when exactly one promise fulfills.
78
117
 
79
118
  ```javascript
80
- // Get only successful results
81
- const successes = await PromiseLogic.allFulfilled([
82
- apiCall1(),
83
- apiCall2(),
84
- apiCall3()
85
- ]);
119
+ try {
120
+ const result = await PromiseLogic.xor([
121
+ Promise.reject('error1'),
122
+ Promise.resolve('success'),
123
+ Promise.reject('error2')
124
+ ]);
125
+ // result = 'success'
126
+ } catch (error) {
127
+ // Throws if zero or multiple promises fulfill
128
+ }
129
+ ```
86
130
 
87
- // Get only failure reasons
88
- const failures = await PromiseLogic.allRejected([
89
- riskyOperation1(),
90
- riskyOperation2()
91
- ]);
131
+ ### `nand(promises)`
132
+ Not AND - resolves when not all promises fulfill.
92
133
 
93
- // Get complete settlement information
94
- const allResults = await PromiseLogic.allResults([
95
- operation1(),
96
- operation2()
134
+ ```javascript
135
+ const results = await PromiseLogic.nand([
136
+ Promise.resolve('success'),
137
+ Promise.reject('error')
97
138
  ]);
139
+ // results = ['success']
140
+ ```
98
141
 
99
- // Strict all-success validation
100
- const allSuccessful = await PromiseLogic.allSuccessful([
101
- validation1(),
102
- validation2(),
103
- validation3()
104
- ]);
142
+ ### `nor(promises)`
143
+ Not OR - resolves only when all promises reject.
105
144
 
106
- // Strict all-failure validation
107
- const allFailed = await PromiseLogic.allFailed([
108
- deprecatedCall1(),
109
- deprecatedCall2()
145
+ ```javascript
146
+ const results = await PromiseLogic.nor([
147
+ Promise.reject('error1'),
148
+ Promise.reject('error2')
110
149
  ]);
150
+ // results = []
111
151
  ```
112
152
 
113
- ## API Reference
114
-
115
- ### Core Logic Gates
116
-
117
- #### `PromiseLogic.and(iterable)`
118
- Equivalent to `Promise.all`. Resolves when all promises fulfill, rejects if any promise rejects.
119
-
120
- #### `PromiseLogic.or(iterable)`
121
- Resolves with the first successful promise. Rejects only if all promises reject.
122
-
123
- #### `PromiseLogic.xor(iterable)`
124
- Resolves when exactly one promise fulfills. Rejects if zero or multiple promises fulfill.
125
-
126
- #### `PromiseLogic.nand(iterable)`
127
- Resolves when not all promises fulfill (at least one rejection). Rejects if all promises fulfill.
128
-
129
- #### `PromiseLogic.nor(iterable)`
130
- Resolves when all promises reject. Rejects if any promise fulfills.
131
-
132
- #### `PromiseLogic.xnor(iterable)`
133
- Resolves when all promises fulfill or all reject. Rejects in mixed scenarios.
134
-
135
- #### `PromiseLogic.majority(iterable)`
136
- Resolves when more than half of promises fulfill. Rejects otherwise.
137
-
138
- ### Extended Operations
139
-
140
- #### `PromiseLogic.allFulfilled(iterable)`
141
- Always resolves with an array of fulfilled values (empty if none).
142
-
143
- #### `PromiseLogic.allRejected(iterable)`
144
- Always resolves with an array of rejection reasons (empty if none).
153
+ ### `xnor(promises)`
154
+ Exclusive NOR - resolves when all promises have the same outcome.
145
155
 
146
- #### `PromiseLogic.allResults(iterable)`
147
- Equivalent to `Promise.allSettled`. Returns complete settlement information.
148
-
149
- #### `PromiseLogic.allSuccessful(iterable)`
150
- Resolves with all values only if every promise fulfills. Rejects otherwise.
151
-
152
- #### `PromiseLogic.allFailed(iterable)`
153
- Resolves with all rejection reasons only if every promise rejects. Rejects otherwise.
154
-
155
- ### Utility Methods
156
-
157
- #### `PromiseLogic.race(iterable)`
158
- Equivalent to `Promise.race`. Resolves or rejects with the first settled promise.
159
-
160
- #### `PromiseLogic.allSettled(iterable)`
161
- Equivalent to `Promise.allSettled`. Always resolves with settlement results.
162
-
163
- #### `PromiseLogic.createFlipFlop(initialState?)`
164
- Creates a stateful flip-flop utility for managing boolean state transitions.
165
-
166
- ## Factory Function
156
+ ```javascript
157
+ const results = await PromiseLogic.xnor([
158
+ Promise.resolve('a'),
159
+ Promise.resolve('b')
160
+ ]);
161
+ // results = ['a', 'b']
162
+ ```
167
163
 
168
- Create customized instances with method name transformations:
164
+ ### `majority(promises)`
165
+ Resolves when majority (>50%) of promises fulfill.
169
166
 
170
167
  ```javascript
171
- import { createPromiseLogic } from 'promise-logic';
172
-
173
- // Default naming
174
- const logic = createPromiseLogic();
175
- await logic.and([promise1, promise2]);
176
-
177
- // With prefix
178
- const asyncLogic = createPromiseLogic({ prefix: 'async' });
179
- await asyncLogic.asyncand([promise1, promise2]);
180
-
181
- // With suffix
182
- const logicUtils = createPromiseLogic({ suffix: 'Logic' });
183
- await logicUtils.andLogic([promise1, promise2]);
184
-
185
- // With custom renaming
186
- const customLogic = createPromiseLogic({
187
- rename: {
188
- and: 'conjunction',
189
- or: 'disjunction',
190
- xor: 'exclusiveOr'
191
- }
192
- });
193
- await customLogic.conjunction([promise1, promise2]);
194
-
195
- // Combined transformations
196
- const advancedLogic = createPromiseLogic({
197
- prefix: 'async',
198
- suffix: 'Logic',
199
- rename: { and: 'conjunction' }
200
- });
201
- await advancedLogic.asyncconjunctionLogic([promise1, promise2]);
168
+ const results = await PromiseLogic.majority([
169
+ Promise.resolve('a'),
170
+ Promise.resolve('b'),
171
+ Promise.reject('error')
172
+ ]);
173
+ // results = ['a', 'b']
202
174
  ```
203
175
 
204
- ## Real-World Examples
176
+ ## NOT Gate - New in v2.3.2
205
177
 
206
- ### Service Orchestration
178
+ ### `not(promise)`
179
+ Inverts promise resolution - successful promises become rejections, and vice versa.
207
180
 
208
181
  ```javascript
209
- // Load balancing with fallback
210
- const userData = await PromiseLogic.or([
211
- primaryUserService.getUser(id),
212
- secondaryUserService.getUser(id),
213
- cacheService.getUser(id)
214
- ]);
215
-
216
- // Multi-step validation
217
- const isValid = await PromiseLogic.and([
218
- validateEmail(email),
219
- validatePassword(password),
220
- checkRateLimit(ipAddress)
221
- ]);
182
+ // Success -> Failure
183
+ try {
184
+ await PromiseLogic.not(Promise.resolve('success'));
185
+ } catch (error) {
186
+ console.log(error); // 'success'
187
+ }
222
188
 
223
- // Consensus-based decision making
224
- const configuration = await PromiseLogic.majority([
225
- configServer1.getConfig(),
226
- configServer2.getConfig(),
227
- configServer3.getConfig()
228
- ]);
189
+ // Failure -> Success
190
+ const result = await PromiseLogic.not(Promise.reject('error'));
191
+ console.log(result); // 'error'
229
192
  ```
230
193
 
231
- ### Error Recovery & Analysis
194
+ **Use Cases:**
195
+ - Transform error handling patterns
196
+ - Create conditional promise flows
197
+ - Implement retry logic with inverted conditions
198
+ - Build fallback mechanisms
232
199
 
233
- ```javascript
234
- // Graceful degradation
235
- const [successfulResults, failedOperations] = await Promise.all([
236
- PromiseLogic.allFulfilled(operations),
237
- PromiseLogic.allRejected(operations)
238
- ]);
200
+ ## Advanced Utilities
239
201
 
240
- // Comprehensive error reporting
241
- const results = await PromiseLogic.allResults(operations);
242
- const successful = results.filter(r => r.status === 'fulfilled');
243
- const failed = results.filter(r => r.status === 'rejected');
202
+ ### `race(promises)`
203
+ Equivalent to `Promise.race()`.
244
204
 
245
- console.log(`Operations: ${successful.length} successful, ${failed.length} failed`);
246
- ```
205
+ ### `allSettled(promises)`
206
+ Equivalent to `Promise.allSettled()`.
247
207
 
248
- ### State Management
208
+ ### `allFulfilled(promises)`
209
+ Resolves with all fulfilled values, ignoring rejections.
249
210
 
250
- ```javascript
251
- // Flip-flop for toggle operations
252
- const toggle = PromiseLogic.createFlipFlop(false);
211
+ ### `allRejected(promises)`
212
+ Resolves with all rejection reasons, ignoring fulfillments.
253
213
 
254
- // Toggle state and wait for change
255
- await toggle.toggle();
256
- console.log(toggle.getState()); // true
214
+ ### `createFlipFlop(initialState?)`
215
+ Creates a stateful flip-flop for managing boolean state across async operations.
257
216
 
258
- // Set specific state
259
- await toggle.setState(false);
260
- ```
217
+ ```javascript
218
+ const flipFlop = PromiseLogic.createFlipFlop(false);
261
219
 
262
- ## Error Handling
220
+ // Get current state
221
+ console.log(flipFlop.getState()); // false
263
222
 
264
- All logic gates throw `PromiseLogicError` with descriptive messages:
223
+ // Toggle state
224
+ await flipFlop.toggle();
225
+ console.log(flipFlop.getState()); // true
265
226
 
266
- ```javascript
267
- try {
268
- await PromiseLogic.xor([apiCall1(), apiCall2()]);
269
- } catch (error) {
270
- if (error.type === 'XOR_ERROR') {
271
- console.log('Expected exactly one successful call');
272
- }
273
- console.log('Failed promises:', error.results);
274
- }
227
+ // Wait for specific state
228
+ await flipFlop.waitFor(true); // Resolves immediately if already true
229
+
230
+ // Async state change
231
+ setTimeout(() => flipFlop.set(false), 100);
232
+ await flipFlop.waitForChange(); // Waits for state change
275
233
  ```
276
234
 
277
- ## TypeScript Support
235
+ ## TypeScript Support - Enhanced in v2.3.2
236
+
237
+ The TypeScript version (`promise-logic/typescript`) provides:
278
238
 
279
- Full TypeScript support with precise type inference:
239
+ - **Full Type Inference**: Automatic type deduction for all operations
240
+ - **Strict Type Checking**: Zero `any` types, complete type safety
241
+ - **IDE Support**: Enhanced IntelliSense and code completion
242
+ - **Generic Type Propagation**: Proper handling of complex generic scenarios
280
243
 
281
244
  ```typescript
282
- import { PromiseLogic } from 'promise-logic';
245
+ import { PromiseLogic } from 'promise-logic/typescript';
283
246
 
284
- // Type inference for successful results
285
- const numbers: number[] = await PromiseLogic.and([
286
- Promise.resolve(1),
287
- Promise.resolve(2),
288
- Promise.resolve(3)
247
+ // TypeScript infers everything
248
+ const result = await PromiseLogic.and([
249
+ Promise.resolve({ id: 1, name: 'Alice' }),
250
+ Promise.resolve({ id: 2, name: 'Bob' })
289
251
  ]);
252
+ // result type: Array<{ id: number, name: string }>
290
253
 
291
- // Type-safe error handling
292
- try {
293
- await PromiseLogic.nand(operations);
294
- } catch (error: PromiseLogicError) {
295
- // error has full type information
254
+ // Complex generic types work seamlessly
255
+ async function processPromises<T>(promises: Promise<T>[]): Promise<T[]> {
256
+ return await PromiseLogic.and(promises);
296
257
  }
297
258
  ```
298
259
 
299
- ## Advanced Usage
260
+ ## Entry Points
300
261
 
301
- ### Custom Logic Composition
262
+ | Import Path | Purpose | Recommended For |
263
+ |------------|---------|----------------|
264
+ | `promise-logic` | Default JavaScript version | General use, mixed codebases |
265
+ | `promise-logic/typescript` | Enhanced TypeScript version | TypeScript projects, strict type safety |
302
266
 
303
- ```javascript
304
- // Create complex logic flows
305
- async function advancedOperation(promises) {
306
- const [successes, failures] = await Promise.all([
307
- PromiseLogic.allFulfilled(promises),
308
- PromiseLogic.allRejected(promises)
309
- ]);
267
+ ## Migration Note
310
268
 
311
- if (successes.length >= failures.length) {
312
- return { data: successes, warnings: failures };
313
- } else {
314
- throw new Error('Operation mostly failed');
315
- }
316
- }
317
- ```
269
+ If you're upgrading from earlier versions, note that the TypeScript system has been completely redesigned for better type safety and developer experience. All existing APIs remain compatible.
318
270
 
319
- ### Performance Optimization
271
+ ## Development
320
272
 
321
- ```javascript
322
- // Batch processing with logic gates
323
- const batches = chunkArray(operations, BATCH_SIZE);
324
- const batchResults = await PromiseLogic.allFulfilled(
325
- batches.map(batch => PromiseLogic.and(batch))
326
- );
327
-
328
- // Flatten results
329
- const allResults = batchResults.flat();
330
- ```
273
+ ```bash
274
+ # Install dependencies
275
+ npm install
331
276
 
332
- ## Contributing
277
+ # Build the project
278
+ npm run build
333
279
 
334
- We welcome contributions! Please see our Contributing Guide for details.
280
+ # Run tests
281
+ npm test
335
282
 
336
- ## License
283
+ # Run tests in watch mode
284
+ npm run test:watch
337
285
 
338
- MIT License - see LICENSE for details.
286
+ # Check code coverage
287
+ npm run test:coverage
288
+ ```
339
289
 
340
- ## Links
290
+ ## Contributing
341
291
 
342
- - GitHub Repository: https://github.com/xier123456/promise-logic
343
- - npm Package: https://www.npmjs.com/package/promise-logic
344
- - Issue Tracker: https://github.com/xier123456/promise-logic/issues
292
+ 1. Fork the repository
293
+ 2. Create a feature branch
294
+ 3. Make your changes
295
+ 4. Add tests for new functionality
296
+ 5. Submit a pull request
345
297
 
346
- ---
298
+ ## License
347
299
 
348
- **PromiseLogic** - Making asynchronous logic as simple as digital circuits.
300
+ MIT Β© 2026
@@ -14,6 +14,7 @@ function createLogicError(type, fulfilledCount, total, results) {
14
14
  const messages = {
15
15
  XOR_ERROR: `XOR condition failed: expected exactly 1 promise to fulfill, but ${fulfilledCount} fulfilled.`,
16
16
  NAND_ERROR: `NAND condition failed: all ${total} promises fulfilled (expected at least one rejection).`,
17
+ NOT_ERROR: `NOT condition failed: promise resolved (expected rejection).`,
17
18
  NOR_ERROR: `NOR condition failed: ${fulfilledCount} promises fulfilled (expected all rejected).`,
18
19
  MAJORITY_ERROR: `Majority condition failed: ${fulfilledCount}/${total} fulfilled (need majority).`,
19
20
  ALL_SUCCESSFUL_ERROR: `All successful condition failed: ${fulfilledCount}/${total} promises fulfilled (expected all to succeed).`,
@@ -32,6 +33,15 @@ class PromiseLogic {
32
33
  return Promise.any(iterable);
33
34
  }
34
35
 
36
+
37
+ static not(promise) {
38
+ return Promise.resolve(promise).then(
39
+ (value) => Promise.reject(value),
40
+ (reason) => Promise.resolve(reason)
41
+ )
42
+ .catch((error) => Promise.resolve(error));
43
+ }
44
+
35
45
  static race(iterable) {
36
46
  return Promise.race(iterable);
37
47
  }
@@ -121,6 +131,7 @@ class PromiseLogic {
121
131
  });
122
132
  }
123
133
 
134
+
124
135
  // θΏ”ε›žζ‰€ζœ‰ζˆεŠŸηš„Promiseη»“ζžœ
125
136
  static allFulfilled(iterable) {
126
137
  return Promise.allSettled(iterable).then((results) => {
@@ -203,10 +214,13 @@ function createPromiseLogic(options = {}) {
203
214
  race: PromiseLogic.race,
204
215
  allSettled: PromiseLogic.allSettled,
205
216
  xor: PromiseLogic.xor,
217
+ not: PromiseLogic.not,
206
218
  nand: PromiseLogic.nand,
207
219
  nor: PromiseLogic.nor,
208
220
  xnor: PromiseLogic.xnor,
209
- majority: PromiseLogic.majority
221
+ majority: PromiseLogic.majority,
222
+ allFulfilled: PromiseLogic.allFulfilled,
223
+ allRejected: PromiseLogic.allRejected
210
224
  };
211
225
 
212
226
  // 应用命名转捒