mnemonica 0.9.943 → 0.9.945

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,6 +1,6 @@
1
1
  export declare const stackCleaners: RegExp[];
2
2
  export declare const cleanupStack: (stack: string[]) => string[];
3
- export declare const getStack: (this: any, title: string, stackAddition: string[], tillFunction?: CallableFunction | undefined) => any;
3
+ export declare const getStack: (this: any, title: string, stackAddition: string[], tillFunction?: CallableFunction) => any;
4
4
  export declare class BASE_MNEMONICA_ERROR extends Error {
5
5
  constructor(message: string | undefined, additionalStack: string[]);
6
6
  }
@@ -1,2 +1,2 @@
1
- declare const compileNewModificatorFunctionBody: (FunctionName: string, asClass?: boolean) => Function;
1
+ declare const compileNewModificatorFunctionBody: (FunctionName: string, asClass?: boolean) => (ConstructHandler: any, CreationHandler: any, SymbolConstructorName: symbol) => any;
2
2
  export default compileNewModificatorFunctionBody;
@@ -1,32 +1,41 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, '__esModule', { value : true });
3
+ const getClassConstructor = (ConstructHandler, CreationHandler) => {
4
+ return class extends ConstructHandler {
5
+ constructor (...args) {
6
+ const answer = super(...args);
7
+ return CreationHandler.call(this, answer);
8
+ }
9
+ };
10
+ };
11
+ const getFunctionConstructor = (ConstructHandler, CreationHandler) => {
12
+ return function (...args) {
13
+ const answer = ConstructHandler.call(this, ...args);
14
+ return CreationHandler.call(this, answer);
15
+ };
16
+ };
3
17
  const compileNewModificatorFunctionBody = function (FunctionName, asClass = false) {
4
- const dt = `${Date.now()}_${`${Math.random()}`.split('.')[1]}`;
5
- const modString = asClass ?
6
- `class ${FunctionName} extends ConstructHandler_${dt} {
7
- constructor(...args) {
8
- const answer = super(...args);
9
- return CreationHandler_${dt}.call(this, answer);
18
+ return function (ConstructHandler, CreationHandler, SymbolConstructorName) {
19
+ return function () {
20
+ let ModificationBody;
21
+ if (asClass) {
22
+ ModificationBody = getClassConstructor(ConstructHandler, CreationHandler);
10
23
  }
11
- }`
12
- :
13
- `const ${FunctionName} = function (...args) {
14
- const answer = ConstructHandler_${dt}.call(this, ...args);
15
- return CreationHandler_${dt}.call(this, answer);
16
- };`;
17
- return new Function(`ConstructHandler_${dt}`, `CreationHandler_${dt}`, 'SymbolConstructorName', `return function () {
18
-
19
- ${modString}
20
-
21
- Object.defineProperty(${FunctionName}, SymbolConstructorName, {
24
+ else {
25
+ ModificationBody = getFunctionConstructor(ConstructHandler, CreationHandler);
26
+ }
27
+ ModificationBody.prototype.constructor = ModificationBody;
28
+ Object.defineProperty(ModificationBody.prototype.constructor, 'name', {
29
+ value : FunctionName,
30
+ writable : false
31
+ });
32
+ Object.defineProperty(ModificationBody, SymbolConstructorName, {
22
33
  get () {
23
- return '${FunctionName}';
34
+ return FunctionName;
24
35
  }
25
36
  });
26
-
27
- return ${FunctionName};
28
-
37
+ return ModificationBody;
29
38
  };
30
- `);
39
+ };
31
40
  };
32
41
  exports.default = compileNewModificatorFunctionBody;
package/build/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { TypeAbsorber, ITypeClass, TypeLookup, IDEF } from './types';
2
2
  export type { IDEF } from './types';
3
3
  export declare const defaultTypes: any;
4
4
  export declare const define: TypeAbsorber;
5
- export declare const tsdefine: <T>(this: any, TypeName: string, constructHandler: IDEF<T>, proto?: object | undefined, config?: object | undefined) => ITypeClass<T>;
5
+ export declare const tsdefine: <T>(this: any, TypeName: string, constructHandler: IDEF<T>, proto?: object, config?: object) => ITypeClass<T>;
6
6
  export declare const lookup: TypeLookup;
7
7
  export declare const mnemonica: {
8
8
  [index: string]: unknown;
@@ -3,21 +3,21 @@ export interface ConstructorFunction<ConstructorInstance extends object> {
3
3
  (this: ConstructorInstance, ...args: any[]): ConstructorInstance;
4
4
  prototype: ConstructorInstance;
5
5
  }
6
- export declare type TypeModificator<T extends object> = (...args: any[]) => ConstructorFunction<T>;
7
- export declare type TypeLookup = (this: Map<string, any>, TypeNestedPath: string) => TypeClass;
8
- export declare type TypeClass = {
6
+ export type TypeModificator<T extends object> = (...args: any[]) => ConstructorFunction<T>;
7
+ export type TypeLookup = (this: Map<string, any>, TypeNestedPath: string) => TypeClass;
8
+ export type TypeClass = {
9
9
  new (...args: any[]): any;
10
10
  define: TypeAbsorber;
11
11
  lookup: TypeLookup;
12
12
  registerHook: (type: 'preCreation' | 'postCreation' | 'creationError', hook: CallableFunction) => any;
13
13
  };
14
- export declare type TypeAbsorber = (this: any, TypeName: string, constructHandler: CallableFunction, proto?: object, config?: object) => TypeClass;
15
- export declare type IDEF<T> = {
14
+ export type TypeAbsorber = (this: any, TypeName: string, constructHandler: CallableFunction, proto?: object, config?: object) => TypeClass;
15
+ export type IDEF<T> = {
16
16
  new (...args: any[]): T;
17
17
  (this: T, ...args: any[]): T;
18
18
  prototype?: ThisType<T>;
19
19
  };
20
- export declare type ITypeAbsorber<T> = (this: any, TypeName: string, constructHandler: IDEF<T>, proto?: object, config?: object) => ITypeClass<T>;
20
+ export type ITypeAbsorber<T> = (this: any, TypeName: string, constructHandler: IDEF<T>, proto?: object, config?: object) => ITypeClass<T>;
21
21
  export interface ITypeClass<T> {
22
22
  new (...args: any[]): T;
23
23
  (this: T, ...args: any[]): T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mnemonica",
3
- "version": "0.9.943",
3
+ "version": "0.9.945",
4
4
  "description": "abstract technique that aids information retention : instance inheritance system",
5
5
  "type": "commonjs",
6
6
  "main": "./build/index.js",