mol_data_all 1.1.280 → 1.1.281

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.test.js CHANGED
@@ -631,6 +631,9 @@ var $;
631
631
  //mol/type/assert/assert.ts
632
632
  ;
633
633
  "use strict";
634
+ //mol/type/equals/equals.test.ts
635
+ ;
636
+ "use strict";
634
637
  //mol/type/partial/deep/deep.test.ts
635
638
  ;
636
639
  "use strict";
@@ -1213,697 +1216,701 @@ var $;
1213
1216
  "use strict";
1214
1217
  var $;
1215
1218
  (function ($) {
1216
- $mol_test({
1217
- 'Is empty array'() {
1218
- $mol_data_array($mol_data_number)([]);
1219
- },
1220
- 'Is array'() {
1221
- $mol_data_array($mol_data_number)([1, 2]);
1222
- },
1223
- 'Is not array'() {
1224
- $mol_assert_fail(() => {
1225
- $mol_data_array($mol_data_number)({ [0]: 1, length: 1, map: () => { } });
1226
- }, '[object Object] is not an array');
1227
- },
1228
- 'Has wrong item'() {
1229
- $mol_assert_fail(() => {
1230
- $mol_data_array($mol_data_number)([1, '1']);
1231
- }, '[1] 1 is not a number');
1232
- },
1233
- 'Has wrong deep item'() {
1234
- $mol_assert_fail(() => {
1235
- $mol_data_array($mol_data_array($mol_data_number))([[], [0, 0, false]]);
1236
- }, '[1] [2] false is not a number');
1237
- },
1238
- });
1219
+ function $mol_log3_area_lazy(event) {
1220
+ const self = this;
1221
+ const stack = self.$mol_log3_stack;
1222
+ const deep = stack.length;
1223
+ let logged = false;
1224
+ stack.push(() => {
1225
+ logged = true;
1226
+ self.$mol_log3_area.call(self, event);
1227
+ });
1228
+ return () => {
1229
+ if (logged)
1230
+ self.console.groupEnd();
1231
+ if (stack.length > deep)
1232
+ stack.length = deep;
1233
+ };
1234
+ }
1235
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1236
+ $.$mol_log3_stack = [];
1239
1237
  })($ || ($ = {}));
1240
- //mol/data/array/array.test.ts
1238
+ //mol/log3/log3.ts
1241
1239
  ;
1242
1240
  "use strict";
1243
1241
  var $;
1244
1242
  (function ($) {
1245
- $mol_test({
1246
- 'Is boolean - true'() {
1247
- $mol_data_boolean(true);
1248
- },
1249
- 'Is boolean - false'() {
1250
- $mol_data_boolean(false);
1251
- },
1252
- 'Is not boolean'() {
1253
- $mol_assert_fail(() => {
1254
- $mol_data_boolean('x');
1255
- }, 'x is not a boolean');
1256
- },
1257
- 'Is object boolean'() {
1258
- $mol_assert_fail(() => {
1259
- $mol_data_boolean(new Boolean(''));
1260
- }, 'false is not a boolean');
1261
- },
1262
- });
1243
+ function $mol_log3_node_make(level, output, type, color) {
1244
+ return function $mol_log3_logger(event) {
1245
+ if (!event.time)
1246
+ event = { time: new Date().toISOString(), ...event };
1247
+ const tree = this.$mol_tree.fromJSON(event).clone({ type });
1248
+ let str = tree.toString();
1249
+ if (process[output].isTTY) {
1250
+ str = $node.colorette[color + 'Bright'](str);
1251
+ }
1252
+ ;
1253
+ this.console[level](str);
1254
+ const self = this;
1255
+ return () => self.console.groupEnd();
1256
+ };
1257
+ }
1258
+ $.$mol_log3_node_make = $mol_log3_node_make;
1259
+ $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', 'blue');
1260
+ $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', 'green');
1261
+ $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', 'red');
1262
+ $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', 'yellow');
1263
+ $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', 'magenta');
1264
+ $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', 'cyan');
1263
1265
  })($ || ($ = {}));
1264
- //mol/data/boolean/boolean.test.ts
1266
+ //mol/log3/log3.node.ts
1265
1267
  ;
1266
1268
  "use strict";
1267
1269
  var $;
1268
- (function ($) {
1269
- $mol_test({
1270
- 'is same number'() {
1271
- $mol_data_const(Number.NaN)(Number.NaN);
1272
- },
1273
- 'is different number'() {
1274
- const Five = $mol_data_const(5);
1275
- $mol_assert_fail(() => Five(6), '6 is not 5');
1276
- },
1270
+ (function ($_1) {
1271
+ $mol_test_mocks.push($ => {
1272
+ $.$mol_log3_come = () => { };
1273
+ $.$mol_log3_done = () => { };
1274
+ $.$mol_log3_fail = () => { };
1275
+ $.$mol_log3_warn = () => { };
1276
+ $.$mol_log3_rise = () => { };
1277
+ $.$mol_log3_area = () => () => { };
1277
1278
  });
1278
1279
  })($ || ($ = {}));
1279
- //mol/data/const/const.test.ts
1280
+ //mol/log3/log3.test.ts
1280
1281
  ;
1281
1282
  "use strict";
1282
1283
  var $;
1283
1284
  (function ($) {
1284
- $mol_test({
1285
- 'Is string'() {
1286
- $mol_data_string('');
1287
- },
1288
- 'Is not string'() {
1289
- $mol_assert_fail(() => {
1290
- $mol_data_string(0);
1291
- }, '0 is not a string');
1292
- },
1293
- 'Is object string'() {
1294
- $mol_assert_fail(() => {
1295
- $mol_data_string(new String('x'));
1296
- }, 'x is not a string');
1297
- },
1298
- });
1285
+ $.$mol_ambient_ref = Symbol('$mol_ambient_ref');
1286
+ function $mol_ambient(overrides) {
1287
+ return Object.setPrototypeOf(overrides, this || $);
1288
+ }
1289
+ $.$mol_ambient = $mol_ambient;
1299
1290
  })($ || ($ = {}));
1300
- //mol/data/string/string.test.ts
1291
+ //mol/ambient/ambient.ts
1301
1292
  ;
1302
1293
  "use strict";
1303
1294
  var $;
1304
1295
  (function ($) {
1305
1296
  $mol_test({
1306
- 'Is fit'() {
1307
- $mol_data_pattern(/^-$/)('-');
1297
+ 'get'() {
1298
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
1299
+ $mol_assert_equal(proxy.foo, 777);
1308
1300
  },
1309
- 'Is not fit'() {
1310
- $mol_assert_fail(() => {
1311
- $mol_data_pattern(/^-$/)('+');
1312
- }, '+ is not a /^-$/');
1301
+ 'has'() {
1302
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
1303
+ $mol_assert_equal('foo' in proxy, true);
1304
+ },
1305
+ 'set'() {
1306
+ const target = { foo: 777 };
1307
+ const proxy = $mol_delegate({}, () => target);
1308
+ proxy.foo = 123;
1309
+ $mol_assert_equal(target.foo, 123);
1310
+ },
1311
+ 'getOwnPropertyDescriptor'() {
1312
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
1313
+ $mol_assert_like(Object.getOwnPropertyDescriptor(proxy, 'foo'), {
1314
+ value: 777,
1315
+ writable: true,
1316
+ enumerable: true,
1317
+ configurable: true,
1318
+ });
1319
+ },
1320
+ 'ownKeys'() {
1321
+ const proxy = $mol_delegate({}, () => ({ foo: 777, [Symbol.toStringTag]: 'bar' }));
1322
+ $mol_assert_like(Reflect.ownKeys(proxy), ['foo', Symbol.toStringTag]);
1323
+ },
1324
+ 'getPrototypeOf'() {
1325
+ class Foo {
1326
+ }
1327
+ const proxy = $mol_delegate({}, () => new Foo);
1328
+ $mol_assert_equal(Object.getPrototypeOf(proxy), Foo.prototype);
1329
+ },
1330
+ 'setPrototypeOf'() {
1331
+ class Foo {
1332
+ }
1333
+ const target = {};
1334
+ const proxy = $mol_delegate({}, () => target);
1335
+ Object.setPrototypeOf(proxy, Foo.prototype);
1336
+ $mol_assert_equal(Object.getPrototypeOf(target), Foo.prototype);
1337
+ },
1338
+ 'instanceof'() {
1339
+ class Foo {
1340
+ }
1341
+ const proxy = $mol_delegate({}, () => new Foo);
1342
+ $mol_assert_ok(proxy instanceof Foo);
1343
+ $mol_assert_ok(proxy instanceof $mol_delegate);
1344
+ },
1345
+ 'autobind'() {
1346
+ class Foo {
1347
+ }
1348
+ const proxy = $mol_delegate({}, () => new Foo);
1349
+ $mol_assert_ok(proxy instanceof Foo);
1350
+ $mol_assert_ok(proxy instanceof $mol_delegate);
1313
1351
  },
1314
1352
  });
1315
1353
  })($ || ($ = {}));
1316
- //mol/data/pattern/pattern.test.ts
1354
+ //mol/delegate/delegate.test.ts
1317
1355
  ;
1318
1356
  "use strict";
1319
1357
  var $;
1320
1358
  (function ($) {
1321
- $mol_test({
1322
- 'Is email'() {
1323
- $mol_data_email('foo@bar');
1324
- },
1325
- 'Has not host'() {
1326
- $mol_assert_fail(() => {
1327
- $mol_data_email('foo@');
1328
- }, 'foo@ is not a /.+@.+/');
1329
- },
1330
- 'Has not name'() {
1331
- $mol_assert_fail(() => {
1332
- $mol_data_email('@bar');
1333
- }, '@bar is not a /.+@.+/');
1334
- },
1335
- 'Has not @'() {
1336
- $mol_assert_fail(() => {
1337
- $mol_data_email('foo.bar');
1338
- }, 'foo.bar is not a /.+@.+/');
1339
- },
1359
+ const instances = new WeakSet();
1360
+ function $mol_delegate(proto, target) {
1361
+ const proxy = new Proxy(proto, {
1362
+ get: (_, field) => {
1363
+ const obj = target();
1364
+ let val = Reflect.get(obj, field);
1365
+ if (typeof val === 'function') {
1366
+ val = val.bind(obj);
1367
+ }
1368
+ return val;
1369
+ },
1370
+ has: (_, field) => Reflect.has(target(), field),
1371
+ set: (_, field, value) => Reflect.set(target(), field, value),
1372
+ getOwnPropertyDescriptor: (_, field) => Reflect.getOwnPropertyDescriptor(target(), field),
1373
+ ownKeys: () => Reflect.ownKeys(target()),
1374
+ getPrototypeOf: () => Reflect.getPrototypeOf(target()),
1375
+ setPrototypeOf: (_, donor) => Reflect.setPrototypeOf(target(), donor),
1376
+ isExtensible: () => Reflect.isExtensible(target()),
1377
+ preventExtensions: () => Reflect.preventExtensions(target()),
1378
+ apply: (_, self, args) => Reflect.apply(target(), self, args),
1379
+ construct: (_, args, retarget) => Reflect.construct(target(), args, retarget),
1380
+ defineProperty: (_, field, descr) => Reflect.defineProperty(target(), field, descr),
1381
+ deleteProperty: (_, field) => Reflect.deleteProperty(target(), field),
1382
+ });
1383
+ instances.add(proxy);
1384
+ return proxy;
1385
+ }
1386
+ $.$mol_delegate = $mol_delegate;
1387
+ Reflect.defineProperty($mol_delegate, Symbol.hasInstance, {
1388
+ value: (obj) => instances.has(obj),
1340
1389
  });
1341
1390
  })($ || ($ = {}));
1342
- //mol/data/email/email.test.ts
1391
+ //mol/delegate/delegate.ts
1343
1392
  ;
1344
1393
  "use strict";
1345
1394
  var $;
1346
1395
  (function ($) {
1347
- let sex;
1348
- (function (sex) {
1349
- sex[sex["male"] = 0] = "male";
1350
- sex[sex["female"] = 1] = "female";
1351
- })(sex || (sex = {}));
1352
- const Sex = $mol_data_enum('sex', sex);
1353
- $mol_test({
1354
- 'config of enum'() {
1355
- $mol_assert_like(Sex.config, {
1356
- name: 'sex',
1357
- dict: sex,
1358
- });
1359
- },
1360
- 'name of enum'() {
1361
- $mol_assert_equal(Sex.config.name, 'sex');
1362
- },
1363
- 'Is right value of enum'() {
1364
- $mol_assert_equal(Sex(0), sex.male);
1365
- },
1366
- 'Is wrong value of enum'() {
1367
- $mol_assert_fail(() => Sex(2), `2 is not value of sex enum`);
1368
- },
1369
- 'Is name instead of value'() {
1370
- $mol_assert_fail(() => Sex('male'), `male is not value of sex enum`);
1371
- },
1372
- 'Is common object field'() {
1373
- $mol_assert_fail(() => Sex('__proto__'), `__proto__ is not value of sex enum`);
1374
- },
1375
- });
1376
- let gender;
1377
- (function (gender) {
1378
- gender["bisexual"] = "bisexual";
1379
- gender["trans"] = "transgender";
1380
- })(gender || (gender = {}));
1381
- const Gender = $mol_data_enum('gender', gender);
1382
- $mol_test({
1383
- 'config of enum'() {
1384
- $mol_assert_like(Gender.config, {
1385
- name: 'gender',
1386
- dict: gender,
1387
- });
1388
- },
1389
- 'Is right value of enum'() {
1390
- $mol_assert_equal(Gender('transgender'), gender.trans);
1391
- },
1392
- 'Is wrong value of enum'() {
1393
- $mol_assert_fail(() => Gender('xxx'), `xxx is not value of gender enum`);
1394
- },
1395
- 'Is name instead of value'() {
1396
- $mol_assert_fail(() => Gender('trans'), `trans is not value of gender enum`);
1397
- },
1398
- 'Is common object field'() {
1399
- $mol_assert_fail(() => Gender('__proto__'), `__proto__ is not value of gender enum`);
1400
- },
1401
- });
1396
+ $.$mol_owning_map = new WeakMap();
1397
+ function $mol_owning_allow(having) {
1398
+ try {
1399
+ if (!having)
1400
+ return false;
1401
+ if (typeof having !== 'object')
1402
+ return false;
1403
+ if (having instanceof $mol_delegate)
1404
+ return false;
1405
+ if (typeof having['destructor'] !== 'function')
1406
+ return false;
1407
+ return true;
1408
+ }
1409
+ catch {
1410
+ return false;
1411
+ }
1412
+ }
1413
+ $.$mol_owning_allow = $mol_owning_allow;
1414
+ function $mol_owning_get(having, Owner) {
1415
+ if (!$mol_owning_allow(having))
1416
+ return null;
1417
+ while (true) {
1418
+ const owner = $.$mol_owning_map.get(having);
1419
+ if (!owner)
1420
+ return owner;
1421
+ if (!Owner)
1422
+ return owner;
1423
+ if (owner instanceof Owner)
1424
+ return owner;
1425
+ having = owner;
1426
+ }
1427
+ }
1428
+ $.$mol_owning_get = $mol_owning_get;
1429
+ function $mol_owning_check(owner, having) {
1430
+ if (!$mol_owning_allow(having))
1431
+ return false;
1432
+ if ($.$mol_owning_map.get(having) !== owner)
1433
+ return false;
1434
+ return true;
1435
+ }
1436
+ $.$mol_owning_check = $mol_owning_check;
1437
+ function $mol_owning_catch(owner, having) {
1438
+ if (!$mol_owning_allow(having))
1439
+ return false;
1440
+ if ($.$mol_owning_map.get(having))
1441
+ return false;
1442
+ $.$mol_owning_map.set(having, owner);
1443
+ return true;
1444
+ }
1445
+ $.$mol_owning_catch = $mol_owning_catch;
1402
1446
  })($ || ($ = {}));
1403
- //mol/data/enum/enum.test.ts
1447
+ //mol/owning/owning.ts
1404
1448
  ;
1405
1449
  "use strict";
1406
- var $;
1407
- (function ($) {
1408
- $mol_test({
1409
- 'Is same class'() {
1410
- $mol_data_instance(Date)(new Date);
1411
- },
1412
- 'Is sub class'() {
1413
- $mol_data_instance(Object)(new Date);
1414
- },
1415
- 'Is super class'() {
1416
- $mol_assert_fail(() => {
1417
- $mol_data_instance(Date)(new Object);
1418
- }, '[object Object] is not a Date');
1419
- },
1420
- 'Is another class'() {
1421
- $mol_assert_fail(() => {
1422
- $mol_data_instance(Date)(new Array);
1423
- }, ' is not a Date');
1424
- },
1425
- 'Is not object'() {
1426
- $mol_assert_fail(() => {
1427
- $mol_data_instance(Date)(null);
1428
- }, 'null is not a Date');
1429
- },
1430
- });
1431
- })($ || ($ = {}));
1432
- //mol/data/instance/instance.test.ts
1450
+ //mol/type/writable/writable.test.ts
1433
1451
  ;
1434
1452
  "use strict";
1435
- var $;
1436
- (function ($) {
1437
- $mol_test({
1438
- 'Is integer'() {
1439
- $mol_data_integer(0);
1440
- },
1441
- 'Is float'() {
1442
- $mol_assert_fail(() => {
1443
- $mol_data_integer(1.1);
1444
- }, '1.1 is not an integer');
1445
- },
1446
- });
1447
- })($ || ($ = {}));
1448
- //mol/data/integer/integer.test.ts
1453
+ //mol/type/writable/writable.ts
1449
1454
  ;
1450
1455
  "use strict";
1451
1456
  var $;
1452
1457
  (function ($) {
1453
- $mol_test({
1454
- 'Nominal typing'() {
1455
- const Weight = $mol_data_nominal({ Weight: $mol_data_integer });
1456
- const Length = $mol_data_nominal({ Length: $mol_data_integer });
1457
- let len = Length(10);
1458
- len = Length(20);
1459
- len = 20;
1460
- },
1461
- });
1458
+ class $mol_object2 {
1459
+ static $ = $;
1460
+ [$mol_ambient_ref] = null;
1461
+ get $() {
1462
+ if (this[$mol_ambient_ref])
1463
+ return this[$mol_ambient_ref];
1464
+ const owner = $mol_owning_get(this);
1465
+ return this[$mol_ambient_ref] = owner?.$ || $mol_object2.$;
1466
+ }
1467
+ set $(next) {
1468
+ if (this[$mol_ambient_ref])
1469
+ $mol_fail_hidden(new Error('Context already defined'));
1470
+ this[$mol_ambient_ref] = next;
1471
+ }
1472
+ static create(init) {
1473
+ const obj = new this;
1474
+ if (init)
1475
+ init(obj);
1476
+ return obj;
1477
+ }
1478
+ static [Symbol.toPrimitive]() {
1479
+ return this.toString();
1480
+ }
1481
+ static toString() {
1482
+ if (Symbol.toStringTag in this)
1483
+ return this[Symbol.toStringTag];
1484
+ return this.name;
1485
+ }
1486
+ destructor() { }
1487
+ toString() {
1488
+ return this[Symbol.toStringTag] || this.constructor.name + '()';
1489
+ }
1490
+ toJSON() {
1491
+ return this.toString();
1492
+ }
1493
+ }
1494
+ $.$mol_object2 = $mol_object2;
1462
1495
  })($ || ($ = {}));
1463
- //mol/data/nominal/nominal.test.ts
1496
+ //mol/object2/object2.ts
1464
1497
  ;
1465
1498
  "use strict";
1466
1499
  var $;
1467
1500
  (function ($) {
1468
- $mol_test({
1469
- 'Is null'() {
1470
- $mol_data_nullable($mol_data_number)(null);
1471
- },
1472
- 'Is not null'() {
1473
- $mol_data_nullable($mol_data_number)(0);
1474
- },
1475
- 'Is undefined'() {
1476
- $mol_assert_fail(() => {
1477
- const Type = $mol_data_nullable($mol_data_number);
1478
- Type(undefined);
1479
- }, 'undefined is not a number');
1480
- },
1481
- });
1501
+ function $mol_deprecated(message) {
1502
+ return (host, field, descr) => {
1503
+ const value = descr.value;
1504
+ let warned = false;
1505
+ descr.value = function $mol_deprecated_wrapper(...args) {
1506
+ if (!warned) {
1507
+ $$.$mol_log3_warn({
1508
+ place: `${host.constructor.name}::${field}`,
1509
+ message: `Deprecated`,
1510
+ hint: message,
1511
+ });
1512
+ warned = true;
1513
+ }
1514
+ return value.call(this, ...args);
1515
+ };
1516
+ };
1517
+ }
1518
+ $.$mol_deprecated = $mol_deprecated;
1482
1519
  })($ || ($ = {}));
1483
- //mol/data/nullable/nullable.test.ts
1520
+ //mol/deprecated/deprecated.ts
1484
1521
  ;
1485
1522
  "use strict";
1486
1523
  var $;
1487
- (function ($) {
1488
- const Age = $mol_data_optional($mol_data_number);
1489
- const Age_or_zero = $mol_data_optional($mol_data_number, () => 0);
1524
+ (function ($_1) {
1490
1525
  $mol_test({
1491
- 'Is not present'() {
1492
- $mol_assert_equal(Age(undefined), undefined);
1493
- },
1494
- 'Is present'() {
1495
- $mol_assert_equal(Age(0), 0);
1526
+ 'tree parsing'() {
1527
+ $mol_assert_equal($mol_tree.fromString("foo\nbar\n").sub.length, 2);
1528
+ $mol_assert_equal($mol_tree.fromString("foo\nbar\n").sub[1].type, "bar");
1529
+ $mol_assert_equal($mol_tree.fromString("foo\n\n\n").sub.length, 1);
1530
+ $mol_assert_equal($mol_tree.fromString("=foo\n\\bar\n").sub.length, 2);
1531
+ $mol_assert_equal($mol_tree.fromString("=foo\n\\bar\n").sub[1].data, "bar");
1532
+ $mol_assert_equal($mol_tree.fromString("foo bar \\pol").sub[0].sub[0].sub[0].data, "pol");
1533
+ $mol_assert_equal($mol_tree.fromString("foo bar\n\t\\pol\n\t\\men").sub[0].sub[0].sub[1].data, "men");
1534
+ $mol_assert_equal($mol_tree.fromString('foo bar \\text\n').toString(), 'foo bar \\text\n');
1496
1535
  },
1497
- 'Fallbacked'() {
1498
- $mol_assert_equal(Age_or_zero(undefined), 0);
1536
+ 'inserting'() {
1537
+ $mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 'a', 'b', 'c').toString(), 'a b \\\n');
1538
+ $mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 'a', 'b', 'c', 'd').toString(), 'a b c \\\n');
1539
+ $mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 0, 0, 0).toString(), 'a b \\\n');
1540
+ $mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 0, 0, 0, 0).toString(), 'a b \\\n\t\\\n');
1541
+ $mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, null, null, null).toString(), 'a b \\\n');
1542
+ $mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, null, null, null, null).toString(), 'a b \\\n\t\\\n');
1499
1543
  },
1500
- 'Is null'() {
1501
- $mol_assert_fail(() => Age(null), 'null is not a number');
1544
+ 'fromJSON'() {
1545
+ $mol_assert_equal($mol_tree.fromJSON([]).toString(), '/\n');
1546
+ $mol_assert_equal($mol_tree.fromJSON([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
1547
+ $mol_assert_equal($mol_tree.fromJSON([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
1548
+ $mol_assert_equal($mol_tree.fromJSON(['', 'foo', 'bar\nbaz']).toString(), '/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n');
1549
+ $mol_assert_equal($mol_tree.fromJSON({ 'foo': false, 'bar\nbaz': 'lol' }).toString(), '*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n');
1502
1550
  },
1503
- });
1504
- })($ || ($ = {}));
1505
- //mol/data/optional/optional.test.ts
1506
- ;
1507
- "use strict";
1508
- //mol/type/equals/equals.test.ts
1509
- ;
1510
- "use strict";
1511
- //mol/type/merge/merge.test.ts
1512
- ;
1513
- "use strict";
1514
- //mol/type/partial/undefined/undefined.test.ts
1515
- ;
1516
- "use strict";
1517
- var $;
1518
- (function ($) {
1519
- $mol_test({
1520
- 'Fit to record'() {
1521
- const User = $mol_data_record({ age: $mol_data_number });
1522
- User({ age: 0 });
1523
- },
1524
- 'Extends record'() {
1525
- const User = $mol_data_record({ age: $mol_data_number });
1526
- User({ age: 0, name: 'Jin' });
1527
- },
1528
- 'Shrinks record'() {
1529
- $mol_assert_fail(() => {
1530
- const User = $mol_data_record({ age: $mol_data_number, name: $mol_data_string });
1531
- User({ age: 0 });
1532
- }, '["name"] undefined is not a string');
1533
- },
1534
- 'Shrinks deep record'() {
1535
- $mol_assert_fail(() => {
1536
- const User = $mol_data_record({ wife: $mol_data_record({ age: $mol_data_number }) });
1537
- User({ wife: {} });
1538
- }, '["wife"] ["age"] undefined is not a number');
1539
- },
1540
- });
1541
- })($ || ($ = {}));
1542
- //mol/data/record/record.test.ts
1543
- ;
1544
- "use strict";
1545
- var $;
1546
- (function ($) {
1547
- $mol_test({
1548
- 'Is first'() {
1549
- $mol_data_variant($mol_data_number, $mol_data_string)(0);
1550
- },
1551
- 'Is second'() {
1552
- $mol_data_variant($mol_data_number, $mol_data_string)('');
1553
- },
1554
- 'Is false'() {
1555
- $mol_assert_fail(() => {
1556
- $mol_data_variant($mol_data_number, $mol_data_string)(false);
1557
- }, 'false is not any of variants\nfalse is not a number\nfalse is not a string');
1551
+ 'toJSON'() {
1552
+ $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n').sub[0]), '[]');
1553
+ $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\tfalse\n\ttrue\n').sub[0]), '[false,true]');
1554
+ $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\t0\n\t1\n\t2.3\n').sub[0]), '[0,1,2.3]');
1555
+ $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n').sub[0]), '["","foo","bar\\nbaz"]');
1556
+ $mol_assert_equal(JSON.stringify($mol_tree.fromString('*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n').sub[0]), '{"foo":false,"bar\\nbaz":"lol"}');
1558
1557
  },
1559
- });
1560
- })($ || ($ = {}));
1561
- //mol/data/variant/variant.test.ts
1562
- ;
1563
- "use strict";
1564
- var $;
1565
- (function ($) {
1566
- class $mol_time_base {
1567
- static patterns = {};
1568
- static formatter(pattern) {
1569
- if (this.patterns[pattern])
1570
- return this.patterns[pattern];
1571
- var tokens = Object.keys(this.patterns)
1572
- .sort()
1573
- .reverse()
1574
- .map((token) => token.replace(/([-+*.\[\]()\^])/g, '\\$1'));
1575
- var lexer = RegExp('(.*?)(' + tokens.join('|') + '|$)', 'g');
1576
- var funcs = [];
1577
- pattern.replace(lexer, (str, text, token) => {
1578
- if (text)
1579
- funcs.push(() => text);
1580
- if (token)
1581
- funcs.push(this.patterns[token]);
1582
- return str;
1558
+ 'hack'() {
1559
+ const res = $mol_tree.fromString(`foo bar xxx`).hack({
1560
+ '': (tree, context) => [tree.hack(context)],
1561
+ 'bar': (tree, context) => [tree.hack(context).clone({ type: '777' })],
1583
1562
  });
1584
- return this.patterns[pattern] = (arg) => {
1585
- return funcs.reduce((res, func) => res + func(arg), '');
1586
- };
1587
- }
1588
- toString(pattern) {
1589
- const Base = this.constructor;
1590
- const formatter = Base.formatter(pattern);
1591
- return formatter(this);
1592
- }
1593
- }
1594
- $.$mol_time_base = $mol_time_base;
1595
- })($ || ($ = {}));
1596
- //mol/time/base/base.ts
1597
- ;
1598
- "use strict";
1599
- var $;
1600
- (function ($) {
1601
- $mol_test({
1602
- 'parse and serial'() {
1603
- $mol_assert_equal(new $mol_time_duration('P42.1Y').toString(), 'P42.1YT');
1604
- $mol_assert_equal(new $mol_time_duration('P42.1M').toString(), 'P42.1MT');
1605
- $mol_assert_equal(new $mol_time_duration('P42.1D').toString(), 'P42.1DT');
1606
- $mol_assert_equal(new $mol_time_duration('PT42.1h').toString(), 'PT42.1H');
1607
- $mol_assert_equal(new $mol_time_duration('PT42.1m').toString(), 'PT42.1M');
1608
- $mol_assert_equal(new $mol_time_duration('PT42.1s').toString(), 'PT42.1S');
1609
- $mol_assert_equal(new $mol_time_duration('P1Y2M3DT4h5m6.7s').toString(), 'P1Y2M3DT4H5M6.7S');
1610
- },
1611
- 'format typed'() {
1612
- $mol_assert_equal(new $mol_time_duration('P1Y2M3DT4h5m6s').toString('P#Y#M#DT#h#m#s'), 'P1Y2M3DT4H5M6S');
1563
+ $mol_assert_equal(res.toString(), new $mol_tree({ type: 'foo 777 xxx' }).toString());
1613
1564
  },
1614
- 'comparison'() {
1615
- const iso = 'P1Y1M1DT1h1m1s';
1616
- $mol_assert_like(new $mol_time_duration(iso), new $mol_time_duration(iso));
1565
+ 'errors handling'($) {
1566
+ const errors = [];
1567
+ class Tree extends $mol_tree {
1568
+ static $ = $.$mol_ambient({
1569
+ $mol_fail: error => errors.push(error.message)
1570
+ });
1571
+ }
1572
+ Tree.fromString(`
1573
+ \t \tfoo
1574
+ bar \\data
1575
+ `, 'test');
1576
+ $mol_assert_like(errors, ['Syntax error at test:2\n \tfoo']);
1617
1577
  },
1618
1578
  });
1619
1579
  })($ || ($ = {}));
1620
- //mol/time/duration/duration.test.ts
1580
+ //mol/tree/tree.test.ts
1621
1581
  ;
1622
1582
  "use strict";
1623
1583
  var $;
1624
1584
  (function ($) {
1625
- class $mol_time_duration extends $mol_time_base {
1626
- constructor(config = 0) {
1585
+ $.$mol_tree_convert = Symbol('$mol_tree_convert');
1586
+ class $mol_tree extends $mol_object2 {
1587
+ type;
1588
+ data;
1589
+ sub;
1590
+ baseUri;
1591
+ row;
1592
+ col;
1593
+ length;
1594
+ constructor(config = {}) {
1627
1595
  super();
1628
- if (typeof config === 'number') {
1629
- this.second = config / 1000;
1630
- return;
1631
- }
1632
- if (typeof config === 'string') {
1633
- if (config === 'Z') {
1634
- this.hour = 0;
1635
- this.minute = 0;
1636
- return;
1637
- }
1638
- duration: {
1639
- const parser = /^P(?:([+-]?\d+(?:\.\d+)?)Y)?(?:([+-]?\d+(?:\.\d+)?)M)?(?:([+-]?\d+(?:\.\d+)?)D)?(?:T(?:([+-]?\d+(?:\.\d+)?)h)?(?:([+-]?\d+(?:\.\d+)?)m)?(?:([+-]?\d+(?:\.\d+)?)s)?)?$/i;
1640
- const found = parser.exec(config);
1641
- if (!found)
1642
- break duration;
1643
- if (found[1])
1644
- this.year = Number(found[1]);
1645
- if (found[2])
1646
- this.month = Number(found[2]);
1647
- if (found[3])
1648
- this.day = Number(found[3]);
1649
- if (found[4])
1650
- this.hour = Number(found[4]);
1651
- if (found[5])
1652
- this.minute = Number(found[5]);
1653
- if (found[6])
1654
- this.second = Number(found[6]);
1655
- return;
1596
+ this.type = config.type || '';
1597
+ if (config.value !== undefined) {
1598
+ var sub = $mol_tree.values(config.value);
1599
+ if (config.type || sub.length > 1) {
1600
+ this.sub = [...sub, ...(config.sub || [])];
1601
+ this.data = config.data || '';
1656
1602
  }
1657
- offset: {
1658
- var parser = /^[+-](\d\d)(?::?(\d\d))?$/i;
1659
- var found = parser.exec(config);
1660
- if (!found)
1661
- break offset;
1662
- if (found[1])
1663
- this.hour = Number(found[1]);
1664
- if (found[2])
1665
- this.minute = Number(found[2]);
1666
- return;
1603
+ else {
1604
+ this.data = sub[0].data;
1605
+ this.sub = config.sub || [];
1667
1606
  }
1668
- throw new Error(`Can not parse time duration (${config})`);
1669
1607
  }
1670
- this.year = config.year || 0;
1671
- this.month = config.month || 0;
1672
- this.day = config.day || 0;
1673
- this.hour = config.hour || 0;
1674
- this.minute = config.minute || 0;
1675
- this.second = config.second || 0;
1608
+ else {
1609
+ this.data = config.data || '';
1610
+ this.sub = config.sub || [];
1611
+ }
1612
+ this.baseUri = config.baseUri || '';
1613
+ this.row = config.row || 0;
1614
+ this.col = config.col || 0;
1615
+ this.length = config.length || 0;
1676
1616
  }
1677
- year = 0;
1678
- month = 0;
1679
- day = 0;
1680
- hour = 0;
1681
- minute = 0;
1682
- second = 0;
1683
- summ(config) {
1684
- const duration = new $mol_time_duration(config);
1685
- return new $mol_time_duration({
1686
- year: this.year + duration.year,
1687
- month: this.month + duration.month,
1688
- day: this.day + duration.day,
1689
- hour: this.hour + duration.hour,
1690
- minute: this.minute + duration.minute,
1691
- second: this.second + duration.second,
1617
+ static values(str, baseUri) {
1618
+ return str.split('\n').map((data, index) => new $mol_tree({
1619
+ data: data,
1620
+ baseUri: baseUri,
1621
+ row: index + 1,
1622
+ length: data.length,
1623
+ }));
1624
+ }
1625
+ clone(config = {}) {
1626
+ return new $mol_tree({
1627
+ type: ('type' in config) ? config.type : this.type,
1628
+ data: ('data' in config) ? config.data : this.data,
1629
+ sub: ('sub' in config) ? config.sub : this.sub,
1630
+ baseUri: ('baseUri' in config) ? config.baseUri : this.baseUri,
1631
+ row: ('row' in config) ? config.row : this.row,
1632
+ col: ('col' in config) ? config.col : this.col,
1633
+ length: ('length' in config) ? config.length : this.length,
1634
+ value: config.value
1692
1635
  });
1693
1636
  }
1694
- mult(numb) {
1695
- return new $mol_time_duration({
1696
- year: this.year && this.year * numb,
1697
- month: this.month && this.month * numb,
1698
- day: this.day && this.day * numb,
1699
- hour: this.hour && this.hour * numb,
1700
- minute: this.minute && this.minute * numb,
1701
- second: this.second && this.second * numb,
1637
+ make(config) {
1638
+ return new $mol_tree({
1639
+ baseUri: this.baseUri,
1640
+ row: this.row,
1641
+ col: this.col,
1642
+ length: this.length,
1643
+ ...config,
1702
1644
  });
1703
1645
  }
1704
- count(config) {
1705
- const duration = new $mol_time_duration(config);
1706
- return this.valueOf() / duration.valueOf();
1646
+ make_data(value, sub) {
1647
+ return this.make({ value, sub });
1707
1648
  }
1708
- valueOf() {
1709
- var day = this.year * 365 + this.month * 30.4 + this.day;
1710
- var second = ((day * 24 + this.hour) * 60 + this.minute) * 60 + this.second;
1711
- return second * 1000;
1649
+ make_struct(type, sub) {
1650
+ return this.make({ type, sub });
1712
1651
  }
1713
- toJSON() { return this.toString(); }
1714
- toString(pattern = 'P#Y#M#DT#h#m#s') {
1715
- return super.toString(pattern);
1652
+ static fromString(str, baseUri) {
1653
+ var root = new $mol_tree({ baseUri: baseUri });
1654
+ var stack = [root];
1655
+ var row = 0;
1656
+ var prefix = str.replace(/^\n?(\t*)[\s\S]*/, '$1');
1657
+ var lines = str.replace(new RegExp('^\\t{0,' + prefix.length + '}', 'mg'), '').split('\n');
1658
+ lines.forEach(line => {
1659
+ ++row;
1660
+ var chunks = /^(\t*)((?:[^\n\t\\ ]+ *)*)(\\[^\n]*)?(.*?)(?:$|\n)/m.exec(line);
1661
+ if (!chunks || chunks[4])
1662
+ return this.$.$mol_fail(new Error(`Syntax error at ${baseUri}:${row}\n${line}`));
1663
+ var indent = chunks[1];
1664
+ var path = chunks[2];
1665
+ var data = chunks[3];
1666
+ var deep = indent.length;
1667
+ var types = path ? path.replace(/ $/, '').split(/ +/) : [];
1668
+ if (stack.length <= deep)
1669
+ return this.$.$mol_fail(new Error(`Too many tabs at ${baseUri}:${row}\n${line}`));
1670
+ stack.length = deep + 1;
1671
+ var parent = stack[deep];
1672
+ let col = deep;
1673
+ types.forEach(type => {
1674
+ if (!type)
1675
+ return this.$.$mol_fail(new Error(`Unexpected space symbol ${baseUri}:${row}\n${line}`));
1676
+ var next = new $mol_tree({ type, baseUri, row, col, length: type.length });
1677
+ const parent_sub = parent.sub;
1678
+ parent_sub.push(next);
1679
+ parent = next;
1680
+ col += type.length + 1;
1681
+ });
1682
+ if (data) {
1683
+ var next = new $mol_tree({ data: data.substring(1), baseUri, row, col, length: data.length });
1684
+ const parent_sub = parent.sub;
1685
+ parent_sub.push(next);
1686
+ parent = next;
1687
+ }
1688
+ stack.push(parent);
1689
+ });
1690
+ return root;
1716
1691
  }
1717
- [Symbol.toPrimitive](mode) {
1718
- return mode === 'number' ? this.valueOf() : this.toString();
1692
+ static fromJSON(json, baseUri = '') {
1693
+ switch (true) {
1694
+ case typeof json === 'boolean':
1695
+ case typeof json === 'number':
1696
+ case json === null:
1697
+ return new $mol_tree({
1698
+ type: String(json),
1699
+ baseUri: baseUri
1700
+ });
1701
+ case typeof json === 'string':
1702
+ return new $mol_tree({
1703
+ value: json,
1704
+ baseUri: baseUri
1705
+ });
1706
+ case Array.isArray(json):
1707
+ return new $mol_tree({
1708
+ type: "/",
1709
+ sub: json.map(json => $mol_tree.fromJSON(json, baseUri))
1710
+ });
1711
+ case json instanceof Date:
1712
+ return new $mol_tree({
1713
+ value: json.toISOString(),
1714
+ baseUri: baseUri
1715
+ });
1716
+ default:
1717
+ if (typeof json[$.$mol_tree_convert] === 'function') {
1718
+ return json[$.$mol_tree_convert]();
1719
+ }
1720
+ if (typeof json.toJSON === 'function') {
1721
+ return $mol_tree.fromJSON(json.toJSON());
1722
+ }
1723
+ if (json instanceof Error) {
1724
+ const { name, message, stack } = json;
1725
+ json = { ...json, name, message, stack };
1726
+ }
1727
+ var sub = [];
1728
+ for (var key in json) {
1729
+ if (json[key] === undefined)
1730
+ continue;
1731
+ const subsub = $mol_tree.fromJSON(json[key], baseUri);
1732
+ if (/^[^\n\t\\ ]+$/.test(key)) {
1733
+ var child = new $mol_tree({
1734
+ type: key,
1735
+ baseUri: baseUri,
1736
+ sub: [subsub],
1737
+ });
1738
+ }
1739
+ else {
1740
+ var child = new $mol_tree({
1741
+ value: key,
1742
+ baseUri: baseUri,
1743
+ sub: [subsub],
1744
+ });
1745
+ }
1746
+ sub.push(child);
1747
+ }
1748
+ return new $mol_tree({
1749
+ type: "*",
1750
+ sub: sub,
1751
+ baseUri: baseUri
1752
+ });
1753
+ }
1719
1754
  }
1720
- static patterns = {
1721
- '#Y': (duration) => {
1722
- if (!duration.year)
1723
- return '';
1724
- return duration.year + 'Y';
1725
- },
1726
- '#M': (duration) => {
1727
- if (!duration.month)
1728
- return '';
1729
- return duration.month + 'M';
1730
- },
1731
- '#D': (duration) => {
1732
- if (!duration.day)
1733
- return '';
1734
- return duration.day + 'D';
1735
- },
1736
- '#h': (duration) => {
1737
- if (!duration.hour)
1738
- return '';
1739
- return duration.hour + 'H';
1740
- },
1741
- '#m': (duration) => {
1742
- if (!duration.minute)
1743
- return '';
1744
- return duration.minute + 'M';
1745
- },
1746
- '#s': (duration) => {
1747
- if (!duration.second)
1748
- return '';
1749
- return duration.second + 'S';
1750
- },
1751
- };
1752
- }
1753
- $.$mol_time_duration = $mol_time_duration;
1754
- })($ || ($ = {}));
1755
- //mol/time/duration/duration.ts
1756
- ;
1757
- "use strict";
1758
- //mol/type/param/param.test.ts
1759
- ;
1760
- "use strict";
1761
- //mol/type/tail/tail.test.ts
1762
- ;
1763
- "use strict";
1764
- var $;
1765
- (function ($) {
1766
- $mol_test({
1767
- 'function'() {
1768
- $mol_assert_not($mol_func_is_class(function () { }));
1769
- },
1770
- 'generator'() {
1771
- $mol_assert_not($mol_func_is_class(function* () { }));
1772
- },
1773
- 'async'() {
1774
- $mol_assert_not($mol_func_is_class(async function () { }));
1775
- },
1776
- 'arrow'() {
1777
- $mol_assert_not($mol_func_is_class(() => null));
1778
- },
1779
- 'named class'() {
1780
- $mol_assert_ok($mol_func_is_class(class Foo {
1781
- }));
1782
- },
1783
- 'unnamed class'() {
1784
- $mol_assert_ok($mol_func_is_class(class {
1785
- }));
1786
- },
1787
- });
1788
- })($ || ($ = {}));
1789
- //mol/func/is/class/class.test.ts
1790
- ;
1791
- "use strict";
1792
- //mol/type/result/result.test.ts
1793
- ;
1794
- "use strict";
1795
- //mol/type/foot/foot.test.ts
1796
- ;
1797
- "use strict";
1798
- var $;
1799
- (function ($) {
1800
- $mol_test({
1801
- 'single function'() {
1802
- const stringify = $mol_data_pipe((input) => input.toString());
1803
- $mol_assert_equal(stringify(5), '5');
1804
- },
1805
- 'two functions'() {
1806
- const isLong = $mol_data_pipe((input) => input.toString(), (input) => input.length > 2);
1807
- $mol_assert_equal(isLong(5.0), false);
1808
- $mol_assert_equal(isLong(5.1), true);
1809
- },
1810
- 'three functions'() {
1811
- const pattern = $mol_data_pipe((input) => input.toString(), (input) => new RegExp(input), (input) => input.toString());
1812
- $mol_assert_equal(pattern(5), '/5/');
1813
- },
1814
- 'classes'() {
1815
- class Box {
1816
- value;
1817
- constructor(value) {
1818
- this.value = value;
1755
+ get uri() {
1756
+ return this.baseUri + '#' + this.row + ':' + this.col;
1757
+ }
1758
+ toString(prefix = '') {
1759
+ var output = '';
1760
+ if (this.type.length) {
1761
+ if (!prefix.length) {
1762
+ prefix = "\t";
1763
+ }
1764
+ output += this.type;
1765
+ if (this.sub.length == 1) {
1766
+ return output + ' ' + this.sub[0].toString(prefix);
1819
1767
  }
1768
+ output += "\n";
1820
1769
  }
1821
- const boxify = $mol_data_pipe((input) => input.toString(), Box);
1822
- $mol_assert_ok(boxify(5) instanceof Box);
1823
- $mol_assert_like(boxify(5).value, '5');
1824
- },
1825
- });
1826
- })($ || ($ = {}));
1827
- //mol/data/pipe/pipe.test.ts
1828
- ;
1829
- "use strict";
1830
- var $;
1831
- (function ($) {
1832
- $mol_test({
1833
- '(De)Serialization'() {
1834
- const Duration = $mol_data_wrapper($mol_data_variant($mol_data_string, $mol_data_integer), $mol_time_duration);
1835
- $mol_assert_equal(JSON.stringify(Duration('P1D')), '"P1DT"');
1836
- $mol_assert_equal(JSON.stringify(Duration(1000)), '"PT1S"');
1837
- },
1838
- });
1839
- })($ || ($ = {}));
1840
- //mol/data/wrapper/wrapper.test.ts
1841
- ;
1842
- "use strict";
1843
- var $;
1844
- (function ($) {
1845
- function $mol_log3_area_lazy(event) {
1846
- const self = this;
1847
- const stack = self.$mol_log3_stack;
1848
- const deep = stack.length;
1849
- let logged = false;
1850
- stack.push(() => {
1851
- logged = true;
1852
- self.$mol_log3_area.call(self, event);
1853
- });
1854
- return () => {
1855
- if (logged)
1856
- self.console.groupEnd();
1857
- if (stack.length > deep)
1858
- stack.length = deep;
1859
- };
1860
- }
1861
- $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1862
- $.$mol_log3_stack = [];
1863
- })($ || ($ = {}));
1864
- //mol/log3/log3.ts
1865
- ;
1866
- "use strict";
1867
- var $;
1868
- (function ($) {
1869
- function $mol_log3_node_make(level, output, type, color) {
1870
- return function $mol_log3_logger(event) {
1871
- if (!event.time)
1872
- event = { time: new Date().toISOString(), ...event };
1873
- const tree = this.$mol_tree.fromJSON(event).clone({ type });
1874
- let str = tree.toString();
1875
- if (process[output].isTTY) {
1876
- str = $node.colorette[color + 'Bright'](str);
1770
+ else if (this.data.length || prefix.length) {
1771
+ output += "\\" + this.data + "\n";
1877
1772
  }
1878
- ;
1879
- this.console[level](str);
1880
- const self = this;
1881
- return () => self.console.groupEnd();
1882
- };
1773
+ for (var child of this.sub) {
1774
+ output += prefix;
1775
+ output += child.toString(prefix + "\t");
1776
+ }
1777
+ return output;
1778
+ }
1779
+ toJSON() {
1780
+ if (!this.type)
1781
+ return this.value;
1782
+ if (this.type === 'true')
1783
+ return true;
1784
+ if (this.type === 'false')
1785
+ return false;
1786
+ if (this.type === 'null')
1787
+ return null;
1788
+ if (this.type === '*') {
1789
+ var obj = {};
1790
+ for (var child of this.sub) {
1791
+ if (child.type === '-')
1792
+ continue;
1793
+ var key = child.type || child.clone({ sub: child.sub.slice(0, child.sub.length - 1) }).value;
1794
+ var val = child.sub[child.sub.length - 1].toJSON();
1795
+ if (val !== undefined)
1796
+ obj[key] = val;
1797
+ }
1798
+ return obj;
1799
+ }
1800
+ if (this.type === '/') {
1801
+ var res = [];
1802
+ this.sub.forEach(child => {
1803
+ if (child.type === '-')
1804
+ return;
1805
+ var val = child.toJSON();
1806
+ if (val !== undefined)
1807
+ res.push(val);
1808
+ });
1809
+ return res;
1810
+ }
1811
+ if (this.type === 'time') {
1812
+ return new Date(this.value);
1813
+ }
1814
+ const numb = Number(this.type);
1815
+ if (!Number.isNaN(numb) || this.type === 'NaN')
1816
+ return numb;
1817
+ throw new Error(`Unknown type (${this.type}) at ${this.uri}`);
1818
+ }
1819
+ get value() {
1820
+ var values = [];
1821
+ for (var child of this.sub) {
1822
+ if (child.type)
1823
+ continue;
1824
+ values.push(child.value);
1825
+ }
1826
+ return this.data + values.join("\n");
1827
+ }
1828
+ insert(value, ...path) {
1829
+ if (path.length === 0)
1830
+ return value;
1831
+ const type = path[0];
1832
+ if (typeof type === 'string') {
1833
+ let replaced = false;
1834
+ const sub = this.sub.map((item, index) => {
1835
+ if (item.type !== type)
1836
+ return item;
1837
+ replaced = true;
1838
+ return item.insert(value, ...path.slice(1));
1839
+ });
1840
+ if (!replaced)
1841
+ sub.push(new $mol_tree({ type }).insert(value, ...path.slice(1)));
1842
+ return this.clone({ sub });
1843
+ }
1844
+ else if (typeof type === 'number') {
1845
+ const sub = this.sub.slice();
1846
+ sub[type] = (sub[type] || new $mol_tree).insert(value, ...path.slice(1));
1847
+ return this.clone({ sub });
1848
+ }
1849
+ else {
1850
+ return this.clone({ sub: ((this.sub.length === 0) ? [new $mol_tree()] : this.sub).map(item => item.insert(value, ...path.slice(1))) });
1851
+ }
1852
+ }
1853
+ select(...path) {
1854
+ var next = [this];
1855
+ for (var type of path) {
1856
+ if (!next.length)
1857
+ break;
1858
+ var prev = next;
1859
+ next = [];
1860
+ for (var item of prev) {
1861
+ switch (typeof (type)) {
1862
+ case 'string':
1863
+ for (var child of item.sub) {
1864
+ if (!type || (child.type == type)) {
1865
+ next.push(child);
1866
+ }
1867
+ }
1868
+ break;
1869
+ case 'number':
1870
+ if (type < item.sub.length)
1871
+ next.push(item.sub[type]);
1872
+ break;
1873
+ default: next.push(...item.sub);
1874
+ }
1875
+ }
1876
+ }
1877
+ return new $mol_tree({ sub: next });
1878
+ }
1879
+ filter(path, value) {
1880
+ var sub = this.sub.filter(function (item) {
1881
+ var found = item.select(...path);
1882
+ if (value == null) {
1883
+ return Boolean(found.sub.length);
1884
+ }
1885
+ else {
1886
+ return found.sub.some(child => child.value == value);
1887
+ }
1888
+ });
1889
+ return new $mol_tree({ sub: sub });
1890
+ }
1891
+ transform(visit, stack = []) {
1892
+ const sub_stack = [this, ...stack];
1893
+ return visit(sub_stack, () => this.sub.map(node => node.transform(visit, sub_stack)).filter(n => n));
1894
+ }
1895
+ hack(context) {
1896
+ const sub = [].concat(...this.sub.map(child => {
1897
+ const handle = context[child.type] || context[''];
1898
+ if (!handle)
1899
+ $mol_fail(child.error('Handler not defined'));
1900
+ return handle(child, context);
1901
+ }));
1902
+ return this.clone({ sub });
1903
+ }
1904
+ error(message) {
1905
+ return new Error(`${message}:\n${this} ${this.baseUri}:${this.row}:${this.col}`);
1906
+ }
1883
1907
  }
1884
- $.$mol_log3_node_make = $mol_log3_node_make;
1885
- $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', 'blue');
1886
- $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', 'green');
1887
- $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', 'red');
1888
- $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', 'yellow');
1889
- $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', 'magenta');
1890
- $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', 'cyan');
1891
- })($ || ($ = {}));
1892
- //mol/log3/log3.node.ts
1893
- ;
1894
- "use strict";
1895
- var $;
1896
- (function ($_1) {
1897
- $mol_test_mocks.push($ => {
1898
- $.$mol_log3_come = () => { };
1899
- $.$mol_log3_done = () => { };
1900
- $.$mol_log3_fail = () => { };
1901
- $.$mol_log3_warn = () => { };
1902
- $.$mol_log3_rise = () => { };
1903
- $.$mol_log3_area = () => () => { };
1904
- });
1908
+ __decorate([
1909
+ $mol_deprecated('Use $mol_tree:hack')
1910
+ ], $mol_tree.prototype, "transform", null);
1911
+ $.$mol_tree = $mol_tree;
1905
1912
  })($ || ($ = {}));
1906
- //mol/log3/log3.test.ts
1913
+ //mol/tree/tree.ts
1907
1914
  ;
1908
1915
  "use strict";
1909
1916
  var $;
@@ -1954,634 +1961,627 @@ var $;
1954
1961
  "use strict";
1955
1962
  var $;
1956
1963
  (function ($) {
1957
- $.$mol_ambient_ref = Symbol('$mol_ambient_ref');
1958
- function $mol_ambient(overrides) {
1959
- return Object.setPrototypeOf(overrides, this || $);
1960
- }
1961
- $.$mol_ambient = $mol_ambient;
1964
+ $mol_test({
1965
+ 'Is empty array'() {
1966
+ $mol_data_array($mol_data_number)([]);
1967
+ },
1968
+ 'Is array'() {
1969
+ $mol_data_array($mol_data_number)([1, 2]);
1970
+ },
1971
+ 'Is not array'() {
1972
+ $mol_assert_fail(() => {
1973
+ $mol_data_array($mol_data_number)({ [0]: 1, length: 1, map: () => { } });
1974
+ }, '[object Object] is not an array');
1975
+ },
1976
+ 'Has wrong item'() {
1977
+ $mol_assert_fail(() => {
1978
+ $mol_data_array($mol_data_number)([1, '1']);
1979
+ }, '[1] 1 is not a number');
1980
+ },
1981
+ 'Has wrong deep item'() {
1982
+ $mol_assert_fail(() => {
1983
+ $mol_data_array($mol_data_array($mol_data_number))([[], [0, 0, false]]);
1984
+ }, '[1] [2] false is not a number');
1985
+ },
1986
+ });
1962
1987
  })($ || ($ = {}));
1963
- //mol/ambient/ambient.ts
1988
+ //mol/data/array/array.test.ts
1964
1989
  ;
1965
1990
  "use strict";
1966
1991
  var $;
1967
1992
  (function ($) {
1968
1993
  $mol_test({
1969
- 'get'() {
1970
- const proxy = $mol_delegate({}, () => ({ foo: 777 }));
1971
- $mol_assert_equal(proxy.foo, 777);
1994
+ 'Is boolean - true'() {
1995
+ $mol_data_boolean(true);
1972
1996
  },
1973
- 'has'() {
1974
- const proxy = $mol_delegate({}, () => ({ foo: 777 }));
1975
- $mol_assert_equal('foo' in proxy, true);
1997
+ 'Is boolean - false'() {
1998
+ $mol_data_boolean(false);
1976
1999
  },
1977
- 'set'() {
1978
- const target = { foo: 777 };
1979
- const proxy = $mol_delegate({}, () => target);
1980
- proxy.foo = 123;
1981
- $mol_assert_equal(target.foo, 123);
2000
+ 'Is not boolean'() {
2001
+ $mol_assert_fail(() => {
2002
+ $mol_data_boolean('x');
2003
+ }, 'x is not a boolean');
1982
2004
  },
1983
- 'getOwnPropertyDescriptor'() {
1984
- const proxy = $mol_delegate({}, () => ({ foo: 777 }));
1985
- $mol_assert_like(Object.getOwnPropertyDescriptor(proxy, 'foo'), {
1986
- value: 777,
1987
- writable: true,
1988
- enumerable: true,
1989
- configurable: true,
1990
- });
1991
- },
1992
- 'ownKeys'() {
1993
- const proxy = $mol_delegate({}, () => ({ foo: 777, [Symbol.toStringTag]: 'bar' }));
1994
- $mol_assert_like(Reflect.ownKeys(proxy), ['foo', Symbol.toStringTag]);
1995
- },
1996
- 'getPrototypeOf'() {
1997
- class Foo {
1998
- }
1999
- const proxy = $mol_delegate({}, () => new Foo);
2000
- $mol_assert_equal(Object.getPrototypeOf(proxy), Foo.prototype);
2001
- },
2002
- 'setPrototypeOf'() {
2003
- class Foo {
2004
- }
2005
- const target = {};
2006
- const proxy = $mol_delegate({}, () => target);
2007
- Object.setPrototypeOf(proxy, Foo.prototype);
2008
- $mol_assert_equal(Object.getPrototypeOf(target), Foo.prototype);
2009
- },
2010
- 'instanceof'() {
2011
- class Foo {
2012
- }
2013
- const proxy = $mol_delegate({}, () => new Foo);
2014
- $mol_assert_ok(proxy instanceof Foo);
2015
- $mol_assert_ok(proxy instanceof $mol_delegate);
2016
- },
2017
- 'autobind'() {
2018
- class Foo {
2019
- }
2020
- const proxy = $mol_delegate({}, () => new Foo);
2021
- $mol_assert_ok(proxy instanceof Foo);
2022
- $mol_assert_ok(proxy instanceof $mol_delegate);
2005
+ 'Is object boolean'() {
2006
+ $mol_assert_fail(() => {
2007
+ $mol_data_boolean(new Boolean(''));
2008
+ }, 'false is not a boolean');
2023
2009
  },
2024
2010
  });
2025
2011
  })($ || ($ = {}));
2026
- //mol/delegate/delegate.test.ts
2012
+ //mol/data/boolean/boolean.test.ts
2027
2013
  ;
2028
2014
  "use strict";
2029
2015
  var $;
2030
2016
  (function ($) {
2031
- const instances = new WeakSet();
2032
- function $mol_delegate(proto, target) {
2033
- const proxy = new Proxy(proto, {
2034
- get: (_, field) => {
2035
- const obj = target();
2036
- let val = Reflect.get(obj, field);
2037
- if (typeof val === 'function') {
2038
- val = val.bind(obj);
2039
- }
2040
- return val;
2041
- },
2042
- has: (_, field) => Reflect.has(target(), field),
2043
- set: (_, field, value) => Reflect.set(target(), field, value),
2044
- getOwnPropertyDescriptor: (_, field) => Reflect.getOwnPropertyDescriptor(target(), field),
2045
- ownKeys: () => Reflect.ownKeys(target()),
2046
- getPrototypeOf: () => Reflect.getPrototypeOf(target()),
2047
- setPrototypeOf: (_, donor) => Reflect.setPrototypeOf(target(), donor),
2048
- isExtensible: () => Reflect.isExtensible(target()),
2049
- preventExtensions: () => Reflect.preventExtensions(target()),
2050
- apply: (_, self, args) => Reflect.apply(target(), self, args),
2051
- construct: (_, args, retarget) => Reflect.construct(target(), args, retarget),
2052
- defineProperty: (_, field, descr) => Reflect.defineProperty(target(), field, descr),
2053
- deleteProperty: (_, field) => Reflect.deleteProperty(target(), field),
2054
- });
2055
- instances.add(proxy);
2056
- return proxy;
2057
- }
2058
- $.$mol_delegate = $mol_delegate;
2059
- Reflect.defineProperty($mol_delegate, Symbol.hasInstance, {
2060
- value: (obj) => instances.has(obj),
2017
+ $mol_test({
2018
+ 'is same number'() {
2019
+ $mol_data_const(Number.NaN)(Number.NaN);
2020
+ },
2021
+ 'is different number'() {
2022
+ const Five = $mol_data_const(5);
2023
+ $mol_assert_fail(() => Five(6), '6 is not 5');
2024
+ },
2061
2025
  });
2062
2026
  })($ || ($ = {}));
2063
- //mol/delegate/delegate.ts
2027
+ //mol/data/const/const.test.ts
2064
2028
  ;
2065
2029
  "use strict";
2066
2030
  var $;
2067
2031
  (function ($) {
2068
- $.$mol_owning_map = new WeakMap();
2069
- function $mol_owning_allow(having) {
2070
- try {
2071
- if (!having)
2072
- return false;
2073
- if (typeof having !== 'object')
2074
- return false;
2075
- if (having instanceof $mol_delegate)
2076
- return false;
2077
- if (typeof having['destructor'] !== 'function')
2078
- return false;
2079
- return true;
2080
- }
2081
- catch {
2082
- return false;
2083
- }
2084
- }
2085
- $.$mol_owning_allow = $mol_owning_allow;
2086
- function $mol_owning_get(having, Owner) {
2087
- if (!$mol_owning_allow(having))
2088
- return null;
2089
- while (true) {
2090
- const owner = $.$mol_owning_map.get(having);
2091
- if (!owner)
2092
- return owner;
2093
- if (!Owner)
2094
- return owner;
2095
- if (owner instanceof Owner)
2096
- return owner;
2097
- having = owner;
2098
- }
2099
- }
2100
- $.$mol_owning_get = $mol_owning_get;
2101
- function $mol_owning_check(owner, having) {
2102
- if (!$mol_owning_allow(having))
2103
- return false;
2104
- if ($.$mol_owning_map.get(having) !== owner)
2105
- return false;
2106
- return true;
2107
- }
2108
- $.$mol_owning_check = $mol_owning_check;
2109
- function $mol_owning_catch(owner, having) {
2110
- if (!$mol_owning_allow(having))
2111
- return false;
2112
- if ($.$mol_owning_map.get(having))
2113
- return false;
2114
- $.$mol_owning_map.set(having, owner);
2115
- return true;
2116
- }
2117
- $.$mol_owning_catch = $mol_owning_catch;
2032
+ $mol_test({
2033
+ 'Is string'() {
2034
+ $mol_data_string('');
2035
+ },
2036
+ 'Is not string'() {
2037
+ $mol_assert_fail(() => {
2038
+ $mol_data_string(0);
2039
+ }, '0 is not a string');
2040
+ },
2041
+ 'Is object string'() {
2042
+ $mol_assert_fail(() => {
2043
+ $mol_data_string(new String('x'));
2044
+ }, 'x is not a string');
2045
+ },
2046
+ });
2118
2047
  })($ || ($ = {}));
2119
- //mol/owning/owning.ts
2120
- ;
2121
- "use strict";
2122
- //mol/type/writable/writable.test.ts
2123
- ;
2124
- "use strict";
2125
- //mol/type/writable/writable.ts
2048
+ //mol/data/string/string.test.ts
2126
2049
  ;
2127
2050
  "use strict";
2128
2051
  var $;
2129
2052
  (function ($) {
2130
- class $mol_object2 {
2131
- static $ = $;
2132
- [$mol_ambient_ref] = null;
2133
- get $() {
2134
- if (this[$mol_ambient_ref])
2135
- return this[$mol_ambient_ref];
2136
- const owner = $mol_owning_get(this);
2137
- return this[$mol_ambient_ref] = owner?.$ || $mol_object2.$;
2138
- }
2139
- set $(next) {
2140
- if (this[$mol_ambient_ref])
2141
- $mol_fail_hidden(new Error('Context already defined'));
2142
- this[$mol_ambient_ref] = next;
2143
- }
2144
- static create(init) {
2145
- const obj = new this;
2146
- if (init)
2147
- init(obj);
2148
- return obj;
2149
- }
2150
- static [Symbol.toPrimitive]() {
2151
- return this.toString();
2152
- }
2153
- static toString() {
2154
- if (Symbol.toStringTag in this)
2155
- return this[Symbol.toStringTag];
2156
- return this.name;
2157
- }
2158
- destructor() { }
2159
- toString() {
2160
- return this[Symbol.toStringTag] || this.constructor.name + '()';
2161
- }
2162
- toJSON() {
2163
- return this.toString();
2164
- }
2165
- }
2166
- $.$mol_object2 = $mol_object2;
2053
+ $mol_test({
2054
+ 'Is fit'() {
2055
+ $mol_data_pattern(/^-$/)('-');
2056
+ },
2057
+ 'Is not fit'() {
2058
+ $mol_assert_fail(() => {
2059
+ $mol_data_pattern(/^-$/)('+');
2060
+ }, '+ is not a /^-$/');
2061
+ },
2062
+ });
2167
2063
  })($ || ($ = {}));
2168
- //mol/object2/object2.ts
2064
+ //mol/data/pattern/pattern.test.ts
2169
2065
  ;
2170
2066
  "use strict";
2171
2067
  var $;
2172
2068
  (function ($) {
2173
- function $mol_deprecated(message) {
2174
- return (host, field, descr) => {
2175
- const value = descr.value;
2176
- let warned = false;
2177
- descr.value = function $mol_deprecated_wrapper(...args) {
2178
- if (!warned) {
2179
- $$.$mol_log3_warn({
2180
- place: `${host.constructor.name}::${field}`,
2181
- message: `Deprecated`,
2182
- hint: message,
2183
- });
2184
- warned = true;
2185
- }
2186
- return value.call(this, ...args);
2187
- };
2188
- };
2189
- }
2190
- $.$mol_deprecated = $mol_deprecated;
2069
+ $mol_test({
2070
+ 'Is email'() {
2071
+ $mol_data_email('foo@bar');
2072
+ },
2073
+ 'Has not host'() {
2074
+ $mol_assert_fail(() => {
2075
+ $mol_data_email('foo@');
2076
+ }, 'foo@ is not a /.+@.+/');
2077
+ },
2078
+ 'Has not name'() {
2079
+ $mol_assert_fail(() => {
2080
+ $mol_data_email('@bar');
2081
+ }, '@bar is not a /.+@.+/');
2082
+ },
2083
+ 'Has not @'() {
2084
+ $mol_assert_fail(() => {
2085
+ $mol_data_email('foo.bar');
2086
+ }, 'foo.bar is not a /.+@.+/');
2087
+ },
2088
+ });
2191
2089
  })($ || ($ = {}));
2192
- //mol/deprecated/deprecated.ts
2090
+ //mol/data/email/email.test.ts
2193
2091
  ;
2194
2092
  "use strict";
2195
2093
  var $;
2196
- (function ($_1) {
2094
+ (function ($) {
2095
+ let sex;
2096
+ (function (sex) {
2097
+ sex[sex["male"] = 0] = "male";
2098
+ sex[sex["female"] = 1] = "female";
2099
+ })(sex || (sex = {}));
2100
+ const Sex = $mol_data_enum('sex', sex);
2197
2101
  $mol_test({
2198
- 'tree parsing'() {
2199
- $mol_assert_equal($mol_tree.fromString("foo\nbar\n").sub.length, 2);
2200
- $mol_assert_equal($mol_tree.fromString("foo\nbar\n").sub[1].type, "bar");
2201
- $mol_assert_equal($mol_tree.fromString("foo\n\n\n").sub.length, 1);
2202
- $mol_assert_equal($mol_tree.fromString("=foo\n\\bar\n").sub.length, 2);
2203
- $mol_assert_equal($mol_tree.fromString("=foo\n\\bar\n").sub[1].data, "bar");
2204
- $mol_assert_equal($mol_tree.fromString("foo bar \\pol").sub[0].sub[0].sub[0].data, "pol");
2205
- $mol_assert_equal($mol_tree.fromString("foo bar\n\t\\pol\n\t\\men").sub[0].sub[0].sub[1].data, "men");
2206
- $mol_assert_equal($mol_tree.fromString('foo bar \\text\n').toString(), 'foo bar \\text\n');
2207
- },
2208
- 'inserting'() {
2209
- $mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 'a', 'b', 'c').toString(), 'a b \\\n');
2210
- $mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 'a', 'b', 'c', 'd').toString(), 'a b c \\\n');
2211
- $mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, 0, 0, 0).toString(), 'a b \\\n');
2212
- $mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, 0, 0, 0, 0).toString(), 'a b \\\n\t\\\n');
2213
- $mol_assert_equal($mol_tree.fromString('a b c d').insert(new $mol_tree, null, null, null).toString(), 'a b \\\n');
2214
- $mol_assert_equal($mol_tree.fromString('a b').insert(new $mol_tree, null, null, null, null).toString(), 'a b \\\n\t\\\n');
2102
+ 'config of enum'() {
2103
+ $mol_assert_like(Sex.config, {
2104
+ name: 'sex',
2105
+ dict: sex,
2106
+ });
2215
2107
  },
2216
- 'fromJSON'() {
2217
- $mol_assert_equal($mol_tree.fromJSON([]).toString(), '/\n');
2218
- $mol_assert_equal($mol_tree.fromJSON([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
2219
- $mol_assert_equal($mol_tree.fromJSON([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
2220
- $mol_assert_equal($mol_tree.fromJSON(['', 'foo', 'bar\nbaz']).toString(), '/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n');
2221
- $mol_assert_equal($mol_tree.fromJSON({ 'foo': false, 'bar\nbaz': 'lol' }).toString(), '*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n');
2108
+ 'name of enum'() {
2109
+ $mol_assert_equal(Sex.config.name, 'sex');
2222
2110
  },
2223
- 'toJSON'() {
2224
- $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n').sub[0]), '[]');
2225
- $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\tfalse\n\ttrue\n').sub[0]), '[false,true]');
2226
- $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\t0\n\t1\n\t2.3\n').sub[0]), '[0,1,2.3]');
2227
- $mol_assert_equal(JSON.stringify($mol_tree.fromString('/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n').sub[0]), '["","foo","bar\\nbaz"]');
2228
- $mol_assert_equal(JSON.stringify($mol_tree.fromString('*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n').sub[0]), '{"foo":false,"bar\\nbaz":"lol"}');
2111
+ 'Is right value of enum'() {
2112
+ $mol_assert_equal(Sex(0), sex.male);
2229
2113
  },
2230
- 'hack'() {
2231
- const res = $mol_tree.fromString(`foo bar xxx`).hack({
2232
- '': (tree, context) => [tree.hack(context)],
2233
- 'bar': (tree, context) => [tree.hack(context).clone({ type: '777' })],
2114
+ 'Is wrong value of enum'() {
2115
+ $mol_assert_fail(() => Sex(2), `2 is not value of sex enum`);
2116
+ },
2117
+ 'Is name instead of value'() {
2118
+ $mol_assert_fail(() => Sex('male'), `male is not value of sex enum`);
2119
+ },
2120
+ 'Is common object field'() {
2121
+ $mol_assert_fail(() => Sex('__proto__'), `__proto__ is not value of sex enum`);
2122
+ },
2123
+ });
2124
+ let gender;
2125
+ (function (gender) {
2126
+ gender["bisexual"] = "bisexual";
2127
+ gender["trans"] = "transgender";
2128
+ })(gender || (gender = {}));
2129
+ const Gender = $mol_data_enum('gender', gender);
2130
+ $mol_test({
2131
+ 'config of enum'() {
2132
+ $mol_assert_like(Gender.config, {
2133
+ name: 'gender',
2134
+ dict: gender,
2234
2135
  });
2235
- $mol_assert_equal(res.toString(), new $mol_tree({ type: 'foo 777 xxx' }).toString());
2236
2136
  },
2237
- 'errors handling'($) {
2238
- const errors = [];
2239
- class Tree extends $mol_tree {
2240
- static $ = $.$mol_ambient({
2241
- $mol_fail: error => errors.push(error.message)
2242
- });
2243
- }
2244
- Tree.fromString(`
2245
- \t \tfoo
2246
- bar \\data
2247
- `, 'test');
2248
- $mol_assert_like(errors, ['Syntax error at test:2\n \tfoo']);
2137
+ 'Is right value of enum'() {
2138
+ $mol_assert_equal(Gender('transgender'), gender.trans);
2139
+ },
2140
+ 'Is wrong value of enum'() {
2141
+ $mol_assert_fail(() => Gender('xxx'), `xxx is not value of gender enum`);
2142
+ },
2143
+ 'Is name instead of value'() {
2144
+ $mol_assert_fail(() => Gender('trans'), `trans is not value of gender enum`);
2145
+ },
2146
+ 'Is common object field'() {
2147
+ $mol_assert_fail(() => Gender('__proto__'), `__proto__ is not value of gender enum`);
2249
2148
  },
2250
2149
  });
2251
2150
  })($ || ($ = {}));
2252
- //mol/tree/tree.test.ts
2151
+ //mol/data/enum/enum.test.ts
2253
2152
  ;
2254
2153
  "use strict";
2255
2154
  var $;
2256
2155
  (function ($) {
2257
- $.$mol_tree_convert = Symbol('$mol_tree_convert');
2258
- class $mol_tree extends $mol_object2 {
2259
- type;
2260
- data;
2261
- sub;
2262
- baseUri;
2263
- row;
2264
- col;
2265
- length;
2266
- constructor(config = {}) {
2267
- super();
2268
- this.type = config.type || '';
2269
- if (config.value !== undefined) {
2270
- var sub = $mol_tree.values(config.value);
2271
- if (config.type || sub.length > 1) {
2272
- this.sub = [...sub, ...(config.sub || [])];
2273
- this.data = config.data || '';
2274
- }
2275
- else {
2276
- this.data = sub[0].data;
2277
- this.sub = config.sub || [];
2278
- }
2279
- }
2280
- else {
2281
- this.data = config.data || '';
2282
- this.sub = config.sub || [];
2283
- }
2284
- this.baseUri = config.baseUri || '';
2285
- this.row = config.row || 0;
2286
- this.col = config.col || 0;
2287
- this.length = config.length || 0;
2288
- }
2289
- static values(str, baseUri) {
2290
- return str.split('\n').map((data, index) => new $mol_tree({
2291
- data: data,
2292
- baseUri: baseUri,
2293
- row: index + 1,
2294
- length: data.length,
2295
- }));
2296
- }
2297
- clone(config = {}) {
2298
- return new $mol_tree({
2299
- type: ('type' in config) ? config.type : this.type,
2300
- data: ('data' in config) ? config.data : this.data,
2301
- sub: ('sub' in config) ? config.sub : this.sub,
2302
- baseUri: ('baseUri' in config) ? config.baseUri : this.baseUri,
2303
- row: ('row' in config) ? config.row : this.row,
2304
- col: ('col' in config) ? config.col : this.col,
2305
- length: ('length' in config) ? config.length : this.length,
2306
- value: config.value
2307
- });
2308
- }
2309
- make(config) {
2310
- return new $mol_tree({
2311
- baseUri: this.baseUri,
2312
- row: this.row,
2313
- col: this.col,
2314
- length: this.length,
2315
- ...config,
2316
- });
2317
- }
2318
- make_data(value, sub) {
2319
- return this.make({ value, sub });
2320
- }
2321
- make_struct(type, sub) {
2322
- return this.make({ type, sub });
2323
- }
2324
- static fromString(str, baseUri) {
2325
- var root = new $mol_tree({ baseUri: baseUri });
2326
- var stack = [root];
2327
- var row = 0;
2328
- var prefix = str.replace(/^\n?(\t*)[\s\S]*/, '$1');
2329
- var lines = str.replace(new RegExp('^\\t{0,' + prefix.length + '}', 'mg'), '').split('\n');
2330
- lines.forEach(line => {
2331
- ++row;
2332
- var chunks = /^(\t*)((?:[^\n\t\\ ]+ *)*)(\\[^\n]*)?(.*?)(?:$|\n)/m.exec(line);
2333
- if (!chunks || chunks[4])
2334
- return this.$.$mol_fail(new Error(`Syntax error at ${baseUri}:${row}\n${line}`));
2335
- var indent = chunks[1];
2336
- var path = chunks[2];
2337
- var data = chunks[3];
2338
- var deep = indent.length;
2339
- var types = path ? path.replace(/ $/, '').split(/ +/) : [];
2340
- if (stack.length <= deep)
2341
- return this.$.$mol_fail(new Error(`Too many tabs at ${baseUri}:${row}\n${line}`));
2342
- stack.length = deep + 1;
2343
- var parent = stack[deep];
2344
- let col = deep;
2345
- types.forEach(type => {
2346
- if (!type)
2347
- return this.$.$mol_fail(new Error(`Unexpected space symbol ${baseUri}:${row}\n${line}`));
2348
- var next = new $mol_tree({ type, baseUri, row, col, length: type.length });
2349
- const parent_sub = parent.sub;
2350
- parent_sub.push(next);
2351
- parent = next;
2352
- col += type.length + 1;
2353
- });
2354
- if (data) {
2355
- var next = new $mol_tree({ data: data.substring(1), baseUri, row, col, length: data.length });
2356
- const parent_sub = parent.sub;
2357
- parent_sub.push(next);
2358
- parent = next;
2359
- }
2360
- stack.push(parent);
2361
- });
2362
- return root;
2363
- }
2364
- static fromJSON(json, baseUri = '') {
2365
- switch (true) {
2366
- case typeof json === 'boolean':
2367
- case typeof json === 'number':
2368
- case json === null:
2369
- return new $mol_tree({
2370
- type: String(json),
2371
- baseUri: baseUri
2372
- });
2373
- case typeof json === 'string':
2374
- return new $mol_tree({
2375
- value: json,
2376
- baseUri: baseUri
2377
- });
2378
- case Array.isArray(json):
2379
- return new $mol_tree({
2380
- type: "/",
2381
- sub: json.map(json => $mol_tree.fromJSON(json, baseUri))
2382
- });
2383
- case json instanceof Date:
2384
- return new $mol_tree({
2385
- value: json.toISOString(),
2386
- baseUri: baseUri
2387
- });
2388
- default:
2389
- if (typeof json[$.$mol_tree_convert] === 'function') {
2390
- return json[$.$mol_tree_convert]();
2391
- }
2392
- if (typeof json.toJSON === 'function') {
2393
- return $mol_tree.fromJSON(json.toJSON());
2394
- }
2395
- if (json instanceof Error) {
2396
- const { name, message, stack } = json;
2397
- json = { ...json, name, message, stack };
2398
- }
2399
- var sub = [];
2400
- for (var key in json) {
2401
- if (json[key] === undefined)
2402
- continue;
2403
- const subsub = $mol_tree.fromJSON(json[key], baseUri);
2404
- if (/^[^\n\t\\ ]+$/.test(key)) {
2405
- var child = new $mol_tree({
2406
- type: key,
2407
- baseUri: baseUri,
2408
- sub: [subsub],
2409
- });
2410
- }
2411
- else {
2412
- var child = new $mol_tree({
2413
- value: key,
2414
- baseUri: baseUri,
2415
- sub: [subsub],
2416
- });
2417
- }
2418
- sub.push(child);
2419
- }
2420
- return new $mol_tree({
2421
- type: "*",
2422
- sub: sub,
2423
- baseUri: baseUri
2424
- });
2425
- }
2426
- }
2427
- get uri() {
2428
- return this.baseUri + '#' + this.row + ':' + this.col;
2429
- }
2430
- toString(prefix = '') {
2431
- var output = '';
2432
- if (this.type.length) {
2433
- if (!prefix.length) {
2434
- prefix = "\t";
2435
- }
2436
- output += this.type;
2437
- if (this.sub.length == 1) {
2438
- return output + ' ' + this.sub[0].toString(prefix);
2439
- }
2440
- output += "\n";
2441
- }
2442
- else if (this.data.length || prefix.length) {
2443
- output += "\\" + this.data + "\n";
2444
- }
2445
- for (var child of this.sub) {
2446
- output += prefix;
2447
- output += child.toString(prefix + "\t");
2448
- }
2449
- return output;
2450
- }
2451
- toJSON() {
2452
- if (!this.type)
2453
- return this.value;
2454
- if (this.type === 'true')
2455
- return true;
2456
- if (this.type === 'false')
2457
- return false;
2458
- if (this.type === 'null')
2459
- return null;
2460
- if (this.type === '*') {
2461
- var obj = {};
2462
- for (var child of this.sub) {
2463
- if (child.type === '-')
2464
- continue;
2465
- var key = child.type || child.clone({ sub: child.sub.slice(0, child.sub.length - 1) }).value;
2466
- var val = child.sub[child.sub.length - 1].toJSON();
2467
- if (val !== undefined)
2468
- obj[key] = val;
2469
- }
2470
- return obj;
2471
- }
2472
- if (this.type === '/') {
2473
- var res = [];
2474
- this.sub.forEach(child => {
2475
- if (child.type === '-')
2476
- return;
2477
- var val = child.toJSON();
2478
- if (val !== undefined)
2479
- res.push(val);
2480
- });
2481
- return res;
2482
- }
2483
- if (this.type === 'time') {
2484
- return new Date(this.value);
2485
- }
2486
- const numb = Number(this.type);
2487
- if (!Number.isNaN(numb) || this.type === 'NaN')
2488
- return numb;
2489
- throw new Error(`Unknown type (${this.type}) at ${this.uri}`);
2156
+ $mol_test({
2157
+ 'Is same class'() {
2158
+ $mol_data_instance(Date)(new Date);
2159
+ },
2160
+ 'Is sub class'() {
2161
+ $mol_data_instance(Object)(new Date);
2162
+ },
2163
+ 'Is super class'() {
2164
+ $mol_assert_fail(() => {
2165
+ $mol_data_instance(Date)(new Object);
2166
+ }, '[object Object] is not a Date');
2167
+ },
2168
+ 'Is another class'() {
2169
+ $mol_assert_fail(() => {
2170
+ $mol_data_instance(Date)(new Array);
2171
+ }, ' is not a Date');
2172
+ },
2173
+ 'Is not object'() {
2174
+ $mol_assert_fail(() => {
2175
+ $mol_data_instance(Date)(null);
2176
+ }, 'null is not a Date');
2177
+ },
2178
+ });
2179
+ })($ || ($ = {}));
2180
+ //mol/data/instance/instance.test.ts
2181
+ ;
2182
+ "use strict";
2183
+ var $;
2184
+ (function ($) {
2185
+ $mol_test({
2186
+ 'Is integer'() {
2187
+ $mol_data_integer(0);
2188
+ },
2189
+ 'Is float'() {
2190
+ $mol_assert_fail(() => {
2191
+ $mol_data_integer(1.1);
2192
+ }, '1.1 is not an integer');
2193
+ },
2194
+ });
2195
+ })($ || ($ = {}));
2196
+ //mol/data/integer/integer.test.ts
2197
+ ;
2198
+ "use strict";
2199
+ var $;
2200
+ (function ($) {
2201
+ $mol_test({
2202
+ 'Nominal typing'() {
2203
+ const Weight = $mol_data_nominal({ Weight: $mol_data_integer });
2204
+ const Length = $mol_data_nominal({ Length: $mol_data_integer });
2205
+ let len = Length(10);
2206
+ len = Length(20);
2207
+ len = 20;
2208
+ },
2209
+ });
2210
+ })($ || ($ = {}));
2211
+ //mol/data/nominal/nominal.test.ts
2212
+ ;
2213
+ "use strict";
2214
+ var $;
2215
+ (function ($) {
2216
+ $mol_test({
2217
+ 'Is null'() {
2218
+ $mol_data_nullable($mol_data_number)(null);
2219
+ },
2220
+ 'Is not null'() {
2221
+ $mol_data_nullable($mol_data_number)(0);
2222
+ },
2223
+ 'Is undefined'() {
2224
+ $mol_assert_fail(() => {
2225
+ const Type = $mol_data_nullable($mol_data_number);
2226
+ Type(undefined);
2227
+ }, 'undefined is not a number');
2228
+ },
2229
+ });
2230
+ })($ || ($ = {}));
2231
+ //mol/data/nullable/nullable.test.ts
2232
+ ;
2233
+ "use strict";
2234
+ var $;
2235
+ (function ($) {
2236
+ const Age = $mol_data_optional($mol_data_number);
2237
+ const Age_or_zero = $mol_data_optional($mol_data_number, () => 0);
2238
+ $mol_test({
2239
+ 'Is not present'() {
2240
+ $mol_assert_equal(Age(undefined), undefined);
2241
+ },
2242
+ 'Is present'() {
2243
+ $mol_assert_equal(Age(0), 0);
2244
+ },
2245
+ 'Fallbacked'() {
2246
+ $mol_assert_equal(Age_or_zero(undefined), 0);
2247
+ },
2248
+ 'Is null'() {
2249
+ $mol_assert_fail(() => Age(null), 'null is not a number');
2250
+ },
2251
+ });
2252
+ })($ || ($ = {}));
2253
+ //mol/data/optional/optional.test.ts
2254
+ ;
2255
+ "use strict";
2256
+ //mol/type/merge/merge.test.ts
2257
+ ;
2258
+ "use strict";
2259
+ //mol/type/partial/undefined/undefined.test.ts
2260
+ ;
2261
+ "use strict";
2262
+ var $;
2263
+ (function ($) {
2264
+ $mol_test({
2265
+ 'Fit to record'() {
2266
+ const User = $mol_data_record({ age: $mol_data_number });
2267
+ User({ age: 0 });
2268
+ },
2269
+ 'Extends record'() {
2270
+ const User = $mol_data_record({ age: $mol_data_number });
2271
+ User({ age: 0, name: 'Jin' });
2272
+ },
2273
+ 'Shrinks record'() {
2274
+ $mol_assert_fail(() => {
2275
+ const User = $mol_data_record({ age: $mol_data_number, name: $mol_data_string });
2276
+ User({ age: 0 });
2277
+ }, '["name"] undefined is not a string');
2278
+ },
2279
+ 'Shrinks deep record'() {
2280
+ $mol_assert_fail(() => {
2281
+ const User = $mol_data_record({ wife: $mol_data_record({ age: $mol_data_number }) });
2282
+ User({ wife: {} });
2283
+ }, '["wife"] ["age"] undefined is not a number');
2284
+ },
2285
+ });
2286
+ })($ || ($ = {}));
2287
+ //mol/data/record/record.test.ts
2288
+ ;
2289
+ "use strict";
2290
+ var $;
2291
+ (function ($) {
2292
+ $mol_test({
2293
+ 'Is first'() {
2294
+ $mol_data_variant($mol_data_number, $mol_data_string)(0);
2295
+ },
2296
+ 'Is second'() {
2297
+ $mol_data_variant($mol_data_number, $mol_data_string)('');
2298
+ },
2299
+ 'Is false'() {
2300
+ $mol_assert_fail(() => {
2301
+ $mol_data_variant($mol_data_number, $mol_data_string)(false);
2302
+ }, 'false is not any of variants\nfalse is not a number\nfalse is not a string');
2303
+ },
2304
+ });
2305
+ })($ || ($ = {}));
2306
+ //mol/data/variant/variant.test.ts
2307
+ ;
2308
+ "use strict";
2309
+ var $;
2310
+ (function ($) {
2311
+ class $mol_time_base {
2312
+ static patterns = {};
2313
+ static formatter(pattern) {
2314
+ if (this.patterns[pattern])
2315
+ return this.patterns[pattern];
2316
+ var tokens = Object.keys(this.patterns)
2317
+ .sort()
2318
+ .reverse()
2319
+ .map((token) => token.replace(/([-+*.\[\]()\^])/g, '\\$1'));
2320
+ var lexer = RegExp('(.*?)(' + tokens.join('|') + '|$)', 'g');
2321
+ var funcs = [];
2322
+ pattern.replace(lexer, (str, text, token) => {
2323
+ if (text)
2324
+ funcs.push(() => text);
2325
+ if (token)
2326
+ funcs.push(this.patterns[token]);
2327
+ return str;
2328
+ });
2329
+ return this.patterns[pattern] = (arg) => {
2330
+ return funcs.reduce((res, func) => res + func(arg), '');
2331
+ };
2490
2332
  }
2491
- get value() {
2492
- var values = [];
2493
- for (var child of this.sub) {
2494
- if (child.type)
2495
- continue;
2496
- values.push(child.value);
2497
- }
2498
- return this.data + values.join("\n");
2333
+ toString(pattern) {
2334
+ const Base = this.constructor;
2335
+ const formatter = Base.formatter(pattern);
2336
+ return formatter(this);
2499
2337
  }
2500
- insert(value, ...path) {
2501
- if (path.length === 0)
2502
- return value;
2503
- const type = path[0];
2504
- if (typeof type === 'string') {
2505
- let replaced = false;
2506
- const sub = this.sub.map((item, index) => {
2507
- if (item.type !== type)
2508
- return item;
2509
- replaced = true;
2510
- return item.insert(value, ...path.slice(1));
2511
- });
2512
- if (!replaced)
2513
- sub.push(new $mol_tree({ type }).insert(value, ...path.slice(1)));
2514
- return this.clone({ sub });
2515
- }
2516
- else if (typeof type === 'number') {
2517
- const sub = this.sub.slice();
2518
- sub[type] = (sub[type] || new $mol_tree).insert(value, ...path.slice(1));
2519
- return this.clone({ sub });
2520
- }
2521
- else {
2522
- return this.clone({ sub: ((this.sub.length === 0) ? [new $mol_tree()] : this.sub).map(item => item.insert(value, ...path.slice(1))) });
2338
+ }
2339
+ $.$mol_time_base = $mol_time_base;
2340
+ })($ || ($ = {}));
2341
+ //mol/time/base/base.ts
2342
+ ;
2343
+ "use strict";
2344
+ var $;
2345
+ (function ($) {
2346
+ $mol_test({
2347
+ 'parse and serial'() {
2348
+ $mol_assert_equal(new $mol_time_duration('P42.1Y').toString(), 'P42.1YT');
2349
+ $mol_assert_equal(new $mol_time_duration('P42.1M').toString(), 'P42.1MT');
2350
+ $mol_assert_equal(new $mol_time_duration('P42.1D').toString(), 'P42.1DT');
2351
+ $mol_assert_equal(new $mol_time_duration('PT42.1h').toString(), 'PT42.1H');
2352
+ $mol_assert_equal(new $mol_time_duration('PT42.1m').toString(), 'PT42.1M');
2353
+ $mol_assert_equal(new $mol_time_duration('PT42.1s').toString(), 'PT42.1S');
2354
+ $mol_assert_equal(new $mol_time_duration('P1Y2M3DT4h5m6.7s').toString(), 'P1Y2M3DT4H5M6.7S');
2355
+ },
2356
+ 'format typed'() {
2357
+ $mol_assert_equal(new $mol_time_duration('P1Y2M3DT4h5m6s').toString('P#Y#M#DT#h#m#s'), 'P1Y2M3DT4H5M6S');
2358
+ },
2359
+ 'comparison'() {
2360
+ const iso = 'P1Y1M1DT1h1m1s';
2361
+ $mol_assert_like(new $mol_time_duration(iso), new $mol_time_duration(iso));
2362
+ },
2363
+ });
2364
+ })($ || ($ = {}));
2365
+ //mol/time/duration/duration.test.ts
2366
+ ;
2367
+ "use strict";
2368
+ var $;
2369
+ (function ($) {
2370
+ class $mol_time_duration extends $mol_time_base {
2371
+ constructor(config = 0) {
2372
+ super();
2373
+ if (typeof config === 'number') {
2374
+ this.second = config / 1000;
2375
+ return;
2523
2376
  }
2524
- }
2525
- select(...path) {
2526
- var next = [this];
2527
- for (var type of path) {
2528
- if (!next.length)
2529
- break;
2530
- var prev = next;
2531
- next = [];
2532
- for (var item of prev) {
2533
- switch (typeof (type)) {
2534
- case 'string':
2535
- for (var child of item.sub) {
2536
- if (!type || (child.type == type)) {
2537
- next.push(child);
2538
- }
2539
- }
2540
- break;
2541
- case 'number':
2542
- if (type < item.sub.length)
2543
- next.push(item.sub[type]);
2544
- break;
2545
- default: next.push(...item.sub);
2546
- }
2377
+ if (typeof config === 'string') {
2378
+ if (config === 'Z') {
2379
+ this.hour = 0;
2380
+ this.minute = 0;
2381
+ return;
2547
2382
  }
2548
- }
2549
- return new $mol_tree({ sub: next });
2550
- }
2551
- filter(path, value) {
2552
- var sub = this.sub.filter(function (item) {
2553
- var found = item.select(...path);
2554
- if (value == null) {
2555
- return Boolean(found.sub.length);
2383
+ duration: {
2384
+ const parser = /^P(?:([+-]?\d+(?:\.\d+)?)Y)?(?:([+-]?\d+(?:\.\d+)?)M)?(?:([+-]?\d+(?:\.\d+)?)D)?(?:T(?:([+-]?\d+(?:\.\d+)?)h)?(?:([+-]?\d+(?:\.\d+)?)m)?(?:([+-]?\d+(?:\.\d+)?)s)?)?$/i;
2385
+ const found = parser.exec(config);
2386
+ if (!found)
2387
+ break duration;
2388
+ if (found[1])
2389
+ this.year = Number(found[1]);
2390
+ if (found[2])
2391
+ this.month = Number(found[2]);
2392
+ if (found[3])
2393
+ this.day = Number(found[3]);
2394
+ if (found[4])
2395
+ this.hour = Number(found[4]);
2396
+ if (found[5])
2397
+ this.minute = Number(found[5]);
2398
+ if (found[6])
2399
+ this.second = Number(found[6]);
2400
+ return;
2556
2401
  }
2557
- else {
2558
- return found.sub.some(child => child.value == value);
2402
+ offset: {
2403
+ var parser = /^[+-](\d\d)(?::?(\d\d))?$/i;
2404
+ var found = parser.exec(config);
2405
+ if (!found)
2406
+ break offset;
2407
+ if (found[1])
2408
+ this.hour = Number(found[1]);
2409
+ if (found[2])
2410
+ this.minute = Number(found[2]);
2411
+ return;
2559
2412
  }
2413
+ throw new Error(`Can not parse time duration (${config})`);
2414
+ }
2415
+ this.year = config.year || 0;
2416
+ this.month = config.month || 0;
2417
+ this.day = config.day || 0;
2418
+ this.hour = config.hour || 0;
2419
+ this.minute = config.minute || 0;
2420
+ this.second = config.second || 0;
2421
+ }
2422
+ year = 0;
2423
+ month = 0;
2424
+ day = 0;
2425
+ hour = 0;
2426
+ minute = 0;
2427
+ second = 0;
2428
+ summ(config) {
2429
+ const duration = new $mol_time_duration(config);
2430
+ return new $mol_time_duration({
2431
+ year: this.year + duration.year,
2432
+ month: this.month + duration.month,
2433
+ day: this.day + duration.day,
2434
+ hour: this.hour + duration.hour,
2435
+ minute: this.minute + duration.minute,
2436
+ second: this.second + duration.second,
2560
2437
  });
2561
- return new $mol_tree({ sub: sub });
2562
2438
  }
2563
- transform(visit, stack = []) {
2564
- const sub_stack = [this, ...stack];
2565
- return visit(sub_stack, () => this.sub.map(node => node.transform(visit, sub_stack)).filter(n => n));
2439
+ mult(numb) {
2440
+ return new $mol_time_duration({
2441
+ year: this.year && this.year * numb,
2442
+ month: this.month && this.month * numb,
2443
+ day: this.day && this.day * numb,
2444
+ hour: this.hour && this.hour * numb,
2445
+ minute: this.minute && this.minute * numb,
2446
+ second: this.second && this.second * numb,
2447
+ });
2566
2448
  }
2567
- hack(context) {
2568
- const sub = [].concat(...this.sub.map(child => {
2569
- const handle = context[child.type] || context[''];
2570
- if (!handle)
2571
- $mol_fail(child.error('Handler not defined'));
2572
- return handle(child, context);
2573
- }));
2574
- return this.clone({ sub });
2449
+ count(config) {
2450
+ const duration = new $mol_time_duration(config);
2451
+ return this.valueOf() / duration.valueOf();
2575
2452
  }
2576
- error(message) {
2577
- return new Error(`${message}:\n${this} ${this.baseUri}:${this.row}:${this.col}`);
2453
+ valueOf() {
2454
+ var day = this.year * 365 + this.month * 30.4 + this.day;
2455
+ var second = ((day * 24 + this.hour) * 60 + this.minute) * 60 + this.second;
2456
+ return second * 1000;
2457
+ }
2458
+ toJSON() { return this.toString(); }
2459
+ toString(pattern = 'P#Y#M#DT#h#m#s') {
2460
+ return super.toString(pattern);
2461
+ }
2462
+ [Symbol.toPrimitive](mode) {
2463
+ return mode === 'number' ? this.valueOf() : this.toString();
2578
2464
  }
2465
+ static patterns = {
2466
+ '#Y': (duration) => {
2467
+ if (!duration.year)
2468
+ return '';
2469
+ return duration.year + 'Y';
2470
+ },
2471
+ '#M': (duration) => {
2472
+ if (!duration.month)
2473
+ return '';
2474
+ return duration.month + 'M';
2475
+ },
2476
+ '#D': (duration) => {
2477
+ if (!duration.day)
2478
+ return '';
2479
+ return duration.day + 'D';
2480
+ },
2481
+ '#h': (duration) => {
2482
+ if (!duration.hour)
2483
+ return '';
2484
+ return duration.hour + 'H';
2485
+ },
2486
+ '#m': (duration) => {
2487
+ if (!duration.minute)
2488
+ return '';
2489
+ return duration.minute + 'M';
2490
+ },
2491
+ '#s': (duration) => {
2492
+ if (!duration.second)
2493
+ return '';
2494
+ return duration.second + 'S';
2495
+ },
2496
+ };
2579
2497
  }
2580
- __decorate([
2581
- $mol_deprecated('Use $mol_tree:hack')
2582
- ], $mol_tree.prototype, "transform", null);
2583
- $.$mol_tree = $mol_tree;
2498
+ $.$mol_time_duration = $mol_time_duration;
2584
2499
  })($ || ($ = {}));
2585
- //mol/tree/tree.ts
2500
+ //mol/time/duration/duration.ts
2501
+ ;
2502
+ "use strict";
2503
+ //mol/type/param/param.test.ts
2504
+ ;
2505
+ "use strict";
2506
+ //mol/type/tail/tail.test.ts
2507
+ ;
2508
+ "use strict";
2509
+ var $;
2510
+ (function ($) {
2511
+ $mol_test({
2512
+ 'function'() {
2513
+ $mol_assert_not($mol_func_is_class(function () { }));
2514
+ },
2515
+ 'generator'() {
2516
+ $mol_assert_not($mol_func_is_class(function* () { }));
2517
+ },
2518
+ 'async'() {
2519
+ $mol_assert_not($mol_func_is_class(async function () { }));
2520
+ },
2521
+ 'arrow'() {
2522
+ $mol_assert_not($mol_func_is_class(() => null));
2523
+ },
2524
+ 'named class'() {
2525
+ $mol_assert_ok($mol_func_is_class(class Foo {
2526
+ }));
2527
+ },
2528
+ 'unnamed class'() {
2529
+ $mol_assert_ok($mol_func_is_class(class {
2530
+ }));
2531
+ },
2532
+ });
2533
+ })($ || ($ = {}));
2534
+ //mol/func/is/class/class.test.ts
2535
+ ;
2536
+ "use strict";
2537
+ //mol/type/result/result.test.ts
2538
+ ;
2539
+ "use strict";
2540
+ //mol/type/foot/foot.test.ts
2541
+ ;
2542
+ "use strict";
2543
+ var $;
2544
+ (function ($) {
2545
+ $mol_test({
2546
+ 'single function'() {
2547
+ const stringify = $mol_data_pipe((input) => input.toString());
2548
+ $mol_assert_equal(stringify(5), '5');
2549
+ },
2550
+ 'two functions'() {
2551
+ const isLong = $mol_data_pipe((input) => input.toString(), (input) => input.length > 2);
2552
+ $mol_assert_equal(isLong(5.0), false);
2553
+ $mol_assert_equal(isLong(5.1), true);
2554
+ },
2555
+ 'three functions'() {
2556
+ const pattern = $mol_data_pipe((input) => input.toString(), (input) => new RegExp(input), (input) => input.toString());
2557
+ $mol_assert_equal(pattern(5), '/5/');
2558
+ },
2559
+ 'classes'() {
2560
+ class Box {
2561
+ value;
2562
+ constructor(value) {
2563
+ this.value = value;
2564
+ }
2565
+ }
2566
+ const boxify = $mol_data_pipe((input) => input.toString(), Box);
2567
+ $mol_assert_ok(boxify(5) instanceof Box);
2568
+ $mol_assert_like(boxify(5).value, '5');
2569
+ },
2570
+ });
2571
+ })($ || ($ = {}));
2572
+ //mol/data/pipe/pipe.test.ts
2573
+ ;
2574
+ "use strict";
2575
+ var $;
2576
+ (function ($) {
2577
+ $mol_test({
2578
+ '(De)Serialization'() {
2579
+ const Duration = $mol_data_wrapper($mol_data_variant($mol_data_string, $mol_data_integer), $mol_time_duration);
2580
+ $mol_assert_equal(JSON.stringify(Duration('P1D')), '"P1DT"');
2581
+ $mol_assert_equal(JSON.stringify(Duration(1000)), '"PT1S"');
2582
+ },
2583
+ });
2584
+ })($ || ($ = {}));
2585
+ //mol/data/wrapper/wrapper.test.ts
2586
2586
 
2587
2587
  //# sourceMappingURL=node.test.js.map