composition-ts 0.1.2 → 0.1.3

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 ADDED
@@ -0,0 +1,21 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),Array.isArray,Array.from,Array.prototype.concat,Array.prototype.filter,Array.prototype.push,Array.prototype.slice,Array.prototype.splice,Function.prototype.toString;const e=Object.defineProperty,t=Object.defineProperties,n=Object.getOwnPropertyDescriptors;Number.isNaN,Number.isInteger,Number.isSafeInteger,Number.isFinite;function r(e){if(typeof e!=`function`)return!0;try{return new new Proxy(e,{construct(){return{}}}),!1}catch{return!0}}
2
+ /**
3
+ * 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.
4
+ * - `initializer` **must not** be an arrow function!
5
+ * - returned class's name is `initializer.name`
6
+ *
7
+ * @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.
8
+ * @param parts An array of objects whose properties will be copied(via descriptors) to the prototype of the new class.
9
+ *
10
+ * ## About
11
+ * @package CompositionTs
12
+ * @author Kasukabe Tsumugi <futami16237@gmail.com>
13
+ * @version 0.1.3 (Last Update: 2026.10.12 10:06:57.524)
14
+ * @license MIT
15
+ * @link git+https://github.com/baendlorel/tsumugi-lib.git
16
+ * @link https://baendlorel.github.io/ Welcome to my site!
17
+ * @description Instead of inheritance, make it composition!
18
+ * @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
19
+ */
20
+ function i(i,...a){if(r(i))throw TypeError(`First argument must be a non-arrow function because it cannot access the instance's 'this' context.`);let o=e(class{constructor(...e){i.apply(this,e)}},`name`,{value:i.name,configurable:!0});for(let e=0;e<a.length;e++){let r=n(a[e]);t(o.prototype,r)}return o}exports.compose=i;
21
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["$define","$defines","$getOwnPropertyDescriptors","notNewable","value","compose","parts","initializer","NewClass","args","i","descriptors"],"sources":["../../_shared/native/std.ts","../src/index.ts"],"sourcesContent":["// Cached native methods for performance optimization\n\n// # Array\nexport const $isArray = Array.isArray;\nexport const $arrayFrom = Array.from;\nexport const $concat = Array.prototype.concat;\nexport const $filter = Array.prototype.filter;\nexport const $push = Array.prototype.push;\nexport const $slice = Array.prototype.slice;\nexport const $splice = Array.prototype.splice;\n\n// # Object\nexport const $fnToString = Function.prototype.toString;\nexport const $toString = Object.prototype.toString;\nexport const $ObjectPrototype = Object.prototype;\nexport const $is = Object.is;\nexport const $assign = Object.assign;\nexport const $hasOwn = Object.prototype.hasOwnProperty;\nexport const $keys = Object.keys as <T>(o: T) => Array<keyof T>;\nexport const $define = Object.defineProperty;\nexport const $defines = Object.defineProperties;\nexport const $entries = Object.entries as <T>(o: T) => Array<[keyof T, T[keyof T]]>;\nexport const $jsonStringify = JSON.stringify;\nexport const $getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors;\nexport const $freeze = Object.freeze;\n\n// # Reflect\n\nexport const $set = Reflect.set;\nexport const $get = Reflect.get;\nexport const $has = Reflect.has;\nexport const $ownKeys = Reflect.ownKeys;\n// & Do not use `Object.defineProperty`\nexport const $reflectDefine = Reflect.defineProperty;\nexport const $delete = Reflect.deleteProperty;\nexport const $getPrototypeOf = Reflect.getPrototypeOf;\nexport const $setPrototypeOf = Reflect.setPrototypeOf;\n\n// # Math and related utilities\nexport const $max = Math.max;\nexport const $min = Math.min;\nexport const $floor = Math.floor;\nexport const $random = Math.random;\nexport const $randomInt = (min: number, max: number) => $floor($random() * (max - min + 1)) + min;\n\n// # Number\nexport const $isNaN = Number.isNaN;\nexport const $isInt = Number.isInteger;\nexport const $isSafeInt = Number.isSafeInteger;\nexport const $isFinite = Number.isFinite;\nexport const $MAX_INT = Number.MAX_SAFE_INTEGER;\nexport const $MIN_INT = Number.MIN_SAFE_INTEGER;\n\nexport const $isThenable = (o: any): o is Promise<any> => typeof o?.then === 'function';\n\nexport const $isPrimitive: (o: unknown) => boolean | null | undefined | symbol | number | bigint = (o) =>\n o === null || (typeof o !== 'object' && typeof o !== 'function');\n","import type { Compose, Constructor, Mutable } from './types.js';\nimport { $define, $defines, $getOwnPropertyDescriptors } from '@shared';\n\nfunction notNewable(value: unknown): value is new (...args: unknown[]) => unknown {\n if (typeof value !== 'function') {\n return true;\n }\n try {\n const a = new Proxy(value as Constructor, {\n construct() {\n return {};\n },\n });\n new a();\n return false;\n } catch {\n return true;\n }\n}\n\n/**\n * 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.\n * - `initializer` **must not** be an arrow function!\n * - returned class's name is `initializer.name`\n *\n * @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.\n * @param parts An array of objects whose properties will be copied(via descriptors) to the prototype of the new class.\n *\n * __PKG_INFO__\n */\nexport function compose<\n Protos extends readonly object[],\n Args extends any[],\n Instance extends Compose<Protos> = Compose<Protos>,\n>(initializer: (this: Mutable<Instance>, ...args: Args) => any, ...parts: Protos): new (...args: Args) => Instance {\n if (notNewable(initializer)) {\n throw new TypeError(\n `First argument must be a non-arrow function because it cannot access the instance's 'this' context.`,\n );\n }\n\n const NewClass = $define(\n class {\n constructor(...args: Args) {\n initializer.apply(this as any, args);\n }\n },\n 'name',\n {\n value: initializer.name,\n configurable: true,\n },\n );\n\n for (let i = 0; i < parts.length; i++) {\n const descriptors = $getOwnPropertyDescriptors(parts[i]);\n $defines(NewClass.prototype, descriptors);\n }\n\n return NewClass as new (...params: Args) => Instance;\n}\n"],"mappings":"mEAGwB,MAAM,QACJ,MAAM,KACT,MAAM,UAAU,OAChB,MAAM,UAAU,OAClB,MAAM,UAAU,KACf,MAAM,UAAU,MACf,MAAM,UAAU,OAGZ,SAAS,UAAU,SAO9C,MAAaA,EAAU,OAAO,eACjBC,EAAW,OAAO,iBAGlBC,EAA6B,OAAO,0BAuB3B,OAAO,MACP,OAAO,UACH,OAAO,cACR,OAAO,SC9ChC,SAASC,EAAW,EAA8D,CAChF,GAAI,OAAOC,GAAU,WACnB,MAAO,GAET,GAAI,CAOF,OADA,IAAI,IALU,MAAMA,EAAsB,CACxC,WAAY,CACV,MAAO,CAAC,CACV,CACF,CACI,EACG,EACT,MAAQ,CACN,MAAO,EACT,CACF;;;;;;;;;;;;;;;;;;;AAYA,SAAgBC,EAId,EAA8D,GAAGC,EAAgD,CACjH,GAAIH,EAAWI,CAAW,EACxB,MAAU,UACR,qGACF,EAGF,IAAMC,EAAWR,EACf,KAAM,CACJ,YAAY,GAAGS,EAAY,CACzBF,EAAY,MAAM,KAAaE,CAAI,CACrC,CACF,EACA,OACA,CACE,MAAOF,EAAY,KACnB,aAAc,EAChB,CACF,EAEA,IAAK,IAAIG,EAAI,EAAGA,EAAIJ,EAAM,OAAQ,IAAK,CACrC,IAAMK,EAAcT,EAA2BI,EAAMI,EAAE,EACvDT,EAASO,EAAS,UAAWG,CAAW,CAC1C,CAEA,OAAOH,CACT"}
@@ -0,0 +1,19 @@
1
+ //#region src/types.d.ts
2
+ type Compose<Types extends readonly unknown[]> = Types extends readonly [infer Head, ...infer Tail] ? Head & Compose<Tail> : unknown;
3
+ type Mutable<T> = { -readonly [P in keyof T]: T[P]; };
4
+ //#endregion
5
+ //#region src/index.d.ts
6
+ /**
7
+ * 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.
8
+ * - `initializer` **must not** be an arrow function!
9
+ * - returned class's name is `initializer.name`
10
+ *
11
+ * @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.
12
+ * @param parts An array of objects whose properties will be copied(via descriptors) to the prototype of the new class.
13
+ *
14
+ * __PKG_INFO__
15
+ */
16
+ declare function compose<Protos extends readonly object[], Args extends any[], Instance extends Compose<Protos> = Compose<Protos>>(initializer: (this: Mutable<Instance>, ...args: Args) => any, ...parts: Protos): new (...args: Args) => Instance;
17
+ //#endregion
18
+ export { compose };
19
+ //# sourceMappingURL=index.d.cts.map
@@ -1,10 +1,8 @@
1
- type Compose<Types extends readonly unknown[]> = Types extends readonly [infer Head, ...infer Tail]
2
- ? Head & Compose<Tail>
3
- : unknown;
4
- type Mutable<T> = {
5
- -readonly [P in keyof T]: T[P];
6
- };
7
-
1
+ //#region src/types.d.ts
2
+ type Compose<Types extends readonly unknown[]> = Types extends readonly [infer Head, ...infer Tail] ? Head & Compose<Tail> : unknown;
3
+ type Mutable<T> = { -readonly [P in keyof T]: T[P]; };
4
+ //#endregion
5
+ //#region src/index.d.ts
8
6
  /**
9
7
  * 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.
10
8
  * - `initializer` **must not** be an arrow function!
@@ -16,13 +14,14 @@ type Mutable<T> = {
16
14
  * ## About
17
15
  * @package CompositionTs
18
16
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
19
- * @version 0.1.2 (Last Update: 2026.03.26 11:27:32.645)
17
+ * @version 0.1.3 (Last Update: 2026.10.12 10:06:57.524)
20
18
  * @license MIT
21
- * @link git+https://github.com/baendlorel/kt-packages.git
19
+ * @link git+https://github.com/baendlorel/tsumugi-lib.git
22
20
  * @link https://baendlorel.github.io/ Welcome to my site!
23
21
  * @description Instead of inheritance, make it composition!
24
22
  * @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
25
23
  */
26
24
  declare function compose<Protos extends readonly object[], Args extends any[], Instance extends Compose<Protos> = Compose<Protos>>(initializer: (this: Mutable<Instance>, ...args: Args) => any, ...parts: Protos): new (...args: Args) => Instance;
27
-
25
+ //#endregion
28
26
  export { compose };
27
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -1,29 +1,21 @@
1
- const t = Object.defineProperty, n = Object.defineProperties, e = Object.getOwnPropertyDescriptors;
2
-
3
- function c(c, ...r) {
4
- if (function(t) {
5
- if ("function" != typeof t) return !0;
6
- try {
7
- return new new Proxy(t, {
8
- construct: () => ({})
9
- }), !1;
10
- } catch {
11
- return !0;
12
- }
13
- }(c)) throw new TypeError("First argument must be a non-arrow function because it cannot access the instance's 'this' context.");
14
- const o = t(class {
15
- constructor(...t) {
16
- c.apply(this, t);
17
- }
18
- }, "name", {
19
- value: c.name,
20
- configurable: !0
21
- });
22
- for (let t = 0; t < r.length; t++) {
23
- const c = e(r[t]);
24
- n(o.prototype, c);
25
- }
26
- return o;
27
- }
28
-
29
- export { c as compose };
1
+ Array.isArray,Array.from,Array.prototype.concat,Array.prototype.filter,Array.prototype.push,Array.prototype.slice,Array.prototype.splice,Function.prototype.toString;const e=Object.defineProperty,t=Object.defineProperties,n=Object.getOwnPropertyDescriptors;Number.isNaN,Number.isInteger,Number.isSafeInteger,Number.isFinite;function r(e){if(typeof e!=`function`)return!0;try{return new new Proxy(e,{construct(){return{}}}),!1}catch{return!0}}
2
+ /**
3
+ * 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.
4
+ * - `initializer` **must not** be an arrow function!
5
+ * - returned class's name is `initializer.name`
6
+ *
7
+ * @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.
8
+ * @param parts An array of objects whose properties will be copied(via descriptors) to the prototype of the new class.
9
+ *
10
+ * ## About
11
+ * @package CompositionTs
12
+ * @author Kasukabe Tsumugi <futami16237@gmail.com>
13
+ * @version 0.1.3 (Last Update: 2026.10.12 10:06:57.524)
14
+ * @license MIT
15
+ * @link git+https://github.com/baendlorel/tsumugi-lib.git
16
+ * @link https://baendlorel.github.io/ Welcome to my site!
17
+ * @description Instead of inheritance, make it composition!
18
+ * @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
19
+ */
20
+ function i(i,...a){if(r(i))throw TypeError(`First argument must be a non-arrow function because it cannot access the instance's 'this' context.`);let o=e(class{constructor(...e){i.apply(this,e)}},`name`,{value:i.name,configurable:!0});for(let e=0;e<a.length;e++){let r=n(a[e]);t(o.prototype,r)}return o}export{i as compose};
21
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["$define","$defines","$getOwnPropertyDescriptors","notNewable","value","compose","parts","initializer","NewClass","args","i","descriptors"],"sources":["../../_shared/native/std.ts","../src/index.ts"],"sourcesContent":["// Cached native methods for performance optimization\n\n// # Array\nexport const $isArray = Array.isArray;\nexport const $arrayFrom = Array.from;\nexport const $concat = Array.prototype.concat;\nexport const $filter = Array.prototype.filter;\nexport const $push = Array.prototype.push;\nexport const $slice = Array.prototype.slice;\nexport const $splice = Array.prototype.splice;\n\n// # Object\nexport const $fnToString = Function.prototype.toString;\nexport const $toString = Object.prototype.toString;\nexport const $ObjectPrototype = Object.prototype;\nexport const $is = Object.is;\nexport const $assign = Object.assign;\nexport const $hasOwn = Object.prototype.hasOwnProperty;\nexport const $keys = Object.keys as <T>(o: T) => Array<keyof T>;\nexport const $define = Object.defineProperty;\nexport const $defines = Object.defineProperties;\nexport const $entries = Object.entries as <T>(o: T) => Array<[keyof T, T[keyof T]]>;\nexport const $jsonStringify = JSON.stringify;\nexport const $getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors;\nexport const $freeze = Object.freeze;\n\n// # Reflect\n\nexport const $set = Reflect.set;\nexport const $get = Reflect.get;\nexport const $has = Reflect.has;\nexport const $ownKeys = Reflect.ownKeys;\n// & Do not use `Object.defineProperty`\nexport const $reflectDefine = Reflect.defineProperty;\nexport const $delete = Reflect.deleteProperty;\nexport const $getPrototypeOf = Reflect.getPrototypeOf;\nexport const $setPrototypeOf = Reflect.setPrototypeOf;\n\n// # Math and related utilities\nexport const $max = Math.max;\nexport const $min = Math.min;\nexport const $floor = Math.floor;\nexport const $random = Math.random;\nexport const $randomInt = (min: number, max: number) => $floor($random() * (max - min + 1)) + min;\n\n// # Number\nexport const $isNaN = Number.isNaN;\nexport const $isInt = Number.isInteger;\nexport const $isSafeInt = Number.isSafeInteger;\nexport const $isFinite = Number.isFinite;\nexport const $MAX_INT = Number.MAX_SAFE_INTEGER;\nexport const $MIN_INT = Number.MIN_SAFE_INTEGER;\n\nexport const $isThenable = (o: any): o is Promise<any> => typeof o?.then === 'function';\n\nexport const $isPrimitive: (o: unknown) => boolean | null | undefined | symbol | number | bigint = (o) =>\n o === null || (typeof o !== 'object' && typeof o !== 'function');\n","import type { Compose, Constructor, Mutable } from './types.js';\nimport { $define, $defines, $getOwnPropertyDescriptors } from '@shared';\n\nfunction notNewable(value: unknown): value is new (...args: unknown[]) => unknown {\n if (typeof value !== 'function') {\n return true;\n }\n try {\n const a = new Proxy(value as Constructor, {\n construct() {\n return {};\n },\n });\n new a();\n return false;\n } catch {\n return true;\n }\n}\n\n/**\n * 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.\n * - `initializer` **must not** be an arrow function!\n * - returned class's name is `initializer.name`\n *\n * @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.\n * @param parts An array of objects whose properties will be copied(via descriptors) to the prototype of the new class.\n *\n * __PKG_INFO__\n */\nexport function compose<\n Protos extends readonly object[],\n Args extends any[],\n Instance extends Compose<Protos> = Compose<Protos>,\n>(initializer: (this: Mutable<Instance>, ...args: Args) => any, ...parts: Protos): new (...args: Args) => Instance {\n if (notNewable(initializer)) {\n throw new TypeError(\n `First argument must be a non-arrow function because it cannot access the instance's 'this' context.`,\n );\n }\n\n const NewClass = $define(\n class {\n constructor(...args: Args) {\n initializer.apply(this as any, args);\n }\n },\n 'name',\n {\n value: initializer.name,\n configurable: true,\n },\n );\n\n for (let i = 0; i < parts.length; i++) {\n const descriptors = $getOwnPropertyDescriptors(parts[i]);\n $defines(NewClass.prototype, descriptors);\n }\n\n return NewClass as new (...params: Args) => Instance;\n}\n"],"mappings":"AAGwB,MAAM,QACJ,MAAM,KACT,MAAM,UAAU,OAChB,MAAM,UAAU,OAClB,MAAM,UAAU,KACf,MAAM,UAAU,MACf,MAAM,UAAU,OAGZ,SAAS,UAAU,SAO9C,MAAaA,EAAU,OAAO,eACjBC,EAAW,OAAO,iBAGlBC,EAA6B,OAAO,0BAuB3B,OAAO,MACP,OAAO,UACH,OAAO,cACR,OAAO,SC9ChC,SAASC,EAAW,EAA8D,CAChF,GAAI,OAAOC,GAAU,WACnB,MAAO,GAET,GAAI,CAOF,OADA,IAAI,IALU,MAAMA,EAAsB,CACxC,WAAY,CACV,MAAO,CAAC,CACV,CACF,CACI,EACG,EACT,MAAQ,CACN,MAAO,EACT,CACF;;;;;;;;;;;;;;;;;;;AAYA,SAAgBC,EAId,EAA8D,GAAGC,EAAgD,CACjH,GAAIH,EAAWI,CAAW,EACxB,MAAU,UACR,qGACF,EAGF,IAAMC,EAAWR,EACf,KAAM,CACJ,YAAY,GAAGS,EAAY,CACzBF,EAAY,MAAM,KAAaE,CAAI,CACrC,CACF,EACA,OACA,CACE,MAAOF,EAAY,KACnB,aAAc,EAChB,CACF,EAEA,IAAK,IAAIG,EAAI,EAAGA,EAAIJ,EAAM,OAAQ,IAAK,CACrC,IAAMK,EAAcT,EAA2BI,EAAMI,EAAE,EACvDT,EAASO,EAAS,UAAWG,CAAW,CAC1C,CAEA,OAAOH,CACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "composition-ts",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "author": {
5
5
  "name": "Kasukabe Tsumugi",
6
6
  "email": "futami16237@gmail.com"
@@ -21,7 +21,7 @@
21
21
  ],
22
22
  "repository": {
23
23
  "type": "git",
24
- "url": "git+https://github.com/baendlorel/kt-packages.git",
24
+ "url": "git+https://github.com/baendlorel/tsumugi-lib.git",
25
25
  "directory": "packages/composition-ts"
26
26
  },
27
27
  "keywords": [
@@ -30,7 +30,7 @@
30
30
  ],
31
31
  "license": "MIT",
32
32
  "bugs": {
33
- "url": "https://github.com/baendlorel/kt-packages/issues"
33
+ "url": "https://github.com/baendlorel/tsumugi-lib/issues"
34
34
  },
35
- "homepage": "https://github.com/baendlorel/kt-packages/tree/main/packages/composition-ts#readme"
36
- }
35
+ "homepage": "https://github.com/baendlorel/tsumugi-lib/tree/main/packages/composition-ts#readme"
36
+ }