@koloseum/utils 0.2.12 → 0.2.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/dist/utils.d.ts CHANGED
@@ -109,6 +109,12 @@ export declare const Utility: {
109
109
  * @returns {Promise<County[]>} A list of objects with the county `name`, `code`, and a list of `subCounties`
110
110
  */
111
111
  getKenyaCounties: (sortBy?: "name" | "code") => Promise<County[]>;
112
+ /**
113
+ * Formats a date to an ISO string in Kenyan time, i.e. `Africa/Nairobi` (UTC+3).
114
+ * @param {Date | string | number | null} date - The date to format
115
+ * @returns {string} The formatted date in ISO string format, or an empty string if invalid input
116
+ */
117
+ getKenyanISOString: (date: Date | string | number | null) => string;
112
118
  /**
113
119
  * Returns the URL for a menu item based on the slug.
114
120
  * @param {string} base - The base URL
package/dist/utils.js CHANGED
@@ -358,6 +358,23 @@ export const Utility = {
358
358
  // Return sorted counties
359
359
  return counties.sort((a, b) => (sortBy === "name" ? a.name.localeCompare(b.name) : a.code - b.code));
360
360
  },
361
+ /**
362
+ * Formats a date to an ISO string in Kenyan time, i.e. `Africa/Nairobi` (UTC+3).
363
+ * @param {Date | string | number | null} date - The date to format
364
+ * @returns {string} The formatted date in ISO string format, or an empty string if invalid input
365
+ */
366
+ getKenyanISOString: (date) => {
367
+ // Return empty string if no date is provided or input is invalid
368
+ if (!date || (typeof date !== "string" && typeof date !== "number" && !(date instanceof Date)))
369
+ return "";
370
+ // Get locale string to format
371
+ const dateObj = date instanceof Date ? date : new Date(date);
372
+ const localeString = dateObj.toLocaleString("sv-SE", {
373
+ timeZone: "Africa/Nairobi"
374
+ });
375
+ // Return formatted string
376
+ return localeString.replace(" ", "T") + "+03:00";
377
+ },
361
378
  /**
362
379
  * Returns the URL for a menu item based on the slug.
363
380
  * @param {string} base - The base URL
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koloseum/utils",
3
- "version": "0.2.12",
3
+ "version": "0.2.14",
4
4
  "author": "Koloseum Technologies Limited",
5
5
  "type": "module",
6
6
  "description": "Utility logic for use across Koloseum web apps (TypeScript)",
@@ -32,6 +32,7 @@
32
32
  "@supabase/supabase-js": "^2.50.1",
33
33
  "@sveltejs/kit": "^2.22.0",
34
34
  "kenya-administrative-divisions": "^0.0.18",
35
+ "postgres-interval": "^4.0.2",
35
36
  "sanitize-html": "^2.17.0",
36
37
  "uuid": "^11.1.0",
37
38
  "validator": "^13.15.15"
@@ -43,7 +44,6 @@
43
44
  "@types/sanitize-html": "^2.16.0",
44
45
  "@types/uuid": "^10.0.0",
45
46
  "@types/validator": "^13.15.2",
46
- "postgres-interval": "^4.0.2",
47
47
  "prettier": "^3.6.0",
48
48
  "typescript": "^5.8.3",
49
49
  "vitest": "^3.2.4"