@hestia-earth/utils 0.14.4 → 0.14.5

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/string.d.ts CHANGED
@@ -20,3 +20,28 @@ export declare const toDashCase: (value?: string) => string;
20
20
  * @returns Date as a string.
21
21
  */
22
22
  export declare const now: () => string;
23
+ /**
24
+ * Parse a markdown link.
25
+ *
26
+ * @param link
27
+ * @returns Title and link if found.
28
+ */
29
+ export declare const parseMarkdownLink: (link: string) => {
30
+ title: string;
31
+ link: string;
32
+ } | {
33
+ title: string;
34
+ link?: undefined;
35
+ };
36
+ /**
37
+ * Parse a citation.
38
+ *
39
+ * @param value
40
+ * @returns
41
+ */
42
+ export declare const parseCitation: (value: string) => {
43
+ original: string;
44
+ name: string;
45
+ title: string;
46
+ link: string;
47
+ };
package/dist/string.js CHANGED
@@ -1,6 +1,22 @@
1
1
  "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
2
18
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.now = exports.toDashCase = exports.keyToLabel = exports.ellipsis = void 0;
19
+ exports.parseCitation = exports.parseMarkdownLink = exports.now = exports.toDashCase = exports.keyToLabel = exports.ellipsis = void 0;
4
20
  /**
5
21
  * Trims the string to a certain max length and replace with `...`.
6
22
  *
@@ -58,3 +74,27 @@ exports.toDashCase = toDashCase;
58
74
  */
59
75
  var now = function () { return new Date().toJSON().substring(0, 10); };
60
76
  exports.now = now;
77
+ /**
78
+ * Parse a markdown link.
79
+ *
80
+ * @param link
81
+ * @returns Title and link if found.
82
+ */
83
+ var parseMarkdownLink = function (link) {
84
+ var regex = /\[(.*?)\]\((.*?)\)/;
85
+ var match = link.match(regex);
86
+ return match && match.length === 3 ? { title: match[1], link: match[2] } : { title: link };
87
+ };
88
+ exports.parseMarkdownLink = parseMarkdownLink;
89
+ /**
90
+ * Parse a citation.
91
+ *
92
+ * @param value
93
+ * @returns
94
+ */
95
+ var parseCitation = function (value) {
96
+ var parsed = exports.parseMarkdownLink(value);
97
+ var _a = __read(parsed.title.match(/(.*[(]\d+[)])?(.*)/), 3), original = _a[0], name = _a[1], title = _a[2];
98
+ return { original: original, name: name === null || name === void 0 ? void 0 : name.trim(), title: title === null || title === void 0 ? void 0 : title.trim(), link: parsed.link };
99
+ };
100
+ exports.parseCitation = parseCitation;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/utils",
3
- "version": "0.14.4",
3
+ "version": "0.14.5",
4
4
  "description": "HESTIA Utils library",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",