@poppinss/utils 4.0.4 → 5.0.0

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.
@@ -1,8 +1,4 @@
1
1
  declare type Constructor = new (...args: any[]) => any;
2
- /**
3
- * Converting unions to intersection
4
- */
5
- declare type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;
6
2
  /**
7
3
  * Normalizes constructor to work with mixins. There is an open bug for mixins
8
4
  * to allow constructors other than `...args: any[]`
@@ -12,10 +8,21 @@ declare type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) ex
12
8
  export declare type NormalizeConstructor<T extends Constructor> = {
13
9
  new (...args: any[]): InstanceType<T>;
14
10
  } & Omit<T, 'constructor'>;
11
+ export interface UnaryFunction<T, R> {
12
+ (source: T): R;
13
+ }
15
14
  /**
16
15
  * Compose a class by applying mixins to it.
17
16
  * The code is inspired by https://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/, its
18
17
  * just that I have added the support for static types too.
19
18
  */
20
- export declare const compose: <SuperClass extends Constructor, M extends ((superclass: SuperClass) => Constructor)[]>(superclass: SuperClass, ...mixins: M) => SuperClass & UnionToIntersection<ReturnType<M[number]>>;
19
+ export declare function compose<T extends Constructor, A>(superclass: T, mixin: UnaryFunction<T, A>): A;
20
+ export declare function compose<T extends Constructor, A, B>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>): B;
21
+ export declare function compose<T extends Constructor, A, B, C>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>): C;
22
+ export declare function compose<T extends Constructor, A, B, C, D>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>): D;
23
+ export declare function compose<T extends Constructor, A, B, C, D, E>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinE: UnaryFunction<D, E>): E;
24
+ export declare function compose<T extends Constructor, A, B, C, D, E, F>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinF: UnaryFunction<E, F>): F;
25
+ export declare function compose<T extends Constructor, A, B, C, D, E, F, G>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinF: UnaryFunction<E, F>, mixinG: UnaryFunction<F, G>): G;
26
+ export declare function compose<T extends Constructor, A, B, C, D, E, F, G, H>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinF: UnaryFunction<E, F>, mixinG: UnaryFunction<F, G>, mixinH: UnaryFunction<G, H>): H;
27
+ export declare function compose<T extends Constructor, A, B, C, D, E, F, G, H, I>(superclass: T, mixin: UnaryFunction<T, A>, mixinB: UnaryFunction<A, B>, mixinC: UnaryFunction<B, C>, mixinD: UnaryFunction<C, D>, mixinF: UnaryFunction<E, F>, mixinG: UnaryFunction<F, G>, mixinH: UnaryFunction<G, H>, mixinI: UnaryFunction<H, I>): I;
21
28
  export {};
@@ -9,12 +9,7 @@
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.compose = void 0;
12
- /**
13
- * Compose a class by applying mixins to it.
14
- * The code is inspired by https://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/, its
15
- * just that I have added the support for static types too.
16
- */
17
- const compose = (superclass, ...mixins) => {
12
+ function compose(superclass, ...mixins) {
18
13
  return mixins.reduce((c, mixin) => mixin(c), superclass);
19
- };
14
+ }
20
15
  exports.compose = compose;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poppinss/utils",
3
- "version": "4.0.4",
3
+ "version": "5.0.0",
4
4
  "description": "Handy utilities for repetitive work",
5
5
  "main": "build/index.js",
6
6
  "files": [