ptn-helpers 0.0.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.
- package/README.md +1 -0
- package/lib/index.d.ts +24 -0
- package/lib/index.js +54 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# ptn helpers
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
itemId?: string;
|
|
22
|
+
};
|
|
23
|
+
export declare const itemToNode: (feedItem: FeedItem, hashtag: string) => PtnNode;
|
|
24
|
+
export {};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.itemToNode = void 0;
|
|
4
|
+
var FEED_LINK_KEYS = [
|
|
5
|
+
"title",
|
|
6
|
+
"_ptr_open_graph_description",
|
|
7
|
+
"_ptr_open_graph_site_name",
|
|
8
|
+
"_ptr_open_graph_type",
|
|
9
|
+
];
|
|
10
|
+
var itemToNode = function (feedItem, hashtag) {
|
|
11
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
12
|
+
var children = [];
|
|
13
|
+
var attachment = (_a = feedItem === null || feedItem === void 0 ? void 0 : feedItem.attachments) === null || _a === void 0 ? void 0 : _a[0];
|
|
14
|
+
var text = (_b = feedItem === null || feedItem === void 0 ? void 0 : feedItem.content_text) !== null && _b !== void 0 ? _b : "";
|
|
15
|
+
if ((attachment === null || attachment === void 0 ? void 0 : attachment._ptr_media_type) === "link") {
|
|
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) {
|
|
17
|
+
children.push({
|
|
18
|
+
text: ""),
|
|
19
|
+
children: [],
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
FEED_LINK_KEYS.forEach(function (k) {
|
|
23
|
+
var v = attachment[k];
|
|
24
|
+
if ((v === null || v === void 0 ? void 0 : v.length) > 0) {
|
|
25
|
+
children.push({
|
|
26
|
+
text: "".concat(k.replace("_ptr_", "").replace(/_/g, " "), ":: ").concat(v.trim()),
|
|
27
|
+
children: [],
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
else if ((attachment === null || attachment === void 0 ? void 0 : attachment._ptr_media_type) === "image") {
|
|
33
|
+
text = "");
|
|
34
|
+
}
|
|
35
|
+
else if ((attachment === null || attachment === void 0 ? void 0 : attachment._ptr_media_type) === "audio") {
|
|
36
|
+
var title = ((_f = (_e = feedItem.content_text) === null || _e === void 0 ? void 0 : _e.trim()) === null || _f === void 0 ? void 0 : _f.length) > 0
|
|
37
|
+
? feedItem.content_text
|
|
38
|
+
: "Audio Recording";
|
|
39
|
+
text = "[".concat(title, "](").concat(attachment.url, ")");
|
|
40
|
+
}
|
|
41
|
+
text = "".concat(text.trim());
|
|
42
|
+
var validHashtag = hashtag && typeof hashtag === "string" && hashtag.length > 0;
|
|
43
|
+
var existingTags = /#\w+to(roam|note)/;
|
|
44
|
+
var needsNewTag = !!!((_g = text.match(existingTags)) === null || _g === void 0 ? void 0 : _g.length);
|
|
45
|
+
if (validHashtag && needsNewTag) {
|
|
46
|
+
text = "".concat(text, " #").concat(hashtag);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
text: "".concat(text),
|
|
50
|
+
children: children,
|
|
51
|
+
itemId: "".concat(feedItem.id),
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
exports.itemToNode = itemToNode;
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ptn-helpers",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "helper functions to fetch and display ptn data",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib/**/*"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "jest --config jestconfig.json",
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
|
|
14
|
+
"lint": "eslint --ext .js,.ts,src/**/*.js,src/**/*.ts",
|
|
15
|
+
"prepare": "npm run build",
|
|
16
|
+
"prepublishOnly": "npm test && npm run lint",
|
|
17
|
+
"preversion": "npm run lint",
|
|
18
|
+
"version": "npm run format && git add -A src",
|
|
19
|
+
"postversion": "git push && git push --tags"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/phonetonote/ptn-helpers.git"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"ptn",
|
|
27
|
+
"phonetonote",
|
|
28
|
+
"phonetonote-helpers"
|
|
29
|
+
],
|
|
30
|
+
"author": "srb",
|
|
31
|
+
"license": "ISC",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/phonetonote/ptn-helpers/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/phonetonote/ptn-helpers#readme",
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/jest": "^27.0.3",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^5.8.0",
|
|
39
|
+
"@typescript-eslint/parser": "^5.8.0",
|
|
40
|
+
"eslint": "^8.5.0",
|
|
41
|
+
"jest": "^27.4.5",
|
|
42
|
+
"prettier": "^2.5.1",
|
|
43
|
+
"ts-jest": "^27.1.2",
|
|
44
|
+
"typescript": "^4.5.4"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"tslint": "^6.1.3"
|
|
48
|
+
}
|
|
49
|
+
}
|