ptn-helpers 0.0.15 → 0.0.16

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/lib/index.d.ts CHANGED
@@ -1,25 +1,4 @@
1
- declare const FEED_LINK_KEYS: readonly ["title", "_ptr_open_graph_description", "_ptr_open_graph_site_name", "_ptr_open_graph_type"];
2
- declare type FeedLinkKey = typeof FEED_LINK_KEYS[number];
3
- declare type FeedAttachment = {
4
- [feedLinkKey in FeedLinkKey]: string;
5
- } & {
6
- _ptr_media_type: string;
7
- _ptr_open_graph_image_url?: string;
8
- url?: string;
9
- };
10
- export declare type FeedItem = {
11
- id: string;
12
- date_published: string;
13
- url: string;
14
- content_text: string;
15
- attachments?: FeedAttachment[];
16
- _ptr_sender_type: string;
17
- };
18
- export declare type PtnNode = {
19
- text: string;
20
- children: PtnNode[];
21
- uid?: string;
22
- };
1
+ import { FeedItem, PtnNode } from "./types";
2
+ export declare const FEED_LINK_KEYS: string[];
23
3
  export declare const itemToNode: (feedItem: FeedItem, hashtag: string) => PtnNode;
24
4
  export declare const organizeFeedItems: (feedItems: FeedItem[], dateFormat?: string) => Record<string, Record<string, FeedItem[]>>;
25
- export {};
package/lib/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.organizeFeedItems = exports.itemToNode = void 0;
4
- var FEED_LINK_KEYS = [
3
+ exports.organizeFeedItems = exports.itemToNode = exports.FEED_LINK_KEYS = void 0;
4
+ var date_fns_1 = require("date-fns");
5
+ exports.FEED_LINK_KEYS = [
5
6
  "title",
6
7
  "_ptr_open_graph_description",
7
8
  "_ptr_open_graph_site_name",
@@ -13,8 +14,9 @@ var itemToNode = function (feedItem, hashtag) {
13
14
  var text = (_a = feedItem === null || feedItem === void 0 ? void 0 : feedItem.content_text) !== null && _a !== void 0 ? _a : "";
14
15
  if (((_c = (_b = feedItem === null || feedItem === void 0 ? void 0 : feedItem.attachments) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) > 1 && ((_d = feedItem === null || feedItem === void 0 ? void 0 : feedItem.attachments) === null || _d === void 0 ? void 0 : _d[0]._ptr_media_type) === "text") {
15
16
  (_e = feedItem === null || feedItem === void 0 ? void 0 : feedItem.attachments) === null || _e === void 0 ? void 0 : _e.forEach(function (element) {
17
+ var _a;
16
18
  children.push({
17
- text: element.title,
19
+ text: (_a = element.title) !== null && _a !== void 0 ? _a : "",
18
20
  children: [],
19
21
  });
20
22
  });
@@ -28,11 +30,12 @@ var itemToNode = function (feedItem, hashtag) {
28
30
  children: [],
29
31
  });
30
32
  }
31
- FEED_LINK_KEYS.forEach(function (k) {
33
+ exports.FEED_LINK_KEYS.forEach(function (k) {
34
+ var _a;
32
35
  var v = attachment_1[k];
33
- if ((v === null || v === void 0 ? void 0 : v.length) > 0) {
36
+ if ((_a = v === null || v === void 0 ? void 0 : v.length) !== null && _a !== void 0 ? _a : 0 > 0) {
34
37
  children.push({
35
- text: "".concat(k.replace("_ptr_", "").replace(/_/g, " "), ":: ").concat(v.trim()),
38
+ text: "".concat(k.replace("_ptr_", "").replace(/_/g, " "), ":: ").concat(v === null || v === void 0 ? void 0 : v.trim()),
36
39
  children: [],
37
40
  });
38
41
  }
@@ -60,6 +63,9 @@ var itemToNode = function (feedItem, hashtag) {
60
63
  var title = ((_p = (_o = feedItem.content_text) === null || _o === void 0 ? void 0 : _o.trim()) === null || _p === void 0 ? void 0 : _p.length) > 0 ? feedItem.content_text : "Audio Recording";
61
64
  text = "[".concat(title, "](").concat(attachment_1.url, ")");
62
65
  }
66
+ else if ((attachment_1 === null || attachment_1 === void 0 ? void 0 : attachment_1._ptr_media_type) === "document" && attachment_1.url) {
67
+ text = "[".concat((attachment_1 === null || attachment_1 === void 0 ? void 0 : attachment_1.title) || "document attachment", "](").concat(attachment_1.url, ")");
68
+ }
63
69
  }
64
70
  text = "".concat(text.trim());
65
71
  var validHashtag = hashtag && typeof hashtag === "string" && hashtag.length > 0;
@@ -75,7 +81,6 @@ var itemToNode = function (feedItem, hashtag) {
75
81
  };
76
82
  };
77
83
  exports.itemToNode = itemToNode;
78
- var date_fns_1 = require("date-fns");
79
84
  var organizeFeedItems = function (feedItems, dateFormat) {
80
85
  if (dateFormat === void 0) { dateFormat = "MMMM do, yyyy"; }
81
86
  var reduceFeedItems = function (obj, feedItem) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ptn-helpers",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "helper functions to fetch and display ptn data",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",