@jiakun-zhao/utils 0.1.1 → 0.1.2

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
@@ -5,6 +5,10 @@ const utils = require('@antfu/utils');
5
5
  function fromTo(value, block) {
6
6
  return block(value);
7
7
  }
8
+ function fromLet(value, block) {
9
+ block(value);
10
+ return value;
11
+ }
8
12
  function takeIf(value, predicate) {
9
13
  return predicate(value) ? value : null;
10
14
  }
@@ -17,6 +21,7 @@ function singleOrNull(arr) {
17
21
  return arr.length === 1 ? arr[0] : null;
18
22
  }
19
23
 
24
+ exports.fromLet = fromLet;
20
25
  exports.fromTo = fromTo;
21
26
  exports.isNotEmpty = isNotEmpty;
22
27
  exports.singleOrNull = singleOrNull;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  export * from '@antfu/utils';
2
2
 
3
3
  declare function fromTo<T, R>(value: T, block: (it: T) => R): R;
4
+ declare function fromLet<T>(value: T, block: (it: T) => void): T;
4
5
  declare function takeIf<T>(value: T, predicate: (it: T) => boolean): T | null;
5
6
  declare function isNotEmpty(o: any): boolean;
6
7
  declare function singleOrNull<T>(arr: T[]): T | null;
7
8
 
8
- export { fromTo, isNotEmpty, singleOrNull, takeIf };
9
+ export { fromLet, fromTo, isNotEmpty, singleOrNull, takeIf };
package/dist/index.mjs CHANGED
@@ -3,6 +3,10 @@ export * from '@antfu/utils';
3
3
  function fromTo(value, block) {
4
4
  return block(value);
5
5
  }
6
+ function fromLet(value, block) {
7
+ block(value);
8
+ return value;
9
+ }
6
10
  function takeIf(value, predicate) {
7
11
  return predicate(value) ? value : null;
8
12
  }
@@ -15,4 +19,4 @@ function singleOrNull(arr) {
15
19
  return arr.length === 1 ? arr[0] : null;
16
20
  }
17
21
 
18
- export { fromTo, isNotEmpty, singleOrNull, takeIf };
22
+ export { fromLet, fromTo, isNotEmpty, singleOrNull, takeIf };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jiakun-zhao/utils",
3
3
  "type": "module",
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "description": "Utils.",
6
6
  "author": "Jiakun Zhao <jiakun.zhao@outlook.com>",
7
7
  "license": "MIT",