mol_dump_lib 0.0.91 → 0.0.92

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/node.mjs CHANGED
@@ -953,6 +953,8 @@ var $;
953
953
  result = compare_pojo(left, right);
954
954
  else if (!Reflect.getPrototypeOf(left_proto))
955
955
  result = compare_pojo(left, right);
956
+ else if (Symbol.toPrimitive in left)
957
+ result = compare_primitive(left, right);
956
958
  else if (Array.isArray(left))
957
959
  result = compare_array(left, right);
958
960
  else if (left instanceof Set)
@@ -963,8 +965,6 @@ var $;
963
965
  result = compare_buffer(left, right);
964
966
  else if (Symbol.iterator in left)
965
967
  result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
966
- else if (Symbol.toPrimitive in left)
967
- result = compare_primitive(left, right);
968
968
  else
969
969
  result = false;
970
970
  }
package/node.test.js CHANGED
@@ -945,6 +945,8 @@ var $;
945
945
  result = compare_pojo(left, right);
946
946
  else if (!Reflect.getPrototypeOf(left_proto))
947
947
  result = compare_pojo(left, right);
948
+ else if (Symbol.toPrimitive in left)
949
+ result = compare_primitive(left, right);
948
950
  else if (Array.isArray(left))
949
951
  result = compare_array(left, right);
950
952
  else if (left instanceof Set)
@@ -955,8 +957,6 @@ var $;
955
957
  result = compare_buffer(left, right);
956
958
  else if (Symbol.iterator in left)
957
959
  result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
958
- else if (Symbol.toPrimitive in left)
959
- result = compare_primitive(left, right);
960
960
  else
961
961
  result = false;
962
962
  }
@@ -7093,6 +7093,283 @@ var $;
7093
7093
  ;
7094
7094
  "use strict";
7095
7095
  var $;
7096
+ (function ($) {
7097
+ function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
7098
+ return new Proxy(new $mol_range2_array(), {
7099
+ get(target, field) {
7100
+ if (typeof field === 'string') {
7101
+ if (field === 'length')
7102
+ return size();
7103
+ const index = Number(field);
7104
+ if (index < 0)
7105
+ return undefined;
7106
+ if (index >= size())
7107
+ return undefined;
7108
+ if (index === Math.trunc(index))
7109
+ return item(index);
7110
+ }
7111
+ return target[field];
7112
+ },
7113
+ set(target, field) {
7114
+ return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
7115
+ },
7116
+ ownKeys(target) {
7117
+ return [...Array(size())].map((v, i) => String(i)).concat('length');
7118
+ },
7119
+ getOwnPropertyDescriptor(target, field) {
7120
+ if (field === "length")
7121
+ return {
7122
+ value: size(),
7123
+ writable: true,
7124
+ enumerable: false,
7125
+ configurable: false,
7126
+ };
7127
+ const index = Number(field);
7128
+ if (index === Math.trunc(index))
7129
+ return {
7130
+ get: () => this.get(target, field, this),
7131
+ enumerable: true,
7132
+ configurable: true,
7133
+ };
7134
+ return Object.getOwnPropertyDescriptor(target, field);
7135
+ }
7136
+ });
7137
+ }
7138
+ $.$mol_range2 = $mol_range2;
7139
+ class $mol_range2_array extends Array {
7140
+ concat(...tail) {
7141
+ if (tail.length === 0)
7142
+ return this;
7143
+ if (tail.length > 1) {
7144
+ let list = this;
7145
+ for (let item of tail)
7146
+ list = list.concat(item);
7147
+ return list;
7148
+ }
7149
+ return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
7150
+ }
7151
+ filter(check, context) {
7152
+ const filtered = new $mol_range2_array();
7153
+ for (let index = 0; index < this.length; ++index) {
7154
+ const item = this[index];
7155
+ if (check.call(context, item, index, this))
7156
+ filtered.push(item);
7157
+ }
7158
+ return filtered;
7159
+ }
7160
+ forEach(proceed, context) {
7161
+ for (let [key, value] of this.entries())
7162
+ proceed.call(context, value, key, this);
7163
+ }
7164
+ map(proceed, context) {
7165
+ return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
7166
+ }
7167
+ reduce(merge, result) {
7168
+ let index = 0;
7169
+ if (arguments.length === 1) {
7170
+ result = this[index++];
7171
+ }
7172
+ for (; index < this.length; ++index) {
7173
+ result = merge(result, this[index], index, this);
7174
+ }
7175
+ return result;
7176
+ }
7177
+ toReversed() {
7178
+ return $mol_range2(index => this[this.length - 1 - index], () => this.length);
7179
+ }
7180
+ slice(from = 0, to = this.length) {
7181
+ return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
7182
+ }
7183
+ some(check, context) {
7184
+ for (let index = 0; index < this.length; ++index) {
7185
+ if (check.call(context, this[index], index, this))
7186
+ return true;
7187
+ }
7188
+ return false;
7189
+ }
7190
+ every(check, context) {
7191
+ for (let index = 0; index < this.length; ++index) {
7192
+ if (!check.call(context, this[index], index, this))
7193
+ return false;
7194
+ }
7195
+ return true;
7196
+ }
7197
+ reverse() {
7198
+ return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
7199
+ }
7200
+ sort() {
7201
+ return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
7202
+ }
7203
+ [Symbol.toPrimitive]() {
7204
+ return $mol_guid();
7205
+ }
7206
+ }
7207
+ $.$mol_range2_array = $mol_range2_array;
7208
+ })($ || ($ = {}));
7209
+ //mol/range2/range2.ts
7210
+ ;
7211
+ "use strict";
7212
+ var $;
7213
+ (function ($) {
7214
+ $mol_test({
7215
+ 'lazy calls'() {
7216
+ let calls = 0;
7217
+ const list = $mol_range2(index => (++calls, index), () => 10);
7218
+ $mol_assert_ok(list instanceof Array);
7219
+ $mol_assert_equal(list.length, 10);
7220
+ $mol_assert_equal(list[-1], undefined);
7221
+ $mol_assert_equal(list[0], 0);
7222
+ $mol_assert_equal(list[9], 9);
7223
+ $mol_assert_equal(list[9.5], undefined);
7224
+ $mol_assert_equal(list[10], undefined);
7225
+ $mol_assert_equal(calls, 2);
7226
+ },
7227
+ 'infinity list'() {
7228
+ let calls = 0;
7229
+ const list = $mol_range2(index => (++calls, index));
7230
+ $mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
7231
+ $mol_assert_equal(list[0], 0);
7232
+ $mol_assert_equal(list[4], 4);
7233
+ $mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
7234
+ $mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
7235
+ $mol_assert_equal(calls, 3);
7236
+ },
7237
+ 'stringify'() {
7238
+ const list = $mol_range2(i => i, () => 5);
7239
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
7240
+ $mol_assert_equal(list.join(';'), '0;1;2;3;4');
7241
+ },
7242
+ 'for-of'() {
7243
+ let log = '';
7244
+ for (let i of $mol_range2(i => i + 1, () => 5)) {
7245
+ log += i;
7246
+ }
7247
+ $mol_assert_equal(log, '12345');
7248
+ },
7249
+ 'for-in'() {
7250
+ let log = '';
7251
+ for (let i in $mol_range2(i => i, () => 5)) {
7252
+ log += i;
7253
+ }
7254
+ $mol_assert_equal(log, '01234');
7255
+ },
7256
+ 'forEach'() {
7257
+ let log = '';
7258
+ $mol_range2(i => i, () => 5).forEach(i => log += i);
7259
+ $mol_assert_equal(log, '01234');
7260
+ },
7261
+ 'lazy concat'() {
7262
+ let calls1 = 0;
7263
+ let calls2 = 0;
7264
+ const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
7265
+ $mol_assert_ok(list instanceof Array);
7266
+ $mol_assert_equal(list.length, 15);
7267
+ $mol_assert_equal(list[0], 0);
7268
+ $mol_assert_equal(list[4], 4);
7269
+ $mol_assert_equal(list[5], 0);
7270
+ $mol_assert_equal(list[9], 4);
7271
+ $mol_assert_equal(list[10], 0);
7272
+ $mol_assert_equal(list[14], 4);
7273
+ $mol_assert_equal(list[15], undefined);
7274
+ $mol_assert_equal(calls1, 2);
7275
+ $mol_assert_equal(calls2, 2);
7276
+ },
7277
+ 'filter'() {
7278
+ let calls = 0;
7279
+ const list = $mol_range2(index => (++calls, index), () => 10).filter(v => v % 2).slice(0, 3);
7280
+ $mol_assert_ok(list instanceof Array);
7281
+ $mol_assert_equal(list.length, 3);
7282
+ $mol_assert_equal(list[0], 1);
7283
+ $mol_assert_equal(list[2], 5);
7284
+ $mol_assert_equal(list[3], undefined);
7285
+ $mol_assert_equal(calls, 10);
7286
+ },
7287
+ 'reverse'() {
7288
+ let calls = 0;
7289
+ const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
7290
+ $mol_assert_ok(list instanceof Array);
7291
+ $mol_assert_equal(list.length, 3);
7292
+ $mol_assert_equal(list[0], 9);
7293
+ $mol_assert_equal(list[2], 7);
7294
+ $mol_assert_equal(list[3], undefined);
7295
+ $mol_assert_equal(calls, 2);
7296
+ },
7297
+ 'reduce'() {
7298
+ let calls = 0;
7299
+ const list = $mol_range2().slice(1, 6);
7300
+ $mol_assert_equal(list.reduce((s, v) => s + v), 15);
7301
+ $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
7302
+ },
7303
+ 'lazy map'() {
7304
+ let calls1 = 0;
7305
+ let calls2 = 0;
7306
+ const source = $mol_range2(index => (++calls1, index), () => 5);
7307
+ const target = source.map((item, index, self) => {
7308
+ ++calls2;
7309
+ $mol_assert_equal(source, self);
7310
+ return index + 10;
7311
+ }, () => 5);
7312
+ $mol_assert_ok(target instanceof Array);
7313
+ $mol_assert_equal(target.length, 5);
7314
+ $mol_assert_equal(target[0], 10);
7315
+ $mol_assert_equal(target[4], 14);
7316
+ $mol_assert_equal(target[5], undefined);
7317
+ $mol_assert_equal(calls1, 2);
7318
+ $mol_assert_equal(calls2, 2);
7319
+ },
7320
+ 'lazy slice'() {
7321
+ let calls = 0;
7322
+ const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
7323
+ $mol_assert_ok(list instanceof Array);
7324
+ $mol_assert_equal(list.length, 4);
7325
+ $mol_assert_equal(list[0], 3);
7326
+ $mol_assert_equal(list[3], 6);
7327
+ $mol_assert_equal(list[4], undefined);
7328
+ $mol_assert_equal(calls, 2);
7329
+ },
7330
+ 'lazy some'() {
7331
+ let calls = 0;
7332
+ $mol_assert_ok($mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
7333
+ $mol_assert_equal(calls, 3);
7334
+ $mol_assert_not($mol_range2(i => i, () => 0).some(v => true));
7335
+ $mol_assert_ok($mol_range2(i => i).some(v => v > 5));
7336
+ },
7337
+ 'lazy every'() {
7338
+ let calls = 0;
7339
+ $mol_assert_not($mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
7340
+ $mol_assert_equal(calls, 3);
7341
+ $mol_assert_ok($mol_range2(i => i, () => 0).every(v => false));
7342
+ $mol_assert_not($mol_range2(i => i).every(v => v < 5));
7343
+ },
7344
+ 'lazyfy'() {
7345
+ let calls = 0;
7346
+ const list = new $mol_range2_array(...[0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
7347
+ $mol_assert_ok(list instanceof Array);
7348
+ $mol_assert_equal(list.length, 4);
7349
+ $mol_assert_equal(calls, 0);
7350
+ $mol_assert_equal(list[0], 12);
7351
+ $mol_assert_equal(list[3], 15);
7352
+ $mol_assert_equal(list[4], undefined);
7353
+ $mol_assert_equal(calls, 2);
7354
+ },
7355
+ 'prevent modification'() {
7356
+ const list = $mol_range2(i => i, () => 5);
7357
+ $mol_assert_fail(() => list.push(4), TypeError);
7358
+ $mol_assert_fail(() => list.pop(), TypeError);
7359
+ $mol_assert_fail(() => list.unshift(4), TypeError);
7360
+ $mol_assert_fail(() => list.shift(), TypeError);
7361
+ $mol_assert_fail(() => list.splice(1, 2), TypeError);
7362
+ $mol_assert_fail(() => list[1] = 2, TypeError);
7363
+ $mol_assert_fail(() => list.reverse(), TypeError);
7364
+ $mol_assert_fail(() => list.sort(), TypeError);
7365
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
7366
+ }
7367
+ });
7368
+ })($ || ($ = {}));
7369
+ //mol/range2/range2.test.ts
7370
+ ;
7371
+ "use strict";
7372
+ var $;
7096
7373
  (function ($) {
7097
7374
  $mol_test({
7098
7375
  'nulls & undefineds'() {
@@ -7122,6 +7399,8 @@ var $;
7122
7399
  $mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
7123
7400
  $mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
7124
7401
  $mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
7402
+ $mol_assert_not($mol_compare_deep($mol_range2().slice(0, 0), new Array()));
7403
+ $mol_assert_not($mol_compare_deep($mol_range2(), $mol_range2()));
7125
7404
  },
7126
7405
  'Non POJO are different'() {
7127
7406
  class Thing extends Object {