@battis/typescript-tricks 0.8.0 → 0.8.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/CHANGELOG.md CHANGED
@@ -2,6 +2,25 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
4
4
 
5
+ ## [0.8.2](https://github.com/battis/typescript-config/compare/typescript-tricks/0.8.1...typescript-tricks/0.8.2) (2026-03-12)
6
+
7
+
8
+ ### Features
9
+
10
+ * isNonEmptyString() & NonEmptyString ([06cd18c](https://github.com/battis/typescript-config/commit/06cd18c4528e1efc1e9c78c60861fb8c9aef308f))
11
+
12
+ ## [0.8.1](https://github.com/battis/typescript-config/compare/typescript-tricks/0.8.0...typescript-tricks/0.8.1) (2026-03-10)
13
+
14
+
15
+ ### Features
16
+
17
+ * isIterable() ([38044eb](https://github.com/battis/typescript-config/commit/38044ebd2b76068c57829df55666a6216bd0f0e0))
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * increased type-safety on isEntries key-checking ([1ec0979](https://github.com/battis/typescript-config/commit/1ec097918c40e8332723c8a4d8f8d417130658a5))
23
+
5
24
  ## [0.8.0](https://github.com/battis/typescript-config/compare/typescript-tricks/0.7.9...typescript-tricks/0.8.0) (2026-03-07)
6
25
 
7
26
 
package/dist/Array.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ import { Key } from './Key';
1
2
  export type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
2
- export declare function isEntries<K extends string | number | symbol = string | number | symbol, V = unknown>(obj: unknown, isK?: (k: unknown) => k is K, isV?: (v: unknown) => v is V): obj is [K, V][];
3
+ export declare function isEntries<K extends Key = Key, V = unknown>(obj: unknown, isK?: (k: unknown) => k is K, isV?: (v: unknown) => v is V): obj is [K, V][];
package/dist/Array.js CHANGED
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isEntries = isEntries;
4
+ const Key_1 = require("./Key");
4
5
  function isEntries(obj, isK, isV) {
5
6
  return (Array.isArray(obj) &&
6
7
  (obj.length === 0 ||
7
8
  obj.reduce((entries, elt) => entries &&
8
9
  Array.isArray(elt) &&
9
10
  elt.length == 2 &&
10
- (!isK || isK(elt[0])) &&
11
+ ((!isK && (0, Key_1.isKey)(elt[0])) || (isK && isK(elt[0]))) &&
11
12
  (!isV || isV(elt[1])), true)));
12
13
  }
@@ -0,0 +1,3 @@
1
+ export type NonEmptyString = Exclude<string, ''>;
2
+ export declare function isNonEmptyString(value: unknown): value is NonEmptyString;
3
+ export declare function isString(obj: unknown): obj is string;
package/dist/String.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNonEmptyString = isNonEmptyString;
4
+ exports.isString = isString;
5
+ function isNonEmptyString(value) {
6
+ return !!value && typeof value === 'string' && value.length > 0;
7
+ }
8
+ function isString(obj) {
9
+ return typeof obj === 'string';
10
+ }
@@ -8,5 +8,9 @@ export type OneOf<T extends object[]> = {
8
8
  [K in keyof T]: Expand<T[K] & Partial<Record<Exclude<UnionKeys<T[number]>, keyof T[K]>, never>>>;
9
9
  }[number];
10
10
  export declare function isUnknown(obj: unknown): obj is unknown;
11
- export declare function isString(obj: unknown): obj is string;
11
+ /**
12
+ * Caution: if an object may be a generator (in which case obj.iterator returns
13
+ * `this`), it will be consumed
14
+ */
15
+ export declare function isIterable<T = unknown>(obj: unknown, isT?: (elt: unknown) => elt is T): obj is Iterable<T>;
12
16
  export {};
@@ -1,10 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isUnknown = isUnknown;
4
- exports.isString = isString;
4
+ exports.isIterable = isIterable;
5
5
  function isUnknown(obj) {
6
6
  return true;
7
7
  }
8
- function isString(obj) {
9
- return typeof obj === 'string';
8
+ /**
9
+ * Caution: if an object may be a generator (in which case obj.iterator returns
10
+ * `this`), it will be consumed
11
+ */
12
+ function isIterable(obj, isT) {
13
+ function _isIterable(obj) {
14
+ return !!obj && typeof obj === 'object' && Symbol.iterator in obj;
15
+ }
16
+ if (_isIterable(obj)) {
17
+ if (isT) {
18
+ for (const elt of obj) {
19
+ if (!isT(elt)) {
20
+ return false;
21
+ }
22
+ }
23
+ }
24
+ return true;
25
+ }
26
+ return false;
10
27
  }
package/dist/index.d.ts CHANGED
@@ -6,5 +6,6 @@ export * from './Methods';
6
6
  export * from './Object';
7
7
  export * from './Properties';
8
8
  export * from './Record';
9
+ export * from './String';
9
10
  export * from './TypeJuggling';
10
11
  export * from './_Deprecated';
package/dist/index.js CHANGED
@@ -22,5 +22,6 @@ __exportStar(require("./Methods"), exports);
22
22
  __exportStar(require("./Object"), exports);
23
23
  __exportStar(require("./Properties"), exports);
24
24
  __exportStar(require("./Record"), exports);
25
+ __exportStar(require("./String"), exports);
25
26
  __exportStar(require("./TypeJuggling"), exports);
26
27
  __exportStar(require("./_Deprecated"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@battis/typescript-tricks",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "A handful of useful types and operators",
5
5
  "homepage": "https://github.com/battis/typescript-config/tree/main/packages/typescript-tricks#readme",
6
6
  "repository": {