@8ms/helpers 2.2.9 → 2.2.10

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.
Files changed (176) hide show
  1. package/_class/BaseClass.js +43 -52
  2. package/_class/BaseNamespace.js +17 -20
  3. package/_class/index.js +2 -7
  4. package/adverity/getJobs.js +7 -11
  5. package/adverity/index.js +51 -54
  6. package/adverity/server.js +1 -5
  7. package/api/ApiResponseClass.js +84 -88
  8. package/api/functions.js +13 -22
  9. package/api/index.js +3 -19
  10. package/api/types.js +5 -9
  11. package/array/index.js +3 -11
  12. package/atInternet/index.js +10 -13
  13. package/aws/ec2/AwsEc2Namespace.js +34 -74
  14. package/aws/ec2/server.js +5 -9
  15. package/aws/ecs/AwsEcsNamespace.js +110 -150
  16. package/aws/ecs/server.js +5 -9
  17. package/aws/glue/AwsGlueNamespace.js +26 -66
  18. package/aws/glue/server.js +5 -9
  19. package/aws/isResponse200.js +3 -7
  20. package/aws/lambda/AwsLambdaNamespace.js +62 -102
  21. package/aws/lambda/server.js +6 -11
  22. package/aws/s3/AwsS3Namespace.js +347 -390
  23. package/aws/s3/payload.js +29 -32
  24. package/aws/s3/server.js +9 -14
  25. package/aws/server.js +5 -10
  26. package/aws/ses/AwsSesNamespace.js +36 -76
  27. package/aws/ses/SimpleEmail.js +267 -304
  28. package/aws/ses/server.js +6 -11
  29. package/aws/sqs/AwsSqsNamespace.js +49 -89
  30. package/aws/sqs/server.js +5 -9
  31. package/aws/ssm/AwsSsmNamespace.js +43 -79
  32. package/aws/ssm/server.js +5 -9
  33. package/axios/deleteRequest.js +8 -15
  34. package/axios/get.js +8 -15
  35. package/axios/index.js +3 -9
  36. package/axios/post.js +8 -15
  37. package/boolean/index.js +3 -10
  38. package/brightData/serpApi/buildGoogleSerpUrl.js +1 -5
  39. package/brightData/serpApi/buildGoogleTrendsUrl.js +1 -5
  40. package/brightData/serpApi/getAsyncRequestId.js +8 -12
  41. package/brightData/serpApi/getAsyncResults.js +8 -12
  42. package/brightData/serpApi/getRealtime.js +3 -7
  43. package/brightData/serpApi/server.js +6 -14
  44. package/brightData/server.js +2 -7
  45. package/brightData/webScraperIde/getBatch.js +3 -7
  46. package/brightData/webScraperIde/getRealtime.js +11 -15
  47. package/brightData/webScraperIde/server.js +2 -7
  48. package/cache/server.js +2 -7
  49. package/cache/test/cache.test.js +4 -6
  50. package/crud/index.js +1 -4
  51. package/crypto/getDecrypt.js +2 -39
  52. package/crypto/getEncrypt.js +2 -39
  53. package/crypto/getRandom.js +1 -5
  54. package/crypto/getSha256.js +4 -41
  55. package/crypto/index.js +4 -11
  56. package/date/calculation.js +70 -99
  57. package/date/financialYear.js +16 -23
  58. package/date/format.js +40 -61
  59. package/date/index.js +4 -20
  60. package/date/type.js +4 -7
  61. package/environment/index.js +15 -25
  62. package/eskimi/getAgeGroup.js +3 -7
  63. package/eskimi/getData.js +3 -7
  64. package/eskimi/getDevice.js +3 -7
  65. package/eskimi/getGender.js +3 -7
  66. package/eskimi/server.js +23 -26
  67. package/file/index.js +8 -46
  68. package/geo/countries.js +1 -4
  69. package/geo/index.js +2 -7
  70. package/geo/languages.js +1 -4
  71. package/google/bigQuery/GoogleBigQueryNamespace.js +108 -148
  72. package/google/bigQuery/loadData.js +1 -5
  73. package/google/bigQuery/server.js +8 -14
  74. package/google/server.js +1 -5
  75. package/google/sheets/GoogleSheetsNamespace.js +34 -74
  76. package/google/sheets/getAssociatedData.js +1 -5
  77. package/google/sheets/server.js +8 -14
  78. package/google/storage/GoogleCloudStorageNamespace.js +62 -102
  79. package/google/storage/server.js +6 -10
  80. package/googleAds/GoogleAdsNamespace.js +28 -68
  81. package/googleAds/keywordPlanner/server.js +32 -35
  82. package/googleAds/server.js +6 -10
  83. package/googlePageSpeed/GooglePageSpeedNamespace.js +21 -28
  84. package/googlePageSpeed/server.js +8 -12
  85. package/googleSearchIncidents/server.js +28 -32
  86. package/greenDomain/server.js +17 -21
  87. package/inngest/server.js +1 -4
  88. package/json/getJsonNewline.js +3 -7
  89. package/json/index.js +2 -7
  90. package/json/isJson.js +1 -5
  91. package/littleWarden/LittleWardenNamespace.js +24 -31
  92. package/littleWarden/getUrlStatus.js +3 -7
  93. package/littleWarden/server.js +14 -22
  94. package/lumar/api/buildRequest.js +14 -18
  95. package/lumar/api/getData.js +3 -7
  96. package/lumar/api/initClient.js +3 -7
  97. package/lumar/api/server.js +6 -12
  98. package/lumar/graphql/columns.js +1 -4
  99. package/lumar/graphql/getData.js +3 -7
  100. package/lumar/graphql/initClient.js +3 -7
  101. package/lumar/graphql/queries/crawl.js +1 -2
  102. package/lumar/graphql/queries/getCrawls.js +1 -3
  103. package/lumar/graphql/queries/getReportDifferences.js +3 -5
  104. package/lumar/graphql/queries/getRows.js +1 -3
  105. package/lumar/graphql/queries/getTotals.js +1 -3
  106. package/lumar/graphql/queries/row.js +1 -2
  107. package/lumar/graphql/reportTemplates.js +1 -4
  108. package/lumar/graphql/server.js +7 -15
  109. package/myTarget/server.js +3 -7
  110. package/nextAuth/index.js +2 -6
  111. package/nextAuth/isSessionReady.js +1 -5
  112. package/nextJs/client/LazyLoad.js +5 -12
  113. package/nextJs/client.js +1 -5
  114. package/nextJs/index.js +2 -7
  115. package/number/format.js +3 -7
  116. package/number/formatCurrency.js +1 -5
  117. package/number/getDecimal.js +3 -7
  118. package/number/getNumber.js +3 -7
  119. package/number/getPercentIncrease.js +4 -8
  120. package/number/getSafeDivide.js +6 -10
  121. package/number/index.js +6 -15
  122. package/object/index.js +1 -5
  123. package/object/replaceKeys.js +3 -7
  124. package/onePassword/OnePasswordNamespace.js +36 -76
  125. package/onePassword/server.js +3 -7
  126. package/openAi/OpenAiNamespace.js +32 -39
  127. package/openAi/server.js +6 -10
  128. package/package.json +7 -1
  129. package/prisma/PrismaNamespace.js +53 -93
  130. package/prisma/getDecimal.js +5 -12
  131. package/prisma/server.js +4 -9
  132. package/snapchat/SnapchatNamespace.js +20 -27
  133. package/snapchat/server.js +6 -10
  134. package/sorting/byNumberAscending.js +1 -5
  135. package/sorting/byNumberDescending.js +1 -5
  136. package/sorting/byStringAscending.js +1 -5
  137. package/sorting/byStringDescending.js +1 -5
  138. package/sorting/index.js +4 -11
  139. package/stream/server.js +1 -5
  140. package/stream/sort.js +1 -5
  141. package/string/getCapitalised.js +3 -7
  142. package/string/getClean.js +17 -21
  143. package/string/getFolder.js +3 -10
  144. package/string/getProperCase.js +4 -8
  145. package/string/getString.js +8 -15
  146. package/string/getStringFromStream.js +1 -5
  147. package/string/getUnescaped.js +3 -10
  148. package/string/getWithoutAccents.js +1 -5
  149. package/string/getWithoutHtmlTags.js +1 -5
  150. package/string/getWithoutPunctuation.js +1 -5
  151. package/string/getWithoutUnderscores.js +1 -5
  152. package/string/getWithoutWhitespaces.js +1 -5
  153. package/string/index.js +12 -27
  154. package/string/reservedWords.js +5 -9
  155. package/swr/index.js +9 -18
  156. package/upTimeRobot/UpTimeRobotNamespace.js +32 -42
  157. package/upTimeRobot/server.js +11 -15
  158. package/url/index.js +12 -23
  159. package/url/server.js +1 -5
  160. package/url/writeUrlContents.js +6 -46
  161. package/util/defaultTo.js +5 -12
  162. package/util/getBrotliCompressed.js +3 -10
  163. package/util/getBrotliDecompressed.js +3 -10
  164. package/util/getClean.js +5 -9
  165. package/util/getError.js +1 -5
  166. package/util/getGzipCompressed.js +3 -10
  167. package/util/getGzipDecompressed.js +3 -10
  168. package/util/getWithoutHash.js +1 -5
  169. package/util/getWithoutParameter.js +1 -5
  170. package/util/index.js +7 -17
  171. package/util/isUndefined.js +3 -7
  172. package/util/promiseChunks.js +6 -10
  173. package/util/server.js +4 -11
  174. package/util/sleep.js +1 -5
  175. package/webWorker/index.js +1 -4
  176. package/xml/getXml.js +3 -7
@@ -1,25 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isLastWeek = exports.isThisWeek = exports.getYesterday = exports.getWeeksAgo = exports.getToday = exports.getTwoWeeksAgo = exports.getThisWeek = exports.getLastWeek = exports.getSunday = exports.getMonday = exports.getMin = exports.getMax = exports.getMonthsBetween = exports.getDatesBetween = exports.differenceInBusinessDays = exports.differenceInMinutes = exports.isWeekend = exports.isSunday = exports.isSaturday = exports.isFriday = exports.isThursday = exports.isWednesday = exports.isTuesday = exports.isMonday = exports.getDate = exports.getUnix = void 0;
4
- const luxon_1 = require("luxon");
5
- const getUnix = (input) => {
6
- return (0, exports.getDate)(input)
1
+ import { DateTime, Interval } from "luxon";
2
+ export const getUnix = (input) => {
3
+ return getDate(input)
7
4
  .toUnixInteger();
8
5
  };
9
- exports.getUnix = getUnix;
10
6
  /**
11
7
  * Assume the input is always UTC.
12
8
  *
13
9
  * If it's not UTC, it needs to be converted to UTC before being used.
14
10
  */
15
- const getDate = (input, setMidnight) => {
16
- let instance = luxon_1.DateTime.now()
11
+ export const getDate = (input, setMidnight) => {
12
+ let instance = DateTime.now()
17
13
  .toUTC();
18
14
  if (input) {
19
15
  if (input instanceof Date) {
20
- instance = luxon_1.DateTime.fromJSDate(input, { zone: "utc" });
16
+ instance = DateTime.fromJSDate(input, { zone: "utc" });
21
17
  }
22
- else if (input instanceof luxon_1.DateTime) {
18
+ else if (input instanceof DateTime) {
23
19
  instance = input.toUTC();
24
20
  }
25
21
  else if ("number" === typeof input) {
@@ -30,21 +26,21 @@ const getDate = (input, setMidnight) => {
30
26
  const year = parseInt(dateStr.substring(0, 4));
31
27
  const month = parseInt(dateStr.substring(4, 6));
32
28
  const day = parseInt(dateStr.substring(6, 8));
33
- instance = luxon_1.DateTime.fromObject({ year, month, day }, { zone: "utc" });
29
+ instance = DateTime.fromObject({ year, month, day }, { zone: "utc" });
34
30
  }
35
31
  else if (input < 10000000000) {
36
32
  // Unix timestamp in seconds
37
- instance = luxon_1.DateTime.fromSeconds(input, { zone: "utc" });
33
+ instance = DateTime.fromSeconds(input, { zone: "utc" });
38
34
  }
39
35
  else {
40
36
  // Unix timestamp in milliseconds
41
- instance = luxon_1.DateTime.fromMillis(input, { zone: "utc" });
37
+ instance = DateTime.fromMillis(input, { zone: "utc" });
42
38
  }
43
39
  }
44
40
  else {
45
- instance = luxon_1.DateTime.fromISO(input.toString(), { zone: "utc" });
41
+ instance = DateTime.fromISO(input.toString(), { zone: "utc" });
46
42
  if (!instance.isValid) {
47
- instance = luxon_1.DateTime.fromFormat(input.toString(), "yyyy-MM-dd HH:mm:ss", { zone: "utc" });
43
+ instance = DateTime.fromFormat(input.toString(), "yyyy-MM-dd HH:mm:ss", { zone: "utc" });
48
44
  }
49
45
  }
50
46
  }
@@ -60,69 +56,59 @@ const getDate = (input, setMidnight) => {
60
56
  }
61
57
  return instance;
62
58
  };
63
- exports.getDate = getDate;
64
- const isMonday = (input) => {
65
- const date = (0, exports.getDate)(input);
59
+ export const isMonday = (input) => {
60
+ const date = getDate(input);
66
61
  return date.weekday === 1;
67
62
  };
68
- exports.isMonday = isMonday;
69
- const isTuesday = (input) => {
70
- const date = (0, exports.getDate)(input);
63
+ export const isTuesday = (input) => {
64
+ const date = getDate(input);
71
65
  return date.weekday === 2;
72
66
  };
73
- exports.isTuesday = isTuesday;
74
- const isWednesday = (input) => {
75
- const date = (0, exports.getDate)(input);
67
+ export const isWednesday = (input) => {
68
+ const date = getDate(input);
76
69
  return date.weekday === 3;
77
70
  };
78
- exports.isWednesday = isWednesday;
79
- const isThursday = (input) => {
80
- const date = (0, exports.getDate)(input);
71
+ export const isThursday = (input) => {
72
+ const date = getDate(input);
81
73
  return date.weekday === 4;
82
74
  };
83
- exports.isThursday = isThursday;
84
- const isFriday = (input) => {
85
- const date = (0, exports.getDate)(input);
75
+ export const isFriday = (input) => {
76
+ const date = getDate(input);
86
77
  return date.weekday === 6;
87
78
  };
88
- exports.isFriday = isFriday;
89
- const isSaturday = (input) => {
90
- const date = (0, exports.getDate)(input);
79
+ export const isSaturday = (input) => {
80
+ const date = getDate(input);
91
81
  return date.weekday === 6;
92
82
  };
93
- exports.isSaturday = isSaturday;
94
- const isSunday = (input) => {
95
- const date = (0, exports.getDate)(input);
83
+ export const isSunday = (input) => {
84
+ const date = getDate(input);
96
85
  return date.weekday === 7;
97
86
  };
98
- exports.isSunday = isSunday;
99
87
  /**
100
88
  * Determines if a given date falls on a weekend.
101
89
  *
102
90
  * This function checks whether the day of the week for the provided input corresponds
103
91
  * to Saturday or Sunday, where weekday values of 6 and 7 represent Saturday and Sunday, respectively.
104
92
  */
105
- const isWeekend = (input) => {
106
- const date = (0, exports.getDate)(input);
93
+ export const isWeekend = (input) => {
94
+ const date = getDate(input);
107
95
  return 6 === date.weekday || 7 === date.weekday;
108
96
  };
109
- exports.isWeekend = isWeekend;
110
97
  /**
111
98
  * Calculates the difference in minutes between two provided dates.
112
99
  */
113
- const differenceInMinutes = (start, end) => {
114
- const startDate = (0, exports.getDate)(start);
115
- const endDate = (0, exports.getDate)(end);
100
+ export const differenceInMinutes = (start, end) => {
101
+ const startDate = getDate(start);
102
+ const endDate = getDate(end);
116
103
  return endDate.diff(startDate, "minutes").minutes;
117
104
  };
118
- exports.differenceInMinutes = differenceInMinutes;
119
105
  /**
120
106
  * Calculates the difference in business days between two dates.
121
107
  * Business days are considered as weekdays (Monday to Friday).
122
108
  */
123
- const differenceInBusinessDays = (start, end) => {
124
- const startDate = (0, exports.getDate)(start);
125
- const endDate = (0, exports.getDate)(end);
109
+ export const differenceInBusinessDays = (start, end) => {
110
+ const startDate = getDate(start);
111
+ const endDate = getDate(end);
126
112
  let businessDays = 0;
127
113
  let current = startDate.startOf("day");
128
114
  while (current < endDate.startOf("day")) {
@@ -134,30 +120,28 @@ const differenceInBusinessDays = (start, end) => {
134
120
  }
135
121
  return businessDays;
136
122
  };
137
- exports.differenceInBusinessDays = differenceInBusinessDays;
138
123
  /**
139
124
  * Similar to date-fns' eachDayOfInterval, however the timezone messes this function up.
140
125
  * https://date-fns.org/v2.28.0/docs/eachDayOfInterval
141
126
  * https://www.gov.uk/when-do-the-clocks-change
142
127
  */
143
- const getDatesBetween = (start, end) => {
144
- const startInstance = (0, exports.getDate)(start);
145
- const endInstance = (0, exports.getDate)(end);
146
- const response = luxon_1.Interval.fromDateTimes(startInstance.startOf("day"), endInstance.endOf("day"))
128
+ export const getDatesBetween = (start, end) => {
129
+ const startInstance = getDate(start);
130
+ const endInstance = getDate(end);
131
+ const response = Interval.fromDateTimes(startInstance.startOf("day"), endInstance.endOf("day"))
147
132
  .splitBy({ day: 1 })
148
133
  .map(d => d.start);
149
134
  return response;
150
135
  };
151
- exports.getDatesBetween = getDatesBetween;
152
136
  /**
153
137
  * Get an array of DateTime objects representing the 1st of each month between start and end dates.
154
138
  */
155
- const getMonthsBetween = (start, end) => {
139
+ export const getMonthsBetween = (start, end) => {
156
140
  const months = [];
157
- const endDate = (0, exports.getDate)(end)
141
+ const endDate = getDate(end)
158
142
  .startOf("month");
159
143
  // Start from the 1st of the month containing startDate
160
- let current = (0, exports.getDate)(start)
144
+ let current = getDate(start)
161
145
  .startOf("month");
162
146
  while (current <= endDate) {
163
147
  months.push(current);
@@ -166,28 +150,25 @@ const getMonthsBetween = (start, end) => {
166
150
  }
167
151
  return months;
168
152
  };
169
- exports.getMonthsBetween = getMonthsBetween;
170
153
  /**
171
154
  * If a given date is beyond the maximum, return the maximum.
172
155
  */
173
- const getMax = (input, max) => {
156
+ export const getMax = (input, max) => {
174
157
  return input > max ? max : input;
175
158
  };
176
- exports.getMax = getMax;
177
159
  /**
178
160
  * If a given date is before the minimum, return the minimum.
179
161
  */
180
- const getMin = (input, min) => {
162
+ export const getMin = (input, min) => {
181
163
  return input < min ? min : input;
182
164
  };
183
- exports.getMin = getMin;
184
165
  /**
185
166
  * Retrieve the closest last Monday relative to the input or today.
186
167
  * 0 weeksAgo - Tuesday (10th), return Monday (8th)
187
168
  * 1 weeksAgo - Tuesday (10th), return Monday (1st)
188
169
  */
189
- const getMonday = (input, weeksAgo) => {
190
- let instance = (0, exports.getDate)(input);
170
+ export const getMonday = (input, weeksAgo) => {
171
+ let instance = getDate(input);
191
172
  if ("Mon" !== instance.toFormat("EEE")) {
192
173
  // Get the ISO Day of week (Monday - 1 to Sunday - 7)
193
174
  const isoDay = Number(instance.toFormat("E")) - 1;
@@ -197,14 +178,13 @@ const getMonday = (input, weeksAgo) => {
197
178
  instance = instance.minus({ weeks: weeksAgo ?? 0 });
198
179
  return instance;
199
180
  };
200
- exports.getMonday = getMonday;
201
181
  /**
202
182
  * Retrieve the closest last Sunday relative to the input or today.
203
183
  * 0 weeksAgo - Tuesday (17th), return Sunday (14th)
204
184
  * 1 weeksAgo - Tuesday (17th), return Monday (7th)
205
185
  */
206
- const getSunday = (input, weeksAgo) => {
207
- let instance = (0, exports.getDate)(input);
186
+ export const getSunday = (input, weeksAgo) => {
187
+ let instance = getDate(input);
208
188
  if ("Sun" !== instance.toFormat("EEE")) {
209
189
  // Get the ISO Day of week (Monday - 1 to Sunday - 7)
210
190
  const isoDay = Number(instance.toFormat("E"));
@@ -214,90 +194,81 @@ const getSunday = (input, weeksAgo) => {
214
194
  instance = instance.minus({ weeks: weeksAgo ?? 0 });
215
195
  return instance;
216
196
  };
217
- exports.getSunday = getSunday;
218
197
  /**
219
198
  * Return an object of start/end predefined date of Last Week.
220
199
  * Creating a date from scratch (no user input), thus needs to be London time.
221
200
  */
222
- const getLastWeek = () => {
201
+ export const getLastWeek = () => {
223
202
  return {
224
- end: (0, exports.getMonday)(undefined, 0),
225
- start: (0, exports.getSunday)(undefined, 1),
203
+ end: getMonday(undefined, 0),
204
+ start: getSunday(undefined, 1),
226
205
  };
227
206
  };
228
- exports.getLastWeek = getLastWeek;
229
207
  /**
230
208
  * Return an object of start/end predefined date of This Week.
231
209
  * Creating a date from scratch (no user input), thus needs to be London time.
232
210
  */
233
- const getThisWeek = () => {
211
+ export const getThisWeek = () => {
234
212
  return {
235
- end: (0, exports.getMonday)(undefined, 0),
236
- start: (0, exports.getSunday)(undefined, -1),
213
+ end: getMonday(undefined, 0),
214
+ start: getSunday(undefined, -1),
237
215
  };
238
216
  };
239
- exports.getThisWeek = getThisWeek;
240
217
  /**
241
218
  * Return an object of start/end predefined date of Two Weeks Ago.
242
219
  * Creating a date from scratch (no user input), thus needs to be London time.
243
220
  */
244
- const getTwoWeeksAgo = () => {
221
+ export const getTwoWeeksAgo = () => {
245
222
  return {
246
- end: (0, exports.getMonday)(undefined, 1),
247
- start: (0, exports.getSunday)(undefined, 2),
223
+ end: getMonday(undefined, 1),
224
+ start: getSunday(undefined, 2),
248
225
  };
249
226
  };
250
- exports.getTwoWeeksAgo = getTwoWeeksAgo;
251
227
  /**
252
228
  * Shortcut to get today's date.
253
229
  * Creating a date from scratch (no user input), thus needs to be London time.
254
230
  */
255
- const getToday = (setMidnight) => {
256
- return (0, exports.getDate)(undefined, setMidnight);
231
+ export const getToday = (setMidnight) => {
232
+ return getDate(undefined, setMidnight);
257
233
  };
258
- exports.getToday = getToday;
259
234
  /**
260
235
  * From a given input, move the date back X weeksAgo
261
236
  */
262
- const getWeeksAgo = (input, weeksAgo) => {
263
- let instance = (0, exports.getDate)(input);
237
+ export const getWeeksAgo = (input, weeksAgo) => {
238
+ let instance = getDate(input);
264
239
  instance = instance.plus({ weeks: weeksAgo });
265
240
  return instance;
266
241
  };
267
- exports.getWeeksAgo = getWeeksAgo;
268
242
  /**
269
243
  * Shortcut to get yesterday's date.
270
244
  * Creating a date from scratch (no user input), thus needs to be London time.
271
245
  */
272
- const getYesterday = (input) => {
273
- let instance = (0, exports.getDate)(input);
246
+ export const getYesterday = (input) => {
247
+ let instance = getDate(input);
274
248
  instance = instance.minus({ days: 1 });
275
249
  return instance;
276
250
  };
277
- exports.getYesterday = getYesterday;
278
251
  /**
279
252
  * Check to see if a given timeframe is This Week.
280
253
  */
281
- const isThisWeek = (start, end) => {
254
+ export const isThisWeek = (start, end) => {
282
255
  const inputWeek = {
283
- start: (0, exports.getDate)(start),
284
- end: (0, exports.getDate)(end),
256
+ start: getDate(start),
257
+ end: getDate(end),
285
258
  };
286
- const thisWeek = (0, exports.getThisWeek)();
259
+ const thisWeek = getThisWeek();
287
260
  // Day confirms same year and month and day
288
261
  return inputWeek.start.hasSame(thisWeek.start, "day") && inputWeek.end.hasSame(thisWeek.end, "day");
289
262
  };
290
- exports.isThisWeek = isThisWeek;
291
263
  /**
292
264
  * Check to see if a given timeframe is Last Week.
293
265
  */
294
- const isLastWeek = (start, end) => {
266
+ export const isLastWeek = (start, end) => {
295
267
  const inputWeek = {
296
- start: (0, exports.getDate)(start),
297
- end: (0, exports.getDate)(end),
268
+ start: getDate(start),
269
+ end: getDate(end),
298
270
  };
299
- const lastWeek = (0, exports.getLastWeek)();
271
+ const lastWeek = getLastWeek();
300
272
  // Day confirms same year and month and day
301
273
  return inputWeek.start.hasSame(lastWeek.start, "day") && inputWeek.end.hasSame(lastWeek.end, "day");
302
274
  };
303
- exports.isLastWeek = isLastWeek;
@@ -1,18 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFinancialYearWeeks = exports.getFinancialYearToYesterday = exports.getFinancialYearToDate = exports.getFinancialYear = void 0;
4
- const calculation_1 = require("./calculation");
5
- const luxon_1 = require("luxon");
1
+ import { getDate, getToday, getYesterday } from "./calculation";
2
+ import { Interval } from "luxon";
6
3
  /**
7
4
  * Get the current financial year.
8
5
  */
9
- const getFinancialYear = (year) => {
6
+ export const getFinancialYear = (year) => {
10
7
  // Either use the current year or a specified year
11
8
  let financialYear = year;
12
9
  if ("undefined" === typeof year) {
13
- const todayInstance = (0, calculation_1.getToday)();
10
+ const todayInstance = getToday();
14
11
  // If today is before 1st of April, then use last year
15
- if (todayInstance < (0, calculation_1.getDate)(`${todayInstance.toFormat("yyyy")}-04-01`)) {
12
+ if (todayInstance < getDate(`${todayInstance.toFormat("yyyy")}-04-01`)) {
16
13
  financialYear = Number(todayInstance.toFormat("yyyy")) - 1;
17
14
  }
18
15
  // On or after 1st of April, use this year
@@ -21,7 +18,7 @@ const getFinancialYear = (year) => {
21
18
  }
22
19
  }
23
20
  // The year start needs to be 1st April this year - if its not a monday we need to shift this to the next monday.
24
- let yearStartInstance = (0, calculation_1.getDate)(`${financialYear}-04-01`);
21
+ let yearStartInstance = getDate(`${financialYear}-04-01`);
25
22
  // Get the previous Monday if the 1st of April isn't a Monday
26
23
  if ("Mon" !== yearStartInstance.toFormat("EEE")) {
27
24
  // Get the ISO Day of the week (Monday - 1 to Sunday - 7)
@@ -32,7 +29,7 @@ const getFinancialYear = (year) => {
32
29
  }
33
30
  // The year-end needs to be 31st March next year
34
31
  // We are specifying the date, so don't change the timezone
35
- let yearEndInstance = (0, calculation_1.getDate)(`${(financialYear + 1)}-03-31`);
32
+ let yearEndInstance = getDate(`${(financialYear + 1)}-03-31`);
36
33
  // Get the next Sunday if the 31st of March isn't a Sunday
37
34
  if ("Sun" !== yearEndInstance.toFormat("EEE")) {
38
35
  // Get the ISO Day of the week (Monday - 1 to Sunday - 7)
@@ -46,40 +43,36 @@ const getFinancialYear = (year) => {
46
43
  start: yearStartInstance,
47
44
  };
48
45
  };
49
- exports.getFinancialYear = getFinancialYear;
50
46
  /**
51
47
  * Return the current financial year up to today.
52
48
  */
53
- const getFinancialYearToDate = () => {
54
- const todayInstance = (0, calculation_1.getToday)();
55
- const thisFinancialYear = (0, exports.getFinancialYear)();
49
+ export const getFinancialYearToDate = () => {
50
+ const todayInstance = getToday();
51
+ const thisFinancialYear = getFinancialYear();
56
52
  return {
57
53
  end: todayInstance,
58
54
  start: thisFinancialYear.start,
59
55
  };
60
56
  };
61
- exports.getFinancialYearToDate = getFinancialYearToDate;
62
57
  /**
63
58
  * Return the current financial year up to yesterday.
64
59
  * Timezone should always be London based
65
60
  */
66
- const getFinancialYearToYesterday = () => {
67
- const yesterdayInstance = (0, calculation_1.getYesterday)();
68
- const thisFinancialYear = (0, exports.getFinancialYear)();
61
+ export const getFinancialYearToYesterday = () => {
62
+ const yesterdayInstance = getYesterday();
63
+ const thisFinancialYear = getFinancialYear();
69
64
  return {
70
65
  end: yesterdayInstance,
71
66
  start: thisFinancialYear.start,
72
67
  };
73
68
  };
74
- exports.getFinancialYearToYesterday = getFinancialYearToYesterday;
75
69
  /**
76
70
  * Get the current financial year.
77
71
  */
78
- const getFinancialYearWeeks = (year) => {
79
- const financialYear = (0, exports.getFinancialYear)(year);
80
- const response = luxon_1.Interval
72
+ export const getFinancialYearWeeks = (year) => {
73
+ const financialYear = getFinancialYear(year);
74
+ const response = Interval
81
75
  .fromDateTimes(financialYear.start, financialYear.end)
82
76
  .splitBy({ weeks: 1 });
83
77
  return response;
84
78
  };
85
- exports.getFinancialYearWeeks = getFinancialYearWeeks;
package/date/format.js CHANGED
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseExcelDate = exports.getYmdString = exports.getYmdNumber = exports.getYmdHisString = exports.getYmdHisNumber = exports.getYearNumber = exports.getTodayYmdHisNumber = exports.getTodayYmdNumber = exports.getTodayYmdHisString = exports.getTodayYmdString = exports.getYearMonthString = exports.getMonthYearString = exports.getFullDateTime = exports.getFullDate = exports.getDayNumber = exports.format = exports.getDurationMinutes = exports.getDurationHours = void 0;
4
- const calculation_1 = require("./calculation");
5
- const luxon_1 = require("luxon");
1
+ import { getDate, getToday } from "./calculation";
2
+ import { DateTime } from "luxon";
6
3
  /**
7
4
  * Convert a number of seconds into HH:MM:SS
8
5
  * https://www.codevertiser.com/convert-seconds-to-hours-and-minutes-javascript/
9
6
  */
10
- const getDurationHours = (seconds) => {
7
+ export const getDurationHours = (seconds) => {
11
8
  let response = "00:00:00";
12
9
  if (seconds > 0) {
13
10
  const calculated = {
@@ -24,12 +21,11 @@ const getDurationHours = (seconds) => {
24
21
  }
25
22
  return response;
26
23
  };
27
- exports.getDurationHours = getDurationHours;
28
24
  /**
29
25
  * Convert a number of seconds into MM:SS
30
26
  * https://www.codevertiser.com/convert-seconds-to-hours-and-minutes-javascript/
31
27
  */
32
- const getDurationMinutes = (seconds) => {
28
+ export const getDurationMinutes = (seconds) => {
33
29
  let response = "00:00";
34
30
  if (seconds > 0) {
35
31
  const calculated = {
@@ -44,130 +40,114 @@ const getDurationMinutes = (seconds) => {
44
40
  }
45
41
  return response;
46
42
  };
47
- exports.getDurationMinutes = getDurationMinutes;
48
43
  /**
49
44
  * Simple function takes any DateTime, String or Number and formats it.
50
45
  */
51
- const format = (input, dateFormat) => {
52
- const instance = (0, calculation_1.getDate)(input);
46
+ export const format = (input, dateFormat) => {
47
+ const instance = getDate(input);
53
48
  return instance.toFormat(dateFormat);
54
49
  };
55
- exports.format = format;
56
50
  /**
57
51
  * Convert a Date into a dd number.
58
52
  */
59
- const getDayNumber = (input) => {
60
- return Number((0, exports.format)(input, "dd"));
53
+ export const getDayNumber = (input) => {
54
+ return Number(format(input, "dd"));
61
55
  };
62
- exports.getDayNumber = getDayNumber;
63
56
  /**
64
57
  * Whenever we are displaying a month and year date in Codex, this will be the standardised format.
65
58
  * Example: 1901-02-03 → 3 Feb 1901
66
59
  */
67
- const getFullDate = (input) => {
68
- return (0, exports.format)(input, "d MMM yyyy");
60
+ export const getFullDate = (input) => {
61
+ return format(input, "d MMM yyyy");
69
62
  };
70
- exports.getFullDate = getFullDate;
71
63
  /**
72
64
  * Whenever we are displaying a month and year date in Codex, this will be the standardised format.
73
65
  * Example: 1901-02-03 01:23:45 → 1:23am 3 Feb 1901
74
66
  */
75
- const getFullDateTime = (input) => {
76
- return (0, exports.format)(input, "d MMM yyyy h:mm:ss");
67
+ export const getFullDateTime = (input) => {
68
+ return format(input, "d MMM yyyy h:mm:ss");
77
69
  };
78
- exports.getFullDateTime = getFullDateTime;
79
70
  /**
80
71
  * Returns a MMM YYYY value as a number for a given year.
81
72
  * Example: 1901-02-03 → Feb 1901
82
73
  */
83
- const getMonthYearString = (input) => {
84
- return (0, exports.format)(input, "MMM yyyy");
74
+ export const getMonthYearString = (input) => {
75
+ return format(input, "MMM yyyy");
85
76
  };
86
- exports.getMonthYearString = getMonthYearString;
87
77
  /**
88
78
  * Returns a YYYY MMM value as a number for a given year.
89
79
  * Example: 1901-02-03 → 1901 Feb
90
80
  */
91
- const getYearMonthString = (input) => {
92
- return (0, exports.format)(input, "yyyy MMM");
81
+ export const getYearMonthString = (input) => {
82
+ return format(input, "yyyy MMM");
93
83
  };
94
- exports.getYearMonthString = getYearMonthString;
95
84
  /**
96
85
  * Shorthand to get the current date.
97
86
  */
98
- const getTodayYmdString = (setMidnight) => {
99
- const today = (0, calculation_1.getToday)(setMidnight);
100
- return (0, exports.getYmdString)(today);
87
+ export const getTodayYmdString = (setMidnight) => {
88
+ const today = getToday(setMidnight);
89
+ return getYmdString(today);
101
90
  };
102
- exports.getTodayYmdString = getTodayYmdString;
103
91
  /**
104
92
  * Shorthand to get the current date.
105
93
  */
106
- const getTodayYmdHisString = (setMidnight) => {
107
- const today = (0, calculation_1.getToday)(setMidnight);
108
- return (0, exports.getYmdHisString)(today);
94
+ export const getTodayYmdHisString = (setMidnight) => {
95
+ const today = getToday(setMidnight);
96
+ return getYmdHisString(today);
109
97
  };
110
- exports.getTodayYmdHisString = getTodayYmdHisString;
111
98
  /**
112
99
  * Shorthand to get the current date.
113
100
  */
114
- const getTodayYmdNumber = (setMidnight) => {
115
- const today = (0, calculation_1.getToday)(setMidnight);
116
- return (0, exports.getYmdNumber)(today);
101
+ export const getTodayYmdNumber = (setMidnight) => {
102
+ const today = getToday(setMidnight);
103
+ return getYmdNumber(today);
117
104
  };
118
- exports.getTodayYmdNumber = getTodayYmdNumber;
119
105
  /**
120
106
  * Shorthand to get the current date.
121
107
  */
122
- const getTodayYmdHisNumber = (setMidnight) => {
123
- const today = (0, calculation_1.getToday)(setMidnight);
124
- return (0, exports.getYmdHisNumber)(today);
108
+ export const getTodayYmdHisNumber = (setMidnight) => {
109
+ const today = getToday(setMidnight);
110
+ return getYmdHisNumber(today);
125
111
  };
126
- exports.getTodayYmdHisNumber = getTodayYmdHisNumber;
127
112
  /**
128
113
  * Convert a Date into a YYYY number.
129
114
  */
130
- const getYearNumber = (input) => {
131
- return Number((0, exports.format)(input, "yyyy"));
115
+ export const getYearNumber = (input) => {
116
+ return Number(format(input, "yyyy"));
132
117
  };
133
- exports.getYearNumber = getYearNumber;
134
118
  /**
135
119
  * Returns a YYYYMMDDHHIISS value as a number.
136
120
  * Example: 1901-02-03 01:23:45 → 19010203012345
137
121
  */
138
- const getYmdHisNumber = (input) => {
139
- return Number((0, exports.format)(input, "yyyyMMddHHmmss"));
122
+ export const getYmdHisNumber = (input) => {
123
+ return Number(format(input, "yyyyMMddHHmmss"));
140
124
  };
141
- exports.getYmdHisNumber = getYmdHisNumber;
142
125
  /**
143
126
  * Returns a YYYY-MM-DD HH:MM:SS value as a string.
144
127
  * Example: 1901-02-03 → 1901-02-03 00:00:00
145
128
  */
146
- const getYmdHisString = (input) => {
147
- return (0, exports.format)(input, "yyyy-MM-dd HH:mm:ss");
129
+ export const getYmdHisString = (input) => {
130
+ return format(input, "yyyy-MM-dd HH:mm:ss");
148
131
  };
149
- exports.getYmdHisString = getYmdHisString;
150
132
  /**
151
133
  * Returns a YYYYMMDD value as a number.
152
134
  * Example: 1901-02-03 → 19010203
153
135
  */
154
- const getYmdNumber = (input) => {
155
- return Number((0, exports.format)(input, "yyyyMMdd"));
136
+ export const getYmdNumber = (input) => {
137
+ return Number(format(input, "yyyyMMdd"));
156
138
  };
157
- exports.getYmdNumber = getYmdNumber;
158
139
  /**
159
140
  * Whenever we are displaying a YYYY-MM-DD date in Codex
160
141
  * Example: 1901-02-03 → 1901-02-03
161
142
  */
162
- const getYmdString = (input) => {
163
- return (0, exports.format)(input, "yyyy-MM-dd");
143
+ export const getYmdString = (input) => {
144
+ return format(input, "yyyy-MM-dd");
164
145
  };
165
- exports.getYmdString = getYmdString;
166
146
  /**
167
147
  * Convert an Excel date "e.g. 44216" into a JavaScript date object.
168
148
  * https://stackoverflow.com/questions/16229494/converting-excel-date-serial-number-to-date-using-javascript
169
149
  */
170
- const parseExcelDate = (serial) => {
150
+ export const parseExcelDate = (serial) => {
171
151
  const utcDates = Math.floor(serial - 25569);
172
152
  const utcValue = utcDates * 86400;
173
153
  const dateInfo = new Date(utcValue * 1000);
@@ -177,6 +157,5 @@ const parseExcelDate = (serial) => {
177
157
  totalSeconds -= seconds;
178
158
  const hours = Math.floor(totalSeconds / (60 * 60));
179
159
  const minutes = Math.floor(totalSeconds / 60) % 60;
180
- return luxon_1.DateTime.fromISO(`${dateInfo.getFullYear()}-${dateInfo.getMonth()}-${dateInfo.getDate()}T${hours}:${minutes}:${seconds}Z`);
160
+ return DateTime.fromISO(`${dateInfo.getFullYear()}-${dateInfo.getMonth()}-${dateInfo.getDate()}T${hours}:${minutes}:${seconds}Z`);
181
161
  };
182
- exports.parseExcelDate = parseExcelDate;
package/date/index.js CHANGED
@@ -1,20 +1,4 @@
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("./type"), exports);
18
- __exportStar(require("./calculation"), exports);
19
- __exportStar(require("./financialYear"), exports);
20
- __exportStar(require("./format"), exports);
1
+ export * from "./type";
2
+ export * from "./calculation";
3
+ export * from "./financialYear";
4
+ export * from "./format";