@h3ravel/support 0.12.0 → 0.13.0

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.
@@ -1,12 +1,12 @@
1
- import { Stringable } from './Helpers/Str'
1
+ import { Stringable } from '..'
2
2
 
3
3
  export { }
4
4
 
5
5
  declare global {
6
6
  /**
7
- * Dump something and kill the process for quick debugging. Based on Laravel's dd()
7
+ * Get a new Stringable object from the given string.
8
8
  *
9
- * @param args
9
+ * @param string
10
10
  */
11
11
  function str (string?: string): Stringable
12
12
  }
package/dist/index.cjs CHANGED
@@ -37,22 +37,22 @@ let util = require("util");
37
37
  util = __toESM(util);
38
38
  let dayjs = require("dayjs");
39
39
  dayjs = __toESM(dayjs);
40
- let dayjs_plugin_advancedFormat = require("dayjs/plugin/advancedFormat");
41
- dayjs_plugin_advancedFormat = __toESM(dayjs_plugin_advancedFormat);
42
- let dayjs_plugin_customParseFormat = require("dayjs/plugin/customParseFormat");
43
- dayjs_plugin_customParseFormat = __toESM(dayjs_plugin_customParseFormat);
44
- let dayjs_plugin_dayOfYear = require("dayjs/plugin/dayOfYear");
45
- dayjs_plugin_dayOfYear = __toESM(dayjs_plugin_dayOfYear);
46
- let dayjs_plugin_isBetween = require("dayjs/plugin/isBetween");
47
- dayjs_plugin_isBetween = __toESM(dayjs_plugin_isBetween);
48
- let dayjs_plugin_isLeapYear = require("dayjs/plugin/isLeapYear");
49
- dayjs_plugin_isLeapYear = __toESM(dayjs_plugin_isLeapYear);
50
- let dayjs_plugin_relativeTime = require("dayjs/plugin/relativeTime");
51
- dayjs_plugin_relativeTime = __toESM(dayjs_plugin_relativeTime);
52
- let dayjs_plugin_timezone = require("dayjs/plugin/timezone");
53
- dayjs_plugin_timezone = __toESM(dayjs_plugin_timezone);
54
- let dayjs_plugin_utc = require("dayjs/plugin/utc");
55
- dayjs_plugin_utc = __toESM(dayjs_plugin_utc);
40
+ let dayjs_plugin_advancedFormat_js = require("dayjs/plugin/advancedFormat.js");
41
+ dayjs_plugin_advancedFormat_js = __toESM(dayjs_plugin_advancedFormat_js);
42
+ let dayjs_plugin_customParseFormat_js = require("dayjs/plugin/customParseFormat.js");
43
+ dayjs_plugin_customParseFormat_js = __toESM(dayjs_plugin_customParseFormat_js);
44
+ let dayjs_plugin_dayOfYear_js = require("dayjs/plugin/dayOfYear.js");
45
+ dayjs_plugin_dayOfYear_js = __toESM(dayjs_plugin_dayOfYear_js);
46
+ let dayjs_plugin_isBetween_js = require("dayjs/plugin/isBetween.js");
47
+ dayjs_plugin_isBetween_js = __toESM(dayjs_plugin_isBetween_js);
48
+ let dayjs_plugin_isLeapYear_js = require("dayjs/plugin/isLeapYear.js");
49
+ dayjs_plugin_isLeapYear_js = __toESM(dayjs_plugin_isLeapYear_js);
50
+ let dayjs_plugin_relativeTime_js = require("dayjs/plugin/relativeTime.js");
51
+ dayjs_plugin_relativeTime_js = __toESM(dayjs_plugin_relativeTime_js);
52
+ let dayjs_plugin_timezone_js = require("dayjs/plugin/timezone.js");
53
+ dayjs_plugin_timezone_js = __toESM(dayjs_plugin_timezone_js);
54
+ let dayjs_plugin_utc_js = require("dayjs/plugin/utc.js");
55
+ dayjs_plugin_utc_js = __toESM(dayjs_plugin_utc_js);
56
56
 
57
57
  //#region src/Helpers/Arr.ts
58
58
  var Arr_exports = /* @__PURE__ */ __export({
@@ -72,7 +72,8 @@ var Arr_exports = /* @__PURE__ */ __export({
72
72
  range: () => range,
73
73
  reverse: () => reverse,
74
74
  shift: () => shift,
75
- take: () => take
75
+ take: () => take,
76
+ wrap: () => wrap
76
77
  });
77
78
  /**
78
79
  * Splits an array into chunks of a specified size.
@@ -170,6 +171,16 @@ const flatten = (arr) => {
170
171
  recurse(arr);
171
172
  return result;
172
173
  };
174
+ /**
175
+ * If the given value is not an array and not null, wrap it in one.
176
+ *
177
+ * @param {Array} value
178
+ * @return array
179
+ */
180
+ const wrap = (value) => {
181
+ if (value === null) return [];
182
+ return Array.isArray(value) ? value : [value];
183
+ };
173
184
 
174
185
  //#endregion
175
186
  //#region src/Helpers/Crypto.ts
@@ -709,6 +720,164 @@ const slugifyKeys = (obj, only = [], separator = "_") => {
709
720
  return Object.fromEntries(entries.map(([key, value]) => [slugify(key), value]));
710
721
  };
711
722
 
723
+ //#endregion
724
+ //#region src/Helpers/Time.ts
725
+ dayjs.default.extend(dayjs_plugin_utc_js.default);
726
+ dayjs.default.extend(dayjs_plugin_timezone_js.default);
727
+ dayjs.default.extend(dayjs_plugin_dayOfYear_js.default);
728
+ dayjs.default.extend(dayjs_plugin_isBetween_js.default);
729
+ dayjs.default.extend(dayjs_plugin_isLeapYear_js.default);
730
+ dayjs.default.extend(dayjs_plugin_relativeTime_js.default);
731
+ dayjs.default.extend(dayjs_plugin_advancedFormat_js.default);
732
+ dayjs.default.extend(dayjs_plugin_customParseFormat_js.default);
733
+ const phpToDayjsTokens = (format$1) => format$1.replace(/Y/g, "YYYY").replace(/m/g, "MM").replace(/d/g, "DD").replace(/H/g, "HH").replace(/i/g, "mm").replace(/s/g, "ss");
734
+ function format(date, fmt) {
735
+ return (0, dayjs.default)(date).format(phpToDayjsTokens(fmt));
736
+ }
737
+ const TimeClass = class {};
738
+ var DateTime = class DateTime extends TimeClass {
739
+ instance;
740
+ constructor(config) {
741
+ super(config);
742
+ this.instance = (0, dayjs.default)(config);
743
+ return new Proxy(this, { get: (target, prop, receiver) => {
744
+ if (prop in target) return Reflect.get(target, prop, receiver);
745
+ const value = Reflect.get(this.instance, prop, receiver);
746
+ if (typeof value === "function") return (...args) => {
747
+ const result = value.apply(this.instance, args);
748
+ return dayjs.default.isDayjs(result) ? new DateTime(result) : result;
749
+ };
750
+ return value;
751
+ } });
752
+ }
753
+ /**
754
+ * Start time of a specific unit.
755
+ *
756
+ * @returns
757
+ */
758
+ start(unit = "days") {
759
+ return this.startOf(unit);
760
+ }
761
+ /**
762
+ * End time of a specific unit.
763
+ *
764
+ * @returns
765
+ */
766
+ end(unit = "days") {
767
+ return this.endOf(unit);
768
+ }
769
+ /**
770
+ * Get the first day of the month of the given date
771
+ *
772
+ * @returns
773
+ */
774
+ firstDayOfMonth() {
775
+ return new DateTime(new Date(Date.UTC(this.year(), this.month(), 1)));
776
+ }
777
+ carbonFormat(template) {
778
+ return template ? this.format(phpToDayjsTokens(template)) : this.format();
779
+ }
780
+ /**
781
+ * Get the last day of the month of the given date
782
+ *
783
+ * @returns
784
+ */
785
+ lastDayOfMonth() {
786
+ return new DateTime(new Date(Date.UTC(this.year(), this.month() + 1, 0)));
787
+ }
788
+ /**
789
+ * Get a random time between the specified hour and minute.
790
+ *
791
+ * @param startHour
792
+ * @param startMinute
793
+ * @param endHour
794
+ * @param endMinute
795
+ * @returns
796
+ */
797
+ randomTime(startHour = 9, startMinute = 0, endHour = 17, endMinute = 0) {
798
+ const today = /* @__PURE__ */ new Date();
799
+ const startMinutes = startHour * 60 + startMinute;
800
+ const endMinutes = endHour * 60 + endMinute;
801
+ const randomMinutes = Math.floor(Math.random() * (endMinutes - startMinutes)) + startMinutes;
802
+ const hour = Math.floor(randomMinutes / 60);
803
+ const minute = randomMinutes % 60;
804
+ const date = new Date(today);
805
+ date.setHours(hour, minute, 0, 0);
806
+ return new DateTime(date);
807
+ }
808
+ /**
809
+ * Create a date for a given timestamp.
810
+ *
811
+ * @param timestamp - Unix timestamp
812
+ *
813
+ * @return {Date} object
814
+ */
815
+ static fromTimestamp(timestamp) {
816
+ return /* @__PURE__ */ new Date(timestamp * 1e3);
817
+ }
818
+ /**
819
+ * Get current time instance.
820
+ *
821
+ * @returns Current time
822
+ */
823
+ static now() {
824
+ return new DateTime();
825
+ }
826
+ /**
827
+ * Parse the time
828
+ *
829
+ * @param date
830
+ * @returns
831
+ */
832
+ static parse(date) {
833
+ return new DateTime(date);
834
+ }
835
+ /**
836
+ * Get the formatted date according to the string of tokens passed in.
837
+ *
838
+ * To escape characters, wrap them in square brackets (e.g. [MM]).
839
+ *
840
+ * @param time - current time
841
+ * @param template - time format
842
+ */
843
+ static format(time, template) {
844
+ return new DateTime(time).format(template);
845
+ }
846
+ /**
847
+ * Get the difference in days from today.
848
+ *
849
+ * @param time
850
+ * @param startHour
851
+ * @param startMinute
852
+ * @param endHour
853
+ * @param endMinute
854
+ * @returns
855
+ */
856
+ static randomTime(time, startHour, startMinute, endHour, endMinute) {
857
+ return new DateTime(time).randomTime(startHour, startMinute, endHour, endMinute);
858
+ }
859
+ /**
860
+ * Get the first day of the month of the given date
861
+ *
862
+ * @param time
863
+ *
864
+ * @returns
865
+ */
866
+ static firstDayOfMonth(time) {
867
+ return new DateTime(time).firstDayOfMonth();
868
+ }
869
+ /**
870
+ * Get the last day of the month of the given date
871
+ *
872
+ * @param time
873
+ *
874
+ * @returns
875
+ */
876
+ static lastDayOfMonth(time) {
877
+ return new DateTime(time).lastDayOfMonth();
878
+ }
879
+ };
880
+
712
881
  //#endregion
713
882
  //#region src/Helpers/Str.ts
714
883
  let Mode = /* @__PURE__ */ function(Mode$1) {
@@ -5048,164 +5217,6 @@ function matchCase(value, comparison) {
5048
5217
  return value;
5049
5218
  }
5050
5219
 
5051
- //#endregion
5052
- //#region src/Helpers/Time.ts
5053
- dayjs.default.extend(dayjs_plugin_utc.default);
5054
- dayjs.default.extend(dayjs_plugin_timezone.default);
5055
- dayjs.default.extend(dayjs_plugin_dayOfYear.default);
5056
- dayjs.default.extend(dayjs_plugin_isBetween.default);
5057
- dayjs.default.extend(dayjs_plugin_isLeapYear.default);
5058
- dayjs.default.extend(dayjs_plugin_relativeTime.default);
5059
- dayjs.default.extend(dayjs_plugin_advancedFormat.default);
5060
- dayjs.default.extend(dayjs_plugin_customParseFormat.default);
5061
- const phpToDayjsTokens = (format$1) => format$1.replace(/Y/g, "YYYY").replace(/m/g, "MM").replace(/d/g, "DD").replace(/H/g, "HH").replace(/i/g, "mm").replace(/s/g, "ss");
5062
- function format(date, fmt) {
5063
- return (0, dayjs.default)(date).format(phpToDayjsTokens(fmt));
5064
- }
5065
- const TimeClass = class {};
5066
- var Time = class Time extends TimeClass {
5067
- instance;
5068
- constructor(config) {
5069
- super(config);
5070
- this.instance = (0, dayjs.default)(config);
5071
- return new Proxy(this, { get: (target, prop, receiver) => {
5072
- if (prop in target) return Reflect.get(target, prop, receiver);
5073
- const value = Reflect.get(this.instance, prop, receiver);
5074
- if (typeof value === "function") return (...args) => {
5075
- const result = value.apply(this.instance, args);
5076
- return dayjs.default.isDayjs(result) ? new Time(result) : result;
5077
- };
5078
- return value;
5079
- } });
5080
- }
5081
- /**
5082
- * Start time of a specific unit.
5083
- *
5084
- * @returns
5085
- */
5086
- start(unit = "days") {
5087
- return this.startOf(unit);
5088
- }
5089
- /**
5090
- * End time of a specific unit.
5091
- *
5092
- * @returns
5093
- */
5094
- end(unit = "days") {
5095
- return this.endOf(unit);
5096
- }
5097
- /**
5098
- * Get the first day of the month of the given date
5099
- *
5100
- * @returns
5101
- */
5102
- firstDayOfMonth() {
5103
- return new Time(new Date(Date.UTC(this.year(), this.month(), 1)));
5104
- }
5105
- carbonFormat(template) {
5106
- return template ? this.format(phpToDayjsTokens(template)) : this.format();
5107
- }
5108
- /**
5109
- * Get the last day of the month of the given date
5110
- *
5111
- * @returns
5112
- */
5113
- lastDayOfMonth() {
5114
- return new Time(new Date(Date.UTC(this.year(), this.month() + 1, 0)));
5115
- }
5116
- /**
5117
- * Get a random time between the specified hour and minute.
5118
- *
5119
- * @param startHour
5120
- * @param startMinute
5121
- * @param endHour
5122
- * @param endMinute
5123
- * @returns
5124
- */
5125
- randomTime(startHour = 9, startMinute = 0, endHour = 17, endMinute = 0) {
5126
- const today = /* @__PURE__ */ new Date();
5127
- const startMinutes = startHour * 60 + startMinute;
5128
- const endMinutes = endHour * 60 + endMinute;
5129
- const randomMinutes = Math.floor(Math.random() * (endMinutes - startMinutes)) + startMinutes;
5130
- const hour = Math.floor(randomMinutes / 60);
5131
- const minute = randomMinutes % 60;
5132
- const date = new Date(today);
5133
- date.setHours(hour, minute, 0, 0);
5134
- return new Time(date);
5135
- }
5136
- /**
5137
- * Create a date for a given timestamp.
5138
- *
5139
- * @param timestamp - Unix timestamp
5140
- *
5141
- * @return {Date} object
5142
- */
5143
- static fromTimestamp(timestamp) {
5144
- return /* @__PURE__ */ new Date(timestamp * 1e3);
5145
- }
5146
- /**
5147
- * Get current time instance.
5148
- *
5149
- * @returns Current time
5150
- */
5151
- static now() {
5152
- return new Time();
5153
- }
5154
- /**
5155
- * Parse the time
5156
- *
5157
- * @param date
5158
- * @returns
5159
- */
5160
- static parse(date) {
5161
- return new Time(date);
5162
- }
5163
- /**
5164
- * Get the formatted date according to the string of tokens passed in.
5165
- *
5166
- * To escape characters, wrap them in square brackets (e.g. [MM]).
5167
- *
5168
- * @param time - current time
5169
- * @param template - time format
5170
- */
5171
- static format(time, template) {
5172
- return new Time(time).format(template);
5173
- }
5174
- /**
5175
- * Get the difference in days from today.
5176
- *
5177
- * @param time
5178
- * @param startHour
5179
- * @param startMinute
5180
- * @param endHour
5181
- * @param endMinute
5182
- * @returns
5183
- */
5184
- static randomTime(time, startHour, startMinute, endHour, endMinute) {
5185
- return new Time(time).randomTime(startHour, startMinute, endHour, endMinute);
5186
- }
5187
- /**
5188
- * Get the first day of the month of the given date
5189
- *
5190
- * @param time
5191
- *
5192
- * @returns
5193
- */
5194
- static firstDayOfMonth(time) {
5195
- return new Time(time).firstDayOfMonth();
5196
- }
5197
- /**
5198
- * Get the last day of the month of the given date
5199
- *
5200
- * @param time
5201
- *
5202
- * @returns
5203
- */
5204
- static lastDayOfMonth(time) {
5205
- return new Time(time).lastDayOfMonth();
5206
- }
5207
- };
5208
-
5209
5220
  //#endregion
5210
5221
  //#region src/GlobalBootstrap.ts
5211
5222
  /**
@@ -5237,7 +5248,7 @@ function loadHelpers(target = globalThis) {
5237
5248
  Number: Number_exports,
5238
5249
  Obj: Obj_exports,
5239
5250
  Str,
5240
- Time,
5251
+ DateTime,
5241
5252
  DumpDie: DumpDie_exports,
5242
5253
  apa: Str.apa,
5243
5254
  title: Str.title,
@@ -5283,13 +5294,13 @@ function loadHelpers(target = globalThis) {
5283
5294
  checksum,
5284
5295
  verifyChecksum,
5285
5296
  caesarCipher,
5286
- now: Time.now,
5287
- format: Time.format,
5288
- fromTimestamp: Time.fromTimestamp,
5289
- parse: Time.parse,
5290
- randomTime: Time.randomTime,
5291
- firstDayOfMonth: Time.firstDayOfMonth,
5292
- lastDayOfMonth: Time.lastDayOfMonth,
5297
+ now: DateTime.now,
5298
+ format: DateTime.format,
5299
+ fromTimestamp: DateTime.fromTimestamp,
5300
+ parse: DateTime.parse,
5301
+ randomTime: DateTime.randomTime,
5302
+ firstDayOfMonth: DateTime.firstDayOfMonth,
5303
+ lastDayOfMonth: DateTime.lastDayOfMonth,
5293
5304
  abbreviate,
5294
5305
  humanize,
5295
5306
  toBytes,
@@ -5399,6 +5410,7 @@ Object.defineProperty(exports, 'Crypto', {
5399
5410
  return Crypto_exports;
5400
5411
  }
5401
5412
  });
5413
+ exports.DateTime = DateTime;
5402
5414
  Object.defineProperty(exports, 'DumpDie', {
5403
5415
  enumerable: true,
5404
5416
  get: function () {
@@ -5421,7 +5433,6 @@ Object.defineProperty(exports, 'Obj', {
5421
5433
  });
5422
5434
  exports.Str = Str;
5423
5435
  exports.Stringable = Stringable;
5424
- exports.Time = Time;
5425
5436
  exports.abbreviate = abbreviate;
5426
5437
  exports.alternate = alternate;
5427
5438
  exports.base64Decode = base64Decode;
@@ -5469,5 +5480,6 @@ exports.toBytes = toBytes;
5469
5480
  exports.toHumanTime = toHumanTime;
5470
5481
  exports.uuid = uuid;
5471
5482
  exports.verifyChecksum = verifyChecksum;
5483
+ exports.wrap = wrap;
5472
5484
  exports.xor = xor;
5473
5485
  //# sourceMappingURL=index.cjs.map