js-dev-tool 1.2.26 → 1.2.27

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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/utils.d.ts +17 -1
  3. package/utils.js +26 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-dev-tool",
3
- "version": "1.2.26",
3
+ "version": "1.2.27",
4
4
  "type": "commonjs",
5
5
  "bin": {
6
6
  "jstool": "tools.js",
package/utils.d.ts CHANGED
@@ -222,4 +222,20 @@ export declare function indexByCol<
222
222
  Entry extends Partial<Record<TProp, string | number>>,
223
223
  R extends Record<TKey, Entry>
224
224
  >(tsvSource: string, opt?: TCSVParseOpt): R;
225
- export const parseDelimitedToIndex: typeof indexByCol;
225
+ export const parseDelimitedToIndex: typeof indexByCol;
226
+ /**
227
+ * Type guard to check if a value is an object.
228
+ * @template {unknown} [T=Record<string, unknown>]
229
+ * @param {unknown} value Value to check.
230
+ * @returns {value is T} True if the value is an object.
231
+ * @date 2025/8/22 10:52:32 from `lmt`
232
+ */
233
+ export declare const isObject: <T extends unknown = Record<string, unknown>>(value: unknown) => value is T;
234
+ export type TTypeOfToken = "string" | "number" | "boolean" | "bigint" | "symbol" | "undefined" | "function" | "object";
235
+ /**
236
+ * @template {unknown} T
237
+ * @param {unknown} data
238
+ * @param {Array<[property: string, type: TTypeOfToken]>} verifier
239
+ * @returns {data is T}
240
+ */
241
+ export declare const isTypeOf: <T>(data: unknown, ...verifier: Array<[property: string, type: TTypeOfToken]>) => data is T;
package/utils.js CHANGED
@@ -314,7 +314,7 @@ function execWithOutputResult(command, doneCallbackWithArgs, cwd) {
314
314
  });
315
315
  }
316
316
  /**
317
- * @import { TCSVParseOpt } from "./utils";
317
+ * @import { TCSVParseOpt, TTypeOfToken } from "./utils";
318
318
  */
319
319
  /**
320
320
  * Builds a key -> row index from a delimited text source (TSV by default).
@@ -473,6 +473,28 @@ function prependStringTo(str_array, content, suffix = "") {
473
473
  str_array[i++] = `${content}${suffix}${target}`;
474
474
  }
475
475
  }
476
+ /**
477
+ * Type guard to check if a value is an object.
478
+ * @template {unknown} [T=Record<string, unknown>]
479
+ * @param {unknown} value Value to check.
480
+ * @returns {value is T} True if the value is an object.
481
+ * @date 2025/8/22 10:52:32 from `lmt`
482
+ */
483
+ const isObject = (value) => typeof value === "object" && value !== null;
484
+ /**
485
+ * @template {unknown} T
486
+ * @param {unknown} data
487
+ * @param {Array<[property: string, type: TTypeOfToken]>} verifier
488
+ * @returns {data is T}
489
+ */
490
+ const isTypeOf = (data, ...verifier) => {
491
+ if (!isObject(data)) return false;
492
+ for (const [prop, type] of verifier) {
493
+ if (!(prop in data && typeof data[prop] === type))
494
+ return false;
495
+ }
496
+ return true;
497
+ };
476
498
  module.exports = {
477
499
  prependStringTo,
478
500
  extractVersion,
@@ -500,5 +522,7 @@ module.exports = {
500
522
  log,
501
523
  listDependenciesOf,
502
524
  indexByCol,
503
- parseDelimitedToIndex: indexByCol
525
+ parseDelimitedToIndex: indexByCol,
526
+ isObject,
527
+ isTypeOf,
504
528
  };