@lowentry/utils 1.10.4 → 1.10.6

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/index.js CHANGED
@@ -245,6 +245,50 @@ var LeUtils = {
245
245
  * @returns {boolean} Returns true if the values are equivalent.
246
246
  */
247
247
  equals: FastDeepEqual,
248
+ /**
249
+ * Returns a deep copy of the given value.
250
+ *
251
+ * @param {*} value
252
+ * @returns {*}
253
+ */
254
+ clone: function clone(value) {
255
+ return CloneDeep(value, true);
256
+ },
257
+ /**
258
+ * Executes the given callback when the document is ready.
259
+ *
260
+ * @param {Function} callback
261
+ * @returns {{remove:Function}}
262
+ */
263
+ onDomReady: function onDomReady(callback) {
264
+ if (typeof window === 'undefined' || !document) {
265
+ // no document, so we can't wait for it to be ready
266
+ return {
267
+ remove: function remove() {}
268
+ };
269
+ }
270
+ if (document.readyState === 'interactive' || document.readyState === 'complete') {
271
+ return LeUtils.setTimeout(callback, 0);
272
+ } else {
273
+ var listening = true;
274
+ var callbackWrapper = function callbackWrapper() {
275
+ if (listening) {
276
+ listening = false;
277
+ document.removeEventListener('DOMContentLoaded', callbackWrapper);
278
+ callback();
279
+ }
280
+ };
281
+ document.addEventListener('DOMContentLoaded', callbackWrapper);
282
+ return {
283
+ remove: function remove() {
284
+ if (listening) {
285
+ listening = false;
286
+ document.removeEventListener('DOMContentLoaded', callbackWrapper);
287
+ }
288
+ }
289
+ };
290
+ }
291
+ },
248
292
  /**
249
293
  * Parses the given version string, and returns an object with the major, minor, and patch numbers, as well as some comparison functions.
250
294
  *
@@ -1083,6 +1127,11 @@ var LeUtils = {
1083
1127
  };
1084
1128
  return setTimeout;
1085
1129
  }(function (callback, ms) {
1130
+ if (typeof window === 'undefined') {
1131
+ return {
1132
+ remove: function remove() {}
1133
+ };
1134
+ }
1086
1135
  ms = FLOAT_LAX(ms);
1087
1136
  var lastTime = performance.now();
1088
1137
  var handler = setTimeout(function () {
@@ -1136,6 +1185,11 @@ var LeUtils = {
1136
1185
  console.error(e);
1137
1186
  }
1138
1187
  }
1188
+ if (typeof window === 'undefined') {
1189
+ return {
1190
+ remove: function remove() {}
1191
+ };
1192
+ }
1139
1193
  var lastTime = performance.now();
1140
1194
  var handler = setInterval(function () {
1141
1195
  var currentTime = performance.now();
@@ -1170,6 +1224,11 @@ var LeUtils = {
1170
1224
  */
1171
1225
  setAnimationFrameTimeout: function setAnimationFrameTimeout(callback) {
1172
1226
  var frames = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
1227
+ if (typeof window === 'undefined') {
1228
+ return {
1229
+ remove: function remove() {}
1230
+ };
1231
+ }
1173
1232
  frames = INT_LAX_ANY(frames, 1);
1174
1233
  var run = true;
1175
1234
  var requestAnimationFrameId = null;
@@ -1228,6 +1287,11 @@ var LeUtils = {
1228
1287
  console.error(e);
1229
1288
  }
1230
1289
  }
1290
+ if (typeof window === 'undefined') {
1291
+ return {
1292
+ remove: function remove() {}
1293
+ };
1294
+ }
1231
1295
  var run = true;
1232
1296
  var requestAnimationFrameId = null;
1233
1297
  var lastTime = performance.now();
@@ -1571,6 +1635,9 @@ var LeUtils = {
1571
1635
  var generateUniqueId = function generateUniqueId() {
1572
1636
  var now;
1573
1637
  try {
1638
+ if (typeof window === 'undefined') {
1639
+ throw new Error();
1640
+ }
1574
1641
  // noinspection JSDeprecatedSymbols
1575
1642
  now = (performance.timeOrigin || performance.timing.navigationStart) + performance.now();
1576
1643
  if (typeof now !== 'number') {
@@ -1646,6 +1713,9 @@ var LeUtils = {
1646
1713
  now = FLOAT_LAX(now);
1647
1714
  } else {
1648
1715
  try {
1716
+ if (typeof window === 'undefined') {
1717
+ throw new Error();
1718
+ }
1649
1719
  // noinspection JSDeprecatedSymbols
1650
1720
  now = (performance.timeOrigin || performance.timing.navigationStart) + performance.now();
1651
1721
  if (typeof now !== 'number') {
@@ -1691,7 +1761,7 @@ var LeUtils = {
1691
1761
  * @returns {Uint8ClampedArray}
1692
1762
  */
1693
1763
  getImagePixels: function getImagePixels(image) {
1694
- if (!document) {
1764
+ if (typeof window === 'undefined' || !document) {
1695
1765
  return new Uint8ClampedArray();
1696
1766
  }
1697
1767
  var canvas = document.createElement('canvas');
@@ -1721,7 +1791,7 @@ var LeUtils = {
1721
1791
  * @returns {string}
1722
1792
  */
1723
1793
  getColoredImage: function getColoredImage(image, color) {
1724
- if (!document) {
1794
+ if (typeof window === 'undefined' || !document) {
1725
1795
  return LeUtils.getEmptyImageSrc();
1726
1796
  }
1727
1797
  var canvas = document.createElement('canvas');
@@ -2154,6 +2224,9 @@ var LeUtils = {
2154
2224
  * @param {string} [mimeType]
2155
2225
  */
2156
2226
  downloadFile: function downloadFile(base64string, fileName, mimeType) {
2227
+ if (typeof window === 'undefined' || !document) {
2228
+ return;
2229
+ }
2157
2230
  var link = document.createElement('a');
2158
2231
  link.setAttribute('download', typeof fileName === 'string' ? fileName : 'file');
2159
2232
  link.href = 'data:' + mimeType + ';base64,' + base64string;
@@ -2641,6 +2714,14 @@ var LeUtils = {
2641
2714
  * @returns {{worker: Worker, sendMessage: function(Object, {timeout: number|undefined}|undefined): Promise<Object>}}
2642
2715
  */
2643
2716
  createWorkerThread: function createWorkerThread(name) {
2717
+ if (typeof window === 'undefined' || typeof Worker === 'undefined') {
2718
+ return {
2719
+ worker: null,
2720
+ sendMessage: new Promise(function (resolve, reject) {
2721
+ reject('Workers are not supported in this environment');
2722
+ })
2723
+ };
2724
+ }
2644
2725
  var worker = new Worker('/workers/' + name + '.worker.js');
2645
2726
  var listeners = {};
2646
2727
  var addListener = function addListener(id, callback) {
@@ -2700,15 +2781,6 @@ var LeUtils = {
2700
2781
  return workers[workerName].sendMessage(data, options);
2701
2782
  };
2702
2783
  }(),
2703
- /**
2704
- * Returns a deep copy of the given value.
2705
- *
2706
- * @param {*} value
2707
- * @returns {*}
2708
- */
2709
- clone: function clone(value) {
2710
- return CloneDeep(value, true);
2711
- },
2712
2784
  /**
2713
2785
  * Purges the given email address, returning an empty string if it's invalid.
2714
2786
  *
@@ -2728,6 +2800,11 @@ var LeUtils = {
2728
2800
  * @returns {boolean}
2729
2801
  */
2730
2802
  isFocusClear: function () {
2803
+ if (typeof window === 'undefined' || !document) {
2804
+ return function () {
2805
+ return true;
2806
+ };
2807
+ }
2731
2808
  var inputTypes = ['text', 'search', 'email', 'number', 'password', 'tel', 'time', 'url', 'week', 'month', 'date', 'datetime-local'];
2732
2809
  return function () {
2733
2810
  var _document, _document2;
@@ -2743,11 +2820,11 @@ var LeUtils = {
2743
2820
  var userLocale = null;
2744
2821
  return function () {
2745
2822
  if (userLocale === null) {
2746
- userLocale = function () {
2747
- if (typeof window === 'undefined') {
2823
+ userLocale = function (_navigator$languages, _navigator) {
2824
+ if (typeof window === 'undefined' || !navigator) {
2748
2825
  return 'en-US';
2749
2826
  }
2750
- var locales = window.navigator.languages;
2827
+ var locales = (_navigator$languages = (_navigator = navigator) === null || _navigator === void 0 ? void 0 : _navigator.languages) !== null && _navigator$languages !== void 0 ? _navigator$languages : [];
2751
2828
  if (!IS_ARRAY(locales) || locales.length <= 0) {
2752
2829
  return 'en-US';
2753
2830
  }
@@ -2780,8 +2857,8 @@ var LeUtils = {
2780
2857
  if (userLocaleDateFormat === null) {
2781
2858
  userLocaleDateFormat = function () {
2782
2859
  var _char = '/';
2783
- if (typeof window !== 'undefined' && typeof Intl !== 'undefined' && typeof Intl.DateTimeFormat !== 'undefined') {
2784
- var formattedDate = new Intl.DateTimeFormat(LeUtils.getUserLocale()).format();
2860
+ if (typeof window !== 'undefined' && typeof window.Intl !== 'undefined' && typeof window.Intl.DateTimeFormat !== 'undefined') {
2861
+ var formattedDate = new window.Intl.DateTimeFormat(LeUtils.getUserLocale()).format();
2785
2862
  if (formattedDate.includes('-')) {
2786
2863
  _char = '-';
2787
2864
  } else if (formattedDate.includes('. ')) {