smsmslib 1.0.76 → 1.0.77
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/javascr/util/dataset.js +12 -2
- package/javascr/util/prop.js +166 -113
- package/package.json +2 -2
package/javascr/util/dataset.js
CHANGED
|
@@ -175,7 +175,12 @@ export function sj_dataset_get_own(o_element, s_prop)
|
|
|
175
175
|
|
|
176
176
|
if (o_element)
|
|
177
177
|
{
|
|
178
|
-
|
|
178
|
+
const o_ret = sj_prop_get_own(o_element.dataset, s_prop);
|
|
179
|
+
|
|
180
|
+
if (o_ret.b_ok)
|
|
181
|
+
{
|
|
182
|
+
s_value = o_ret.value;
|
|
183
|
+
}
|
|
179
184
|
}
|
|
180
185
|
|
|
181
186
|
return s_value;
|
|
@@ -205,7 +210,12 @@ export function sj_dataset_delete_own(o_element, s_prop)
|
|
|
205
210
|
|
|
206
211
|
if (o_element)
|
|
207
212
|
{
|
|
208
|
-
|
|
213
|
+
const o_ret = sj_prop_delete_own(o_element.dataset, s_prop);
|
|
214
|
+
|
|
215
|
+
if (o_ret.b_ok)
|
|
216
|
+
{
|
|
217
|
+
value = o_ret.value;
|
|
218
|
+
}
|
|
209
219
|
}
|
|
210
220
|
|
|
211
221
|
return value;
|
package/javascr/util/prop.js
CHANGED
|
@@ -12,7 +12,18 @@
|
|
|
12
12
|
* Imports.
|
|
13
13
|
* --------------------------------------------------------------------------- */
|
|
14
14
|
|
|
15
|
-
import
|
|
15
|
+
import
|
|
16
|
+
{
|
|
17
|
+
sj_is_object,
|
|
18
|
+
sj_is_primitive_text,
|
|
19
|
+
}
|
|
20
|
+
from "./type.js";
|
|
21
|
+
|
|
22
|
+
import
|
|
23
|
+
{
|
|
24
|
+
sj_new_lit,
|
|
25
|
+
}
|
|
26
|
+
from "./new.js";
|
|
16
27
|
|
|
17
28
|
|
|
18
29
|
/** ---------------------------------------------------------------------------
|
|
@@ -20,259 +31,301 @@ import {sj_is_object, sj_is_primitive_text} from "./type.js";
|
|
|
20
31
|
* --------------------------------------------------------------------------- */
|
|
21
32
|
|
|
22
33
|
/**
|
|
23
|
-
* Safely updates the value of an **existing own data property**
|
|
24
|
-
*
|
|
34
|
+
* Safely updates the value of an **existing own data property**
|
|
35
|
+
* (including array elements) only if the new value is different from the
|
|
36
|
+
* current one.
|
|
37
|
+
*
|
|
38
|
+
* This setting is performed only if the property already exists directly on the
|
|
39
|
+
* target (ignoring the prototype chain), is writable, and the new value is
|
|
40
|
+
* different (evaluated via Object.is). Optionally, the previous value can be
|
|
41
|
+
* output to the o_chg argument. For arrays, this ensures that only
|
|
42
|
+
* elements at existing indices are updated, preventing length expansion.
|
|
25
43
|
*
|
|
26
44
|
* @param {any} o_any [in]
|
|
27
|
-
* The object whose property is to be changed.
|
|
45
|
+
* The object or array whose property/element is to be changed.
|
|
28
46
|
*
|
|
29
|
-
* @param {string}
|
|
30
|
-
* The name
|
|
47
|
+
* @param {string|number} prop [in]
|
|
48
|
+
* The property name (non-empty string) or array index (non-negative integer).
|
|
31
49
|
*
|
|
32
50
|
* @param {any} value [in]
|
|
33
51
|
* The new value to assign.
|
|
34
52
|
*
|
|
35
|
-
* @param {object}
|
|
36
|
-
* Optional. An object to store the previous value
|
|
53
|
+
* @param {object} o_chg [out]
|
|
54
|
+
* Optional. An object to store the previous value if a change occurs.
|
|
37
55
|
*
|
|
38
56
|
* @returns {boolean}
|
|
39
57
|
* true : The property was successfully updated with a different value.
|
|
40
|
-
* false : No change was made (e.g., property
|
|
41
|
-
*
|
|
42
|
-
* The return value is guaranteed to be a primitive boolean.
|
|
58
|
+
* false : No change was made (e.g., property does not exist, is not writable,
|
|
59
|
+
* value is identical, or arguments are invalid).
|
|
43
60
|
*/
|
|
44
|
-
export function sj_prop_chg_own(o_any,
|
|
61
|
+
export function sj_prop_chg_own(o_any, prop, value, o_chg)
|
|
45
62
|
{
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
63
|
+
const b_obj = sj_is_object(o_any);
|
|
64
|
+
const b_num = Number.isInteger(prop);
|
|
65
|
+
const b_text = sj_is_primitive_text(prop);
|
|
66
|
+
let b_ok = b_obj && (b_text || (b_num && (0 <= prop)));
|
|
49
67
|
|
|
50
|
-
if (
|
|
68
|
+
if (b_ok)
|
|
51
69
|
{
|
|
52
|
-
const o_desc = Object.getOwnPropertyDescriptor(o_any,
|
|
70
|
+
const o_desc = Object.getOwnPropertyDescriptor(o_any, prop);
|
|
53
71
|
|
|
54
|
-
|
|
72
|
+
b_ok = o_desc && o_desc.writable && (!Object.is(o_any[prop], value));
|
|
55
73
|
|
|
56
|
-
if (
|
|
74
|
+
if (b_ok)
|
|
57
75
|
{
|
|
58
76
|
if (o_chg)
|
|
59
77
|
{
|
|
60
|
-
sj_prop_upsert_own(o_chg,
|
|
78
|
+
sj_prop_upsert_own(o_chg, prop, o_any[prop]);
|
|
61
79
|
}
|
|
62
80
|
|
|
63
|
-
o_any[
|
|
81
|
+
o_any[prop] = value;
|
|
64
82
|
}
|
|
65
83
|
}
|
|
66
84
|
|
|
67
|
-
return !!
|
|
85
|
+
return !!b_ok;
|
|
68
86
|
}
|
|
69
87
|
|
|
70
88
|
|
|
71
89
|
/**
|
|
72
|
-
* Safely adds a **new own property** to an object
|
|
90
|
+
* Safely adds a **new own property** (including array elements) to an object
|
|
91
|
+
* or array.
|
|
73
92
|
*
|
|
74
|
-
* This function
|
|
75
|
-
*
|
|
76
|
-
*
|
|
93
|
+
* This function ensures that the setting is performed only if the property
|
|
94
|
+
* does not already exist directly on the target (ignoring the prototype chain)
|
|
95
|
+
* and the target is extensible. For arrays, this can be used to fill an
|
|
96
|
+
* empty slot or add a new element at the end, provided the index is not
|
|
97
|
+
* already occupied.
|
|
77
98
|
*
|
|
78
99
|
* @param {any} o_any [in]
|
|
79
|
-
* The object to which the new property should be added.
|
|
100
|
+
* The object or array to which the new property or element should be added.
|
|
80
101
|
*
|
|
81
|
-
* @param {string}
|
|
82
|
-
* The name
|
|
102
|
+
* @param {string|number} prop [in]
|
|
103
|
+
* The property name (non-empty string) or array index (non-negative integer).
|
|
83
104
|
*
|
|
84
105
|
* @param {any} value [in]
|
|
85
|
-
* The value to assign to the new property.
|
|
106
|
+
* The value to assign to the new property or element.
|
|
86
107
|
*
|
|
87
108
|
* @returns {boolean}
|
|
88
|
-
*
|
|
109
|
+
* true : The new property/element was successfully added.
|
|
110
|
+
* false : No change was made (e.g., property already exists, object is not
|
|
111
|
+
* extensible, or arguments are invalid).
|
|
89
112
|
*/
|
|
90
|
-
export function sj_prop_add_own_new(o_any,
|
|
113
|
+
export function sj_prop_add_own_new(o_any, prop, value)
|
|
91
114
|
{
|
|
92
|
-
const b_obj
|
|
93
|
-
const
|
|
94
|
-
|
|
115
|
+
const b_obj = sj_is_object(o_any);
|
|
116
|
+
const b_num = Number.isInteger(prop);
|
|
117
|
+
const b_text = sj_is_primitive_text(prop);
|
|
118
|
+
let b_ok = b_obj && (b_text || (b_num && (0 <= prop)));
|
|
95
119
|
|
|
96
|
-
if (
|
|
120
|
+
if (b_ok)
|
|
97
121
|
{
|
|
98
|
-
|
|
122
|
+
b_ok = !Object.hasOwn(o_any, prop);
|
|
99
123
|
|
|
100
|
-
if (
|
|
124
|
+
if (b_ok)
|
|
101
125
|
{
|
|
102
|
-
|
|
126
|
+
b_ok = Object.isExtensible(o_any);
|
|
103
127
|
}
|
|
104
128
|
}
|
|
105
129
|
|
|
106
|
-
if (
|
|
130
|
+
if (b_ok)
|
|
107
131
|
{
|
|
108
|
-
o_any[
|
|
132
|
+
o_any[prop] = value;
|
|
109
133
|
}
|
|
110
134
|
|
|
111
|
-
return
|
|
135
|
+
return b_ok;
|
|
112
136
|
}
|
|
113
137
|
|
|
114
138
|
|
|
115
139
|
/**
|
|
116
|
-
* Safely performs Upsert (Update or Insert) for **own data properties**
|
|
117
|
-
*
|
|
140
|
+
* Safely performs an Upsert (Update or Insert) for **own data properties**
|
|
141
|
+
* (including array elements).
|
|
118
142
|
*
|
|
119
|
-
* This
|
|
120
|
-
*
|
|
143
|
+
* This setting is performed only if the property already exists and is writable,
|
|
144
|
+
* or if the property does not exist but the object or array is extensible.
|
|
145
|
+
* For arrays, this allows updating existing elements or adding new elements
|
|
146
|
+
* (potentially expanding the length) as long as the array is not frozen or sealed.
|
|
121
147
|
*
|
|
122
148
|
* @param {any} o_any [in]
|
|
123
|
-
* The object on which to perform the upsert operation.
|
|
149
|
+
* The object or array on which to perform the upsert operation.
|
|
124
150
|
*
|
|
125
|
-
* @param {string}
|
|
126
|
-
* The name
|
|
151
|
+
* @param {string|number} prop [in]
|
|
152
|
+
* The property name (non-empty string) or array index (non-negative integer).
|
|
127
153
|
*
|
|
128
154
|
* @param {any} value [in]
|
|
129
155
|
* The value to assign.
|
|
130
156
|
*
|
|
131
157
|
* @returns {boolean}
|
|
132
|
-
*
|
|
158
|
+
* true : The property was successfully updated or inserted.
|
|
159
|
+
* false: No change was made (e.g., property is not writable, object is not
|
|
160
|
+
* extensible, or arguments are invalid).
|
|
133
161
|
*/
|
|
134
|
-
export function sj_prop_upsert_own(o_any,
|
|
162
|
+
export function sj_prop_upsert_own(o_any, prop, value)
|
|
135
163
|
{
|
|
136
|
-
const b_obj
|
|
137
|
-
const
|
|
138
|
-
|
|
164
|
+
const b_obj = sj_is_object(o_any);
|
|
165
|
+
const b_num = Number.isInteger(prop);
|
|
166
|
+
const b_text = sj_is_primitive_text(prop);
|
|
167
|
+
let b_ok = b_obj && (b_text || (b_num && (0 <= prop)));
|
|
139
168
|
|
|
140
|
-
if (
|
|
169
|
+
if (b_ok)
|
|
141
170
|
{
|
|
142
|
-
const o_desc = Object.getOwnPropertyDescriptor(o_any,
|
|
171
|
+
const o_desc = Object.getOwnPropertyDescriptor(o_any, prop);
|
|
143
172
|
|
|
144
|
-
|
|
173
|
+
b_ok = o_desc;
|
|
145
174
|
|
|
146
|
-
if (
|
|
175
|
+
if (b_ok)
|
|
147
176
|
{
|
|
148
|
-
|
|
177
|
+
b_ok = o_desc.writable;
|
|
149
178
|
}
|
|
150
179
|
else
|
|
151
180
|
{
|
|
152
|
-
|
|
181
|
+
// !freeze, !seal, and !preventExtensions
|
|
182
|
+
b_ok = Object.isExtensible(o_any);
|
|
153
183
|
}
|
|
154
184
|
}
|
|
155
185
|
|
|
156
|
-
if (
|
|
186
|
+
if (b_ok)
|
|
157
187
|
{
|
|
158
|
-
o_any[
|
|
188
|
+
o_any[prop] = value;
|
|
159
189
|
}
|
|
160
190
|
|
|
161
|
-
return !!
|
|
191
|
+
return !!b_ok;
|
|
162
192
|
}
|
|
163
193
|
|
|
164
194
|
|
|
165
195
|
/**
|
|
166
|
-
* Safely sets (overwrites) the value of an **existing own data property**
|
|
196
|
+
* Safely sets (overwrites) the value of an **existing own data property**
|
|
197
|
+
* (including array elements).
|
|
167
198
|
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
199
|
+
* This setting is performed only if the property already exists directly
|
|
200
|
+
* on the object or array (ignoring the prototype chain) and its descriptor
|
|
201
|
+
* indicates that it is writable. For arrays, this ensures that only
|
|
202
|
+
* elements at existing indices are updated, preventing unintended expansion
|
|
203
|
+
* of the array length.
|
|
170
204
|
*
|
|
171
205
|
* @param {any} o_any [in]
|
|
172
|
-
* The object to set the value in.
|
|
206
|
+
* The object or array to set the value in.
|
|
173
207
|
*
|
|
174
|
-
* @param {string}
|
|
175
|
-
* The name
|
|
208
|
+
* @param {string|number} prop [in]
|
|
209
|
+
* The property name (non-empty string) or array index (non-negative integer)
|
|
210
|
+
* to set.
|
|
176
211
|
*
|
|
177
212
|
* @param {any} value [in]
|
|
178
|
-
* The value to assign to the property.
|
|
213
|
+
* The new value to assign to the property.
|
|
179
214
|
*
|
|
180
215
|
* @returns {boolean}
|
|
181
|
-
*
|
|
216
|
+
* true : The own property existed and was successfully overwritten.
|
|
217
|
+
* false : No change was made (e.g., property does not exist, is not writable,
|
|
218
|
+
* or arguments are invalid).
|
|
182
219
|
*/
|
|
183
|
-
export function sj_prop_set_own(o_any,
|
|
220
|
+
export function sj_prop_set_own(o_any, prop, value)
|
|
184
221
|
{
|
|
185
222
|
const b_obj = sj_is_object(o_any);
|
|
186
|
-
const
|
|
187
|
-
|
|
223
|
+
const b_num = Number.isInteger(prop);
|
|
224
|
+
const b_text = sj_is_primitive_text(prop);
|
|
225
|
+
let b_ok = b_obj && (b_text || (b_num && (0 <= prop)));
|
|
188
226
|
|
|
189
|
-
if (
|
|
227
|
+
if (b_ok)
|
|
190
228
|
{
|
|
191
|
-
const o_desc = Object.getOwnPropertyDescriptor(o_any,
|
|
229
|
+
const o_desc = Object.getOwnPropertyDescriptor(o_any, prop);
|
|
192
230
|
|
|
193
|
-
|
|
231
|
+
b_ok = !!(o_desc && o_desc.writable);
|
|
194
232
|
|
|
195
|
-
if (
|
|
233
|
+
if (b_ok)
|
|
196
234
|
{
|
|
197
|
-
o_any[
|
|
235
|
+
o_any[prop] = value;
|
|
198
236
|
}
|
|
199
237
|
}
|
|
200
238
|
|
|
201
|
-
return
|
|
239
|
+
return b_ok;
|
|
202
240
|
}
|
|
203
241
|
|
|
204
242
|
|
|
205
243
|
/**
|
|
206
|
-
* Safely retrieves the value of an **own property** (
|
|
207
|
-
* from an object.
|
|
244
|
+
* Safely retrieves the value of an **own property** (including array elements)
|
|
245
|
+
* from an object or array.
|
|
208
246
|
*
|
|
209
|
-
* This function only accesses properties directly defined on the
|
|
210
|
-
* ignoring the prototype chain.
|
|
247
|
+
* This function only accesses properties directly defined on the target itself,
|
|
248
|
+
* completely ignoring the prototype chain.
|
|
211
249
|
*
|
|
212
250
|
* @param {any} o_any [in]
|
|
213
|
-
* The object
|
|
251
|
+
* The object or array to retrieve the property or element from.
|
|
214
252
|
*
|
|
215
|
-
* @param {string}
|
|
216
|
-
* The name
|
|
253
|
+
* @param {string|number} prop [in]
|
|
254
|
+
* The property name (non-empty string) or array index (non-negative integer)
|
|
255
|
+
* to retrieve.
|
|
217
256
|
*
|
|
218
|
-
* @returns {
|
|
219
|
-
*
|
|
220
|
-
*
|
|
257
|
+
* @returns {object}
|
|
258
|
+
* A literal object (via sj_new_lit) containing:
|
|
259
|
+
* - b_ok : true if the property exists as an own property.
|
|
260
|
+
* - value: The value of the property if b_ok is true; otherwise, undefined.
|
|
221
261
|
*/
|
|
222
|
-
export function sj_prop_get_own(o_any,
|
|
262
|
+
export function sj_prop_get_own(o_any, prop)
|
|
223
263
|
{
|
|
224
264
|
let value = undefined;
|
|
225
265
|
const b_obj = sj_is_object(o_any);
|
|
226
|
-
const
|
|
266
|
+
const b_num = Number.isInteger(prop);
|
|
267
|
+
const b_text = sj_is_primitive_text(prop);
|
|
268
|
+
let b_ok = b_obj && (b_text || (b_num && (0 <= prop)));
|
|
227
269
|
|
|
228
|
-
if (
|
|
270
|
+
if (b_ok)
|
|
229
271
|
{
|
|
230
|
-
const b_has = Object.hasOwn(o_any,
|
|
272
|
+
const b_has = Object.hasOwn(o_any, prop);
|
|
231
273
|
|
|
232
274
|
if (b_has)
|
|
233
275
|
{
|
|
234
|
-
value = o_any[
|
|
276
|
+
value = o_any[prop];
|
|
235
277
|
}
|
|
236
278
|
}
|
|
237
279
|
|
|
238
|
-
|
|
280
|
+
const s_lit = sj_new_lit(() => ({b_ok, value}));
|
|
281
|
+
return s_lit;
|
|
239
282
|
}
|
|
240
283
|
|
|
241
284
|
|
|
242
285
|
/**
|
|
243
|
-
* Safely deletes an **own property**
|
|
286
|
+
* Safely deletes an **own property** (including array elements) and returns
|
|
287
|
+
* the deleted value along with the success status.
|
|
244
288
|
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
289
|
+
* This function targets properties directly defined on the object or array,
|
|
290
|
+
* ignoring the prototype chain. If the target is an array, using this function
|
|
291
|
+
* will create a "hole" (sparse array) at the specified index.
|
|
248
292
|
*
|
|
249
293
|
* @param {any} o_any [in]
|
|
250
|
-
* The object from which to delete the property.
|
|
294
|
+
* The object or array from which to delete the property/element.
|
|
251
295
|
*
|
|
252
|
-
* @param {string}
|
|
253
|
-
* The name
|
|
296
|
+
* @param {string|number} prop [in]
|
|
297
|
+
* The property name (non-empty string) or array index (non-negative integer)
|
|
298
|
+
* to delete.
|
|
254
299
|
*
|
|
255
|
-
* @returns {
|
|
256
|
-
*
|
|
300
|
+
* @returns {object}
|
|
301
|
+
* A literal object containing:
|
|
302
|
+
* - b_ok : true if the property existed and was successfully deleted.
|
|
303
|
+
* - value: The value of the property before deletion if b_ok is true;
|
|
304
|
+
* otherwise, undefined.
|
|
257
305
|
*/
|
|
258
|
-
export function sj_prop_delete_own(o_any,
|
|
306
|
+
export function sj_prop_delete_own(o_any, prop)
|
|
259
307
|
{
|
|
260
308
|
let value = undefined;
|
|
261
309
|
const b_obj = sj_is_object(o_any);
|
|
262
|
-
const
|
|
310
|
+
const b_num = Number.isInteger(prop);
|
|
311
|
+
const b_text = sj_is_primitive_text(prop);
|
|
312
|
+
let b_ok = b_obj && (b_text || (b_num && (0 <= prop)));
|
|
263
313
|
|
|
264
|
-
if (
|
|
314
|
+
if (b_ok)
|
|
265
315
|
{
|
|
266
|
-
const o_desc = Object.getOwnPropertyDescriptor(o_any,
|
|
316
|
+
const o_desc = Object.getOwnPropertyDescriptor(o_any, prop);
|
|
317
|
+
|
|
318
|
+
b_ok = o_desc && o_desc.configurable;
|
|
267
319
|
|
|
268
|
-
if (
|
|
320
|
+
if (b_ok)
|
|
269
321
|
{
|
|
270
|
-
value = o_any[
|
|
271
|
-
delete o_any[
|
|
322
|
+
value = o_any[prop];
|
|
323
|
+
delete o_any[prop];
|
|
272
324
|
}
|
|
273
325
|
}
|
|
274
326
|
|
|
275
|
-
|
|
327
|
+
const s_lit = sj_new_lit(() => ({b_ok, value}));
|
|
328
|
+
return s_lit;
|
|
276
329
|
}
|
|
277
330
|
|
|
278
331
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smsmslib",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.77",
|
|
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.
|
|
22
|
+
"smsmslib": "^1.0.77"
|
|
23
23
|
}
|
|
24
24
|
}
|