@morphql/language-definitions 0.1.26 → 0.1.28

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/index.cjs CHANGED
@@ -466,6 +466,175 @@ var FUNCTIONS = [
466
466
  returns: "array",
467
467
  example: "array(1, 2, 3) // [1, 2, 3]"
468
468
  }
469
+ },
470
+ // ── Math functions ────────────────────────────────────────────────────────
471
+ {
472
+ name: "floor",
473
+ doc: {
474
+ signature: "floor(value)",
475
+ description: "Rounds a number down to the nearest integer.",
476
+ parameters: [{ name: "value", description: "The number to round down" }],
477
+ returns: "number",
478
+ example: "floor(4.9) // 4"
479
+ }
480
+ },
481
+ {
482
+ name: "ceil",
483
+ doc: {
484
+ signature: "ceil(value)",
485
+ description: "Rounds a number up to the nearest integer.",
486
+ parameters: [{ name: "value", description: "The number to round up" }],
487
+ returns: "number",
488
+ example: "ceil(4.1) // 5"
489
+ }
490
+ },
491
+ {
492
+ name: "round",
493
+ doc: {
494
+ signature: "round(value, [mode])",
495
+ description: `Rounds a number to the nearest integer. Mode controls tie-breaking: "half-up" (default) rounds .5 away from zero; "half-even" uses banker's rounding (rounds .5 to the nearest even integer).`,
496
+ parameters: [
497
+ { name: "value", description: "The number to round" },
498
+ {
499
+ name: "mode",
500
+ description: '(Optional) Rounding mode: "half-up" (default) or "half-even"'
501
+ }
502
+ ],
503
+ returns: "number",
504
+ example: `round(4.5) // 5 (half-up)
505
+ round(4.5, "half-even") // 4 (banker's)
506
+ round(3.5, "half-even") // 4 (banker's)`
507
+ }
508
+ },
509
+ {
510
+ name: "abs",
511
+ doc: {
512
+ signature: "abs(value)",
513
+ description: "Returns the absolute value of a number.",
514
+ parameters: [{ name: "value", description: "The number" }],
515
+ returns: "number",
516
+ example: "abs(-42) // 42"
517
+ }
518
+ },
519
+ {
520
+ name: "fixed",
521
+ doc: {
522
+ signature: "fixed(value, [decimals], [mode])",
523
+ description: `Formats a number to a fixed number of decimal places. Mode controls tie-breaking: "half-up" (default) rounds .5 away from zero; "half-even" uses banker's rounding. Returns a string. Default decimals: 2.`,
524
+ parameters: [
525
+ { name: "value", description: "The number to format" },
526
+ {
527
+ name: "decimals",
528
+ description: "(Optional) Number of decimal places. Default: 2"
529
+ },
530
+ {
531
+ name: "mode",
532
+ description: '(Optional) Rounding mode: "half-up" (default) or "half-even"'
533
+ }
534
+ ],
535
+ returns: "string",
536
+ example: `fixed(2.5, 2) // "2.50" (half-up)
537
+ fixed(2.5, 2, "half-even") // "2.50" (banker's, no tie at 2 decimals)
538
+ fixed(2.5, 0, "half-even") // "2" (banker's, rounds to even)`
539
+ }
540
+ },
541
+ {
542
+ name: "min",
543
+ doc: {
544
+ signature: "min(a, b, ...)",
545
+ description: "Returns the smallest of two or more numbers.",
546
+ parameters: [{ name: "a, b, ...", description: "Numbers to compare" }],
547
+ returns: "number",
548
+ example: "min(3, 1, 4) // 1"
549
+ }
550
+ },
551
+ {
552
+ name: "max",
553
+ doc: {
554
+ signature: "max(a, b, ...)",
555
+ description: "Returns the largest of two or more numbers.",
556
+ parameters: [{ name: "a, b, ...", description: "Numbers to compare" }],
557
+ returns: "number",
558
+ example: "max(3, 1, 4) // 4"
559
+ }
560
+ },
561
+ // ── String functions ──────────────────────────────────────────────────────
562
+ {
563
+ name: "trim",
564
+ doc: {
565
+ signature: "trim(str)",
566
+ description: "Removes leading and trailing whitespace from a string.",
567
+ parameters: [{ name: "str", description: "The string to trim" }],
568
+ returns: "string",
569
+ example: 'trim(" hello ") // "hello"'
570
+ }
571
+ },
572
+ {
573
+ name: "padstart",
574
+ doc: {
575
+ signature: "padstart(str, length, [char])",
576
+ description: "Pads the start of a string with a character until it reaches the target length.",
577
+ parameters: [
578
+ { name: "str", description: "The string to pad" },
579
+ { name: "length", description: "Target total length" },
580
+ { name: "char", description: '(Optional) Pad character. Default: " "' }
581
+ ],
582
+ returns: "string",
583
+ example: 'padstart(id, 8, "0") // "00000042"'
584
+ }
585
+ },
586
+ {
587
+ name: "padend",
588
+ doc: {
589
+ signature: "padend(str, length, [char])",
590
+ description: "Pads the end of a string with a character until it reaches the target length.",
591
+ parameters: [
592
+ { name: "str", description: "The string to pad" },
593
+ { name: "length", description: "Target total length" },
594
+ { name: "char", description: '(Optional) Pad character. Default: " "' }
595
+ ],
596
+ returns: "string",
597
+ example: 'padend(name, 20) // "Alice "'
598
+ }
599
+ },
600
+ {
601
+ name: "indexof",
602
+ doc: {
603
+ signature: "indexof(str, search)",
604
+ description: "Returns the index of the first occurrence of a substring. Returns -1 if not found.",
605
+ parameters: [
606
+ { name: "str", description: "The string to search in" },
607
+ { name: "search", description: "The substring to find" }
608
+ ],
609
+ returns: "number",
610
+ example: 'indexof("hello world", "world") // 6'
611
+ }
612
+ },
613
+ {
614
+ name: "startswith",
615
+ doc: {
616
+ signature: "startswith(str, prefix)",
617
+ description: "Returns true if the string starts with the given prefix.",
618
+ parameters: [
619
+ { name: "str", description: "The string to check" },
620
+ { name: "prefix", description: "The prefix to look for" }
621
+ ],
622
+ returns: "boolean",
623
+ example: 'startswith("hello", "he") // true'
624
+ }
625
+ },
626
+ {
627
+ name: "endswith",
628
+ doc: {
629
+ signature: "endswith(str, suffix)",
630
+ description: "Returns true if the string ends with the given suffix.",
631
+ parameters: [
632
+ { name: "str", description: "The string to check" },
633
+ { name: "suffix", description: "The suffix to look for" }
634
+ ],
635
+ returns: "boolean",
636
+ example: 'endswith("hello", "lo") // true'
637
+ }
469
638
  }
470
639
  ];
471
640
  var getFunctionNames = () => FUNCTIONS.map((f) => f.name);
@@ -491,6 +660,7 @@ var OPERATORS = [
491
660
  { symbol: "-", category: "arithmetic", precedence: 10 },
492
661
  { symbol: "*", category: "arithmetic", precedence: 11 },
493
662
  { symbol: "/", category: "arithmetic", precedence: 11 },
663
+ { symbol: "%", category: "arithmetic", precedence: 11 },
494
664
  // Assignment
495
665
  { symbol: "=", category: "assignment", precedence: 1 }
496
666
  ];
package/dist/index.js CHANGED
@@ -424,6 +424,175 @@ var FUNCTIONS = [
424
424
  returns: "array",
425
425
  example: "array(1, 2, 3) // [1, 2, 3]"
426
426
  }
427
+ },
428
+ // ── Math functions ────────────────────────────────────────────────────────
429
+ {
430
+ name: "floor",
431
+ doc: {
432
+ signature: "floor(value)",
433
+ description: "Rounds a number down to the nearest integer.",
434
+ parameters: [{ name: "value", description: "The number to round down" }],
435
+ returns: "number",
436
+ example: "floor(4.9) // 4"
437
+ }
438
+ },
439
+ {
440
+ name: "ceil",
441
+ doc: {
442
+ signature: "ceil(value)",
443
+ description: "Rounds a number up to the nearest integer.",
444
+ parameters: [{ name: "value", description: "The number to round up" }],
445
+ returns: "number",
446
+ example: "ceil(4.1) // 5"
447
+ }
448
+ },
449
+ {
450
+ name: "round",
451
+ doc: {
452
+ signature: "round(value, [mode])",
453
+ description: `Rounds a number to the nearest integer. Mode controls tie-breaking: "half-up" (default) rounds .5 away from zero; "half-even" uses banker's rounding (rounds .5 to the nearest even integer).`,
454
+ parameters: [
455
+ { name: "value", description: "The number to round" },
456
+ {
457
+ name: "mode",
458
+ description: '(Optional) Rounding mode: "half-up" (default) or "half-even"'
459
+ }
460
+ ],
461
+ returns: "number",
462
+ example: `round(4.5) // 5 (half-up)
463
+ round(4.5, "half-even") // 4 (banker's)
464
+ round(3.5, "half-even") // 4 (banker's)`
465
+ }
466
+ },
467
+ {
468
+ name: "abs",
469
+ doc: {
470
+ signature: "abs(value)",
471
+ description: "Returns the absolute value of a number.",
472
+ parameters: [{ name: "value", description: "The number" }],
473
+ returns: "number",
474
+ example: "abs(-42) // 42"
475
+ }
476
+ },
477
+ {
478
+ name: "fixed",
479
+ doc: {
480
+ signature: "fixed(value, [decimals], [mode])",
481
+ description: `Formats a number to a fixed number of decimal places. Mode controls tie-breaking: "half-up" (default) rounds .5 away from zero; "half-even" uses banker's rounding. Returns a string. Default decimals: 2.`,
482
+ parameters: [
483
+ { name: "value", description: "The number to format" },
484
+ {
485
+ name: "decimals",
486
+ description: "(Optional) Number of decimal places. Default: 2"
487
+ },
488
+ {
489
+ name: "mode",
490
+ description: '(Optional) Rounding mode: "half-up" (default) or "half-even"'
491
+ }
492
+ ],
493
+ returns: "string",
494
+ example: `fixed(2.5, 2) // "2.50" (half-up)
495
+ fixed(2.5, 2, "half-even") // "2.50" (banker's, no tie at 2 decimals)
496
+ fixed(2.5, 0, "half-even") // "2" (banker's, rounds to even)`
497
+ }
498
+ },
499
+ {
500
+ name: "min",
501
+ doc: {
502
+ signature: "min(a, b, ...)",
503
+ description: "Returns the smallest of two or more numbers.",
504
+ parameters: [{ name: "a, b, ...", description: "Numbers to compare" }],
505
+ returns: "number",
506
+ example: "min(3, 1, 4) // 1"
507
+ }
508
+ },
509
+ {
510
+ name: "max",
511
+ doc: {
512
+ signature: "max(a, b, ...)",
513
+ description: "Returns the largest of two or more numbers.",
514
+ parameters: [{ name: "a, b, ...", description: "Numbers to compare" }],
515
+ returns: "number",
516
+ example: "max(3, 1, 4) // 4"
517
+ }
518
+ },
519
+ // ── String functions ──────────────────────────────────────────────────────
520
+ {
521
+ name: "trim",
522
+ doc: {
523
+ signature: "trim(str)",
524
+ description: "Removes leading and trailing whitespace from a string.",
525
+ parameters: [{ name: "str", description: "The string to trim" }],
526
+ returns: "string",
527
+ example: 'trim(" hello ") // "hello"'
528
+ }
529
+ },
530
+ {
531
+ name: "padstart",
532
+ doc: {
533
+ signature: "padstart(str, length, [char])",
534
+ description: "Pads the start of a string with a character until it reaches the target length.",
535
+ parameters: [
536
+ { name: "str", description: "The string to pad" },
537
+ { name: "length", description: "Target total length" },
538
+ { name: "char", description: '(Optional) Pad character. Default: " "' }
539
+ ],
540
+ returns: "string",
541
+ example: 'padstart(id, 8, "0") // "00000042"'
542
+ }
543
+ },
544
+ {
545
+ name: "padend",
546
+ doc: {
547
+ signature: "padend(str, length, [char])",
548
+ description: "Pads the end of a string with a character until it reaches the target length.",
549
+ parameters: [
550
+ { name: "str", description: "The string to pad" },
551
+ { name: "length", description: "Target total length" },
552
+ { name: "char", description: '(Optional) Pad character. Default: " "' }
553
+ ],
554
+ returns: "string",
555
+ example: 'padend(name, 20) // "Alice "'
556
+ }
557
+ },
558
+ {
559
+ name: "indexof",
560
+ doc: {
561
+ signature: "indexof(str, search)",
562
+ description: "Returns the index of the first occurrence of a substring. Returns -1 if not found.",
563
+ parameters: [
564
+ { name: "str", description: "The string to search in" },
565
+ { name: "search", description: "The substring to find" }
566
+ ],
567
+ returns: "number",
568
+ example: 'indexof("hello world", "world") // 6'
569
+ }
570
+ },
571
+ {
572
+ name: "startswith",
573
+ doc: {
574
+ signature: "startswith(str, prefix)",
575
+ description: "Returns true if the string starts with the given prefix.",
576
+ parameters: [
577
+ { name: "str", description: "The string to check" },
578
+ { name: "prefix", description: "The prefix to look for" }
579
+ ],
580
+ returns: "boolean",
581
+ example: 'startswith("hello", "he") // true'
582
+ }
583
+ },
584
+ {
585
+ name: "endswith",
586
+ doc: {
587
+ signature: "endswith(str, suffix)",
588
+ description: "Returns true if the string ends with the given suffix.",
589
+ parameters: [
590
+ { name: "str", description: "The string to check" },
591
+ { name: "suffix", description: "The suffix to look for" }
592
+ ],
593
+ returns: "boolean",
594
+ example: 'endswith("hello", "lo") // true'
595
+ }
427
596
  }
428
597
  ];
429
598
  var getFunctionNames = () => FUNCTIONS.map((f) => f.name);
@@ -449,6 +618,7 @@ var OPERATORS = [
449
618
  { symbol: "-", category: "arithmetic", precedence: 10 },
450
619
  { symbol: "*", category: "arithmetic", precedence: 11 },
451
620
  { symbol: "/", category: "arithmetic", precedence: 11 },
621
+ { symbol: "%", category: "arithmetic", precedence: 11 },
452
622
  // Assignment
453
623
  { symbol: "=", category: "assignment", precedence: 1 }
454
624
  ];
@@ -529,6 +529,241 @@
529
529
  "returns": "array",
530
530
  "example": "array(1, 2, 3) // [1, 2, 3]"
531
531
  }
532
+ },
533
+ {
534
+ "name": "floor",
535
+ "doc": {
536
+ "signature": "floor(value)",
537
+ "description": "Rounds a number down to the nearest integer.",
538
+ "parameters": [
539
+ {
540
+ "name": "value",
541
+ "description": "The number to round down"
542
+ }
543
+ ],
544
+ "returns": "number",
545
+ "example": "floor(4.9) // 4"
546
+ }
547
+ },
548
+ {
549
+ "name": "ceil",
550
+ "doc": {
551
+ "signature": "ceil(value)",
552
+ "description": "Rounds a number up to the nearest integer.",
553
+ "parameters": [
554
+ {
555
+ "name": "value",
556
+ "description": "The number to round up"
557
+ }
558
+ ],
559
+ "returns": "number",
560
+ "example": "ceil(4.1) // 5"
561
+ }
562
+ },
563
+ {
564
+ "name": "round",
565
+ "doc": {
566
+ "signature": "round(value, [mode])",
567
+ "description": "Rounds a number to the nearest integer. Mode controls tie-breaking: \"half-up\" (default) rounds .5 away from zero; \"half-even\" uses banker's rounding (rounds .5 to the nearest even integer).",
568
+ "parameters": [
569
+ {
570
+ "name": "value",
571
+ "description": "The number to round"
572
+ },
573
+ {
574
+ "name": "mode",
575
+ "description": "(Optional) Rounding mode: \"half-up\" (default) or \"half-even\""
576
+ }
577
+ ],
578
+ "returns": "number",
579
+ "example": "round(4.5) // 5 (half-up)\nround(4.5, \"half-even\") // 4 (banker's)\nround(3.5, \"half-even\") // 4 (banker's)"
580
+ }
581
+ },
582
+ {
583
+ "name": "abs",
584
+ "doc": {
585
+ "signature": "abs(value)",
586
+ "description": "Returns the absolute value of a number.",
587
+ "parameters": [
588
+ {
589
+ "name": "value",
590
+ "description": "The number"
591
+ }
592
+ ],
593
+ "returns": "number",
594
+ "example": "abs(-42) // 42"
595
+ }
596
+ },
597
+ {
598
+ "name": "fixed",
599
+ "doc": {
600
+ "signature": "fixed(value, [decimals], [mode])",
601
+ "description": "Formats a number to a fixed number of decimal places. Mode controls tie-breaking: \"half-up\" (default) rounds .5 away from zero; \"half-even\" uses banker's rounding. Returns a string. Default decimals: 2.",
602
+ "parameters": [
603
+ {
604
+ "name": "value",
605
+ "description": "The number to format"
606
+ },
607
+ {
608
+ "name": "decimals",
609
+ "description": "(Optional) Number of decimal places. Default: 2"
610
+ },
611
+ {
612
+ "name": "mode",
613
+ "description": "(Optional) Rounding mode: \"half-up\" (default) or \"half-even\""
614
+ }
615
+ ],
616
+ "returns": "string",
617
+ "example": "fixed(2.5, 2) // \"2.50\" (half-up)\nfixed(2.5, 2, \"half-even\") // \"2.50\" (banker's, no tie at 2 decimals)\nfixed(2.5, 0, \"half-even\") // \"2\" (banker's, rounds to even)"
618
+ }
619
+ },
620
+ {
621
+ "name": "min",
622
+ "doc": {
623
+ "signature": "min(a, b, ...)",
624
+ "description": "Returns the smallest of two or more numbers.",
625
+ "parameters": [
626
+ {
627
+ "name": "a, b, ...",
628
+ "description": "Numbers to compare"
629
+ }
630
+ ],
631
+ "returns": "number",
632
+ "example": "min(3, 1, 4) // 1"
633
+ }
634
+ },
635
+ {
636
+ "name": "max",
637
+ "doc": {
638
+ "signature": "max(a, b, ...)",
639
+ "description": "Returns the largest of two or more numbers.",
640
+ "parameters": [
641
+ {
642
+ "name": "a, b, ...",
643
+ "description": "Numbers to compare"
644
+ }
645
+ ],
646
+ "returns": "number",
647
+ "example": "max(3, 1, 4) // 4"
648
+ }
649
+ },
650
+ {
651
+ "name": "trim",
652
+ "doc": {
653
+ "signature": "trim(str)",
654
+ "description": "Removes leading and trailing whitespace from a string.",
655
+ "parameters": [
656
+ {
657
+ "name": "str",
658
+ "description": "The string to trim"
659
+ }
660
+ ],
661
+ "returns": "string",
662
+ "example": "trim(\" hello \") // \"hello\""
663
+ }
664
+ },
665
+ {
666
+ "name": "padstart",
667
+ "doc": {
668
+ "signature": "padstart(str, length, [char])",
669
+ "description": "Pads the start of a string with a character until it reaches the target length.",
670
+ "parameters": [
671
+ {
672
+ "name": "str",
673
+ "description": "The string to pad"
674
+ },
675
+ {
676
+ "name": "length",
677
+ "description": "Target total length"
678
+ },
679
+ {
680
+ "name": "char",
681
+ "description": "(Optional) Pad character. Default: \" \""
682
+ }
683
+ ],
684
+ "returns": "string",
685
+ "example": "padstart(id, 8, \"0\") // \"00000042\""
686
+ }
687
+ },
688
+ {
689
+ "name": "padend",
690
+ "doc": {
691
+ "signature": "padend(str, length, [char])",
692
+ "description": "Pads the end of a string with a character until it reaches the target length.",
693
+ "parameters": [
694
+ {
695
+ "name": "str",
696
+ "description": "The string to pad"
697
+ },
698
+ {
699
+ "name": "length",
700
+ "description": "Target total length"
701
+ },
702
+ {
703
+ "name": "char",
704
+ "description": "(Optional) Pad character. Default: \" \""
705
+ }
706
+ ],
707
+ "returns": "string",
708
+ "example": "padend(name, 20) // \"Alice \""
709
+ }
710
+ },
711
+ {
712
+ "name": "indexof",
713
+ "doc": {
714
+ "signature": "indexof(str, search)",
715
+ "description": "Returns the index of the first occurrence of a substring. Returns -1 if not found.",
716
+ "parameters": [
717
+ {
718
+ "name": "str",
719
+ "description": "The string to search in"
720
+ },
721
+ {
722
+ "name": "search",
723
+ "description": "The substring to find"
724
+ }
725
+ ],
726
+ "returns": "number",
727
+ "example": "indexof(\"hello world\", \"world\") // 6"
728
+ }
729
+ },
730
+ {
731
+ "name": "startswith",
732
+ "doc": {
733
+ "signature": "startswith(str, prefix)",
734
+ "description": "Returns true if the string starts with the given prefix.",
735
+ "parameters": [
736
+ {
737
+ "name": "str",
738
+ "description": "The string to check"
739
+ },
740
+ {
741
+ "name": "prefix",
742
+ "description": "The prefix to look for"
743
+ }
744
+ ],
745
+ "returns": "boolean",
746
+ "example": "startswith(\"hello\", \"he\") // true"
747
+ }
748
+ },
749
+ {
750
+ "name": "endswith",
751
+ "doc": {
752
+ "signature": "endswith(str, suffix)",
753
+ "description": "Returns true if the string ends with the given suffix.",
754
+ "parameters": [
755
+ {
756
+ "name": "str",
757
+ "description": "The string to check"
758
+ },
759
+ {
760
+ "name": "suffix",
761
+ "description": "The suffix to look for"
762
+ }
763
+ ],
764
+ "returns": "boolean",
765
+ "example": "endswith(\"hello\", \"lo\") // true"
766
+ }
532
767
  }
533
768
  ],
534
769
  "operators": [
@@ -607,6 +842,11 @@
607
842
  "category": "arithmetic",
608
843
  "precedence": 11
609
844
  },
845
+ {
846
+ "symbol": "%",
847
+ "category": "arithmetic",
848
+ "precedence": 11
849
+ },
610
850
  {
611
851
  "symbol": "=",
612
852
  "category": "assignment",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@morphql/language-definitions",
3
- "version": "0.1.26",
3
+ "version": "0.1.28",
4
4
  "description": "Shared language definitions for MorphQL across VSCode, Monaco, and documentation",
5
5
  "type": "module",
6
6
  "publishConfig": {