bare-script 3.0.2 → 3.0.3

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/lib/library.js CHANGED
@@ -471,10 +471,10 @@ function datetimeISOFormat([datetime = null, isDate = false]) {
471
471
  }
472
472
 
473
473
  if (valueBoolean(isDate)) {
474
- const year = datetime.getFullYear();
475
- const month = datetime.getMonth() + 1;
476
- const day = datetime.getDate();
477
- return `${year}-${month < 10 ? '0' : ''}${month}-${day < 10 ? '0' : ''}${day}`;
474
+ const year = String(datetime.getFullYear()).padStart(4, '0');
475
+ const month = String(datetime.getMonth() + 1).padStart(2, '0');
476
+ const day = String(datetime.getDate()).padStart(2, '0');
477
+ return `${year}-${month}-${day}`;
478
478
  }
479
479
 
480
480
  return valueString(datetime);
@@ -549,7 +549,7 @@ function datetimeMonth([datetime = null]) {
549
549
  // $arg millisecond: Optional (default is 0). The millisecond.
550
550
  // $return: The new datetime
551
551
  function datetimeNew([year, month, day, hour = 0, minute = 0, second = 0, millisecond = 0]) {
552
- if (valueType(year) !== 'number' || Math.floor(year) !== year ||
552
+ if (valueType(year) !== 'number' || Math.floor(year) !== year || year < 100 ||
553
553
  valueType(month) !== 'number' || Math.floor(month) !== month ||
554
554
  valueType(day) !== 'number' || Math.floor(day) !== day || day < -10000 || day > 10000 ||
555
555
  valueType(hour) !== 'number' || Math.floor(hour) !== hour ||
package/lib/value.js CHANGED
@@ -54,29 +54,23 @@ export function valueString(value) {
54
54
  } else if (type === 'number') {
55
55
  return `${value}`;
56
56
  } else if (value instanceof Date) {
57
- const year = value.getFullYear();
58
- const month = value.getMonth() + 1;
59
- const monthStr = `${month < 10 ? '0' : ''}${month}`;
60
- const day = value.getDate();
61
- const dayStr = `${day < 10 ? '0' : ''}${day}`;
62
- const hour = value.getHours();
63
- const hourStr = `${hour < 10 ? '0' : ''}${hour}`;
64
- const minute = value.getMinutes();
65
- const minuteStr = `${minute < 10 ? '0' : ''}${minute}`;
66
- const second = value.getSeconds();
67
- const secondStr = `${second < 10 ? '0' : ''}${second}`;
68
- const millisecond = value.getMilliseconds();
69
- const millisecondStr = millisecond === 0 ? '' : `.${millisecond < 100 ? '0' : ''}${millisecond < 10 ? '0' : ''}${millisecond}`;
57
+ const year = String(value.getFullYear()).padStart(4, '0');
58
+ const month = String(value.getMonth() + 1).padStart(2, '0');
59
+ const day = String(value.getDate()).padStart(2, '0');
60
+ const hour = String(value.getHours()).padStart(2, '0');
61
+ const minute = String(value.getMinutes()).padStart(2, '0');
62
+ const second = String(value.getSeconds()).padStart(2, '0');
63
+ const millisecond = value.getMilliseconds() === 0 ? '' : `.${String(value.getMilliseconds()).padStart(3, '0')}`;
70
64
  const tzOffset = value.getTimezoneOffset();
71
65
  /* c8 ignore next */
72
66
  const tzSign = tzOffset < 0 ? '+' : '-';
73
67
  const tzHour = Math.floor(Math.abs(tzOffset) / 60);
74
68
  /* c8 ignore next */
75
- const tzHourStr = `${tzHour < 10 ? '0' : ''}${tzHour}`;
69
+ const tzHourStr = String(tzHour).padStart(2, '0');
76
70
  const tzMinute = Math.abs(tzOffset) - tzHour * 60;
77
71
  /* c8 ignore next */
78
- const tzMinuteStr = `${tzMinute < 10 ? '0' : ''}${tzMinute}`;
79
- return `${year}-${monthStr}-${dayStr}T${hourStr}:${minuteStr}:${secondStr}${millisecondStr}${tzSign}${tzHourStr}:${tzMinuteStr}`;
72
+ const tzMinuteStr = String(tzMinute).padStart(2, '0');
73
+ return `${year}-${month}-${day}T${hour}:${minute}:${second}${millisecond}${tzSign}${tzHourStr}:${tzMinuteStr}`;
80
74
  } else if (Array.isArray(value)) {
81
75
  return valueJSON(value);
82
76
  } else if (value instanceof RegExp) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "bare-script",
4
- "version": "3.0.2",
4
+ "version": "3.0.3",
5
5
  "description": "BareScript; a lightweight scripting and expression language",
6
6
  "keywords": [
7
7
  "expression",