@gtkx/utils 1.0.0-rc.2 → 1.0.0-rc.4

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 (239) hide show
  1. package/README.md +4 -5
  2. package/dist/array/index-before-or-end.d.ts +0 -12
  3. package/dist/array/index-before-or-end.d.ts.map +1 -1
  4. package/dist/array/index-before-or-end.js +0 -12
  5. package/dist/array/index-before-or-end.js.map +1 -1
  6. package/dist/array/index.d.ts +5 -5
  7. package/dist/array/index.js.map +1 -1
  8. package/dist/array/remove.d.ts +0 -11
  9. package/dist/array/remove.d.ts.map +1 -1
  10. package/dist/array/remove.js +0 -11
  11. package/dist/array/remove.js.map +1 -1
  12. package/dist/array/sort-strings-by.d.ts +0 -12
  13. package/dist/array/sort-strings-by.d.ts.map +1 -1
  14. package/dist/array/sort-strings-by.js +0 -12
  15. package/dist/array/sort-strings-by.js.map +1 -1
  16. package/dist/array/sort-strings.d.ts +0 -9
  17. package/dist/array/sort-strings.d.ts.map +1 -1
  18. package/dist/array/sort-strings.js +0 -9
  19. package/dist/array/sort-strings.js.map +1 -1
  20. package/dist/array/uniq-by.d.ts +0 -15
  21. package/dist/array/uniq-by.d.ts.map +1 -1
  22. package/dist/array/uniq-by.js +0 -15
  23. package/dist/array/uniq-by.js.map +1 -1
  24. package/dist/class/any-class.d.ts +0 -3
  25. package/dist/class/any-class.d.ts.map +1 -1
  26. package/dist/class/any-class.js.map +1 -1
  27. package/dist/class/get-parent-class.d.ts +1 -7
  28. package/dist/class/get-parent-class.d.ts.map +1 -1
  29. package/dist/class/get-parent-class.js +0 -6
  30. package/dist/class/get-parent-class.js.map +1 -1
  31. package/dist/class/index.d.ts +3 -3
  32. package/dist/class/index.js.map +1 -1
  33. package/dist/class/walk-class-chain.d.ts +1 -10
  34. package/dist/class/walk-class-chain.d.ts.map +1 -1
  35. package/dist/class/walk-class-chain.js +0 -9
  36. package/dist/class/walk-class-chain.js.map +1 -1
  37. package/dist/error/error-like.js.map +1 -1
  38. package/dist/error/error-message.d.ts +0 -10
  39. package/dist/error/error-message.d.ts.map +1 -1
  40. package/dist/error/error-message.js +0 -10
  41. package/dist/error/error-message.js.map +1 -1
  42. package/dist/error/format-child-process-error.d.ts +0 -9
  43. package/dist/error/format-child-process-error.d.ts.map +1 -1
  44. package/dist/error/format-child-process-error.js +0 -9
  45. package/dist/error/format-child-process-error.js.map +1 -1
  46. package/dist/error/index.d.ts +3 -3
  47. package/dist/error/index.js.map +1 -1
  48. package/dist/error/normalize-error.d.ts +0 -10
  49. package/dist/error/normalize-error.d.ts.map +1 -1
  50. package/dist/error/normalize-error.js +0 -10
  51. package/dist/error/normalize-error.js.map +1 -1
  52. package/dist/index.d.ts +12 -13
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +0 -1
  55. package/dist/index.js.map +1 -1
  56. package/dist/log/create-logger.d.ts +1 -12
  57. package/dist/log/create-logger.d.ts.map +1 -1
  58. package/dist/log/create-logger.js +0 -11
  59. package/dist/log/create-logger.js.map +1 -1
  60. package/dist/log/default-logger.d.ts +4 -30
  61. package/dist/log/default-logger.d.ts.map +1 -1
  62. package/dist/log/default-logger.js +3 -29
  63. package/dist/log/default-logger.js.map +1 -1
  64. package/dist/log/index.d.ts +5 -3
  65. package/dist/log/index.d.ts.map +1 -1
  66. package/dist/log/index.js +3 -1
  67. package/dist/log/index.js.map +1 -1
  68. package/dist/log/logger.d.ts +2 -43
  69. package/dist/log/logger.d.ts.map +1 -1
  70. package/dist/log/logger.js +3 -34
  71. package/dist/log/logger.js.map +1 -1
  72. package/dist/map/get-or-insert.d.ts +0 -15
  73. package/dist/map/get-or-insert.d.ts.map +1 -1
  74. package/dist/map/get-or-insert.js +0 -15
  75. package/dist/map/get-or-insert.js.map +1 -1
  76. package/dist/map/index.d.ts +1 -1
  77. package/dist/map/index.js.map +1 -1
  78. package/dist/object/index.d.ts +3 -3
  79. package/dist/object/index.js.map +1 -1
  80. package/dist/object/omit.d.ts +0 -12
  81. package/dist/object/omit.d.ts.map +1 -1
  82. package/dist/object/omit.js +0 -12
  83. package/dist/object/omit.js.map +1 -1
  84. package/dist/object/pick-by.d.ts +0 -12
  85. package/dist/object/pick-by.d.ts.map +1 -1
  86. package/dist/object/pick-by.js +0 -12
  87. package/dist/object/pick-by.js.map +1 -1
  88. package/dist/object/structured-clone.d.ts +0 -16
  89. package/dist/object/structured-clone.d.ts.map +1 -1
  90. package/dist/object/structured-clone.js +0 -16
  91. package/dist/object/structured-clone.js.map +1 -1
  92. package/dist/predicate/index.d.ts +6 -6
  93. package/dist/predicate/index.js.map +1 -1
  94. package/dist/predicate/is-deep-equal.d.ts.map +1 -1
  95. package/dist/predicate/is-deep-equal.js +0 -13
  96. package/dist/predicate/is-deep-equal.js.map +1 -1
  97. package/dist/predicate/is-plain-object.d.ts +0 -14
  98. package/dist/predicate/is-plain-object.d.ts.map +1 -1
  99. package/dist/predicate/is-plain-object.js +0 -14
  100. package/dist/predicate/is-plain-object.js.map +1 -1
  101. package/dist/predicate/is-record.d.ts +0 -11
  102. package/dist/predicate/is-record.d.ts.map +1 -1
  103. package/dist/predicate/is-record.js +0 -11
  104. package/dist/predicate/is-record.js.map +1 -1
  105. package/dist/predicate/is-same-array-by.d.ts +0 -12
  106. package/dist/predicate/is-same-array-by.d.ts.map +1 -1
  107. package/dist/predicate/is-same-array-by.js +0 -12
  108. package/dist/predicate/is-same-array-by.js.map +1 -1
  109. package/dist/predicate/is-same-array.d.ts +0 -12
  110. package/dist/predicate/is-same-array.d.ts.map +1 -1
  111. package/dist/predicate/is-same-array.js +0 -12
  112. package/dist/predicate/is-same-array.js.map +1 -1
  113. package/dist/predicate/is-shallow-equal.d.ts.map +1 -1
  114. package/dist/predicate/is-shallow-equal.js +0 -14
  115. package/dist/predicate/is-shallow-equal.js.map +1 -1
  116. package/dist/process/exit-code-for-signal.d.ts +0 -11
  117. package/dist/process/exit-code-for-signal.d.ts.map +1 -1
  118. package/dist/process/exit-code-for-signal.js +0 -11
  119. package/dist/process/exit-code-for-signal.js.map +1 -1
  120. package/dist/process/index.d.ts +3 -3
  121. package/dist/process/index.js.map +1 -1
  122. package/dist/process/install-graceful-shutdown.d.ts +0 -6
  123. package/dist/process/install-graceful-shutdown.d.ts.map +1 -1
  124. package/dist/process/install-graceful-shutdown.js +7 -13
  125. package/dist/process/install-graceful-shutdown.js.map +1 -1
  126. package/dist/process/resolve-executable.d.ts +0 -11
  127. package/dist/process/resolve-executable.d.ts.map +1 -1
  128. package/dist/process/resolve-executable.js +0 -11
  129. package/dist/process/resolve-executable.js.map +1 -1
  130. package/dist/set/drain.d.ts +0 -8
  131. package/dist/set/drain.d.ts.map +1 -1
  132. package/dist/set/drain.js +0 -8
  133. package/dist/set/drain.js.map +1 -1
  134. package/dist/set/index.d.ts +1 -1
  135. package/dist/set/index.js.map +1 -1
  136. package/dist/source/index.d.ts +3 -3
  137. package/dist/source/index.js.map +1 -1
  138. package/dist/source/sanitize-identifier.d.ts +0 -11
  139. package/dist/source/sanitize-identifier.d.ts.map +1 -1
  140. package/dist/source/sanitize-identifier.js +0 -11
  141. package/dist/source/sanitize-identifier.js.map +1 -1
  142. package/dist/source/source-string-literal.d.ts +0 -10
  143. package/dist/source/source-string-literal.d.ts.map +1 -1
  144. package/dist/source/source-string-literal.js +0 -10
  145. package/dist/source/source-string-literal.js.map +1 -1
  146. package/dist/source/to-camel-identifier.d.ts +0 -10
  147. package/dist/source/to-camel-identifier.d.ts.map +1 -1
  148. package/dist/source/to-camel-identifier.js +0 -10
  149. package/dist/source/to-camel-identifier.js.map +1 -1
  150. package/dist/string/camel-case.d.ts +0 -14
  151. package/dist/string/camel-case.d.ts.map +1 -1
  152. package/dist/string/camel-case.js +0 -14
  153. package/dist/string/camel-case.js.map +1 -1
  154. package/dist/string/index.d.ts +5 -5
  155. package/dist/string/index.js.map +1 -1
  156. package/dist/string/kebab-case.d.ts +0 -11
  157. package/dist/string/kebab-case.d.ts.map +1 -1
  158. package/dist/string/kebab-case.js +0 -11
  159. package/dist/string/kebab-case.js.map +1 -1
  160. package/dist/string/lower-first.d.ts +0 -10
  161. package/dist/string/lower-first.d.ts.map +1 -1
  162. package/dist/string/lower-first.js +0 -10
  163. package/dist/string/lower-first.js.map +1 -1
  164. package/dist/string/pascal-case.d.ts +0 -13
  165. package/dist/string/pascal-case.d.ts.map +1 -1
  166. package/dist/string/pascal-case.js +0 -13
  167. package/dist/string/pascal-case.js.map +1 -1
  168. package/dist/string/upper-first.d.ts +0 -10
  169. package/dist/string/upper-first.d.ts.map +1 -1
  170. package/dist/string/upper-first.js +0 -10
  171. package/dist/string/upper-first.js.map +1 -1
  172. package/dist/util/index.d.ts +1 -1
  173. package/dist/util/index.js.map +1 -1
  174. package/dist/util/package-version.d.ts +0 -9
  175. package/dist/util/package-version.d.ts.map +1 -1
  176. package/dist/util/package-version.js +0 -9
  177. package/dist/util/package-version.js.map +1 -1
  178. package/package.json +1 -1
  179. package/src/array/index-before-or-end.ts +0 -12
  180. package/src/array/index.ts +5 -5
  181. package/src/array/remove.ts +0 -11
  182. package/src/array/sort-strings-by.ts +0 -12
  183. package/src/array/sort-strings.ts +0 -9
  184. package/src/array/uniq-by.ts +0 -15
  185. package/src/class/any-class.ts +0 -3
  186. package/src/class/get-parent-class.ts +1 -7
  187. package/src/class/index.ts +3 -3
  188. package/src/class/walk-class-chain.ts +2 -11
  189. package/src/error/error-like.ts +1 -1
  190. package/src/error/error-message.ts +1 -11
  191. package/src/error/format-child-process-error.ts +2 -11
  192. package/src/error/index.ts +3 -3
  193. package/src/error/normalize-error.ts +2 -12
  194. package/src/index.ts +12 -13
  195. package/src/log/create-logger.ts +1 -12
  196. package/src/log/default-logger.ts +4 -30
  197. package/src/log/index.ts +5 -3
  198. package/src/log/logger.ts +4 -45
  199. package/src/map/get-or-insert.ts +0 -15
  200. package/src/map/index.ts +1 -1
  201. package/src/object/index.ts +3 -3
  202. package/src/object/omit.ts +0 -12
  203. package/src/object/pick-by.ts +0 -12
  204. package/src/object/structured-clone.ts +1 -17
  205. package/src/predicate/index.ts +6 -6
  206. package/src/predicate/is-deep-equal.ts +2 -15
  207. package/src/predicate/is-plain-object.ts +0 -14
  208. package/src/predicate/is-record.ts +0 -11
  209. package/src/predicate/is-same-array-by.ts +0 -12
  210. package/src/predicate/is-same-array.ts +1 -13
  211. package/src/predicate/is-shallow-equal.ts +2 -16
  212. package/src/process/exit-code-for-signal.ts +0 -11
  213. package/src/process/index.ts +3 -3
  214. package/src/process/install-graceful-shutdown.ts +11 -17
  215. package/src/process/resolve-executable.ts +0 -11
  216. package/src/set/drain.ts +0 -8
  217. package/src/set/index.ts +1 -1
  218. package/src/source/index.ts +3 -3
  219. package/src/source/sanitize-identifier.ts +0 -11
  220. package/src/source/source-string-literal.ts +0 -10
  221. package/src/source/to-camel-identifier.ts +2 -12
  222. package/src/string/camel-case.ts +2 -16
  223. package/src/string/index.ts +5 -5
  224. package/src/string/kebab-case.ts +0 -11
  225. package/src/string/lower-first.ts +0 -10
  226. package/src/string/pascal-case.ts +2 -15
  227. package/src/string/upper-first.ts +0 -10
  228. package/src/util/index.ts +1 -1
  229. package/src/util/package-version.ts +0 -9
  230. package/dist/function/call-method.d.ts +0 -3
  231. package/dist/function/call-method.d.ts.map +0 -1
  232. package/dist/function/call-method.js +0 -19
  233. package/dist/function/call-method.js.map +0 -1
  234. package/dist/function/index.d.ts +0 -2
  235. package/dist/function/index.d.ts.map +0 -1
  236. package/dist/function/index.js +0 -2
  237. package/dist/function/index.js.map +0 -1
  238. package/src/function/call-method.ts +0 -22
  239. package/src/function/index.ts +0 -1
@@ -10,16 +10,6 @@ const SOURCE_ESCAPES: Record<string, string> = {
10
10
 
11
11
  const UNSAFE_SOURCE_CHARS = new RegExp(`[${Object.keys(SOURCE_ESCAPES).join("")}]`, "g");
12
12
 
13
- /**
14
- * Encodes a string as a JavaScript string literal, additionally escaping characters that are unsafe
15
- * to embed in generated source (angle brackets and the line and paragraph separators).
16
- *
17
- * @param value - The string to encode.
18
- * @returns The quoted, source-safe string literal.
19
- *
20
- * @example
21
- * sourceStringLiteral("hello"); // '"hello"'
22
- */
23
13
  function sourceStringLiteral(value: string): string {
24
14
  return JSON.stringify(value).replaceAll(UNSAFE_SOURCE_CHARS, (char) => SOURCE_ESCAPES[char] ?? char);
25
15
  }
@@ -1,16 +1,6 @@
1
- import { camelCase } from "../string/camel-case.js";
2
- import { sanitizeIdentifier } from "./sanitize-identifier.js";
1
+ import { camelCase } from "../string/camel-case.ts";
2
+ import { sanitizeIdentifier } from "./sanitize-identifier.ts";
3
3
 
4
- /**
5
- * Converts a name to camel case and sanitizes it into a valid JavaScript identifier.
6
- *
7
- * @param name - The name to convert.
8
- * @returns The camel-cased, reserved-word-safe identifier.
9
- *
10
- * @example
11
- * toCamelIdentifier("icon_name"); // "iconName"
12
- * toCamelIdentifier("class"); // "class_"
13
- */
14
4
  function toCamelIdentifier(name: string): string {
15
5
  return sanitizeIdentifier(camelCase(name));
16
6
  }
@@ -1,20 +1,6 @@
1
- import { upperFirst } from "./upper-first.js";
2
- import { mapWordSegments } from "./word-segments.js";
1
+ import { upperFirst } from "./upper-first.ts";
2
+ import { mapWordSegments } from "./word-segments.ts";
3
3
 
4
- /**
5
- * Converts an underscore- or hyphen-delimited string to camel case.
6
- *
7
- * Unlike a general-purpose converter, this splits only on `_` and `-` and keeps the first segment
8
- * verbatim, so GObject acronyms are preserved (`camelCase("GLArea")` stays `"GLArea"`).
9
- *
10
- * @param str - The string to convert.
11
- * @returns The camel-cased string.
12
- *
13
- * @example
14
- * camelCase("icon_name"); // "iconName"
15
- * camelCase("start-widget"); // "startWidget"
16
- * camelCase("Box"); // "Box"
17
- */
18
4
  function camelCase(str: string): string {
19
5
  return mapWordSegments(str, (part, index) => (index === 0 ? part : upperFirst(part)));
20
6
  }
@@ -1,5 +1,5 @@
1
- export { camelCase } from "./camel-case.js";
2
- export { kebabCase } from "./kebab-case.js";
3
- export { lowerFirst } from "./lower-first.js";
4
- export { pascalCase } from "./pascal-case.js";
5
- export { upperFirst } from "./upper-first.js";
1
+ export { camelCase } from "./camel-case.ts";
2
+ export { kebabCase } from "./kebab-case.ts";
3
+ export { lowerFirst } from "./lower-first.ts";
4
+ export { pascalCase } from "./pascal-case.ts";
5
+ export { upperFirst } from "./upper-first.ts";
@@ -1,14 +1,3 @@
1
- /**
2
- * Converts a camelCase or PascalCase string to kebab case by lower-casing uppercase letters and
3
- * inserting hyphens before interior ones.
4
- *
5
- * @param str - The string to convert.
6
- * @returns The kebab-cased string.
7
- *
8
- * @example
9
- * kebabCase("iconName"); // "icon-name"
10
- * kebabCase("Title"); // "title"
11
- */
12
1
  function kebabCase(str: string): string {
13
2
  return str.replaceAll(/[A-Z]/g, (char, index: number) =>
14
3
  index === 0 ? char.toLowerCase() : `-${char.toLowerCase()}`,
@@ -1,13 +1,3 @@
1
- /**
2
- * Converts the first character of a string to lower case.
3
- *
4
- * @param str - The string to transform.
5
- * @returns The string with its first character lower-cased.
6
- *
7
- * @example
8
- * lowerFirst("Fred"); // "fred"
9
- * lowerFirst("FRED"); // "fRED"
10
- */
11
1
  function lowerFirst(str: string): string {
12
2
  return str.charAt(0).toLowerCase() + str.slice(1);
13
3
  }
@@ -1,19 +1,6 @@
1
- import { upperFirst } from "./upper-first.js";
2
- import { mapWordSegments } from "./word-segments.js";
1
+ import { upperFirst } from "./upper-first.ts";
2
+ import { mapWordSegments } from "./word-segments.ts";
3
3
 
4
- /**
5
- * Converts an underscore- or hyphen-delimited string to Pascal case.
6
- *
7
- * Splits only on `_` and `-` and capitalizes each segment's first character, so GObject acronyms
8
- * are preserved (`pascalCase("GLArea")` stays `"GLArea"`).
9
- *
10
- * @param str - The string to convert.
11
- * @returns The Pascal-cased string.
12
- *
13
- * @example
14
- * pascalCase("icon_name"); // "IconName"
15
- * pascalCase("scrolled-window"); // "ScrolledWindow"
16
- */
17
4
  function pascalCase(str: string): string {
18
5
  return mapWordSegments(str, upperFirst);
19
6
  }
@@ -1,13 +1,3 @@
1
- /**
2
- * Converts the first character of a string to upper case.
3
- *
4
- * @param str - The string to transform.
5
- * @returns The string with its first character upper-cased.
6
- *
7
- * @example
8
- * upperFirst("fred"); // "Fred"
9
- * upperFirst("Fred"); // "Fred"
10
- */
11
1
  function upperFirst(str: string): string {
12
2
  return str.charAt(0).toUpperCase() + str.slice(1);
13
3
  }
package/src/util/index.ts CHANGED
@@ -1 +1 @@
1
- export { packageVersion } from "./package-version.js";
1
+ export { packageVersion } from "./package-version.ts";
@@ -1,14 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
2
 
3
- /**
4
- * Reads the `version` field from the `package.json` next to the calling module.
5
- *
6
- * @param importMetaUrl - The caller's `import.meta.url`, used to resolve the sibling `package.json`.
7
- * @returns The package's version string.
8
- *
9
- * @example
10
- * packageVersion(import.meta.url); // "1.2.3"
11
- */
12
3
  function packageVersion(importMetaUrl: string): string {
13
4
  return (createRequire(importMetaUrl)("../package.json") as { version: string }).version;
14
5
  }
@@ -1,3 +0,0 @@
1
- declare function callMethod(target: object, method: string, args: unknown[]): unknown;
2
- export { callMethod };
3
- //# sourceMappingURL=call-method.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"call-method.d.ts","sourceRoot":"","sources":["../../src/function/call-method.ts"],"names":[],"mappings":"AAeA,iBAAS,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAI5E;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -1,19 +0,0 @@
1
- /**
2
- * Calls the named method on `target` with the given arguments, returning `undefined` when the
3
- * property is missing or not callable.
4
- *
5
- * @param target - The object to read the method from and bind as `this`.
6
- * @param method - The name of the method to look up.
7
- * @param args - The arguments passed to the method.
8
- * @returns The method's return value, or `undefined` when it is not a function.
9
- *
10
- * @example
11
- * callMethod(console, "log", ["hi"]); // logs "hi"; returns undefined
12
- */
13
- const isCallable = (value) => typeof value === "function";
14
- function callMethod(target, method, args) {
15
- const fn = Reflect.get(target, method);
16
- return isCallable(fn) ? Reflect.apply(fn, target, args) : undefined;
17
- }
18
- export { callMethod };
19
- //# sourceMappingURL=call-method.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"call-method.js","sourceRoot":"","sources":["../../src/function/call-method.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,GAAG,CAAC,KAAc,EAA0D,EAAE,CAC1F,OAAO,KAAK,KAAK,UAAU,CAAC;AAEhC,SAAS,UAAU,CAAC,MAAc,EAAE,MAAc,EAAE,IAAe;IAC/D,MAAM,EAAE,GAAY,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEhD,OAAO,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACxE,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["/**\n * Calls the named method on `target` with the given arguments, returning `undefined` when the\n * property is missing or not callable.\n *\n * @param target - The object to read the method from and bind as `this`.\n * @param method - The name of the method to look up.\n * @param args - The arguments passed to the method.\n * @returns The method's return value, or `undefined` when it is not a function.\n *\n * @example\n * callMethod(console, \"log\", [\"hi\"]); // logs \"hi\"; returns undefined\n */\nconst isCallable = (value: unknown): value is (this: object, ...args: unknown[]) => unknown =>\n typeof value === \"function\";\n\nfunction callMethod(target: object, method: string, args: unknown[]): unknown {\n const fn: unknown = Reflect.get(target, method);\n\n return isCallable(fn) ? Reflect.apply(fn, target, args) : undefined;\n}\n\nexport { callMethod };\n"]}
@@ -1,2 +0,0 @@
1
- export { callMethod } from "./call-method.js";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/function/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
@@ -1,2 +0,0 @@
1
- export { callMethod } from "./call-method.js";
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/function/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["export { callMethod } from \"./call-method.js\";\n"]}
@@ -1,22 +0,0 @@
1
- /**
2
- * Calls the named method on `target` with the given arguments, returning `undefined` when the
3
- * property is missing or not callable.
4
- *
5
- * @param target - The object to read the method from and bind as `this`.
6
- * @param method - The name of the method to look up.
7
- * @param args - The arguments passed to the method.
8
- * @returns The method's return value, or `undefined` when it is not a function.
9
- *
10
- * @example
11
- * callMethod(console, "log", ["hi"]); // logs "hi"; returns undefined
12
- */
13
- const isCallable = (value: unknown): value is (this: object, ...args: unknown[]) => unknown =>
14
- typeof value === "function";
15
-
16
- function callMethod(target: object, method: string, args: unknown[]): unknown {
17
- const fn: unknown = Reflect.get(target, method);
18
-
19
- return isCallable(fn) ? Reflect.apply(fn, target, args) : undefined;
20
- }
21
-
22
- export { callMethod };
@@ -1 +0,0 @@
1
- export { callMethod } from "./call-method.js";