@pawover/kit 0.0.0-beta.5 → 0.0.0-beta.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/dist/index.js CHANGED
@@ -12,6 +12,7 @@ const PROTOTYPE_TAGS = {
12
12
  file: "[object File]",
13
13
  function: "[object Function]",
14
14
  generatorFunction: "[object GeneratorFunction]",
15
+ iframe: "[object HTMLIFrameElement]",
15
16
  map: "[object Map]",
16
17
  null: "[object Null]",
17
18
  number: "[object Number]",
@@ -70,8 +71,13 @@ function isBigInt(value) {
70
71
  //#endregion
71
72
  //#region src/utils/typeof/isBlob.ts
72
73
  function isBlob(value) {
74
+ if (typeof window === "undefined") return false;
73
75
  return resolvePrototypeString(value) === PROTOTYPE_TAGS.blob;
74
76
  }
77
+ function isFile(value) {
78
+ if (typeof window === "undefined") return false;
79
+ return resolvePrototypeString(value) === PROTOTYPE_TAGS.file;
80
+ }
75
81
 
76
82
  //#endregion
77
83
  //#region src/utils/typeof/isBoolean.ts
@@ -118,6 +124,25 @@ function isDate(value) {
118
124
  }
119
125
  }
120
126
 
127
+ //#endregion
128
+ //#region src/utils/typeof/isEnumeration.ts
129
+ /**
130
+ * 判断一个值是否为有效的枚举对象
131
+ * - 枚举不能为空
132
+ * - 枚举所有的值必须是 string 或 number
133
+ *
134
+ * @param obj
135
+ * @returns
136
+ */
137
+ function isEnumeration(obj) {
138
+ if (!isObject(obj)) return [false, false];
139
+ const keys = Object.keys(obj);
140
+ if (!keys.length) return [false, false];
141
+ const values = Object.values(obj);
142
+ if (!values.every((v) => typeof v === "string" || typeof v === "number")) return [false, false];
143
+ return [true, keys.every((k) => values.some((v) => v.toString() === k))];
144
+ }
145
+
121
146
  //#endregion
122
147
  //#region src/utils/typeof/isEqual.ts
123
148
  /**
@@ -159,12 +184,6 @@ function isFalsyLike(value) {
159
184
  return typeof value === "string" && (value === "null" || value === "undefined" || value === "NaN" || value === "false" || value === "0" || value === "0n");
160
185
  }
161
186
 
162
- //#endregion
163
- //#region src/utils/typeof/isFile.ts
164
- function isFile(value) {
165
- return resolvePrototypeString(value) === PROTOTYPE_TAGS.file;
166
- }
167
-
168
187
  //#endregion
169
188
  //#region src/utils/typeof/isFunction.ts
170
189
  function isFunction(value) {
@@ -569,6 +588,55 @@ function arraySplit(initialList, size = 10) {
569
588
  });
570
589
  }
571
590
 
591
+ //#endregion
592
+ //#region src/utils/device/isMobile.ts
593
+ /**
594
+ * 检测当前设备是否为移动设备
595
+ *
596
+ * @param maxWidth - 移动设备最大宽度(默认 768px)
597
+ * @param dpi - 标准 DPI 基准(默认 160)
598
+ */
599
+ function isMobile(maxWidth = 768, dpi = 160) {
600
+ if (typeof window === "undefined" || !isPositiveInteger(maxWidth)) return false;
601
+ return !isTablet(maxWidth, 1200, dpi);
602
+ }
603
+ /**
604
+ * 检测当前设备是否为IOS移动设备
605
+ *
606
+ * @param maxWidth - 移动设备最大宽度(默认 768px)
607
+ * @param dpi - 标准 DPI 基准(默认 160)
608
+ */
609
+ function isISOMobile(maxWidth = 768, dpi = 160) {
610
+ if (typeof navigator === "undefined" || !navigator.userAgent || !isPositiveInteger(maxWidth)) return false;
611
+ return /iPhone|iPad|iPod/i.test(navigator.userAgent) && !isTablet(maxWidth, 1200, dpi);
612
+ }
613
+
614
+ //#endregion
615
+ //#region src/utils/device/isTablet.ts
616
+ /**
617
+ * 检测当前设备是否为平板
618
+ *
619
+ * @param minWidth - 平板最小宽度(默认 768px)
620
+ * @param maxWidth - 平板最大宽度(默认 1200px)
621
+ * @param dpi - 标准 DPI 基准(默认 160)
622
+ */
623
+ function isTablet(minWidth = 768, maxWidth = 1200, dpi = 160) {
624
+ if (typeof window === "undefined" || !isPositiveInteger(minWidth) || !isPositiveInteger(maxWidth)) return false;
625
+ const width = window.innerWidth;
626
+ const isWithinWidthRange = width >= minWidth && width <= maxWidth;
627
+ try {
628
+ const widthPx = window.screen.width;
629
+ const heightPx = window.screen.height;
630
+ const DPI = dpi * (window.devicePixelRatio || 1);
631
+ const widthInch = widthPx / DPI;
632
+ const heightInch = heightPx / DPI;
633
+ const screenInches = Math.sqrt(widthInch ** 2 + heightInch ** 2);
634
+ return isWithinWidthRange || screenInches >= 7;
635
+ } catch {
636
+ return isWithinWidthRange;
637
+ }
638
+ }
639
+
572
640
  //#endregion
573
641
  //#region src/utils/function/to.ts
574
642
  /**
@@ -722,94 +790,42 @@ function cloneDeep(root, customStrategy) {
722
790
  return cloneDeep$1(root, strategy);
723
791
  }
724
792
 
725
- //#endregion
726
- //#region src/utils/object/objectKeys.ts
727
- /**
728
- * 返回对象的可枚举属性和方法的名称
729
- * - `Object.keys` 始终返回 `string[]` 类型,此函数可以返回具体类型
730
- *
731
- * @param obj 对象
732
- */
733
- function objectKeys(obj) {
734
- return Object.keys(obj);
735
- }
736
-
737
- //#endregion
738
- //#region src/utils/object/enumTypeCheck.ts
739
- function enumTypeCheck(enumeration) {
740
- if (!isObject(enumeration)) throw Error(`function enumKeys expected parameter is a enum, but got ${typeof enumeration}`);
741
- if (!objectKeys(enumeration).length) throw Error("Enum requires at least one member");
742
- return enumeration;
743
- }
744
-
745
- //#endregion
746
- //#region src/utils/object/objectEntries.ts
747
- /**
748
- * 返回对象的可枚举属性的键/值数组
749
- *
750
- * @param obj 对象
751
- */
752
- function objectEntries(obj) {
753
- return Object.entries(obj);
754
- }
755
-
756
- //#endregion
757
- //#region src/utils/object/objectValues.ts
758
- /**
759
- * 返回对象的可枚举属性的值数组
760
- *
761
- * @param obj 对象
762
- */
763
- function objectValues(obj) {
764
- return Object.values(obj);
765
- }
766
-
767
793
  //#endregion
768
794
  //#region src/utils/object/enumEntries.ts
769
- /**
770
- * 返回枚举的属性的键/值数组
771
- *
772
- * @param enumeration 枚举
773
- */
774
795
  function enumEntries(enumeration) {
775
- const e = enumTypeCheck(enumeration);
776
- const keys = objectKeys(e);
777
- const values = objectValues(e);
778
- const entries = objectEntries(e);
779
- if (keys.every((k) => values.some((v) => `${v}` === k))) return entries.splice(keys.length / 2, keys.length / 2);
796
+ const [isEnum, isTwoWayEnum] = isEnumeration(enumeration);
797
+ if (!isEnum) throw Error("function enumEntries expected parameter is a enum, and requires at least one member");
798
+ const entries = objectEntries(enumeration);
799
+ if (isTwoWayEnum) return entries.splice(entries.length / 2, entries.length / 2);
780
800
  return entries;
781
801
  }
782
802
 
783
803
  //#endregion
784
804
  //#region src/utils/object/enumKeys.ts
785
- /**
786
- * 获取枚举所有属性的键
787
- *
788
- * @param enumeration 枚举
789
- */
790
805
  function enumKeys(enumeration) {
791
- const e = enumTypeCheck(enumeration);
792
- const keys = objectKeys(e);
793
- const values = objectValues(e);
794
- if (keys.every((k) => values.some((v) => `${v}` === k))) return keys.splice(keys.length / 2, keys.length / 2);
806
+ const [isEnum, isTwoWayEnum] = isEnumeration(enumeration);
807
+ if (!isEnum) throw Error("function enumKeys expected parameter is a enum, and requires at least one member");
808
+ const keys = objectKeys(enumeration);
809
+ if (isTwoWayEnum) return keys.splice(keys.length / 2, keys.length / 2);
795
810
  return keys;
796
811
  }
797
812
 
798
813
  //#endregion
799
814
  //#region src/utils/object/enumValues.ts
800
- /**
801
- * 获取枚举所有属性的值
802
- *
803
- * @param enumeration 枚举
804
- */
805
815
  function enumValues(enumeration) {
806
- const e = enumTypeCheck(enumeration);
807
- const keys = objectKeys(e);
808
- const values = objectValues(e);
809
- if (keys.every((k) => values.some((v) => `${v}` === k))) return values.splice(keys.length / 2, keys.length / 2);
816
+ const [isEnum, isTwoWayEnum] = isEnumeration(enumeration);
817
+ if (!isEnum) throw Error("function enumValues expected parameter is a enum, and requires at least one member");
818
+ const values = objectValues(enumeration);
819
+ if (isTwoWayEnum) return values.splice(values.length / 2, values.length / 2);
810
820
  return values;
811
821
  }
812
822
 
823
+ //#endregion
824
+ //#region src/utils/object/objectEntries.ts
825
+ function objectEntries(value) {
826
+ return Object.entries(value);
827
+ }
828
+
813
829
  //#endregion
814
830
  //#region src/utils/object/mapEntries.ts
815
831
  function mapEntries(obj, toEntry) {
@@ -824,13 +840,6 @@ function mapEntries(obj, toEntry) {
824
840
 
825
841
  //#endregion
826
842
  //#region src/utils/object/objectAssign.ts
827
- /**
828
- * 递归地将第二个对象合并到第一个对象的副本中
829
- * - 只有普通对象才会递归合并
830
- *
831
- * @param initial 初始对象
832
- * @param override 待合并对象
833
- */
834
843
  function objectAssign(initial, override) {
835
844
  if (!isObject(initial) || !isObject(override)) return initial ?? override ?? {};
836
845
  const proto = Object.getPrototypeOf(initial);
@@ -841,14 +850,29 @@ function objectAssign(initial, override) {
841
850
 
842
851
  //#endregion
843
852
  //#region src/utils/object/objectCrush.ts
844
- function objectCrush(value) {
845
- if (!value) return {};
846
- function crushReducer(crushed, value$1, path) {
847
- if (isObject(value$1) || isArray(value$1)) for (const [prop, propValue] of Object.entries(value$1)) crushReducer(crushed, propValue, path ? `${path}.${prop}` : prop);
848
- else crushed[path] = value$1;
853
+ function objectCrush(obj) {
854
+ if (!obj) return {};
855
+ function crushReducer(crushed, value, path) {
856
+ if (isObject(value) || isArray(value)) for (const [prop, propValue] of Object.entries(value)) crushReducer(crushed, propValue, path ? `${path}.${prop}` : prop);
857
+ else crushed[path] = value;
849
858
  return crushed;
850
859
  }
851
- return crushReducer({}, value, "");
860
+ return crushReducer({}, obj, "");
861
+ }
862
+
863
+ //#endregion
864
+ //#region src/utils/object/objectInvert.ts
865
+ function objectInvert(obj) {
866
+ const result = {};
867
+ if (!isObject(obj)) return result;
868
+ for (const [k, v] of objectEntries(obj)) if (isString(v) || isNumber(v) || isSymbol(v)) result[v] = k;
869
+ return result;
870
+ }
871
+
872
+ //#endregion
873
+ //#region src/utils/object/objectKeys.ts
874
+ function objectKeys(value) {
875
+ return Object.keys(value);
852
876
  }
853
877
 
854
878
  //#endregion
@@ -864,18 +888,9 @@ function objectPick(obj, keys) {
864
888
  }
865
889
 
866
890
  //#endregion
867
- //#region src/utils/object/objectSwitch.ts
868
- /**
869
- * 对象反转
870
- * - 返回交换了对象的可枚举属性的值/键对象
871
- *
872
- * @param obj 对象
873
- */
874
- function objectSwitch(obj) {
875
- const result = {};
876
- if (!isObject(obj)) return result;
877
- for (const [k, v] of objectEntries(obj)) result[v] = k;
878
- return result;
891
+ //#region src/utils/object/objectValues.ts
892
+ function objectValues(value) {
893
+ return Object.values(value);
879
894
  }
880
895
 
881
896
  //#endregion
@@ -1437,5 +1452,5 @@ function treeToRows(tree, options = {}) {
1437
1452
  }
1438
1453
 
1439
1454
  //#endregion
1440
- export { arrayCast, arrayCompete, arrayCounting, arrayDifference, arrayFirst, arrayFork, arrayIntersection, arrayLast, arrayMerge, arrayPick, arrayReplace, arraySplit, cloneDeep, enumEntries, enumKeys, enumTypeCheck, enumValues, getTimeZone, isAbortSignal, isArray, isAsyncFunction, isAsyncGeneratorFunction, isBigInt, isBlob, isBoolean, isClass, isDate, isEqual, isError, isFalsy, isFalsyLike, isFile, isFunction, isGeneratorFunction, isInfinity, isInfinityLike, isInteger, isIterable, isMap, isNaN, isNegativeInteger, isNull, isNumber, isObject, isPositiveInteger, isPromise, isPromiseLike, isReadableStream, isRegExp, isSet, isString, isSymbol, isTypedArray, isURLSearchParams, isUndefined, isWeakMap, isWeakSet, isWebSocket, isWindow, mapEntries, objectAssign, objectCrush, objectEntries, objectKeys, objectPick, objectSwitch, objectValues, rowsToTree, stringInitialCase, stringReplace, stringTemplate, stringToJson, stringToNumber, stringToPosix, stringToValues, stringTrim, stringTruncate, to, toMathBignumber, toMathDecimal, toMathEvaluate, treeFilter, treeFind, treeForEach, treeMap, treeToRows };
1455
+ export { arrayCast, arrayCompete, arrayCounting, arrayDifference, arrayFirst, arrayFork, arrayIntersection, arrayLast, arrayMerge, arrayPick, arrayReplace, arraySplit, cloneDeep, enumEntries, enumKeys, enumValues, getTimeZone, isAbortSignal, isArray, isAsyncFunction, isAsyncGeneratorFunction, isBigInt, isBlob, isBoolean, isClass, isDate, isEnumeration, isEqual, isError, isFalsy, isFalsyLike, isFile, isFunction, isGeneratorFunction, isISOMobile, isInfinity, isInfinityLike, isInteger, isIterable, isMap, isMobile, isNaN, isNegativeInteger, isNull, isNumber, isObject, isPositiveInteger, isPromise, isPromiseLike, isReadableStream, isRegExp, isSet, isString, isSymbol, isTablet, isTypedArray, isURLSearchParams, isUndefined, isWeakMap, isWeakSet, isWebSocket, isWindow, mapEntries, objectAssign, objectCrush, objectEntries, objectInvert, objectKeys, objectPick, objectValues, rowsToTree, stringInitialCase, stringReplace, stringTemplate, stringToJson, stringToNumber, stringToPosix, stringToValues, stringTrim, stringTruncate, to, toMathBignumber, toMathDecimal, toMathEvaluate, treeFilter, treeFind, treeForEach, treeMap, treeToRows };
1441
1456
  //# sourceMappingURL=index.js.map