ptn-helpers 0.0.11 → 0.0.14
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 +1 -0
- package/lib/index.js +55 -27
- package/package.json +4 -1
package/lib/index.d.ts
CHANGED
|
@@ -21,4 +21,5 @@ export declare type PtnNode = {
|
|
|
21
21
|
uid?: string;
|
|
22
22
|
};
|
|
23
23
|
export declare const itemToNode: (feedItem: FeedItem, hashtag: string) => PtnNode;
|
|
24
|
+
export declare const organizeFeedItems: (feedItems: FeedItem[], dateFormat?: string) => Record<string, Record<string, FeedItem[]>>;
|
|
24
25
|
export {};
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.itemToNode = void 0;
|
|
3
|
+
exports.organizeFeedItems = exports.itemToNode = void 0;
|
|
4
4
|
var FEED_LINK_KEYS = [
|
|
5
5
|
"title",
|
|
6
6
|
"_ptr_open_graph_description",
|
|
@@ -8,52 +8,80 @@ var FEED_LINK_KEYS = [
|
|
|
8
8
|
"_ptr_open_graph_type",
|
|
9
9
|
];
|
|
10
10
|
var itemToNode = function (feedItem, hashtag) {
|
|
11
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
11
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
12
12
|
var children = [];
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if ((_d = (_c = attachment === null || attachment === void 0 ? void 0 : attachment._ptr_open_graph_image_url) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0 > 0) {
|
|
13
|
+
var text = (_a = feedItem === null || feedItem === void 0 ? void 0 : feedItem.content_text) !== null && _a !== void 0 ? _a : "";
|
|
14
|
+
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
|
+
(_e = feedItem === null || feedItem === void 0 ? void 0 : feedItem.attachments) === null || _e === void 0 ? void 0 : _e.forEach(function (element) {
|
|
17
16
|
children.push({
|
|
18
|
-
text:
|
|
17
|
+
text: element.title,
|
|
19
18
|
children: [],
|
|
20
19
|
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
var attachment_1 = (_f = feedItem === null || feedItem === void 0 ? void 0 : feedItem.attachments) === null || _f === void 0 ? void 0 : _f[0];
|
|
24
|
+
if ((attachment_1 === null || attachment_1 === void 0 ? void 0 : attachment_1._ptr_media_type) === "link") {
|
|
25
|
+
if ((_h = (_g = attachment_1 === null || attachment_1 === void 0 ? void 0 : attachment_1._ptr_open_graph_image_url) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 0 > 0) {
|
|
25
26
|
children.push({
|
|
26
|
-
text: "".concat(
|
|
27
|
+
text: ""),
|
|
27
28
|
children: [],
|
|
28
29
|
});
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
FEED_LINK_KEYS.forEach(function (k) {
|
|
32
|
+
var v = attachment_1[k];
|
|
33
|
+
if ((v === null || v === void 0 ? void 0 : v.length) > 0) {
|
|
34
|
+
children.push({
|
|
35
|
+
text: "".concat(k.replace("_ptr_", "").replace(/_/g, " "), ":: ").concat(v.trim()),
|
|
36
|
+
children: [],
|
|
37
|
+
});
|
|
38
|
+
}
|
|
37
39
|
});
|
|
38
40
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
else if ((attachment_1 === null || attachment_1 === void 0 ? void 0 : attachment_1._ptr_media_type) === "text") {
|
|
42
|
+
if ((_k = (_j = attachment_1 === null || attachment_1 === void 0 ? void 0 : attachment_1.title) === null || _j === void 0 ? void 0 : _j.length) !== null && _k !== void 0 ? _k : 0 > 0) {
|
|
43
|
+
children.push({
|
|
44
|
+
text: "".concat(attachment_1.title),
|
|
45
|
+
children: [],
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else if ((attachment_1 === null || attachment_1 === void 0 ? void 0 : attachment_1._ptr_media_type) === "image") {
|
|
50
|
+
text = "");
|
|
51
|
+
}
|
|
52
|
+
else if ((attachment_1 === null || attachment_1 === void 0 ? void 0 : attachment_1._ptr_media_type) === "audio") {
|
|
53
|
+
var title = ((_m = (_l = feedItem.content_text) === null || _l === void 0 ? void 0 : _l.trim()) === null || _m === void 0 ? void 0 : _m.length) > 0 ? feedItem.content_text : "Audio Recording";
|
|
54
|
+
text = "[".concat(title, "](").concat(attachment_1.url, ")");
|
|
55
|
+
}
|
|
46
56
|
}
|
|
47
57
|
text = "".concat(text.trim());
|
|
48
58
|
var validHashtag = hashtag && typeof hashtag === "string" && hashtag.length > 0;
|
|
49
59
|
var existingTags = /#\w+to(roam|note)/;
|
|
50
|
-
var needsNewTag = !!!((
|
|
60
|
+
var needsNewTag = !!!((_o = text.match(existingTags)) === null || _o === void 0 ? void 0 : _o.length);
|
|
51
61
|
if (validHashtag && needsNewTag) {
|
|
52
62
|
text = "".concat(text, " #").concat(hashtag);
|
|
53
63
|
}
|
|
54
64
|
return {
|
|
55
65
|
text: "".concat(text),
|
|
56
66
|
children: children,
|
|
67
|
+
uid: feedItem.id,
|
|
57
68
|
};
|
|
58
69
|
};
|
|
59
70
|
exports.itemToNode = itemToNode;
|
|
71
|
+
var date_fns_1 = require("date-fns");
|
|
72
|
+
var organizeFeedItems = function (feedItems, dateFormat) {
|
|
73
|
+
if (dateFormat === void 0) { dateFormat = "MMMM do, yyyy"; }
|
|
74
|
+
var reduceFeedItems = function (obj, feedItem) {
|
|
75
|
+
var date = new Date(feedItem.date_published), pageName = (0, date_fns_1.format)(date, dateFormat), senderType = feedItem._ptr_sender_type;
|
|
76
|
+
if (!obj.hasOwnProperty(pageName)) {
|
|
77
|
+
obj[pageName] = {};
|
|
78
|
+
}
|
|
79
|
+
if (!obj[pageName][senderType]) {
|
|
80
|
+
obj[pageName][senderType] = [];
|
|
81
|
+
}
|
|
82
|
+
obj[pageName][senderType].push(feedItem);
|
|
83
|
+
return obj;
|
|
84
|
+
};
|
|
85
|
+
return feedItems.reduce(reduceFeedItems, {});
|
|
86
|
+
};
|
|
87
|
+
exports.organizeFeedItems = organizeFeedItems;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ptn-helpers",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "helper functions to fetch and display ptn data",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -42,5 +42,8 @@
|
|
|
42
42
|
"prettier": "^2.5.1",
|
|
43
43
|
"ts-jest": "^27.1.2",
|
|
44
44
|
"typescript": "^4.5.4"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"date-fns": "^2.28.0"
|
|
45
48
|
}
|
|
46
49
|
}
|