@react-pakistan/util-functions 1.24.82 → 1.24.84

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.
@@ -0,0 +1,13 @@
1
+ export interface IMonthNameMap {
2
+ /**
3
+ *
4
+ */
5
+ [key: string]: number;
6
+ }
7
+ export declare const monthNameMap: IMonthNameMap;
8
+ /**
9
+ * Get the UTC month number (0-11) from a month name
10
+ * @param monthName - The name of the month (case-insensitive)
11
+ * @returns The UTC month number (0-11), or -1 if the month name is invalid
12
+ */
13
+ export declare const getMonthNumber: (monthName: string) => number;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMonthNumber = exports.monthNameMap = void 0;
4
+ exports.monthNameMap = {
5
+ january: 0,
6
+ february: 1,
7
+ march: 2,
8
+ april: 3,
9
+ may: 4,
10
+ june: 5,
11
+ july: 6,
12
+ august: 7,
13
+ september: 8,
14
+ october: 9,
15
+ november: 10,
16
+ december: 11,
17
+ };
18
+ /**
19
+ * Get the UTC month number (0-11) from a month name
20
+ * @param monthName - The name of the month (case-insensitive)
21
+ * @returns The UTC month number (0-11), or -1 if the month name is invalid
22
+ */
23
+ var getMonthNumber = function (monthName) {
24
+ var normalizedName = monthName.toLowerCase().trim();
25
+ return exports.monthNameMap[normalizedName] !== undefined
26
+ ? exports.monthNameMap[normalizedName]
27
+ : -1;
28
+ };
29
+ exports.getMonthNumber = getMonthNumber;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Converts a remote image URL to a base64 string
3
+ * @param url - The remote URL of the image
4
+ * @returns Promise<string> - The base64 encoded string of the image
5
+ * @throws Error if the image cannot be fetched or converted
6
+ */
7
+ export declare const imageUrlToBase64: (url: string) => Promise<string>;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ /**
3
+ * Converts a remote image URL to a base64 string
4
+ * @param url - The remote URL of the image
5
+ * @returns Promise<string> - The base64 encoded string of the image
6
+ * @throws Error if the image cannot be fetched or converted
7
+ */
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ var __generator = (this && this.__generator) || function (thisArg, body) {
18
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
19
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
20
+ function verb(n) { return function (v) { return step([n, v]); }; }
21
+ function step(op) {
22
+ if (f) throw new TypeError("Generator is already executing.");
23
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
24
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
25
+ if (y = 0, t) op = [op[0] & 2, t.value];
26
+ switch (op[0]) {
27
+ case 0: case 1: t = op; break;
28
+ case 4: _.label++; return { value: op[1], done: false };
29
+ case 5: _.label++; y = op[1]; op = [0]; continue;
30
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
31
+ default:
32
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
33
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
34
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
35
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
36
+ if (t[2]) _.ops.pop();
37
+ _.trys.pop(); continue;
38
+ }
39
+ op = body.call(thisArg, _);
40
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
41
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
42
+ }
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.imageUrlToBase64 = void 0;
46
+ var imageUrlToBase64 = function (url) { return __awaiter(void 0, void 0, void 0, function () {
47
+ var response, blob_1, error_1;
48
+ return __generator(this, function (_a) {
49
+ switch (_a.label) {
50
+ case 0:
51
+ _a.trys.push([0, 3, , 4]);
52
+ return [4 /*yield*/, fetch(url)];
53
+ case 1:
54
+ response = _a.sent();
55
+ if (!response.ok) {
56
+ throw new Error("Failed to fetch image: ".concat(response.statusText));
57
+ }
58
+ return [4 /*yield*/, response.blob()];
59
+ case 2:
60
+ blob_1 = _a.sent();
61
+ // Convert blob to base64
62
+ return [2 /*return*/, new Promise(function (resolve, reject) {
63
+ var reader = new FileReader();
64
+ reader.onloadend = function () {
65
+ var base64String = reader.result;
66
+ resolve(base64String);
67
+ };
68
+ reader.onerror = function () {
69
+ reject(new Error('Failed to convert image to base64'));
70
+ };
71
+ reader.readAsDataURL(blob_1);
72
+ })];
73
+ case 3:
74
+ error_1 = _a.sent();
75
+ throw new Error("Error converting image URL to base64: ".concat(error_1 instanceof Error ? error_1.message : 'Unknown error'));
76
+ case 4: return [2 /*return*/];
77
+ }
78
+ });
79
+ }); };
80
+ exports.imageUrlToBase64 = imageUrlToBase64;
@@ -33,6 +33,7 @@ export * from './get-day-name';
33
33
  export * from './get-full-name';
34
34
  export * from './get-href';
35
35
  export * from './get-month-name';
36
+ export * from './get-month-number';
36
37
  export * from './get-number-of-days-in-month';
37
38
  export * from './get-pathname';
38
39
  export * from './get-week-day';
package/general/index.js CHANGED
@@ -49,6 +49,7 @@ __exportStar(require("./get-day-name"), exports);
49
49
  __exportStar(require("./get-full-name"), exports);
50
50
  __exportStar(require("./get-href"), exports);
51
51
  __exportStar(require("./get-month-name"), exports);
52
+ __exportStar(require("./get-month-number"), exports);
52
53
  __exportStar(require("./get-number-of-days-in-month"), exports);
53
54
  __exportStar(require("./get-pathname"), exports);
54
55
  __exportStar(require("./get-week-day"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pakistan/util-functions",
3
- "version": "1.24.82",
3
+ "version": "1.24.84",
4
4
  "description": "A library of all util functions",
5
5
  "main": "index.js",
6
6
  "scripts": {