smsmslib 1.0.55 → 1.0.59

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.
@@ -1,132 +1,199 @@
1
1
  /**
2
2
  * @file
3
- * A collection of utility functions for **safely modifying and manipulating**
4
- * JavaScript Array instances.
5
- *
6
- * These functions wrap native Array methods (`push`, `splice`, etc.) to
7
- * ensure the target variable is a true Array instance before execution
8
- * and to gracefully handle potential runtime errors during the operation.
3
+ * Provides core utility functions for **safe inspection and property modification**
4
+ * of Array instances.
9
5
  *
10
6
  * @module src/array
11
7
  */
12
8
 
13
-
14
9
  /** ---------------------------------------------------------------------------
15
10
  * Imports.
16
11
  * --------------------------------------------------------------------------- */
17
12
 
13
+ import
14
+ {
15
+ go_typeof
16
+ }
17
+ from "./type.js"
18
+
19
+ import
20
+ {
21
+ sj_set_new
22
+ }
23
+ from "./set.js"
24
+
18
25
 
19
26
  /** ---------------------------------------------------------------------------
20
27
  * Functions.
21
28
  * --------------------------------------------------------------------------- */
22
29
 
23
30
  /**
24
- * Safely executes Array.prototype.splice() to change the contents of an array by
25
- * removing or replacing existing elements and/or adding new elements.
31
+ * Safely searches for the first occurrence of the element specified by `old_any`
32
+ * in the array `a_dst` and replaces it with `new_any`.
33
+ *
34
+ * The replacement operation is performed only if the target variable `a_dst`
35
+ * is a true Array instance and the element is found within it using indexOf().
26
36
  *
27
- * @param {any} a_any [in]
37
+ * @param {any} a_dst [in/out]
28
38
  * The array to be modified. Must be a true Array instance.
29
39
  *
30
- * @param {number} i_start [in]
31
- * The zero-based index at which to start changing the array.
40
+ * @param {any} old_any [in]
41
+ * The value to search for and replace (the element currently in the array).
32
42
  *
33
- * @param {number} i_remove [in]
34
- * The number of elements to remove from the starting index.
43
+ * @param {any} new_any [in]
44
+ * The value to replace the target element with.
35
45
  *
36
- * @param {...any} insert [in]
37
- * The element(s) to add to the array, starting at `i_start`.
38
- *
39
- * @returns {Array<any> | null}
40
- * An array containing the deleted elements if the operation was successful
41
- * (may be an empty array []).
42
- * Returns `null` if the target variable is not an array or if a runtime error occurred
43
- * during the splice operation.
46
+ * @returns {boolean}
47
+ * `true` if the `old_any` was found and successfully replaced, otherwise `false`.
48
+ */
49
+ export function sj_array_replace(a_dst, old_any, new_any)
50
+ {
51
+ let b_replaced = Array.isArray(a_dst);
52
+
53
+ if (b_replaced)
54
+ {
55
+ const i_ret = a_dst.indexOf(old_any);
56
+ const b_found = (- 1 < i_ret);
57
+
58
+ if (b_found)
59
+ {
60
+ a_dst[i_ret] = new_any;
61
+ }
62
+
63
+ b_replaced = b_found
64
+ }
65
+
66
+ return b_replaced;
67
+ }
68
+
69
+
70
+ /**
71
+ * Safely modifies the length of an array and optionally fills new slots.
72
+ *
73
+ * @param {any} a_dst [in/out]
74
+ * The array to modify. Must be a true Array instance.
75
+ *
76
+ * @param {number} i_dst_len [in]
77
+ * The new length. Must be a non-negative integer.
78
+ *
79
+ * @param {any} initial [in, optional]
80
+ * The value to fill the newly created slots with.
81
+ *
82
+ * @returns {number}
83
+ * The new length of the array, or -1 if the operation failed.
44
84
  */
45
- export function sj_array_splice(a_any, i_start, i_remove, ...insert)
85
+ export function sj_array_lengthen(a_dst, i_dst_len, initial = undefined)
46
86
  {
47
- const b_array = Array.isArray(a_any);
48
- let a_spliced = null;
87
+ const b_array = Array.isArray(a_dst);
88
+ let i_result = - 1;
49
89
 
50
- if (b_array)
90
+ if (b_array && (- 1 < i_dst_len))
51
91
  {
52
92
  try
53
93
  {
54
- a_spliced = a_any.splice(i_start, i_remove, ...insert);
94
+ const i_src_len = a_dst.length;
95
+
96
+ a_dst.length = i_dst_len;
97
+ i_result = a_dst.length;
98
+
99
+ if (sj_array_lengthen.length < arguments.length)
100
+ {
101
+ for (let i_idx = i_src_len; i_idx < i_dst_len; i_idx++)
102
+ {
103
+ a_dst[i_idx] = initial;
104
+ }
105
+ }
55
106
  }
56
107
  catch (o_err)
57
108
  {
58
- console.error(`${sj_array_splice.name}: ${o_err.message}`);
109
+ console.error(`${sj_array_lengthen.name}: ${o_err.message}`);
59
110
  }
60
111
  }
61
112
 
62
- return a_spliced;
113
+ return i_result;
63
114
  }
64
115
 
65
116
 
66
117
  /**
67
- * Safely adds one or more elements to the end of an array using
68
- * Array.prototype.push().
118
+ * Safely executes Array.prototype.filter().
69
119
  *
70
- * @param {any} a_any [in]
71
- * The array to which the element(s) should be pushed. Must be a true Array instance.
120
+ * @param {any} a_src [in]
121
+ * The source array to filter.
72
122
  *
73
- * @param {...any} push [in]
74
- * The element(s) to add to the array.
123
+ * @param {function} f_filter [in]
124
+ * The predicate function to test each element, following the
125
+ * `Array.prototype.filter` callback signature: `(value, index, array) => boolean`.
75
126
  *
76
- * @returns {number}
77
- * The new length of the array if the operation was successful
78
- * (equivalent to native push).
79
- * Returns -1 if the target variable is not an array or
80
- * if a runtime error occurred during the push operation.
127
+ * @returns {Array<any> | null}
128
+ * A new array with the elements that pass the test.
129
+ * Returns `null` if the input is not an array, f_filter is not a function,
130
+ * or if a runtime error occurs.
81
131
  */
82
- export function sj_array_push(a_any, ...push)
132
+ export function sj_array_filter(a_src, f_filter)
83
133
  {
84
- const b_array = Array.isArray(a_any);
85
- let i_len = - 1;
134
+ let a_result = null;
86
135
 
87
- if (b_array)
136
+ const b_valid = Array.isArray(a_src) && (typeof f_filter === go_typeof.s_function);
137
+
138
+ if (b_valid)
88
139
  {
89
140
  try
90
141
  {
91
- i_len = a_any.push(...push);
142
+ a_result = a_src.filter(f_filter);
92
143
  }
93
144
  catch (o_err)
94
145
  {
95
- console.error(`${sj_array_push.name}: ${o_err.message}`);
146
+ console.error(`${sj_array_filter.name}: ${o_err.message}`);
147
+ a_result = null;
96
148
  }
97
149
  }
98
150
 
99
- return i_len;
151
+ return a_result;
100
152
  }
101
153
 
102
154
 
103
155
  /**
104
- * Safely creates a new Array instance with a specified length.
105
- *
106
- * @param {number} i_len [in]
107
- * The length of the new array. Must be a non-negative integer.
156
+ * Checks if all elements in the array are unique.
108
157
  *
109
- * @param {any} initial [in, optional]
110
- * The value to fill each element with.
158
+ * @param {Array} a_src [in]
159
+ * The array to be checked.
111
160
  *
112
- * @returns {Array<any> | null}
113
- * A new array of the specified length filled with `initial`.
114
- * Returns `null` if the length is invalid or a runtime error occurs.
161
+ * @returns {number}
162
+ * Returns one of the following codes:
163
+ * - 1: Success. The input is an array and all elements are unique.
164
+ * - 0: Success. The input is an array but contains duplicate elements.
165
+ * - -1: Failure. The input is not an array or an internal error occurred.
115
166
  */
116
- export function sj_array_new(i_len, initial)
167
+ export function sj_array_is_unique(a_src)
117
168
  {
118
- let a_any = null;
169
+ let i_result = - 1;
170
+ let b_src_array = Array.isArray(a_src);
119
171
 
120
- try
172
+ if (b_src_array)
121
173
  {
122
- a_any = new Array(i_len).fill(initial);
123
- }
124
- catch (o_err)
125
- {
126
- console.error(`${sj_array_new.name}: ${o_err.message}`);
174
+ if (1 < a_src.length)
175
+ {
176
+ const o_set = sj_set_new(a_src);
177
+
178
+ if (o_set)
179
+ {
180
+ if (a_src.length === o_set.size)
181
+ {
182
+ i_result = 1;
183
+ }
184
+ else
185
+ {
186
+ i_result = 0;
187
+ }
188
+ }
189
+ }
190
+ else
191
+ {
192
+ i_result = 1;
193
+ }
127
194
  }
128
195
 
129
- return a_any;
196
+ return i_result;
130
197
  }
131
198
 
132
199
 
@@ -0,0 +1,104 @@
1
+ /**
2
+ * @file
3
+ * Provides utility functions for **safely merging and concatenating**
4
+ * Array instances.
5
+ *
6
+ * @module src/arrayconcat
7
+ */
8
+
9
+ /** ---------------------------------------------------------------------------
10
+ * Imports.
11
+ * --------------------------------------------------------------------------- */
12
+
13
+ import
14
+ {
15
+ sj_array_lengthen,
16
+ }
17
+ from "./array.js";
18
+
19
+ import
20
+ {
21
+ sj_set_new,
22
+ }
23
+ from "./set.js";
24
+
25
+
26
+ /** ---------------------------------------------------------------------------
27
+ * Functions.
28
+ * --------------------------------------------------------------------------- */
29
+
30
+ /**
31
+ * Concatenates elements to an array only if both the source and target
32
+ * contain no overlapping elements and the source itself is unique.
33
+ *
34
+ * @param {Array} a_dst - The target array to append to.
35
+ * @param {Array} a_src - The source array containing elements to add.
36
+ * @returns {number} - The new length of the array after the push,
37
+ * or -1 if validation fails or elements are not disjoint.
38
+ */
39
+ export function sj_array_concat_new(a_dst, a_src)
40
+ {
41
+ let i_len = - 1;
42
+ const b_dst = Array.isArray(a_dst);
43
+ const b_cat = Array.isArray(a_src);
44
+
45
+ if (b_dst && b_cat)
46
+ {
47
+ const o_set_dst = sj_set_new(a_dst);
48
+ const o_set_cat = sj_set_new(a_src);
49
+
50
+ if (o_set_dst && o_set_cat &&
51
+ (a_src.length === o_set_cat.size)) /* if all elements in a_src are unique */
52
+ {
53
+ const b_disjoint = o_set_dst.isDisjointFrom(o_set_cat);
54
+
55
+ if (b_disjoint)
56
+ {
57
+ i_len = sj_array_concat(a_dst, a_src);
58
+ }
59
+ }
60
+ }
61
+
62
+ return i_len;
63
+ }
64
+
65
+
66
+ /**
67
+ * Safely concatenates elements from the source array to the destination array.
68
+ * Uses a loop to prevent stack overflow errors that can occur with
69
+ * large arrays when using spread syntax.
70
+ *
71
+ * @param {Array} a_dst [in/out]
72
+ * The target array to append to. Must be a true Array instance.
73
+ *
74
+ * @param {Array} a_src [in]
75
+ * The source array containing elements to add. Must be a true Array instance.
76
+ *
77
+ * @returns {number}
78
+ * The new length of the destination array, or -1 if an error occurred.
79
+ */
80
+ export function sj_array_concat(a_dst, a_src)
81
+ {
82
+ const b_dst_array = Array.isArray(a_dst);
83
+ const b_src_array = Array.isArray(a_src);
84
+ let i_dst_len = - 1;
85
+
86
+ if (b_dst_array && b_src_array)
87
+ {
88
+ const i_org_dst_len = a_dst.length;
89
+
90
+ i_dst_len = sj_array_lengthen(a_dst, a_dst.length + a_src.length);
91
+
92
+ if (- 1 < i_dst_len)
93
+ {
94
+ for (let i_src = 0; i_src < a_src.length; i_src++)
95
+ {
96
+ a_dst[i_org_dst_len + i_src] = a_src[i_src];
97
+ }
98
+ }
99
+ }
100
+
101
+ return i_dst_len;
102
+ }
103
+
104
+
@@ -0,0 +1,91 @@
1
+ /**
2
+ * @file
3
+ * Provides utility functions for **creating and initializing** Array instances
4
+ * safely.
5
+ *
6
+ * @module src/arraynew
7
+ */
8
+
9
+ /** ---------------------------------------------------------------------------
10
+ * Imports.
11
+ * --------------------------------------------------------------------------- */
12
+
13
+
14
+ /** ---------------------------------------------------------------------------
15
+ * Functions.
16
+ * --------------------------------------------------------------------------- */
17
+
18
+ /**
19
+ * Creates a shallow copy of the source array.
20
+ *
21
+ * @param {any} a_src [in]
22
+ * The source array to be copied.
23
+ *
24
+ * @returns {Array<any> | null}
25
+ * A new array instance containing the same elements as `a_src`.
26
+ * Returns `null` if the input is not an array or if the new array
27
+ * allocation fails.
28
+ */
29
+ export function sj_array_new_copy(a_src)
30
+ {
31
+ let a_dst = null;
32
+ const b_src_is_array = Array.isArray(a_src);
33
+
34
+ if (b_src_is_array)
35
+ {
36
+ a_dst = sj_array_new(a_src.length);
37
+ }
38
+
39
+ if (a_dst)
40
+ {
41
+ for (let i_cnt = 0; i_cnt < a_src.length; i_cnt++)
42
+ {
43
+ a_dst[i_cnt] = a_src[i_cnt];
44
+ }
45
+ }
46
+
47
+ return a_dst;
48
+ }
49
+
50
+
51
+ /**
52
+ * Safely creates a new Array instance with a specified length.
53
+ *
54
+ * @param {number} i_len [in]
55
+ * The length of the new array. Must be a non-negative integer.
56
+ *
57
+ * @param {any} initial [in, optional]
58
+ * The value to fill each element with. If omitted, the array elements
59
+ * remain uninitialized (empty slots) for better performance.
60
+ *
61
+ * @returns {Array<any> | null}
62
+ * A new array of the specified length.
63
+ * - If `initial` is provided, each element is filled with that value.
64
+ * - If `initial` is omitted, the array is returned with uninitialized slots.
65
+ * Returns `null` if the length is invalid or a runtime error occurs.
66
+ */
67
+ export function sj_array_new(i_len, initial = undefined)
68
+ {
69
+ let a_new = null;
70
+
71
+ if (- 1 < i_len)
72
+ {
73
+ try
74
+ {
75
+ a_new = new Array(i_len);
76
+
77
+ if (sj_array_new.length < arguments.length)
78
+ {
79
+ a_new.fill(initial);
80
+ }
81
+ }
82
+ catch (o_err)
83
+ {
84
+ console.error(`${sj_array_new.name}: ${o_err.message}`);
85
+ }
86
+ }
87
+
88
+ return a_new;
89
+ }
90
+
91
+
@@ -0,0 +1,90 @@
1
+ /**
2
+ * @file
3
+ * Provides utility functions for **safely adding elements** to the end of
4
+ * Array instances.
5
+ *
6
+ * @module src/arraypush
7
+ */
8
+
9
+
10
+ /** ---------------------------------------------------------------------------
11
+ * Imports.
12
+ * --------------------------------------------------------------------------- */
13
+
14
+
15
+ /** ---------------------------------------------------------------------------
16
+ * Functions.
17
+ * --------------------------------------------------------------------------- */
18
+
19
+ /**
20
+ * Adds an element to the end of an array only if it is not already present.
21
+ *
22
+ * @param {Array} a_dst [in/out]
23
+ * The target array to be modified.
24
+ *
25
+ * @param {any} any [in]
26
+ * The element to add (uses strict equality for the uniqueness check).
27
+ *
28
+ * @returns {number}
29
+ * Returns the new length of the array if the element was added.
30
+ * Returns -1 if the element already exists, the input is not an array,
31
+ * or the push operation failed.
32
+ */
33
+ export function sj_array_push_new(a_dst, any)
34
+ {
35
+ let i_len = - 1;
36
+ let b_added = Array.isArray(a_dst);
37
+
38
+ if (b_added)
39
+ {
40
+ let i_ret = a_dst.indexOf(any);
41
+
42
+ if (i_ret < 0)
43
+ {
44
+ i_len = sj_array_push(a_dst, any);
45
+ }
46
+ }
47
+
48
+ return i_len;
49
+ }
50
+
51
+
52
+ /**
53
+ * Safely adds one or more elements to the end of an array using
54
+ * Array.prototype.push().
55
+ *
56
+ * @param {any} a_dst [in]
57
+ * The array to which the element(s) should be pushed. Must be a true Array instance.
58
+ *
59
+ * @param {any} push [in]
60
+ * The element to add to the array.
61
+ *
62
+ * @returns {number}
63
+ * The new length of the array if the operation was successful
64
+ * (equivalent to native push).
65
+ * Returns -1 if the target variable is not an array or
66
+ * if a runtime error occurred during the push operation.
67
+ *
68
+ * @see sj_array_concat
69
+ */
70
+ export function sj_array_push(a_dst, push)
71
+ {
72
+ const b_array = Array.isArray(a_dst);
73
+ let i_len = - 1;
74
+
75
+ if (b_array)
76
+ {
77
+ try
78
+ {
79
+ i_len = a_dst.push(push);
80
+ }
81
+ catch (o_err)
82
+ {
83
+ console.error(`${sj_array_push.name}: ${o_err.message}`);
84
+ }
85
+ }
86
+
87
+ return i_len;
88
+ }
89
+
90
+
@@ -0,0 +1,168 @@
1
+ /**
2
+ * @file
3
+ * Provides utility functions for **safely modifying array contents** through
4
+ * splicing, removal, and replacement.
5
+ *
6
+ * @module src/arraysplice
7
+ */
8
+
9
+ /** ---------------------------------------------------------------------------
10
+ * Imports.
11
+ * --------------------------------------------------------------------------- */
12
+
13
+ import
14
+ {
15
+ sj_array_concat,
16
+ }
17
+ from "./arrayconcat.js";
18
+
19
+ import
20
+ {
21
+ sj_array_new,
22
+ }
23
+ from "./arraynew.js";
24
+
25
+
26
+ /** ---------------------------------------------------------------------------
27
+ * Functions.
28
+ * --------------------------------------------------------------------------- */
29
+
30
+ /**
31
+ * Removes all occurrences of a specific element from an array.
32
+ *
33
+ * @param {Array} a_dst [in/out]
34
+ * The target array to be filtered in-place.
35
+ *
36
+ * @param {any} rem [in]
37
+ * The specific element to remove (uses strict equality).
38
+ *
39
+ * @returns {boolean}
40
+ * Returns true if the splice operation succeeded.
41
+ */
42
+ export function sj_array_splice_element_all(a_dst, rem)
43
+ {
44
+ let b_spliced = false;
45
+ let b_ret = Array.isArray(a_dst);
46
+
47
+ if (b_ret)
48
+ {
49
+ let a_rem = sj_array_new(0);
50
+
51
+ for (let i_cnt = a_dst.length - 1; (- 1 < i_cnt) && (a_rem !== null); i_cnt--)
52
+ {
53
+ if (a_dst[i_cnt] === rem)
54
+ {
55
+ a_rem = sj_array_splice(a_dst, i_cnt, 1, null);
56
+ }
57
+ }
58
+
59
+ b_spliced = (a_rem !== null);
60
+ }
61
+
62
+ return b_spliced;
63
+ }
64
+
65
+
66
+ /**
67
+ * Replaces a specific element in an array with new elements provided as an array.
68
+ *
69
+ * @param {Array} a_dst [in/out]
70
+ * The target array to be modified.
71
+ *
72
+ * @param {any} rem [in]
73
+ * The specific element to search for (uses strict equality(===)).
74
+ *
75
+ * @param {Array<any> | null} a_ins [in]
76
+ * An array of elements to insert in place of the found element.
77
+ * If null or not an array, no elements are inserted after removal.
78
+ *
79
+ * @returns {boolean}
80
+ * Returns true if the element was found and the replacement operation succeeded,
81
+ * false otherwise.
82
+ */
83
+ export function sj_array_splice_element(a_dst, rem, a_ins)
84
+ {
85
+ let b_spliced = false;
86
+ let b_ret = Array.isArray(a_dst);
87
+
88
+ if (b_ret)
89
+ {
90
+ const i_ret = a_dst.indexOf(rem);
91
+
92
+ if (- 1 < i_ret)
93
+ {
94
+ const a_ret = sj_array_splice(a_dst, i_ret, 1, a_ins);
95
+
96
+ b_spliced = (a_ret !== null);
97
+ }
98
+ }
99
+
100
+ return b_spliced;
101
+ }
102
+
103
+
104
+ /**
105
+ * Safely executes a splice-like operation to change the contents of an array.
106
+ * This implementation avoids stack overflow errors by using manual iteration
107
+ * instead of spread syntax for the elements to be inserted.
108
+ *
109
+ * @param {any} a_dst [in/out]
110
+ * The array to be modified. Must be a true Array instance.
111
+ *
112
+ * @param {number} i_start [in]
113
+ * The zero-based index at which to start changing the array.
114
+ *
115
+ * @param {number} i_remove [in]
116
+ * The number of elements to remove from `i_start`.
117
+ *
118
+ * @param {Array<any> | null} a_insert [in]
119
+ * An array of elements to insert at `i_start`. If `null` or not an array,
120
+ * no elements are inserted.
121
+ *
122
+ * @returns {Array<any> | null}
123
+ * A new array containing the removed elements if the operation succeeded
124
+ * (returns an empty array `[]` if no elements were removed).
125
+ * Returns `null` if `a_dst` is not an array, or if an internal concatenation
126
+ * error occurs.
127
+ */
128
+ export function sj_array_splice(a_dst, i_start, i_remove, a_insert)
129
+ {
130
+ const b_array_dst = Array.isArray(a_dst);
131
+ let a_remove = null;
132
+
133
+ if (b_array_dst)
134
+ {
135
+ try
136
+ {
137
+ const b_array_ins = Array.isArray(a_insert);
138
+ const a_tail = a_dst.splice(i_start, a_dst.length - i_start);
139
+ let i_dst_len = a_dst.length;
140
+
141
+ a_remove = a_tail.splice(0, i_remove);
142
+
143
+ if (b_array_ins)
144
+ {
145
+ i_dst_len = sj_array_concat(a_dst, a_insert);
146
+ }
147
+
148
+ if (- 1 < i_dst_len)
149
+ {
150
+ i_dst_len = sj_array_concat(a_dst, a_tail);
151
+ }
152
+
153
+ if (i_dst_len < 0)
154
+ {
155
+ a_remove = null;
156
+ }
157
+ }
158
+ catch (o_err)
159
+ {
160
+ console.error(`${sj_array_splice.name}: ${o_err.message}`);
161
+ a_remove = null;
162
+ }
163
+ }
164
+
165
+ return a_remove;
166
+ }
167
+
168
+
@@ -11,7 +11,11 @@ export * from "./Observer_t.js";
11
11
  export * from "./SubjectSet_t.js";
12
12
  export * from "./Subject_t.js";
13
13
  export * from "./array.js";
14
- export * from "./arrayapp.js";
14
+ export * from "./arraynew.js";
15
+ export * from "./arraypush.js";
16
+ export * from "./arraysplice.js";
17
+ export * from "./arrayconcat.js";
18
+ export * from "./matnew.js";
15
19
  export * from "./dataset.js";
16
20
  export * from "./document.js";
17
21
  export * from "./error.js";
@@ -0,0 +1,104 @@
1
+ /**
2
+ * @file
3
+ *
4
+ * @module src/matnew
5
+ */
6
+
7
+ /** ---------------------------------------------------------------------------
8
+ * Imports.
9
+ * --------------------------------------------------------------------------- */
10
+
11
+ import
12
+ {
13
+ sj_array_new,
14
+ sj_array_push,
15
+ sj_array_lengthen,
16
+ }
17
+ from "./array.js";
18
+
19
+
20
+ /** ---------------------------------------------------------------------------
21
+ * Functions.
22
+ * --------------------------------------------------------------------------- */
23
+
24
+ export function sj_mat_new(...ai_dim)
25
+ {
26
+ let a_mat = null;
27
+ const aa_stack = sj_array_new(0);
28
+
29
+ if (aa_stack)
30
+ {
31
+ a_mat = mat_new_init(ai_dim);
32
+ }
33
+
34
+ while (a_mat && (a_mat.length < ai_dim[aa_stack.length]))
35
+ {
36
+ if (aa_stack.length < (ai_dim.length - 1))
37
+ {
38
+ a_mat = mat_new_push(aa_stack, a_mat);
39
+ }
40
+ else
41
+ {
42
+ sj_array_lengthen(a_mat, ai_dim[aa_stack.length], 0);
43
+ a_mat = mat_new_pop(aa_stack, a_mat, ai_dim);
44
+ }
45
+ }
46
+
47
+ return a_mat;
48
+ }
49
+
50
+
51
+ function mat_new_init(ai_dim)
52
+ {
53
+ let a_mat = null;
54
+
55
+ if (0 < ai_dim.length)
56
+ {
57
+ const b_every_ok =
58
+ ai_dim.every(i_dim => Number.isInteger(i_dim) && (0 < i_dim));
59
+
60
+ if (b_every_ok)
61
+ {
62
+ a_mat = sj_array_new(0);
63
+ }
64
+ }
65
+
66
+ return a_mat;
67
+ }
68
+
69
+
70
+ function mat_new_push(aa_stack, a_mat)
71
+ {
72
+ const a_push = sj_array_new(0, 0);
73
+
74
+ if (a_push)
75
+ {
76
+ let i_len = sj_array_push(a_mat, a_push);
77
+
78
+ if (0 < i_len)
79
+ {
80
+ i_len = sj_array_push(aa_stack, a_mat);
81
+ }
82
+
83
+ if (i_len < 1)
84
+ {
85
+ a_push = null;
86
+ }
87
+ }
88
+
89
+ return a_push;
90
+ }
91
+
92
+
93
+ function mat_new_pop(aa_stack, a_mat, ai_dim)
94
+ {
95
+ let a_mat_now = a_mat;
96
+
97
+ while ((0 < aa_stack.length) && (ai_dim[aa_stack.length] <= a_mat_now.length))
98
+ {
99
+ a_mat_now = aa_stack.pop();
100
+ }
101
+
102
+ return a_mat_now;
103
+ }
104
+
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @file
3
+ * Set utility functions.
4
+ * Provides helper functions for creating and managing Set objects.
5
+ *
6
+ * @module src/set
7
+ */
8
+
9
+ /** ---------------------------------------------------------------------------
10
+ * Imports.
11
+ * --------------------------------------------------------------------------- */
12
+
13
+
14
+ /** ---------------------------------------------------------------------------
15
+ * Functions.
16
+ * --------------------------------------------------------------------------- */
17
+
18
+ /**
19
+ * Creates a new Set object from the provided source.
20
+ *
21
+ * @param {Iterable|null|undefined} src [in]
22
+ * An iterable object (such as an Array, String, or another Set).
23
+ *
24
+ * @returns {Set|null}
25
+ * A new Set containing the source elements, or null if instantiation fails.
26
+ */
27
+ export function sj_set_new(src)
28
+ {
29
+ let o_set = null;
30
+
31
+ try
32
+ {
33
+ o_set = new Set(src);
34
+ }
35
+ catch (o_err)
36
+ {
37
+ console.error(`${sj_set_new.name}: ${o_err.message}`);
38
+ }
39
+
40
+ return o_set;
41
+ }
42
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smsmslib",
3
- "version": "1.0.55",
3
+ "version": "1.0.59",
4
4
  "description": "Reusable functions for me.",
5
5
  "files": [
6
6
  "javascr/**/*.js",
@@ -19,6 +19,6 @@
19
19
  "author": "",
20
20
  "license": "ISC",
21
21
  "dependencies": {
22
- "smsmslib": "^1.0.55"
22
+ "smsmslib": "^1.0.59"
23
23
  }
24
24
  }
@@ -1,223 +0,0 @@
1
- /**
2
- * @file
3
- * A collection of utility functions for safe and unique array manipulations.
4
- * Provides enhanced array operations including disjoint concatenation, uniqueness
5
- * checks, and safe in-place modifications (push, replace, and splice).
6
- *
7
- * Key Features:
8
- * - Integrity: Validates array types before execution.
9
- * - Uniqueness: Supports operations that prevent duplicate entries.
10
- * - Safety: Wraps native methods to prevent runtime exceptions in critical flows.
11
- *
12
- * @module src/arrayapp
13
- */
14
-
15
-
16
- /** ---------------------------------------------------------------------------
17
- * Imports.
18
- * --------------------------------------------------------------------------- */
19
-
20
- import {sj_array_push} from "./array.js";
21
-
22
-
23
- /** ---------------------------------------------------------------------------
24
- * Functions.
25
- * --------------------------------------------------------------------------- */
26
-
27
- /**
28
- * Concatenates elements to an array only if both the source and target
29
- * contain no overlapping elements and the source itself is unique.
30
- *
31
- * @param {any} a_any - The target array to append to.
32
- * @param {any} a_cat - The source array containing elements to add.
33
- * @returns {number} - The new length of the array after the push,
34
- * or -1 if validation fails or elements are not disjoint.
35
- */
36
- export function sj_array_concat_new(a_any, a_cat)
37
- {
38
- let i_len = - 1;
39
- const b_any = Array.isArray(a_any);
40
- const b_cat = Array.isArray(a_cat);
41
-
42
- if (b_any && b_cat)
43
- {
44
- const o_set_any = new Set(a_any);
45
- const o_set_cat = new Set(a_cat);
46
-
47
- if (a_cat.length === o_set_cat.size) /* if all elements in a_cat are unique */
48
- {
49
- const b_disjoint = o_set_any.isDisjointFrom(o_set_cat);
50
-
51
- if (b_disjoint)
52
- {
53
- i_len = sj_array_push(a_any, ...a_cat);
54
- }
55
- }
56
- }
57
-
58
- return i_len;
59
- }
60
-
61
-
62
- /**
63
- * Checks if all elements in the array are unique.
64
- *
65
- * @param {any} a_any [i]
66
- * The target to check.
67
- *
68
- * @returns {boolean}
69
- * Returns true if the input is an array with no duplicates.
70
- */
71
- export function sj_array_is_unique(a_any)
72
- {
73
- let b_ret = Array.isArray(a_any);
74
-
75
- if (b_ret && (1 < a_any.length))
76
- {
77
- const o_set = new Set(a_any);
78
-
79
- b_ret = (a_any.length === o_set.size);
80
- }
81
-
82
- return b_ret;
83
- }
84
-
85
-
86
- /**
87
- * Adds an element to the end of an array only if it is not already present.
88
- *
89
- * @param {Array} a_any [in/out]
90
- * The target array to be modified.
91
- *
92
- * @param {any} any [in]
93
- * The element to add (uses strict equality for the uniqueness check).
94
- *
95
- * @returns {number}
96
- * Returns the new length of the array if the element was added.
97
- * Returns -1 if the element already exists, the input is not an array,
98
- * or the push operation failed.
99
- */
100
- export function sj_array_push_new(a_any, any)
101
- {
102
- let i_len = - 1;
103
- let b_added = Array.isArray(a_any);
104
-
105
- if (b_added)
106
- {
107
- let i_ret = a_any.indexOf(any);
108
-
109
- if (i_ret < 0)
110
- {
111
- i_len = sj_array_push(a_any, any);
112
- }
113
- }
114
-
115
- return i_len;
116
- }
117
-
118
-
119
- /**
120
- * Removes all occurrences of a specific element from an array.
121
- *
122
- * @param {Array} a_any [in/out]
123
- * The target array to be filtered in-place.
124
- *
125
- * @param {any} any [in]
126
- * The specific element to remove (uses strict equality).
127
- *
128
- * @returns {boolean}
129
- * Returns true if the splice operation succeeded.
130
- */
131
- export function sj_array_splice_element_all(a_any, any)
132
- {
133
- let a_ret;
134
- let b_spliced = Array.isArray(a_any);
135
-
136
- if (b_spliced)
137
- {
138
- const a_insert = a_any.filter(item => (item !== any));
139
-
140
- a_ret = sj_array_splice(a_any, 0, a_any.length, ...a_insert);
141
- b_spliced = (a_ret !== null);
142
- }
143
-
144
- return b_spliced;
145
- }
146
-
147
-
148
- /**
149
- * Replaces a specific element in an array with new elements.
150
- *
151
- * @param {Array} a_any [in/out]
152
- * The target array to be modified.
153
- *
154
- * @param {any} old_any [in]
155
- * The specific element to search for (uses strict equality).
156
- *
157
- * @param {...any} insert [in]
158
- * The elements to insert in place of the found element.
159
- *
160
- * @returns {boolean}
161
- * Returns true if the element was found and spliced, false otherwise.
162
- */
163
- export function sj_array_splice_element(a_any, old_any, ...insert)
164
- {
165
- let b_spliced = false;
166
- let b_ret = Array.isArray(a_any);
167
-
168
- if (b_ret)
169
- {
170
- const i_ret = a_any.indexOf(old_any);
171
-
172
- if (- 1 < i_ret)
173
- {
174
- const a_ret = sj_array_splice(a_any, i_ret, 1, ...insert);
175
-
176
- b_spliced = (a_ret !== null);
177
- }
178
- }
179
-
180
- return b_spliced;
181
- }
182
-
183
-
184
- /**
185
- * Safely searches for the first occurrence of the element specified by `old_any`
186
- * in the array `a_any` and replaces it with `new_any`.
187
- *
188
- * The replacement operation is performed only if the target variable `a_any`
189
- * is a true Array instance and the element is found within it using indexOf().
190
- *
191
- * @param {any} a_any [in/out]
192
- * The array to be modified. Must be a true Array instance.
193
- *
194
- * @param {any} old_any [in]
195
- * The value to search for and replace (the element currently in the array).
196
- *
197
- * @param {any} new_any [in]
198
- * The value to replace the target element with.
199
- *
200
- * @returns {boolean}
201
- * `true` if the `old_any` was found and successfully replaced, otherwise `false`.
202
- */
203
- export function sj_array_replace(a_any, old_any, new_any)
204
- {
205
- let b_replaced = Array.isArray(a_any);
206
-
207
- if (b_replaced)
208
- {
209
- const i_ret = a_any.indexOf(old_any);
210
- const b_found = (- 1 < i_ret);
211
-
212
- if (b_found)
213
- {
214
- a_any[i_ret] = new_any;
215
- }
216
-
217
- b_replaced = b_found
218
- }
219
-
220
- return b_replaced;
221
- }
222
-
223
-