need4deed-sdk 0.0.176 → 0.0.178

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/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./constants";
2
2
  export * from "./types";
3
+ export * from "./utils";
package/dist/index.js CHANGED
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./constants"), exports);
18
18
  __exportStar(require("./types"), exports);
19
+ __exportStar(require("./utils"), exports);
@@ -160,6 +160,7 @@ export interface ApiOpportunityGetList {
160
160
  volunteerType: VolunteerStateTypeType;
161
161
  statusOpportunity: OpportunityStatusType;
162
162
  statusMatch: OpportunityMatchStatusType;
163
+ noMatchFound?: boolean;
163
164
  numberOfVolunteers: number;
164
165
  createdAt: Date;
165
166
  activities: OptionById[];
@@ -71,3 +71,10 @@ export interface ApiAvailability {
71
71
  day?: ByDay | Occasionally;
72
72
  daytime?: TimeSlot | OccasionalType | string;
73
73
  }
74
+ export declare enum AvailabilityFilterGroup {
75
+ DAYS = "days",
76
+ TIMES = "times",
77
+ OCCASIONAL = "occasional"
78
+ }
79
+ export declare const AVAILABILITY_FILTER_SEPARATOR = "~";
80
+ export type AvailabilityFilterValue = `${AvailabilityFilterGroup.DAYS}~${ByDay}` | `${AvailabilityFilterGroup.TIMES}~${TimeSlot}` | `${AvailabilityFilterGroup.OCCASIONAL}~${OccasionalType}`;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TimeSlot = exports.Hour = exports.OccasionalType = exports.Occasionally = exports.ByDay = void 0;
3
+ exports.AVAILABILITY_FILTER_SEPARATOR = exports.AvailabilityFilterGroup = exports.TimeSlot = exports.Hour = exports.OccasionalType = exports.Occasionally = exports.ByDay = void 0;
4
4
  var ByDay;
5
5
  (function (ByDay) {
6
6
  ByDay["MO"] = "Monday";
@@ -55,3 +55,10 @@ var TimeSlot;
55
55
  TimeSlot["afternoon"] = "14-17";
56
56
  TimeSlot["evening"] = "17-20";
57
57
  })(TimeSlot || (exports.TimeSlot = TimeSlot = {}));
58
+ var AvailabilityFilterGroup;
59
+ (function (AvailabilityFilterGroup) {
60
+ AvailabilityFilterGroup["DAYS"] = "days";
61
+ AvailabilityFilterGroup["TIMES"] = "times";
62
+ AvailabilityFilterGroup["OCCASIONAL"] = "occasional";
63
+ })(AvailabilityFilterGroup || (exports.AvailabilityFilterGroup = AvailabilityFilterGroup = {}));
64
+ exports.AVAILABILITY_FILTER_SEPARATOR = "~";
@@ -0,0 +1 @@
1
+ export * from "./working-days";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./working-days"), exports);
@@ -0,0 +1,4 @@
1
+ export declare function isBerlinPublicHoliday(date: Date): boolean;
2
+ export declare function isWorkingDay(date: Date): boolean;
3
+ export declare function addWorkingDays(from: Date, days: number): Date;
4
+ export declare function berlinToday(): Date;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isBerlinPublicHoliday = isBerlinPublicHoliday;
4
+ exports.isWorkingDay = isWorkingDay;
5
+ exports.addWorkingDays = addWorkingDays;
6
+ exports.berlinToday = berlinToday;
7
+ function easterSunday(year) {
8
+ const a = year % 19;
9
+ const b = Math.floor(year / 100);
10
+ const c = year % 100;
11
+ const d = Math.floor(b / 4);
12
+ const e = b % 4;
13
+ const f = Math.floor((b + 8) / 25);
14
+ const g = Math.floor((b - f + 1) / 3);
15
+ const h = (19 * a + b - d - g + 15) % 30;
16
+ const i = Math.floor(c / 4);
17
+ const k = c % 4;
18
+ const l = (32 + 2 * e + 2 * i - h - k) % 7;
19
+ const m = Math.floor((a + 11 * h + 22 * l) / 451);
20
+ const month = Math.floor((h + l - 7 * m + 114) / 31) - 1;
21
+ const day = ((h + l - 7 * m + 114) % 31) + 1;
22
+ return new Date(year, month, day);
23
+ }
24
+ function addDays(date, n) {
25
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + n);
26
+ }
27
+ function monthDayKey(date) {
28
+ return date.getMonth() * 100 + date.getDate();
29
+ }
30
+ const holidaysByYear = new Map();
31
+ function holidaysOf(year) {
32
+ let holidays = holidaysByYear.get(year);
33
+ if (!holidays) {
34
+ const easter = easterSunday(year);
35
+ holidays = new Set([
36
+ new Date(year, 0, 1),
37
+ new Date(year, 2, 8),
38
+ new Date(year, 4, 1),
39
+ new Date(year, 9, 3),
40
+ new Date(year, 11, 25),
41
+ new Date(year, 11, 26),
42
+ addDays(easter, -2),
43
+ addDays(easter, 1),
44
+ addDays(easter, 39),
45
+ addDays(easter, 50),
46
+ ].map(monthDayKey));
47
+ holidaysByYear.set(year, holidays);
48
+ }
49
+ return holidays;
50
+ }
51
+ function isBerlinPublicHoliday(date) {
52
+ return holidaysOf(date.getFullYear()).has(monthDayKey(date));
53
+ }
54
+ function isWorkingDay(date) {
55
+ const dow = date.getDay();
56
+ return dow !== 0 && dow !== 6 && !isBerlinPublicHoliday(date);
57
+ }
58
+ function addWorkingDays(from, days) {
59
+ if (!Number.isInteger(days)) {
60
+ throw new RangeError(`addWorkingDays: days must be an integer, got ${days}`);
61
+ }
62
+ let result = new Date(from.getFullYear(), from.getMonth(), from.getDate());
63
+ const direction = days < 0 ? -1 : 1;
64
+ const remaining = Math.abs(days);
65
+ let added = 0;
66
+ while (added < remaining) {
67
+ result = addDays(result, direction);
68
+ if (isWorkingDay(result)) {
69
+ added++;
70
+ }
71
+ }
72
+ return result;
73
+ }
74
+ const berlinDateFormat = new Intl.DateTimeFormat("en-US", {
75
+ timeZone: "Europe/Berlin",
76
+ year: "numeric",
77
+ month: "numeric",
78
+ day: "numeric",
79
+ });
80
+ function berlinToday() {
81
+ const parts = Object.fromEntries(berlinDateFormat
82
+ .formatToParts(new Date())
83
+ .map(({ type, value }) => [type, Number(value)]));
84
+ return new Date(parts.year, parts.month - 1, parts.day);
85
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "need4deed-sdk",
3
- "version": "0.0.176",
3
+ "version": "0.0.178",
4
4
  "description": "Need4Deed.org SDK",
5
5
  "type": "commonjs",
6
6
  "main": "dist/index.js",
@@ -18,12 +18,13 @@
18
18
  },
19
19
  "scripts": {
20
20
  "what": "node -e 'console.log(require(\"./package.json\").version)'",
21
- "build:tsc": "tsc",
21
+ "build:tsc": "tsc -p tsconfig.build.json",
22
22
  "build": "yarn build:tsc",
23
23
  "watch": "tsc --watch --project tsconfig.cjs.json",
24
24
  "prepublishOnly": "yarn build",
25
25
  "create-pr": "./create-pr.sh",
26
- "typecheck": "tsc --noEmit"
26
+ "typecheck": "tsc --noEmit",
27
+ "test": "vitest run"
27
28
  },
28
29
  "keywords": [
29
30
  "sdk",
@@ -38,6 +39,7 @@
38
39
  "devDependencies": {
39
40
  "@types/react": "^18.0.0",
40
41
  "@types/react-dom": "^18.0.0",
41
- "typescript": "^5.8.3"
42
+ "typescript": "^5.8.3",
43
+ "vitest": "^4.0.18"
42
44
  }
43
45
  }