@jiakun-zhao/utils 0.1.0 → 0.1.1

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
@@ -8,8 +8,18 @@ function fromTo(value, block) {
8
8
  function takeIf(value, predicate) {
9
9
  return predicate(value) ? value : null;
10
10
  }
11
+ function isNotEmpty(o) {
12
+ if (typeof o !== "object")
13
+ return Boolean(o);
14
+ return Array.isArray(o) ? !!o.length : !!Object.keys(o).length;
15
+ }
16
+ function singleOrNull(arr) {
17
+ return arr.length === 1 ? arr[0] : null;
18
+ }
11
19
 
12
20
  exports.fromTo = fromTo;
21
+ exports.isNotEmpty = isNotEmpty;
22
+ exports.singleOrNull = singleOrNull;
13
23
  exports.takeIf = takeIf;
14
24
  Object.keys(utils).forEach(function (k) {
15
25
  if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = utils[k];
package/dist/index.d.ts CHANGED
@@ -2,5 +2,7 @@ export * from '@antfu/utils';
2
2
 
3
3
  declare function fromTo<T, R>(value: T, block: (it: T) => R): R;
4
4
  declare function takeIf<T>(value: T, predicate: (it: T) => boolean): T | null;
5
+ declare function isNotEmpty(o: any): boolean;
6
+ declare function singleOrNull<T>(arr: T[]): T | null;
5
7
 
6
- export { fromTo, takeIf };
8
+ export { fromTo, isNotEmpty, singleOrNull, takeIf };
package/dist/index.mjs CHANGED
@@ -6,5 +6,13 @@ function fromTo(value, block) {
6
6
  function takeIf(value, predicate) {
7
7
  return predicate(value) ? value : null;
8
8
  }
9
+ function isNotEmpty(o) {
10
+ if (typeof o !== "object")
11
+ return Boolean(o);
12
+ return Array.isArray(o) ? !!o.length : !!Object.keys(o).length;
13
+ }
14
+ function singleOrNull(arr) {
15
+ return arr.length === 1 ? arr[0] : null;
16
+ }
9
17
 
10
- export { fromTo, takeIf };
18
+ export { 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.0",
4
+ "version": "0.1.1",
5
5
  "description": "Utils.",
6
6
  "author": "Jiakun Zhao <jiakun.zhao@outlook.com>",
7
7
  "license": "MIT",