@jiakun-zhao/utils 0.1.6 → 0.1.8

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.cjs CHANGED
@@ -20,12 +20,29 @@ function isNotEmpty(o) {
20
20
  function singleOrNull(arr) {
21
21
  return arr.length === 1 ? arr[0] : null;
22
22
  }
23
+ function createArray(length, fn) {
24
+ const block = fn ? (_, idx) => fn(idx) : (_, idx) => idx;
25
+ return Array.from({ length }, block);
26
+ }
27
+ function random(max, min = 0) {
28
+ return Math.floor(Math.random() * max) + min;
29
+ }
30
+ function hScreen() {
31
+ document.body.style.setProperty("--h-screen", `${window.innerHeight}px`);
32
+ }
33
+ function fixHeightScreen() {
34
+ hScreen();
35
+ window.addEventListener("resize", hScreen);
36
+ }
23
37
 
38
+ exports.createArray = createArray;
39
+ exports.fixHeightScreen = fixHeightScreen;
24
40
  exports.isNotEmpty = isNotEmpty;
41
+ exports.random = random;
25
42
  exports.singleOrNull = singleOrNull;
26
43
  exports.takeIf = takeIf;
27
44
  exports.to = to;
28
45
  exports.use = use;
29
46
  Object.keys(utils).forEach(function (k) {
30
- if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = utils[k];
47
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = utils[k];
31
48
  });
@@ -0,0 +1,13 @@
1
+ export * from '@antfu/utils';
2
+
3
+ declare function to<T, R>(value: T, block: (it: T) => R): R;
4
+ declare function use<T>(value: T, block: (it: T) => void): T;
5
+ declare function takeIf<T>(value: T, predicate: (it: T) => boolean): T | null;
6
+ declare function isNotEmpty(o: any): boolean;
7
+ declare function singleOrNull<T>(arr: T[]): T | null;
8
+ declare function createArray(length: number): number[];
9
+ declare function createArray<R>(length: number, fn: (index: number) => R): R[];
10
+ declare function random(max: number, min?: number): number;
11
+ declare function fixHeightScreen(): void;
12
+
13
+ export { createArray, fixHeightScreen, isNotEmpty, random, singleOrNull, takeIf, to, use };
@@ -0,0 +1,13 @@
1
+ export * from '@antfu/utils';
2
+
3
+ declare function to<T, R>(value: T, block: (it: T) => R): R;
4
+ declare function use<T>(value: T, block: (it: T) => void): T;
5
+ declare function takeIf<T>(value: T, predicate: (it: T) => boolean): T | null;
6
+ declare function isNotEmpty(o: any): boolean;
7
+ declare function singleOrNull<T>(arr: T[]): T | null;
8
+ declare function createArray(length: number): number[];
9
+ declare function createArray<R>(length: number, fn: (index: number) => R): R[];
10
+ declare function random(max: number, min?: number): number;
11
+ declare function fixHeightScreen(): void;
12
+
13
+ export { createArray, fixHeightScreen, isNotEmpty, random, singleOrNull, takeIf, to, use };
package/dist/index.d.ts CHANGED
@@ -5,5 +5,9 @@ declare function use<T>(value: T, block: (it: T) => void): T;
5
5
  declare function takeIf<T>(value: T, predicate: (it: T) => boolean): T | null;
6
6
  declare function isNotEmpty(o: any): boolean;
7
7
  declare function singleOrNull<T>(arr: T[]): T | null;
8
+ declare function createArray(length: number): number[];
9
+ declare function createArray<R>(length: number, fn: (index: number) => R): R[];
10
+ declare function random(max: number, min?: number): number;
11
+ declare function fixHeightScreen(): void;
8
12
 
9
- export { isNotEmpty, singleOrNull, takeIf, to, use };
13
+ export { createArray, fixHeightScreen, isNotEmpty, random, singleOrNull, takeIf, to, use };
package/dist/index.mjs CHANGED
@@ -18,5 +18,19 @@ function isNotEmpty(o) {
18
18
  function singleOrNull(arr) {
19
19
  return arr.length === 1 ? arr[0] : null;
20
20
  }
21
+ function createArray(length, fn) {
22
+ const block = fn ? (_, idx) => fn(idx) : (_, idx) => idx;
23
+ return Array.from({ length }, block);
24
+ }
25
+ function random(max, min = 0) {
26
+ return Math.floor(Math.random() * max) + min;
27
+ }
28
+ function hScreen() {
29
+ document.body.style.setProperty("--h-screen", `${window.innerHeight}px`);
30
+ }
31
+ function fixHeightScreen() {
32
+ hScreen();
33
+ window.addEventListener("resize", hScreen);
34
+ }
21
35
 
22
- export { isNotEmpty, singleOrNull, takeIf, to, use };
36
+ export { createArray, fixHeightScreen, isNotEmpty, random, singleOrNull, takeIf, to, use };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jiakun-zhao/utils",
3
3
  "type": "module",
4
- "version": "0.1.6",
4
+ "version": "0.1.8",
5
5
  "description": "Utils.",
6
6
  "author": "Jiakun Zhao <jiakun.zhao@outlook.com>",
7
7
  "license": "MIT",
@@ -30,10 +30,10 @@
30
30
  "@antfu/utils": "^0.7.6"
31
31
  },
32
32
  "devDependencies": {
33
- "@jiakun-zhao/eslint-config": "^1.2.2",
34
- "@types/node": "^20.5.7",
33
+ "@jiakun-zhao/eslint-config": "^1.3.1",
34
+ "@types/node": "^20.8.10",
35
35
  "bumpp": "^9.2.0",
36
- "eslint": "^8.48.0",
36
+ "eslint": "^8.53.0",
37
37
  "esno": "^0.17.0",
38
38
  "typescript": "^5.2.2",
39
39
  "unbuild": "^2.0.0"