composition-ts 0.0.1 → 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/README.md CHANGED
@@ -31,8 +31,9 @@ const PersonModel = compose(
31
31
  this.id = id;
32
32
  this.name = name;
33
33
  },
34
- [statePart, renamable, describable],
35
- 'PersonModel',
34
+ statePart,
35
+ renamable,
36
+ describable,
36
37
  );
37
38
 
38
39
  const person = new PersonModel(1, 'Ada');
@@ -43,15 +44,14 @@ console.log(person.label); // 1:Grace
43
44
 
44
45
  ## API
45
46
 
46
- ### compose(initializer, parts, className?)
47
+ ### compose(initializer, ...parts)
47
48
 
48
49
  Creates a new class and copies every property descriptor from `parts` onto its prototype.
49
50
 
50
51
  ```ts
51
52
  declare function compose<Protos extends readonly object[], Args extends any[], Instance extends Compose<Protos>>(
52
53
  initializer: (this: Instance, ...args: Args) => any,
53
- parts: Protos,
54
- className?: string,
54
+ ...parts: Protos
55
55
  ): new (...args: Args) => Instance;
56
56
  ```
57
57
 
@@ -59,7 +59,6 @@ Parameters:
59
59
 
60
60
  - `initializer`: A regular function invoked inside the generated constructor with the new instance bound as `this`.
61
61
  - `parts`: An array of objects whose own property descriptors are copied onto the generated class prototype.
62
- - `className`: Optional class name for the generated constructor. Defaults to `initializer.name`.
63
62
 
64
63
  Notes:
65
64
 
package/dist/index.d.ts CHANGED
@@ -5,21 +5,21 @@ type Compose<Types extends readonly unknown[]> = Types extends readonly [infer H
5
5
  /**
6
6
  * Instead of using class inheritance, we can compose prototypes from multiple objects. This function takes a constructor function and an array of objects, and returns a new class that creates instances with the combined prototype of all the objects.
7
7
  * - `initializer` **must not** be an arrow function!
8
+ * - returned class's name is `initializer.name`
8
9
  *
9
10
  * @param initializer A function that initializes the instance. It will be called with the instance as `this` and use the arguments passed to the constructor.
10
11
  * @param parts An array of objects whose properties will be copied(via descriptors) to the prototype of the new class.
11
- * @param className An optional name for the new class. If not provided, it will default to the name of the `initializer` function.
12
12
  *
13
13
  * ## About
14
14
  * @package CompositionTs
15
15
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
16
- * @version 0.0.1 (Last Update: 2026.03.26 10:29:11.705)
16
+ * @version 0.1.1 (Last Update: 2026.03.26 11:24:23.847)
17
17
  * @license MIT
18
18
  * @link git+https://github.com/baendlorel/kt-packages.git
19
19
  * @link https://baendlorel.github.io/ Welcome to my site!
20
20
  * @description Instead of inheritance, make it composition!
21
21
  * @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
22
22
  */
23
- declare function compose<Protos extends readonly object[], Args extends any[], Instance extends Compose<Protos>>(initializer: (this: Instance, ...args: Args) => any, parts: Protos, className?: string): new (...args: Args) => Instance;
23
+ declare function compose<Protos extends readonly object[], Args extends any[], Instance extends Compose<Protos> = Compose<Protos>>(initializer: (this: Instance, ...args: Args) => any, ...parts: Protos): new (...args: Args) => Instance;
24
24
 
25
25
  export { compose };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  const t = Object.defineProperty, n = Object.defineProperties, e = Object.getOwnPropertyDescriptors;
2
2
 
3
- function c(c, r, o) {
3
+ function c(c, ...r) {
4
4
  if (function(t) {
5
5
  if ("function" != typeof t) return !0;
6
6
  try {
@@ -11,19 +11,19 @@ function c(c, r, o) {
11
11
  return !0;
12
12
  }
13
13
  }(c)) throw new TypeError("First argument must be a non-arrow function because it cannot access the instance's 'this' context.");
14
- const s = t(class {
14
+ const o = t(class {
15
15
  constructor(...t) {
16
16
  c.apply(this, t);
17
17
  }
18
18
  }, "name", {
19
- value: o ?? c.name,
19
+ value: c.name,
20
20
  configurable: !0
21
21
  });
22
22
  for (let t = 0; t < r.length; t++) {
23
23
  const c = e(r[t]);
24
- n(s.prototype, c);
24
+ n(o.prototype, c);
25
25
  }
26
- return s;
26
+ return o;
27
27
  }
28
28
 
29
29
  export { c as compose };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "composition-ts",
3
- "version": "0.0.1",
3
+ "version": "0.1.1",
4
4
  "author": {
5
5
  "name": "Kasukabe Tsumugi",
6
6
  "email": "futami16237@gmail.com"