semantic-typescript 0.3.0 → 0.3.1

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.

Potentially problematic release.


This version of semantic-typescript might be problematic. Click here for more details.

package/dist/factory.d.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  import { Semantic } from "./semantic";
2
2
  import type { BiFunctional, BiPredicate, Functional, Predicate, Supplier, TriFunctional, Generator } from "./utility";
3
3
  export declare let animationFrame: Functional<number, Semantic<number>> & BiFunctional<number, number, Semantic<number>>;
4
+ interface Attribute<T> {
5
+ key: keyof T;
6
+ value: T[keyof T];
7
+ }
8
+ export declare let attribute: <T extends object>(target: T) => Semantic<Attribute<T>>;
4
9
  export declare let blob: Functional<Blob, Semantic<Uint8Array>> & BiFunctional<Blob, bigint, Semantic<Uint8Array>>;
5
10
  export declare let empty: <E>() => Semantic<E>;
6
11
  export declare let fill: (<E>(element: E, count: bigint) => Semantic<E>) & (<E>(supplier: Supplier<E>, count: bigint) => Semantic<E>);
@@ -11,3 +16,4 @@ export declare let iterate: <E>(generator: Generator<E>) => Semantic<E>;
11
16
  export declare let promise: (<T>(promise: Promise<T>) => Semantic<T>);
12
17
  export declare let range: BiFunctional<number, number, Semantic<number>> & TriFunctional<number, number, number, Semantic<number>>;
13
18
  export declare let websocket: Functional<WebSocket, Semantic<MessageEvent | CloseEvent | Event>>;
19
+ export {};
package/dist/factory.js CHANGED
@@ -1,5 +1,5 @@
1
- import { isBigInt, isFunction, isIterable, isNumber, isPromise } from "./guard";
2
- import { useCompare } from "./hook";
1
+ import { isBigInt, isFunction, isIterable, isNumber, isObject, isPromise } from "./guard";
2
+ import { useCompare, useTraverse } from "./hook";
3
3
  import { Semantic } from "./semantic";
4
4
  import { invalidate, validate } from "./utility";
5
5
  export let animationFrame = (period, delay = 0) => {
@@ -25,6 +25,27 @@ export let animationFrame = (period, delay = 0) => {
25
25
  };
26
26
  });
27
27
  };
28
+ ;
29
+ export let attribute = (target) => {
30
+ if (isObject(target)) {
31
+ return new Semantic((accept, interrupt) => {
32
+ let index = 0n;
33
+ useTraverse(target, (key, value) => {
34
+ let attribute = {
35
+ key: key,
36
+ value: value
37
+ };
38
+ if (interrupt(attribute, index)) {
39
+ return true;
40
+ }
41
+ accept(attribute, index);
42
+ index++;
43
+ return false;
44
+ });
45
+ });
46
+ }
47
+ throw new TypeError("Target must be an object.");
48
+ };
28
49
  export let blob = (blob, chunk = 64n * 1024n) => {
29
50
  let size = Number(chunk);
30
51
  if (size <= 0 || !Number.isSafeInteger(size)) {
package/dist/hook.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type BiConsumer, type DeepPropertyKey, type DeepPropertyValue } from "./utility";
1
+ import { type BiPredicate, type DeepPropertyKey, type DeepPropertyValue } from "./utility";
2
2
  export declare let useCompare: <T>(t1: T, t2: T) => number;
3
3
  export declare let useRandom: <T = number | bigint>(index: T) => T;
4
- export declare let useTraverse: <T extends object>(t: T, callback: BiConsumer<DeepPropertyKey<T>, DeepPropertyValue<T>>) => void;
4
+ export declare let useTraverse: <T extends object>(t: T, callback: BiPredicate<DeepPropertyKey<T>, DeepPropertyValue<T>>) => void;
package/dist/hook.js CHANGED
@@ -69,26 +69,38 @@ export let useTraverse = (t, callback) => {
69
69
  let traverse = (target) => {
70
70
  if (!seen.has(target)) {
71
71
  seen.add(target);
72
+ let stop = false;
72
73
  let properties = Reflect.ownKeys(target);
73
74
  for (let property of properties) {
74
75
  let value = target[property];
76
+ if (stop) {
77
+ break;
78
+ }
75
79
  if (validate(value)) {
76
80
  if (isObject(value)) {
77
81
  if (isIterable(value)) {
82
+ let index = 0;
78
83
  for (let item of value) {
79
84
  if (validate(item)) {
80
85
  if (isObject(item)) {
81
86
  traverse(item);
82
87
  }
83
88
  else {
84
- callback(property, item);
89
+ if (callback(index, item)) {
90
+ stop = true;
91
+ break;
92
+ }
85
93
  }
86
94
  }
95
+ index++;
87
96
  }
88
97
  }
89
98
  }
90
99
  else {
91
- callback(property, value);
100
+ if (callback(property, value)) {
101
+ stop = true;
102
+ break;
103
+ }
92
104
  }
93
105
  }
94
106
  }
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "url": "https://github.com/eloyhere"
7
7
  },
8
8
  "description": "A modern type-safe stream processing library inspired by JavaScript Generator, Java Stream, and MySQL Index. Supports lazy evaluation, async streams, statistics, and IO-like operations.",
9
- "version": "0.3.0",
9
+ "version": "0.3.1",
10
10
  "type": "module",
11
11
  "readme": "readme.md",
12
12
  "main": "dist/index.js",
package/readme.md CHANGED
@@ -111,6 +111,7 @@ if(isIterable(value)){
111
111
  |------|------|------------|------------|
112
112
  | `useCompare<T>(t1: T, t2: T): number` | Generic comparison function | O(1) | O(1) |
113
113
  | `useRandom<T = number \| bigint>(index: T): T` | Pseudo-random number generator | O(log n) | O(1) |
114
+ | `useTraverse(t, callback)` | Deep traverse an object without cyclic references | O(n) | O(1) |
114
115
 
115
116
  ```typescript
116
117
  // Utility function usage examples
@@ -224,6 +225,7 @@ average.collect([1,2,3,4,5]); // Averages from an iterable object
224
225
  | Method | Description | Time Complexity | Space Complexity |
225
226
  |------|------|------------|------------|
226
227
  | `animationFrame(period: number, delay: number = 0)` | Create a timed animation frame stream | O(1)* | O(1) |
228
+ | `attribute(target)` | Create a stream from an object deep attributes | O(n) | O(1) |
227
229
  | `blob(blob, chunkSize)` | Create a stream from a Blob | O(n) | O(chunkSize) |
228
230
  | `empty<E>()` | Create an empty stream | O(1) | O(1) |
229
231
  | `fill<E>(element, count)` | Create a filled stream | O(n) | O(1) |
@@ -389,27 +391,41 @@ let customizedCollector = from([1, 2, 3, 4, 5]).toCollectable((generator: Genera
389
391
 
390
392
  | Method | Description | Time Complexity | Space Complexity |
391
393
  |------|------|------------|------------|
392
- | `anyMatch(predicate)` | Whether any element matches | O(n) | O(1) |
393
- | `allMatch(predicate)` | Whether all elements match | O(n) | O(1) |
394
- | `count()` | Element count | O(n) | O(1) |
395
- | `isEmpty()` | Whether it is empty | O(1) | O(1) |
396
- | `findAny()` | Find any element | O(n) | O(1) |
397
- | `findFirst()` | Find the first element | O(n) | O(1) |
398
- | `findLast()` | Find the last element | O(n) | O(1) |
399
- | `forEach(action)` | Iterate over all elements | O(n) | O(1) |
400
- | `group(classifier)` | Group by classifier | O(n) | O(n) |
401
- | `groupBy(keyExtractor, valueExtractor)` | Group by key-value extractor | O(n) | O(n) |
402
- | `join()` | Join as string | O(n) | O(n) |
403
- | `join(delimiter)` | Join using a delimiter | O(n) | O(n) |
404
- | `nonMatch(predicate)` | Whether no elements match | O(n) | O(1) |
405
- | `partition(count)` | Partition by count | O(n) | O(n) |
406
- | `partitionBy(classifier)` | Partition by classifier | O(n) | O(n) |
407
- | `reduce(accumulator)` | Reduction operation | O(n) | O(1) |
408
- | `reduce(identity, accumulator)` | Reduction with initial value | O(n) | O(1) |
409
- | `toArray()` | Convert to array | O(n) | O(n) |
410
- | `toMap(keyExtractor, valueExtractor)` | Convert to Map | O(n) | O(n) |
411
- | `toSet()` | Convert to Set | O(n) | O(n) |
412
- | `write(stream)` | Write to stream | O(n) | O(1) |
394
+ | `anyMatch(predicate)` | Whether any element matches the predicate | O(n) | O(1) |
395
+ | `allMatch(predicate)` | Whether all elements match the predicate | O(n) | O(1) |
396
+ | `collect(collector)` | Collect elements using the given collector | O(n) | O(1) |
397
+ | `collect(identity, accumulator, finisher)` | Collect elements with identity, accumulator, and finisher | O(n) | O(1) |
398
+ | `collect(identity, interruptor, accumulator, finisher)` | Collect elements with identity, interruptor, accumulator, and finisher | O(n) | O(1) |
399
+ | `count()` | Count the number of elements | O(n) | O(1) |
400
+ | `error()` | Log elements to console with default error format | O(n) | O(1) |
401
+ | `error(accumulator)` | Log elements via custom accumulator error format | O(n) | O(1) |
402
+ | `error(prefix, accumulator, suffix)` | Log elements with prefix, custom accumulator, and suffix | O(n) | O(1) |
403
+ | `isEmpty()` | Check whether the collectable is empty | O(n) | O(1) |
404
+ | `findAny()` | Find any element in the collectable | O(n) | O(1) |
405
+ | `findFirst()` | Find the first element in the collectable | O(n) | O(1) |
406
+ | `findLast()` | Find the last element in the collectable | O(n) | O(1) |
407
+ | `forEach(action)` | Iterate over all elements with a consumer or bi-consumer | O(n) | O(1) |
408
+ | `group(classifier)` | Group elements by a classifier function | O(n) | O(n) |
409
+ | `groupBy(keyExtractor, valueExtractor)` | Group elements by key and value extractors | O(n) | O(n) |
410
+ | `join()` | Join elements into a string with default format | O(n) | O(n) |
411
+ | `join(delimiter)` | Join elements into a string with a delimiter | O(n) | O(n) |
412
+ | `join(prefix, delimiter, suffix)` | Join elements with prefix, delimiter, and suffix | O(n) | O(n) |
413
+ | `join(prefix, accumulator, suffix)` | Join elements via custom accumulator with prefix and suffix | O(n) | O(n) |
414
+ | `log()` | Log elements to console with default format | O(n) | O(1) |
415
+ | `log(accumulator)` | Log elements via custom accumulator | O(n) | O(1) |
416
+ | `log(prefix, accumulator, suffix)` | Log elements with prefix, custom accumulator, and suffix | O(n) | O(1) |
417
+ | `nonMatch(predicate)` | Whether no elements match the predicate | O(n) | O(1) |
418
+ | `partition(count)` | Partition elements into chunks of specified size | O(n) | O(n) |
419
+ | `partitionBy(classifier)` | Partition elements by a classifier function | O(n) | O(n) |
420
+ | `reduce(accumulator)` | Reduce elements using an accumulator (no initial value) | O(n) | O(1) |
421
+ | `reduce(identity, accumulator)` | Reduce elements with an initial value and accumulator | O(n) | O(1) |
422
+ | `reduce(identity, accumulator, finisher)` | Reduce elements with initial value, accumulator, and finisher | O(n) | O(1) |
423
+ | `semantic()` | Convert the collectable to a semantic object | O(1) | O(1) |
424
+ | `toArray()` | Convert elements to an array | O(n) | O(n) |
425
+ | `toMap(keyExtractor, valueExtractor)` | Convert elements to a Map via key and value extractors | O(n) | O(n) |
426
+ | `toSet()` | Convert elements to a Set | O(n) | O(n) |
427
+ | `write(stream)` | Write elements to a stream (default format) | O(n) | O(1) |
428
+ | `write(stream, accumulator)` | Write elements to a stream via custom accumulator | O(n) | O(1) |
413
429
 
414
430
  ```typescript
415
431
  // Collectable operation examples