@fraqjs/fraq 0.3.0 → 0.3.1

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.
Files changed (2) hide show
  1. package/dist/index.mjs +30 -1
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -632,7 +632,36 @@ function msg(strings, ...values) {
632
632
  type: "text",
633
633
  data: { text: buffer }
634
634
  });
635
- return segments;
635
+ return trimBoundaryTextSegments(segments);
636
+ }
637
+ function isTextSegment(segment) {
638
+ return segment.type === "text";
639
+ }
640
+ function withText(segment, text) {
641
+ return {
642
+ ...segment,
643
+ data: {
644
+ ...segment.data,
645
+ text
646
+ }
647
+ };
648
+ }
649
+ function trimBoundaryTextSegments(segments) {
650
+ const result = [...segments];
651
+ const first = result[0];
652
+ if (first && isTextSegment(first)) {
653
+ const text = first.data.text.trimStart();
654
+ if (text) result[0] = withText(first, text);
655
+ else result.shift();
656
+ }
657
+ const lastIndex = result.length - 1;
658
+ const last = result[lastIndex];
659
+ if (last && isTextSegment(last)) {
660
+ const text = last.data.text.trimEnd();
661
+ if (text) result[lastIndex] = withText(last, text);
662
+ else result.pop();
663
+ }
664
+ return result;
636
665
  }
637
666
  let seg;
638
667
  (function(_seg) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fraqjs/fraq",
3
3
  "type": "module",
4
- "version": "0.3.0",
4
+ "version": "0.3.1",
5
5
  "description": "Milky Bot framework",
6
6
  "files": [
7
7
  "dist"