@react-pakistan/util-functions 1.23.74 → 1.23.76

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.
@@ -5,6 +5,6 @@ export interface FetchDataParams {
5
5
  body?: string;
6
6
  }
7
7
  export declare const fetchData: ({ url, method, body, }: FetchDataParams) => Promise<{
8
- data: any | Array<any> | undefined;
8
+ data: any | undefined;
9
9
  error: Error | undefined;
10
10
  }>;
@@ -72,7 +72,7 @@ var fetchData = function (_a) { return __awaiter(void 0, [_a], void 0, function
72
72
  error = err_1;
73
73
  return [3 /*break*/, 4];
74
74
  case 4: return [2 /*return*/, {
75
- data: data.data,
75
+ data: data,
76
76
  error: error,
77
77
  }];
78
78
  }
@@ -29,6 +29,7 @@ export * from './is-next-button-disabled';
29
29
  export * from './is-odd';
30
30
  export * from './is-previous-button-disabled';
31
31
  export * from './linear-gradients';
32
+ export * from './parse-frontmatter';
32
33
  export * from './remove-data-image-prefix';
33
34
  export * from './repeat-times';
34
35
  export * from './resolve-anchor-link';
package/general/index.js CHANGED
@@ -46,6 +46,7 @@ __exportStar(require("./is-next-button-disabled"), exports);
46
46
  __exportStar(require("./is-odd"), exports);
47
47
  __exportStar(require("./is-previous-button-disabled"), exports);
48
48
  __exportStar(require("./linear-gradients"), exports);
49
+ __exportStar(require("./parse-frontmatter"), exports);
49
50
  __exportStar(require("./remove-data-image-prefix"), exports);
50
51
  __exportStar(require("./repeat-times"), exports);
51
52
  __exportStar(require("./resolve-anchor-link"), exports);
@@ -0,0 +1,29 @@
1
+ export interface BlogMetadata {
2
+ authorImage: string;
3
+ authorName: string;
4
+ banner: string;
5
+ category: string;
6
+ claps: number;
7
+ createdAt: string;
8
+ excerpt: string;
9
+ id: string;
10
+ isPublished: boolean;
11
+ slug: string;
12
+ timeToRead: string;
13
+ title: string;
14
+ updatedAt: string;
15
+ }
16
+ export interface RemoteBlogData {
17
+ claps: number;
18
+ content: string;
19
+ createdAt: string;
20
+ id: string;
21
+ isPublished: boolean;
22
+ slug: string;
23
+ updatedAt: string;
24
+ }
25
+ export interface Frontmatter {
26
+ content: string;
27
+ metadata: BlogMetadata;
28
+ }
29
+ export declare const parseFrontmatter: (data: RemoteBlogData) => Frontmatter;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseFrontmatter = void 0;
4
+ var parseFrontmatter = function (data) {
5
+ var _a;
6
+ var frontmatterRegex = /---\s*([\s\S]*?)\s*---/;
7
+ var match = frontmatterRegex.exec(data.content);
8
+ // eslint-disable-next-line
9
+ var frontMatterBlock = match[1];
10
+ var content = (_a = data.content) === null || _a === void 0 ? void 0 : _a.replace(frontmatterRegex, '').trim();
11
+ var frontMatterLines = frontMatterBlock.trim().split('\n');
12
+ var metadata = {
13
+ authorImage: '',
14
+ authorName: '',
15
+ banner: '',
16
+ category: '',
17
+ excerpt: '',
18
+ timeToRead: '',
19
+ title: '',
20
+ updatedAt: data.updatedAt,
21
+ slug: data.slug,
22
+ isPublished: data.isPublished,
23
+ id: data.id,
24
+ createdAt: data.createdAt,
25
+ claps: data.claps,
26
+ };
27
+ frontMatterLines.forEach(function (line) {
28
+ var _a = line.trim().split(': '), key = _a[0], valueArr = _a.slice(1);
29
+ var value = valueArr.join(': ').trim();
30
+ value = value.replace(/^['"](.*)['"]$/, '$1'); // Remove quotes
31
+ // @ts-expect-error resolve error
32
+ metadata[key.trim()] = value;
33
+ });
34
+ return { metadata: metadata, content: content };
35
+ };
36
+ exports.parseFrontmatter = parseFrontmatter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pakistan/util-functions",
3
- "version": "1.23.74",
3
+ "version": "1.23.76",
4
4
  "description": "A library of all util functions",
5
5
  "main": "index.js",
6
6
  "scripts": {