bare-script 2.2.10 → 2.2.12

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/README.md CHANGED
@@ -83,7 +83,7 @@ console.log(await executeScriptAsync(script, {'fetchFn': fetch}));
83
83
  This outputs:
84
84
 
85
85
  ~~~
86
- The BareScript Library has 89 functions
86
+ The BareScript Library has 100 functions
87
87
  ~~~
88
88
 
89
89
 
package/lib/data.js CHANGED
@@ -160,16 +160,19 @@ function parseNumber(text) {
160
160
 
161
161
 
162
162
  export function parseDatetime(text) {
163
- if (rDate.test(text)) {
164
- const localDate = new Date(text);
165
- return new Date(localDate.getUTCFullYear(), localDate.getUTCMonth(), localDate.getUTCDate());
163
+ const mDate = text.match(rDate);
164
+ if (mDate !== null) {
165
+ const year = Number.parseInt(mDate.groups.year, 10);
166
+ const month = Number.parseInt(mDate.groups.month, 10);
167
+ const day = Number.parseInt(mDate.groups.day, 10);
168
+ return new Date(year, month - 1, day);
166
169
  } else if (rDatetime.test(text)) {
167
170
  return new Date(text);
168
171
  }
169
172
  return null;
170
173
  }
171
174
 
172
- const rDate = /^\d{4}-\d{2}-\d{2}$/;
175
+ const rDate = /^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$/;
173
176
  const rDatetime = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?(?:Z|[+-]\d{2}:\d{2})$/;
174
177
 
175
178
 
package/lib/library.js CHANGED
@@ -257,15 +257,17 @@ export const scriptFunctions = {
257
257
  // $group: Datetime
258
258
  // $doc: Get the day of the month of a datetime
259
259
  // $arg datetime: The datetime
260
+ // $arg utc: Optional (default is false). If true, return the UTC day of the month.
260
261
  // $return: The day of the month
261
- 'datetimeDay': ([datetime]) => (datetime instanceof Date ? datetime.getDate() : null),
262
+ 'datetimeDay': ([datetime, utc = false]) => (datetime instanceof Date ? (utc ? datetime.getUTCDate() : datetime.getDate()) : null),
262
263
 
263
264
  // $function: datetimeHour
264
265
  // $group: Datetime
265
266
  // $doc: Get the hour of a datetime
266
267
  // $arg datetime: The datetime
268
+ // $arg utc: Optional (default is false). If true, return the UTC hour.
267
269
  // $return: The hour
268
- 'datetimeHour': ([datetime]) => (datetime instanceof Date ? datetime.getHours() : null),
270
+ 'datetimeHour': ([datetime, utc = false]) => (datetime instanceof Date ? (utc ? datetime.getUTCHours() : datetime.getHours()) : null),
269
271
 
270
272
  // $function: datetimeISOFormat
271
273
  // $group: Datetime
@@ -295,15 +297,21 @@ export const scriptFunctions = {
295
297
  // $group: Datetime
296
298
  // $doc: Get the number of minutes of a datetime
297
299
  // $arg datetime: The datetime
300
+ // $arg utc: Optional (default is false). If true, return the UTC minutes.
298
301
  // $return: The number of minutes
299
- 'datetimeMinute': ([datetime]) => (datetime instanceof Date ? datetime.getMinutes() : null),
302
+ 'datetimeMinute': ([datetime, utc = false]) => (
303
+ datetime instanceof Date ? (utc ? datetime.getUTCMinutes() : datetime.getMinutes()) : null
304
+ ),
300
305
 
301
306
  // $function: datetimeMonth
302
307
  // $group: Datetime
303
308
  // $doc: Get the number of the month (1-12) of a datetime
304
309
  // $arg datetime: The datetime
310
+ // $arg utc: Optional (default is false). If true, return the UTC month.
305
311
  // $return: The number of the month
306
- 'datetimeMonth': ([datetime]) => (datetime instanceof Date ? datetime.getMonth() + 1 : null),
312
+ 'datetimeMonth': ([datetime, utc = false]) => (
313
+ datetime instanceof Date ? (utc ? datetime.getUTCMonth() + 1 : datetime.getMonth() + 1) : null
314
+ ),
307
315
 
308
316
  // $function: datetimeNew
309
317
  // $group: Datetime
@@ -345,8 +353,11 @@ export const scriptFunctions = {
345
353
  // $group: Datetime
346
354
  // $doc: Get the number of seconds of a datetime
347
355
  // $arg datetime: The datetime
356
+ // $arg utc: Optional (default is false). If true, return the UTC seconds.
348
357
  // $return: The number of seconds
349
- 'datetimeSecond': ([datetime]) => (datetime instanceof Date ? datetime.getSeconds() : null),
358
+ 'datetimeSecond': ([datetime, utc = false]) => (
359
+ datetime instanceof Date ? (utc ? datetime.getUTCSeconds() : datetime.getSeconds()) : null
360
+ ),
350
361
 
351
362
  // $function: datetimeToday
352
363
  // $group: Datetime
@@ -361,8 +372,11 @@ export const scriptFunctions = {
361
372
  // $group: Datetime
362
373
  // $doc: Get the full year of a datetime
363
374
  // $arg datetime: The datetime
375
+ // $arg utc: Optional (default is false). If true, return the UTC year.
364
376
  // $return: The full year
365
- 'datetimeYear': ([datetime]) => (datetime instanceof Date ? datetime.getFullYear() : null),
377
+ 'datetimeYear': ([datetime, utc = false]) => (
378
+ datetime instanceof Date ? (utc ? datetime.getUTCFullYear() : datetime.getFullYear()) : null
379
+ ),
366
380
 
367
381
 
368
382
  //
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "bare-script",
4
- "version": "2.2.10",
4
+ "version": "2.2.12",
5
5
  "description": "BareScript; a lightweight scripting and expression language",
6
6
  "keywords": [
7
7
  "expression",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "devDependencies": {
33
33
  "c8": "~8.0",
34
- "eslint": "~8.50",
34
+ "eslint": "~8.52",
35
35
  "jsdoc": "~4.0"
36
36
  }
37
37
  }