@wcstack/typescript 4.1.1 → 4.3.0

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/dist/tsc-core.cjs CHANGED
@@ -255,11 +255,17 @@ function optionsRequired(fnName) {
255
255
  function optionMustBeNumber(fnName) {
256
256
  raise(27, [fnName]);
257
257
  }
258
- function valueMustBeNumber(fnName) {
259
- raise(28, [fnName]);
258
+ function styleInvalid(fnName, value) {
259
+ raise(52, [fnName, value]);
260
260
  }
261
- function valueMustBeDate(fnName) {
262
- raise(29, [fnName]);
261
+ function currencyInvalid(value) {
262
+ raise(53, [value]);
263
+ }
264
+ function valueMustBeNumber(fnName, value) {
265
+ raise(28, [fnName, value]);
266
+ }
267
+ function valueMustBeDate(fnName, value) {
268
+ raise(29, [fnName, value]);
263
269
  }
264
270
  function valueMustBeArray(fnName) {
265
271
  raise(30, [fnName]);
@@ -326,7 +332,7 @@ var numeric = (name, op) => ({
326
332
  const opt = requiredNumberOption(options, 0, name);
327
333
  return (value) => {
328
334
  if (typeof value !== "number") {
329
- valueMustBeNumber(name);
335
+ valueMustBeNumber(name, value);
330
336
  }
331
337
  return op(value, opt);
332
338
  };
@@ -356,7 +362,7 @@ var toFixed = (options) => {
356
362
  const opt = numberOption(options?.[0] ?? "0", "toFixed");
357
363
  return (value) => {
358
364
  if (typeof value !== "number") {
359
- valueMustBeNumber("toFixed");
365
+ valueMustBeNumber("toFixed", value);
360
366
  }
361
367
  return value.toFixed(opt);
362
368
  };
@@ -365,7 +371,7 @@ var round = (options) => {
365
371
  const optValue = Math.pow(10, numberOption(options?.[0] ?? "0", "round"));
366
372
  return (value) => {
367
373
  if (typeof value !== "number") {
368
- valueMustBeNumber("round");
374
+ valueMustBeNumber("round", value);
369
375
  }
370
376
  return Math.round(value * optValue) / optValue;
371
377
  };
@@ -374,7 +380,7 @@ var floor = (options) => {
374
380
  const optValue = Math.pow(10, numberOption(options?.[0] ?? "0", "floor"));
375
381
  return (value) => {
376
382
  if (typeof value !== "number") {
377
- valueMustBeNumber("floor");
383
+ valueMustBeNumber("floor", value);
378
384
  }
379
385
  return Math.floor(value * optValue) / optValue;
380
386
  };
@@ -383,7 +389,7 @@ var ceil = (options) => {
383
389
  const optValue = Math.pow(10, numberOption(options?.[0] ?? "0", "ceil"));
384
390
  return (value) => {
385
391
  if (typeof value !== "number") {
386
- valueMustBeNumber("ceil");
392
+ valueMustBeNumber("ceil", value);
387
393
  }
388
394
  return Math.ceil(value * optValue) / optValue;
389
395
  };
@@ -392,7 +398,7 @@ var percent = (options) => {
392
398
  const opt = numberOption(options?.[0] ?? "0", "percent");
393
399
  return (value) => {
394
400
  if (typeof value !== "number") {
395
- valueMustBeNumber("percent");
401
+ valueMustBeNumber("percent", value);
396
402
  }
397
403
  return `${(value * 100).toFixed(opt)}%`;
398
404
  };
@@ -419,11 +425,29 @@ var locale = (options) => {
419
425
  const explicit = options?.[0];
420
426
  return (value) => {
421
427
  if (typeof value !== "number") {
422
- valueMustBeNumber("locale");
428
+ valueMustBeNumber("locale", value);
423
429
  }
424
430
  return value.toLocaleString(explicit ?? defaultLocale());
425
431
  };
426
432
  };
433
+ var currency = (options) => {
434
+ const code = options?.[0] ?? optionsRequired("currency");
435
+ const explicit = options?.[1];
436
+ const format = { style: "currency", currency: code };
437
+ try {
438
+ new Intl.NumberFormat("en", format);
439
+ const known = Intl.supportedValuesOf?.("currency");
440
+ if (known && !known.includes(code.toUpperCase())) throw 0;
441
+ } catch {
442
+ currencyInvalid(code);
443
+ }
444
+ return (value) => {
445
+ if (typeof value !== "number") {
446
+ valueMustBeNumber("currency", value);
447
+ }
448
+ return value.toLocaleString(explicit ?? defaultLocale(), format);
449
+ };
450
+ };
427
451
  var upper = () => (value) => String(value).toUpperCase();
428
452
  var lower = () => (value) => String(value).toLowerCase();
429
453
  var capitalize = () => (value) => {
@@ -480,38 +504,48 @@ var join = (options) => {
480
504
  return value.join(opt);
481
505
  };
482
506
  };
507
+ var STYLES = ["full", "long", "medium", "short"];
508
+ function dateOptions(options, fn) {
509
+ let [loc, style] = options ?? [];
510
+ if (style === void 0 && loc !== void 0 && STYLES.includes(loc)) [loc, style] = [void 0, loc];
511
+ if (style !== void 0 && !STYLES.includes(style)) styleInvalid(fn, style);
512
+ return [loc, style];
513
+ }
483
514
  var date = (options) => {
484
- const explicit = options?.[0];
515
+ const [explicit, style] = dateOptions(options, "date");
516
+ const format = style && { dateStyle: style };
485
517
  return (value) => {
486
518
  if (!(value instanceof Date)) {
487
- valueMustBeDate("date");
519
+ valueMustBeDate("date", value);
488
520
  }
489
- return value.toLocaleDateString(explicit ?? defaultLocale());
521
+ return value.toLocaleDateString(explicit ?? defaultLocale(), format);
490
522
  };
491
523
  };
492
524
  var time = (options) => {
493
- const explicit = options?.[0];
525
+ const [explicit, style] = dateOptions(options, "time");
526
+ const format = style && { timeStyle: style };
494
527
  return (value) => {
495
528
  if (!(value instanceof Date)) {
496
- valueMustBeDate("time");
529
+ valueMustBeDate("time", value);
497
530
  }
498
- return value.toLocaleTimeString(explicit ?? defaultLocale());
531
+ return value.toLocaleTimeString(explicit ?? defaultLocale(), format);
499
532
  };
500
533
  };
501
534
  var datetime = (options) => {
502
- const explicit = options?.[0];
535
+ const [explicit, style] = dateOptions(options, "datetime");
536
+ const format = style && { dateStyle: style, timeStyle: style };
503
537
  return (value) => {
504
538
  if (!(value instanceof Date)) {
505
- valueMustBeDate("datetime");
539
+ valueMustBeDate("datetime", value);
506
540
  }
507
- return value.toLocaleString(explicit ?? defaultLocale());
541
+ return value.toLocaleString(explicit ?? defaultLocale(), format);
508
542
  };
509
543
  };
510
544
  var ymd = (options) => {
511
545
  const opt = options?.[0] ?? "-";
512
546
  return (value) => {
513
547
  if (!(value instanceof Date)) {
514
- valueMustBeDate("ymd");
548
+ valueMustBeDate("ymd", value);
515
549
  }
516
550
  const year = value.getFullYear().toString();
517
551
  const month = (value.getMonth() + 1).toString().padStart(2, "0");
@@ -523,7 +557,7 @@ var hms = (options) => {
523
557
  const opt = options?.[0] ?? ":";
524
558
  return (value) => {
525
559
  if (!(value instanceof Date)) {
526
- valueMustBeDate("hms");
560
+ valueMustBeDate("hms", value);
527
561
  }
528
562
  const hours = value.getHours().toString().padStart(2, "0");
529
563
  const minutes = value.getMinutes().toString().padStart(2, "0");
@@ -533,7 +567,7 @@ var hms = (options) => {
533
567
  };
534
568
  var abs = () => (value) => {
535
569
  if (typeof value !== "number") {
536
- valueMustBeNumber("abs");
570
+ valueMustBeNumber("abs", value);
537
571
  }
538
572
  return Math.abs(value);
539
573
  };
@@ -542,7 +576,7 @@ var clamp = (options) => {
542
576
  const max = requiredNumberOption(options, 1, "clamp");
543
577
  return (value) => {
544
578
  if (typeof value !== "number") {
545
- valueMustBeNumber("clamp");
579
+ valueMustBeNumber("clamp", value);
546
580
  }
547
581
  return Math.min(Math.max(value, min), max);
548
582
  };
@@ -589,10 +623,10 @@ var registered = {
589
623
  ceil: { factory: ceil, arity: [0, 1] },
590
624
  percent: { factory: percent, arity: [0, 1] },
591
625
  unit: { factory: nullishPassthrough(unit), arity: [1, 1] },
592
- // The locale-dependent three take a locale like `locale` does (`date(ja-JP)`)
593
- date: { factory: date, arity: [0, 1] },
594
- time: { factory: time, arity: [0, 1] },
595
- datetime: { factory: datetime, arity: [0, 1] },
626
+ // The locale-dependent three take a locale like `locale` does (`date(ja-JP)`), and a style (`date(ja-JP,long)`)
627
+ date: { factory: date, arity: [0, 2] },
628
+ time: { factory: time, arity: [0, 2] },
629
+ datetime: { factory: datetime, arity: [0, 2] },
596
630
  ymd: { factory: ymd, arity: [0, 1] },
597
631
  hms: { factory: hms, arity: [0, 1] },
598
632
  // the core set of 4.0.0-rc.3 (the core's own: eq ne not lt le gt ge falsy truthy boolean)
@@ -619,7 +653,9 @@ var registered = {
619
653
  boolean: boolean2,
620
654
  number: { factory: number, arity: [0, 0] },
621
655
  string: { factory: string, arity: [0, 0] },
622
- nullIfEmpty: { factory: nullIfEmpty, arity: [0, 0] }
656
+ nullIfEmpty: { factory: nullIfEmpty, arity: [0, 0] },
657
+ // (added in 4.2: last, so the order of the others is unchanged)
658
+ currency: { factory: currency, arity: [1, 2] }
623
659
  };
624
660
  var formatFilters = /* @__PURE__ */ Object.fromEntries(
625
661
  /* @__PURE__ */ Object.entries(registered).filter(([name]) => !(name in coreFilters))
@@ -651,10 +687,11 @@ var builtinFilterMeta = {
651
687
  // `not` は真偽性(truthy / falsy)の反転。`if:` が `Boolean()` で寄せるのと同じ規則で、
652
688
  // `else:` はこのフィルタを足した束縛として組み立てられる(structural/createNotFilter.ts)
653
689
  not: { description: "\u771F\u507D\u6027\u3092\u53CD\u8EE2\uFF08falsy \u2192 true\uFF09", hasArgs: false, resultType: "boolean", acceptTypes: "any", minArgs: 0, maxArgs: 0 },
654
- lt: { description: "\u3088\u308A\u5C0F\u3055\u3044\u304B", hasArgs: true, resultType: "boolean", acceptTypes: ["number", "string"], minArgs: 1, maxArgs: 1, argTypes: ["number"] },
655
- le: { description: "\u4EE5\u4E0B\u304B", hasArgs: true, resultType: "boolean", acceptTypes: ["number", "string"], minArgs: 1, maxArgs: 1, argTypes: ["number"] },
656
- gt: { description: "\u3088\u308A\u5927\u304D\u3044\u304B", hasArgs: true, resultType: "boolean", acceptTypes: ["number", "string"], minArgs: 1, maxArgs: 1, argTypes: ["number"] },
657
- ge: { description: "\u4EE5\u4E0A\u304B", hasArgs: true, resultType: "boolean", acceptTypes: ["number", "string"], minArgs: 1, maxArgs: 1, argTypes: ["number"] },
690
+ // 比較は数値だけを受ける(filters/core.ts の `numeric` は数値以外の値で #28。3.x も同じで、"string" は誤りだった)
691
+ lt: { description: "\u3088\u308A\u5C0F\u3055\u3044\u304B", hasArgs: true, resultType: "boolean", acceptTypes: ["number"], minArgs: 1, maxArgs: 1, argTypes: ["number"] },
692
+ le: { description: "\u4EE5\u4E0B\u304B", hasArgs: true, resultType: "boolean", acceptTypes: ["number"], minArgs: 1, maxArgs: 1, argTypes: ["number"] },
693
+ gt: { description: "\u3088\u308A\u5927\u304D\u3044\u304B", hasArgs: true, resultType: "boolean", acceptTypes: ["number"], minArgs: 1, maxArgs: 1, argTypes: ["number"] },
694
+ ge: { description: "\u4EE5\u4E0A\u304B", hasArgs: true, resultType: "boolean", acceptTypes: ["number"], minArgs: 1, maxArgs: 1, argTypes: ["number"] },
658
695
  // 算術
659
696
  add: { description: "\u52A0\u7B97", hasArgs: true, resultType: "number", acceptTypes: ["number"], minArgs: 1, maxArgs: 1, argTypes: ["number"] },
660
697
  sub: { description: "\u6E1B\u7B97", hasArgs: true, resultType: "number", acceptTypes: ["number"], minArgs: 1, maxArgs: 1, argTypes: ["number"] },
@@ -690,10 +727,11 @@ var builtinFilterMeta = {
690
727
  unit: { description: "\u5358\u4F4D\uFF08\u63A5\u5C3E\u8F9E\uFF09\u3092\u4ED8\u52A0", hasArgs: true, resultType: "string", acceptTypes: ["number", "string"], minArgs: 1, maxArgs: 1, argTypes: ["string"] },
691
728
  // 日付・時刻
692
729
  // `locale` と同じくロケールを 1 つ受ける(`date(ja-JP)`)。実装は最初からこれを読んでいたが、
693
- // メタデータ側が maxArgs: 0 だったため lint と補完が正しい書き方を誤りとして報告していた
694
- date: { description: "\u30ED\u30B1\u30FC\u30EB\u5F62\u5F0F\u306E\u65E5\u4ED8 ([locale]\u3002\u65E2\u5B9A\u306F config.locale)", hasArgs: true, resultType: "string", acceptTypes: "any", minArgs: 0, maxArgs: 1, argTypes: ["string"] },
695
- time: { description: "\u30ED\u30B1\u30FC\u30EB\u5F62\u5F0F\u306E\u6642\u523B ([locale]\u3002\u65E2\u5B9A\u306F config.locale)", hasArgs: true, resultType: "string", acceptTypes: "any", minArgs: 0, maxArgs: 1, argTypes: ["string"] },
696
- datetime: { description: "\u30ED\u30B1\u30FC\u30EB\u5F62\u5F0F\u306E\u65E5\u6642 ([locale]\u3002\u65E2\u5B9A\u306F config.locale)", hasArgs: true, resultType: "string", acceptTypes: "any", minArgs: 0, maxArgs: 1, argTypes: ["string"] },
730
+ // メタデータ側が maxArgs: 0 だったため lint と補完が正しい書き方を誤りとして報告していた。
731
+ // 4.2: 2 つ目は書式(full / long / medium / short — Intl の dateStyle / timeStyle)。書式だけなら既定のロケール
732
+ date: { description: "\u30ED\u30B1\u30FC\u30EB\u5F62\u5F0F\u306E\u65E5\u4ED8 ([locale][, style]\u3002style \u306F full / long / medium / short\u3001\u65E2\u5B9A\u306E\u30ED\u30B1\u30FC\u30EB\u306F config.locale)", hasArgs: true, resultType: "string", acceptTypes: "any", minArgs: 0, maxArgs: 2, argTypes: ["string", "string"] },
733
+ time: { description: "\u30ED\u30B1\u30FC\u30EB\u5F62\u5F0F\u306E\u6642\u523B ([locale][, style]\u3002style \u306F full / long / medium / short\u3001\u65E2\u5B9A\u306E\u30ED\u30B1\u30FC\u30EB\u306F config.locale)", hasArgs: true, resultType: "string", acceptTypes: "any", minArgs: 0, maxArgs: 2, argTypes: ["string", "string"] },
734
+ datetime: { description: "\u30ED\u30B1\u30FC\u30EB\u5F62\u5F0F\u306E\u65E5\u6642 ([locale][, style]\u3002style \u306F full / long / medium / short\u3001\u65E2\u5B9A\u306E\u30ED\u30B1\u30FC\u30EB\u306F config.locale)", hasArgs: true, resultType: "string", acceptTypes: "any", minArgs: 0, maxArgs: 2, argTypes: ["string", "string"] },
697
735
  ymd: { description: "YYYY-MM-DD \u5F62\u5F0F ([separator]\u3002\u65E2\u5B9A\u306F -)", hasArgs: true, resultType: "string", acceptTypes: "any", minArgs: 0, maxArgs: 1, argTypes: ["string"] },
698
736
  hms: { description: "HH:MM:SS \u5F62\u5F0F ([separator]\u3002\u65E2\u5B9A\u306F :)", hasArgs: true, resultType: "string", acceptTypes: "any", minArgs: 0, maxArgs: 1, argTypes: ["string"] },
699
737
  // 真偽値・変換
@@ -704,7 +742,9 @@ var builtinFilterMeta = {
704
742
  boolean: { description: "\u30D6\u30FC\u30EB\u5024\u306B\u5909\u63DB", hasArgs: false, resultType: "boolean", acceptTypes: "any", minArgs: 0, maxArgs: 0 },
705
743
  number: { description: "\u6570\u5024\u306B\u5909\u63DB", hasArgs: false, resultType: "number", acceptTypes: "any", minArgs: 0, maxArgs: 0 },
706
744
  string: { description: "\u6587\u5B57\u5217\u306B\u5909\u63DB", hasArgs: false, resultType: "string", acceptTypes: "any", minArgs: 0, maxArgs: 0 },
707
- nullIfEmpty: { description: "\u7A7A\u6587\u5B57\u5217\u3092null\u306B\u5909\u63DB", hasArgs: false, resultType: "passthrough", acceptTypes: ["string"], minArgs: 0, maxArgs: 0 }
745
+ nullIfEmpty: { description: "\u7A7A\u6587\u5B57\u5217\u3092null\u306B\u5909\u63DB", hasArgs: false, resultType: "passthrough", acceptTypes: ["string"], minArgs: 0, maxArgs: 0 },
746
+ // 4.2(formats の最後に登録)
747
+ currency: { description: "\u901A\u8CA8\u306E\u66F8\u5F0F (code[, locale]\u3002code \u306F ISO 4217 \u2014 JPY / USD / EUR\u3001\u65E2\u5B9A\u306E\u30ED\u30B1\u30FC\u30EB\u306F config.locale)", hasArgs: true, resultType: "string", acceptTypes: ["number"], minArgs: 1, maxArgs: 2, argTypes: ["string", "string"] }
708
748
  };
709
749
  var WCS_MANIFEST_VERSION = 2;
710
750
  var builtinFilterAliases = Object.freeze({});
@@ -573,7 +573,7 @@ function loadSchemaCore() {
573
573
  return cached;
574
574
  }
575
575
 
576
- var version = "4.1.1";
576
+ var version = "4.3.0";
577
577
  var pkg = {
578
578
  version: version};
579
579
 
package/dist/wcs-tsc.mjs CHANGED
@@ -5,7 +5,7 @@ import { tmpdir } from 'node:os';
5
5
  import { dirname, join, isAbsolute, resolve, basename } from 'node:path';
6
6
  import { fileURLToPath } from 'node:url';
7
7
 
8
- var version = "4.1.1";
8
+ var version = "4.3.0";
9
9
  var pkg = {
10
10
  version: version};
11
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wcstack/typescript",
3
- "version": "4.1.1",
3
+ "version": "4.3.0",
4
4
  "description": "TypeScript tooling for wcstack apps: wcs-schema generates the sidecar stateSchema from a typed state file, so wcs-validate checks data-wcs paths against real types in CI and every editor.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.esm.js",