what-are-you 0.1.8 → 0.1.11

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.
@@ -0,0 +1,17 @@
1
+ type _ProtectedCtor<T extends object> = typeof _ProtectedCtorClass & {
2
+ prototype: T;
3
+ };
4
+ type _PrivateCtor<T extends object> = typeof _PrivateCtorClass & {
5
+ prototype: T;
6
+ };
7
+ type _PublicCtor<T extends object> = abstract new (...args: any[]) => T;
8
+ export type AnyCtor<T extends object> = _ProtectedCtor<T> | _PublicCtor<T> | _PrivateCtor<T>;
9
+ export type InstanceTypeOf<T extends AnyCtor<any>> = T extends _PrivateCtor<infer U> ? U : T extends _ProtectedCtor<infer U> ? U : T extends _PublicCtor<infer U> ? U : never;
10
+ declare abstract class _ProtectedCtorClass {
11
+ protected constructor(...args: any[]);
12
+ }
13
+ declare abstract class _PrivateCtorClass {
14
+ private constructor();
15
+ }
16
+ export {};
17
+ //# sourceMappingURL=ctor-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ctor-type.d.ts","sourceRoot":"","sources":["../../src/ctor-type.ts"],"names":[],"mappings":"AAAA,KAAK,cAAc,CAAC,CAAC,SAAS,MAAM,IAAI,OAAO,mBAAmB,GAAG;IACjE,SAAS,EAAE,CAAC,CAAA;CACf,CAAA;AACD,KAAK,YAAY,CAAC,CAAC,SAAS,MAAM,IAAI,OAAO,iBAAiB,GAAG;IAC7D,SAAS,EAAE,CAAC,CAAA;CACf,CAAA;AACD,KAAK,WAAW,CAAC,CAAC,SAAS,MAAM,IAAI,QAAQ,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;AACvE,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,MAAM,IAAI,cAAc,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAA;AAE5F,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC,IAC7C,CAAC,SAAS,YAAY,CAAC,MAAM,CAAC,CAAC,GACzB,CAAC,GACD,CAAC,SAAS,cAAc,CAAC,MAAM,CAAC,CAAC,GAC/B,CAAC,GACD,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,CAAC,GAC5B,CAAC,GACD,KAAK,CAAA;AACnB,OAAO,CAAC,QAAQ,OAAO,mBAAmB;IACtC,SAAS,aAAa,GAAG,IAAI,EAAE,GAAG,EAAE;CACvC;AAED,OAAO,CAAC,QAAQ,OAAO,iBAAiB;IACpC,OAAO;CACV"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ctor-type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ctor-type.js","sourceRoot":"","sources":["../../src/ctor-type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export declare function createNamedFunction<T extends (...args: any[]) => any>(name: string, func: T): T;
2
+ //# sourceMappingURL=function.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../src/function.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,KAO3F"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNamedFunction = createNamedFunction;
4
+ function createNamedFunction(name, func) {
5
+ const f = {
6
+ [name](...args) {
7
+ return func.call(null, ...args);
8
+ }
9
+ }[name];
10
+ return f;
11
+ }
12
+ //# sourceMappingURL=function.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function.js","sourceRoot":"","sources":["../../src/function.ts"],"names":[],"mappings":";;AAAA,kDAOC;AAPD,SAAgB,mBAAmB,CAAoC,IAAY,EAAE,IAAO;IACxF,MAAM,CAAC,GAAG;QACN,CAAC,IAAI,CAAC,CAAC,GAAG,IAAmB;YACzB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAA;QACnC,CAAC;KACJ,CAAC,IAAI,CAAM,CAAA;IACZ,OAAO,CAAC,CAAA;AACZ,CAAC"}
@@ -1,4 +1,7 @@
1
+ export type { AnyCtor, InstanceTypeOf } from "./ctor-type.js";
2
+ export { createNamedFunction } from "./function.js";
1
3
  export { getFunctionName, getNiceClassName, getNiceTypeOf, getNiceValueName, getSymbolDescription } from "./get-text.js";
2
4
  export { isArray, isBigInt, isBool, isError, isFunction, isInt, isIntOrInfinity, isNat, isNatOrInfinity, isNotNullish, isNullish, isNumber, isObject, isPair, isPosInt, isPropertyKey, isString, isSymbol, isThenable } from "./is-basic.js";
3
5
  export { isAnyIterable, isArrayLike, isAsyncIterable, isDoddle, isIterable, isNextable } from "./is-special.js";
6
+ export { getPrototypeChain, isInstanceOf, isPrototypeObject } from "./prototypes.js";
4
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,oBAAoB,EACvB,MAAM,eAAe,CAAA;AACtB,OAAO,EACH,OAAO,EACP,QAAQ,EACR,MAAM,EACN,OAAO,EACP,UAAU,EACV,KAAK,EACL,eAAe,EACf,KAAK,EACL,eAAe,EACf,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,UAAU,EACb,MAAM,eAAe,CAAA;AACtB,OAAO,EACH,aAAa,EACb,WAAW,EACX,eAAe,EACf,QAAQ,EACR,UAAU,EACV,UAAU,EACb,MAAM,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EACH,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,oBAAoB,EACvB,MAAM,eAAe,CAAA;AACtB,OAAO,EACH,OAAO,EACP,QAAQ,EACR,MAAM,EACN,OAAO,EACP,UAAU,EACV,KAAK,EACL,eAAe,EACf,KAAK,EACL,eAAe,EACf,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,UAAU,EACb,MAAM,eAAe,CAAA;AACtB,OAAO,EACH,aAAa,EACb,WAAW,EACX,eAAe,EACf,QAAQ,EACR,UAAU,EACV,UAAU,EACb,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA"}
package/dist/cjs/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNextable = exports.isIterable = exports.isDoddle = exports.isAsyncIterable = exports.isArrayLike = exports.isAnyIterable = exports.isThenable = exports.isSymbol = exports.isString = exports.isPropertyKey = exports.isPosInt = exports.isPair = exports.isObject = exports.isNumber = exports.isNullish = exports.isNotNullish = exports.isNatOrInfinity = exports.isNat = exports.isIntOrInfinity = exports.isInt = exports.isFunction = exports.isError = exports.isBool = exports.isBigInt = exports.isArray = exports.getSymbolDescription = exports.getNiceValueName = exports.getNiceTypeOf = exports.getNiceClassName = exports.getFunctionName = void 0;
3
+ exports.isPrototypeObject = exports.isInstanceOf = exports.getPrototypeChain = exports.isNextable = exports.isIterable = exports.isDoddle = exports.isAsyncIterable = exports.isArrayLike = exports.isAnyIterable = exports.isThenable = exports.isSymbol = exports.isString = exports.isPropertyKey = exports.isPosInt = exports.isPair = exports.isObject = exports.isNumber = exports.isNullish = exports.isNotNullish = exports.isNatOrInfinity = exports.isNat = exports.isIntOrInfinity = exports.isInt = exports.isFunction = exports.isError = exports.isBool = exports.isBigInt = exports.isArray = exports.getSymbolDescription = exports.getNiceValueName = exports.getNiceTypeOf = exports.getNiceClassName = exports.getFunctionName = exports.createNamedFunction = void 0;
4
+ var function_js_1 = require("./function.js");
5
+ Object.defineProperty(exports, "createNamedFunction", { enumerable: true, get: function () { return function_js_1.createNamedFunction; } });
4
6
  var get_text_js_1 = require("./get-text.js");
5
7
  Object.defineProperty(exports, "getFunctionName", { enumerable: true, get: function () { return get_text_js_1.getFunctionName; } });
6
8
  Object.defineProperty(exports, "getNiceClassName", { enumerable: true, get: function () { return get_text_js_1.getNiceClassName; } });
@@ -34,4 +36,8 @@ Object.defineProperty(exports, "isAsyncIterable", { enumerable: true, get: funct
34
36
  Object.defineProperty(exports, "isDoddle", { enumerable: true, get: function () { return is_special_js_1.isDoddle; } });
35
37
  Object.defineProperty(exports, "isIterable", { enumerable: true, get: function () { return is_special_js_1.isIterable; } });
36
38
  Object.defineProperty(exports, "isNextable", { enumerable: true, get: function () { return is_special_js_1.isNextable; } });
39
+ var prototypes_js_1 = require("./prototypes.js");
40
+ Object.defineProperty(exports, "getPrototypeChain", { enumerable: true, get: function () { return prototypes_js_1.getPrototypeChain; } });
41
+ Object.defineProperty(exports, "isInstanceOf", { enumerable: true, get: function () { return prototypes_js_1.isInstanceOf; } });
42
+ Object.defineProperty(exports, "isPrototypeObject", { enumerable: true, get: function () { return prototypes_js_1.isPrototypeObject; } });
37
43
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,6CAMsB;AALlB,8GAAA,eAAe,OAAA;AACf,+GAAA,gBAAgB,OAAA;AAChB,4GAAA,aAAa,OAAA;AACb,+GAAA,gBAAgB,OAAA;AAChB,mHAAA,oBAAoB,OAAA;AAExB,6CAoBsB;AAnBlB,sGAAA,OAAO,OAAA;AACP,uGAAA,QAAQ,OAAA;AACR,qGAAA,MAAM,OAAA;AACN,sGAAA,OAAO,OAAA;AACP,yGAAA,UAAU,OAAA;AACV,oGAAA,KAAK,OAAA;AACL,8GAAA,eAAe,OAAA;AACf,oGAAA,KAAK,OAAA;AACL,8GAAA,eAAe,OAAA;AACf,2GAAA,YAAY,OAAA;AACZ,wGAAA,SAAS,OAAA;AACT,uGAAA,QAAQ,OAAA;AACR,uGAAA,QAAQ,OAAA;AACR,qGAAA,MAAM,OAAA;AACN,uGAAA,QAAQ,OAAA;AACR,4GAAA,aAAa,OAAA;AACb,uGAAA,QAAQ,OAAA;AACR,uGAAA,QAAQ,OAAA;AACR,yGAAA,UAAU,OAAA;AAEd,iDAOwB;AANpB,8GAAA,aAAa,OAAA;AACb,4GAAA,WAAW,OAAA;AACX,gHAAA,eAAe,OAAA;AACf,yGAAA,QAAQ,OAAA;AACR,2GAAA,UAAU,OAAA;AACV,2GAAA,UAAU,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,6CAAmD;AAA1C,kHAAA,mBAAmB,OAAA;AAC5B,6CAMsB;AALlB,8GAAA,eAAe,OAAA;AACf,+GAAA,gBAAgB,OAAA;AAChB,4GAAA,aAAa,OAAA;AACb,+GAAA,gBAAgB,OAAA;AAChB,mHAAA,oBAAoB,OAAA;AAExB,6CAoBsB;AAnBlB,sGAAA,OAAO,OAAA;AACP,uGAAA,QAAQ,OAAA;AACR,qGAAA,MAAM,OAAA;AACN,sGAAA,OAAO,OAAA;AACP,yGAAA,UAAU,OAAA;AACV,oGAAA,KAAK,OAAA;AACL,8GAAA,eAAe,OAAA;AACf,oGAAA,KAAK,OAAA;AACL,8GAAA,eAAe,OAAA;AACf,2GAAA,YAAY,OAAA;AACZ,wGAAA,SAAS,OAAA;AACT,uGAAA,QAAQ,OAAA;AACR,uGAAA,QAAQ,OAAA;AACR,qGAAA,MAAM,OAAA;AACN,uGAAA,QAAQ,OAAA;AACR,4GAAA,aAAa,OAAA;AACb,uGAAA,QAAQ,OAAA;AACR,uGAAA,QAAQ,OAAA;AACR,yGAAA,UAAU,OAAA;AAEd,iDAOwB;AANpB,8GAAA,aAAa,OAAA;AACb,4GAAA,WAAW,OAAA;AACX,gHAAA,eAAe,OAAA;AACf,yGAAA,QAAQ,OAAA;AACR,2GAAA,UAAU,OAAA;AACV,2GAAA,UAAU,OAAA;AAEd,iDAAoF;AAA3E,kHAAA,iBAAiB,OAAA;AAAE,6GAAA,YAAY,OAAA;AAAE,kHAAA,iBAAiB,OAAA"}
@@ -0,0 +1,6 @@
1
+ import { AnyCtor } from "./ctor-type.js";
2
+ export declare const isInstanceOf: <Parent extends object>(instance: object, what: AnyCtor<Parent>) => instance is Parent;
3
+ /** Return true when `obj` looks like the prototype object of some constructor. */
4
+ export declare function isPrototypeObject(obj: object): boolean;
5
+ export declare function getPrototypeChain<T>(obj: T, depth?: number): T[];
6
+ //# sourceMappingURL=prototypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prototypes.d.ts","sourceRoot":"","sources":["../../src/prototypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAYxC,eAAO,MAAM,YAAY,GAAI,MAAM,SAAS,MAAM,EAC9C,UAAU,MAAM,EAChB,MAAM,OAAO,CAAC,MAAM,CAAC,KACtB,QAAQ,IAAI,MAEd,CAAA;AAED,kFAAkF;AAClF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAYtD;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,GAAE,MAAc,GAAG,CAAC,EAAE,CAcvE"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isInstanceOf = void 0;
4
+ exports.isPrototypeObject = isPrototypeObject;
5
+ exports.getPrototypeChain = getPrototypeChain;
6
+ const is_basic_js_1 = require("./is-basic.js");
7
+ const sCtor = "constructor";
8
+ const sPrototype = "prototype";
9
+ function getCtor(obj) {
10
+ return obj[sCtor];
11
+ }
12
+ function getCtorProto(obj) {
13
+ return obj[sPrototype];
14
+ }
15
+ const isInstanceOf = (instance, what) => {
16
+ return instance instanceof what;
17
+ };
18
+ exports.isInstanceOf = isInstanceOf;
19
+ /** Return true when `obj` looks like the prototype object of some constructor. */
20
+ function isPrototypeObject(obj) {
21
+ if (!(0, is_basic_js_1.isObject)(obj)) {
22
+ return false;
23
+ }
24
+ if (!Object.hasOwn(obj, sCtor)) {
25
+ return false;
26
+ }
27
+ const ctor = getCtor(obj);
28
+ const ctorPtoto = getCtorProto(ctor);
29
+ return (0, is_basic_js_1.isFunction)(ctor) && ctorPtoto === obj && (0, exports.isInstanceOf)(obj, ctor);
30
+ }
31
+ function getPrototypeChain(obj, depth = 10000) {
32
+ const chain = [];
33
+ let current = obj;
34
+ while (current) {
35
+ if (depth <= 0) {
36
+ break;
37
+ }
38
+ depth--;
39
+ chain.push(current);
40
+ current = Object.getPrototypeOf(current);
41
+ }
42
+ return chain;
43
+ }
44
+ //# sourceMappingURL=prototypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prototypes.js","sourceRoot":"","sources":["../../src/prototypes.ts"],"names":[],"mappings":";;;AAoBA,8CAYC;AAED,8CAcC;AA/CD,+CAAoD;AAEpD,MAAM,KAAK,GAAG,aAAa,CAAA;AAC3B,MAAM,UAAU,GAAG,WAAW,CAAA;AAE9B,SAAS,OAAO,CAAmB,GAAM;IACrC,OAAO,GAAG,CAAC,KAAK,CAAe,CAAA;AACnC,CAAC;AACD,SAAS,YAAY,CAAqB,GAAM;IAC5C,OAAO,GAAG,CAAC,UAAU,CAAM,CAAA;AAC/B,CAAC;AACM,MAAM,YAAY,GAAG,CACxB,QAAgB,EAChB,IAAqB,EACH,EAAE;IACpB,OAAO,QAAQ,YAAY,IAAI,CAAA;AACnC,CAAC,CAAA;AALY,QAAA,YAAY,gBAKxB;AAED,kFAAkF;AAClF,SAAgB,iBAAiB,CAAC,GAAW;IACzC,IAAI,CAAC,IAAA,sBAAQ,EAAC,GAAG,CAAC,EAAE,CAAC;QACjB,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;IACzB,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC,CAAA;IACpC,OAAO,IAAA,wBAAU,EAAC,IAAI,CAAC,IAAI,SAAS,KAAK,GAAG,IAAI,IAAA,oBAAY,EAAC,GAAG,EAAE,IAAI,CAAC,CAAA;AAC3E,CAAC;AAED,SAAgB,iBAAiB,CAAI,GAAM,EAAE,QAAgB,KAAK;IAC9D,MAAM,KAAK,GAAQ,EAAE,CAAA;IACrB,IAAI,OAAO,GAAa,GAAG,CAAA;IAE3B,OAAO,OAAO,EAAE,CAAC;QACb,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;YACb,MAAK;QACT,CAAC;QACD,KAAK,EAAE,CAAA;QACP,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACnB,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;IAC5C,CAAC;IAED,OAAO,KAAK,CAAA;AAChB,CAAC"}
@@ -0,0 +1,17 @@
1
+ type _ProtectedCtor<T extends object> = typeof _ProtectedCtorClass & {
2
+ prototype: T;
3
+ };
4
+ type _PrivateCtor<T extends object> = typeof _PrivateCtorClass & {
5
+ prototype: T;
6
+ };
7
+ type _PublicCtor<T extends object> = abstract new (...args: any[]) => T;
8
+ export type AnyCtor<T extends object> = _ProtectedCtor<T> | _PublicCtor<T> | _PrivateCtor<T>;
9
+ export type InstanceTypeOf<T extends AnyCtor<any>> = T extends _PrivateCtor<infer U> ? U : T extends _ProtectedCtor<infer U> ? U : T extends _PublicCtor<infer U> ? U : never;
10
+ declare abstract class _ProtectedCtorClass {
11
+ protected constructor(...args: any[]);
12
+ }
13
+ declare abstract class _PrivateCtorClass {
14
+ private constructor();
15
+ }
16
+ export {};
17
+ //# sourceMappingURL=ctor-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ctor-type.d.ts","sourceRoot":"","sources":["../../src/ctor-type.ts"],"names":[],"mappings":"AAAA,KAAK,cAAc,CAAC,CAAC,SAAS,MAAM,IAAI,OAAO,mBAAmB,GAAG;IACjE,SAAS,EAAE,CAAC,CAAA;CACf,CAAA;AACD,KAAK,YAAY,CAAC,CAAC,SAAS,MAAM,IAAI,OAAO,iBAAiB,GAAG;IAC7D,SAAS,EAAE,CAAC,CAAA;CACf,CAAA;AACD,KAAK,WAAW,CAAC,CAAC,SAAS,MAAM,IAAI,QAAQ,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;AACvE,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,MAAM,IAAI,cAAc,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAA;AAE5F,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC,IAC7C,CAAC,SAAS,YAAY,CAAC,MAAM,CAAC,CAAC,GACzB,CAAC,GACD,CAAC,SAAS,cAAc,CAAC,MAAM,CAAC,CAAC,GAC/B,CAAC,GACD,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,CAAC,GAC5B,CAAC,GACD,KAAK,CAAA;AACnB,OAAO,CAAC,QAAQ,OAAO,mBAAmB;IACtC,SAAS,aAAa,GAAG,IAAI,EAAE,GAAG,EAAE;CACvC;AAED,OAAO,CAAC,QAAQ,OAAO,iBAAiB;IACpC,OAAO;CACV"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ctor-type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ctor-type.js","sourceRoot":"","sources":["../../src/ctor-type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export declare function createNamedFunction<T extends (...args: any[]) => any>(name: string, func: T): T;
2
+ //# sourceMappingURL=function.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../src/function.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,KAO3F"}
@@ -0,0 +1,9 @@
1
+ export function createNamedFunction(name, func) {
2
+ const f = {
3
+ [name](...args) {
4
+ return func.call(null, ...args);
5
+ }
6
+ }[name];
7
+ return f;
8
+ }
9
+ //# sourceMappingURL=function.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function.js","sourceRoot":"","sources":["../../src/function.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,mBAAmB,CAAoC,IAAY,EAAE,IAAO;IACxF,MAAM,CAAC,GAAG;QACN,CAAC,IAAI,CAAC,CAAC,GAAG,IAAmB;YACzB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAA;QACnC,CAAC;KACJ,CAAC,IAAI,CAAM,CAAA;IACZ,OAAO,CAAC,CAAA;AACZ,CAAC"}
@@ -1,4 +1,7 @@
1
+ export type { AnyCtor, InstanceTypeOf } from "./ctor-type.js";
2
+ export { createNamedFunction } from "./function.js";
1
3
  export { getFunctionName, getNiceClassName, getNiceTypeOf, getNiceValueName, getSymbolDescription } from "./get-text.js";
2
4
  export { isArray, isBigInt, isBool, isError, isFunction, isInt, isIntOrInfinity, isNat, isNatOrInfinity, isNotNullish, isNullish, isNumber, isObject, isPair, isPosInt, isPropertyKey, isString, isSymbol, isThenable } from "./is-basic.js";
3
5
  export { isAnyIterable, isArrayLike, isAsyncIterable, isDoddle, isIterable, isNextable } from "./is-special.js";
6
+ export { getPrototypeChain, isInstanceOf, isPrototypeObject } from "./prototypes.js";
4
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,oBAAoB,EACvB,MAAM,eAAe,CAAA;AACtB,OAAO,EACH,OAAO,EACP,QAAQ,EACR,MAAM,EACN,OAAO,EACP,UAAU,EACV,KAAK,EACL,eAAe,EACf,KAAK,EACL,eAAe,EACf,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,UAAU,EACb,MAAM,eAAe,CAAA;AACtB,OAAO,EACH,aAAa,EACb,WAAW,EACX,eAAe,EACf,QAAQ,EACR,UAAU,EACV,UAAU,EACb,MAAM,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EACH,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,oBAAoB,EACvB,MAAM,eAAe,CAAA;AACtB,OAAO,EACH,OAAO,EACP,QAAQ,EACR,MAAM,EACN,OAAO,EACP,UAAU,EACV,KAAK,EACL,eAAe,EACf,KAAK,EACL,eAAe,EACf,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,UAAU,EACb,MAAM,eAAe,CAAA;AACtB,OAAO,EACH,aAAa,EACb,WAAW,EACX,eAAe,EACf,QAAQ,EACR,UAAU,EACV,UAAU,EACb,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA"}
package/dist/esm/index.js CHANGED
@@ -1,4 +1,6 @@
1
+ export { createNamedFunction } from "./function.js";
1
2
  export { getFunctionName, getNiceClassName, getNiceTypeOf, getNiceValueName, getSymbolDescription } from "./get-text.js";
2
3
  export { isArray, isBigInt, isBool, isError, isFunction, isInt, isIntOrInfinity, isNat, isNatOrInfinity, isNotNullish, isNullish, isNumber, isObject, isPair, isPosInt, isPropertyKey, isString, isSymbol, isThenable } from "./is-basic.js";
3
4
  export { isAnyIterable, isArrayLike, isAsyncIterable, isDoddle, isIterable, isNextable } from "./is-special.js";
5
+ export { getPrototypeChain, isInstanceOf, isPrototypeObject } from "./prototypes.js";
4
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,oBAAoB,EACvB,MAAM,eAAe,CAAA;AACtB,OAAO,EACH,OAAO,EACP,QAAQ,EACR,MAAM,EACN,OAAO,EACP,UAAU,EACV,KAAK,EACL,eAAe,EACf,KAAK,EACL,eAAe,EACf,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,UAAU,EACb,MAAM,eAAe,CAAA;AACtB,OAAO,EACH,aAAa,EACb,WAAW,EACX,eAAe,EACf,QAAQ,EACR,UAAU,EACV,UAAU,EACb,MAAM,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,EACH,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,oBAAoB,EACvB,MAAM,eAAe,CAAA;AACtB,OAAO,EACH,OAAO,EACP,QAAQ,EACR,MAAM,EACN,OAAO,EACP,UAAU,EACV,KAAK,EACL,eAAe,EACf,KAAK,EACL,eAAe,EACf,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,UAAU,EACb,MAAM,eAAe,CAAA;AACtB,OAAO,EACH,aAAa,EACb,WAAW,EACX,eAAe,EACf,QAAQ,EACR,UAAU,EACV,UAAU,EACb,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { AnyCtor } from "./ctor-type.js";
2
+ export declare const isInstanceOf: <Parent extends object>(instance: object, what: AnyCtor<Parent>) => instance is Parent;
3
+ /** Return true when `obj` looks like the prototype object of some constructor. */
4
+ export declare function isPrototypeObject(obj: object): boolean;
5
+ export declare function getPrototypeChain<T>(obj: T, depth?: number): T[];
6
+ //# sourceMappingURL=prototypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prototypes.d.ts","sourceRoot":"","sources":["../../src/prototypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAYxC,eAAO,MAAM,YAAY,GAAI,MAAM,SAAS,MAAM,EAC9C,UAAU,MAAM,EAChB,MAAM,OAAO,CAAC,MAAM,CAAC,KACtB,QAAQ,IAAI,MAEd,CAAA;AAED,kFAAkF;AAClF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAYtD;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,GAAE,MAAc,GAAG,CAAC,EAAE,CAcvE"}
@@ -0,0 +1,38 @@
1
+ import { isFunction, isObject } from "./is-basic.js";
2
+ const sCtor = "constructor";
3
+ const sPrototype = "prototype";
4
+ function getCtor(obj) {
5
+ return obj[sCtor];
6
+ }
7
+ function getCtorProto(obj) {
8
+ return obj[sPrototype];
9
+ }
10
+ export const isInstanceOf = (instance, what) => {
11
+ return instance instanceof what;
12
+ };
13
+ /** Return true when `obj` looks like the prototype object of some constructor. */
14
+ export function isPrototypeObject(obj) {
15
+ if (!isObject(obj)) {
16
+ return false;
17
+ }
18
+ if (!Object.hasOwn(obj, sCtor)) {
19
+ return false;
20
+ }
21
+ const ctor = getCtor(obj);
22
+ const ctorPtoto = getCtorProto(ctor);
23
+ return isFunction(ctor) && ctorPtoto === obj && isInstanceOf(obj, ctor);
24
+ }
25
+ export function getPrototypeChain(obj, depth = 10000) {
26
+ const chain = [];
27
+ let current = obj;
28
+ while (current) {
29
+ if (depth <= 0) {
30
+ break;
31
+ }
32
+ depth--;
33
+ chain.push(current);
34
+ current = Object.getPrototypeOf(current);
35
+ }
36
+ return chain;
37
+ }
38
+ //# sourceMappingURL=prototypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prototypes.js","sourceRoot":"","sources":["../../src/prototypes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAEpD,MAAM,KAAK,GAAG,aAAa,CAAA;AAC3B,MAAM,UAAU,GAAG,WAAW,CAAA;AAE9B,SAAS,OAAO,CAAmB,GAAM;IACrC,OAAO,GAAG,CAAC,KAAK,CAAe,CAAA;AACnC,CAAC;AACD,SAAS,YAAY,CAAqB,GAAM;IAC5C,OAAO,GAAG,CAAC,UAAU,CAAM,CAAA;AAC/B,CAAC;AACD,MAAM,CAAC,MAAM,YAAY,GAAG,CACxB,QAAgB,EAChB,IAAqB,EACH,EAAE;IACpB,OAAO,QAAQ,YAAY,IAAI,CAAA;AACnC,CAAC,CAAA;AAED,kFAAkF;AAClF,MAAM,UAAU,iBAAiB,CAAC,GAAW;IACzC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACjB,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;IACzB,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC,CAAA;IACpC,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,SAAS,KAAK,GAAG,IAAI,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;AAC3E,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAI,GAAM,EAAE,QAAgB,KAAK;IAC9D,MAAM,KAAK,GAAQ,EAAE,CAAA;IACrB,IAAI,OAAO,GAAa,GAAG,CAAA;IAE3B,OAAO,OAAO,EAAE,CAAC;QACb,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;YACb,MAAK;QACT,CAAC;QACD,KAAK,EAAE,CAAA;QACP,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACnB,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;IAC5C,CAAC;IAED,OAAO,KAAK,CAAA;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "what-are-you",
3
- "version": "0.1.8",
3
+ "version": "0.1.11",
4
4
  "description": "Assortment of type-related checks and information.",
5
5
  "keywords": [
6
6
  "type",
@@ -63,7 +63,6 @@
63
63
  "devDependencies": {
64
64
  "@gregros/eslint-config": "^0.7.1",
65
65
  "@types/jest": "^29.5.14",
66
- "@types/lodash": "^4.17.16",
67
66
  "@types/node": "^22.15.2",
68
67
  "@types/shelljs": "^0",
69
68
  "@typescript-eslint/eslint-plugin": "^8.31.0",
@@ -72,7 +71,6 @@
72
71
  "husky": "^9.1.7",
73
72
  "jest": "^29.7.0",
74
73
  "lint-staged": "^15.5.1",
75
- "lodash": "^4.17.21",
76
74
  "npm-run-all": "^4.1.5",
77
75
  "prettier": "^3.5.3",
78
76
  "prettier-plugin-jsdoc": "^1.3.2",
@@ -0,0 +1,24 @@
1
+ type _ProtectedCtor<T extends object> = typeof _ProtectedCtorClass & {
2
+ prototype: T
3
+ }
4
+ type _PrivateCtor<T extends object> = typeof _PrivateCtorClass & {
5
+ prototype: T
6
+ }
7
+ type _PublicCtor<T extends object> = abstract new (...args: any[]) => T
8
+ export type AnyCtor<T extends object> = _ProtectedCtor<T> | _PublicCtor<T> | _PrivateCtor<T>
9
+
10
+ export type InstanceTypeOf<T extends AnyCtor<any>> =
11
+ T extends _PrivateCtor<infer U>
12
+ ? U
13
+ : T extends _ProtectedCtor<infer U>
14
+ ? U
15
+ : T extends _PublicCtor<infer U>
16
+ ? U
17
+ : never
18
+ declare abstract class _ProtectedCtorClass {
19
+ protected constructor(...args: any[])
20
+ }
21
+
22
+ declare abstract class _PrivateCtorClass {
23
+ private constructor(...args: any[])
24
+ }
@@ -0,0 +1,8 @@
1
+ export function createNamedFunction<T extends (...args: any[]) => any>(name: string, func: T) {
2
+ const f = {
3
+ [name](...args: Parameters<T>) {
4
+ return func.call(null, ...args)
5
+ }
6
+ }[name] as T
7
+ return f
8
+ }
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export type { AnyCtor, InstanceTypeOf } from "./ctor-type.js"
2
+ export { createNamedFunction } from "./function.js"
1
3
  export {
2
4
  getFunctionName,
3
5
  getNiceClassName,
@@ -34,3 +36,4 @@ export {
34
36
  isIterable,
35
37
  isNextable
36
38
  } from "./is-special.js"
39
+ export { getPrototypeChain, isInstanceOf, isPrototypeObject } from "./prototypes.js"
@@ -0,0 +1,49 @@
1
+ import { AnyCtor } from "./ctor-type.js"
2
+ import { isFunction, isObject } from "./is-basic.js"
3
+
4
+ const sCtor = "constructor"
5
+ const sPrototype = "prototype"
6
+
7
+ function getCtor<T extends object>(obj: T): AnyCtor<T> {
8
+ return obj[sCtor] as AnyCtor<T>
9
+ }
10
+ function getCtorProto<T extends Function>(obj: T): T {
11
+ return obj[sPrototype] as T
12
+ }
13
+ export const isInstanceOf = <Parent extends object>(
14
+ instance: object,
15
+ what: AnyCtor<Parent>
16
+ ): instance is Parent => {
17
+ return instance instanceof what
18
+ }
19
+
20
+ /** Return true when `obj` looks like the prototype object of some constructor. */
21
+ export function isPrototypeObject(obj: object): boolean {
22
+ if (!isObject(obj)) {
23
+ return false
24
+ }
25
+
26
+ if (!Object.hasOwn(obj, sCtor)) {
27
+ return false
28
+ }
29
+
30
+ const ctor = getCtor(obj)
31
+ const ctorPtoto = getCtorProto(ctor)
32
+ return isFunction(ctor) && ctorPtoto === obj && isInstanceOf(obj, ctor)
33
+ }
34
+
35
+ export function getPrototypeChain<T>(obj: T, depth: number = 10000): T[] {
36
+ const chain: T[] = []
37
+ let current: T | null = obj
38
+
39
+ while (current) {
40
+ if (depth <= 0) {
41
+ break
42
+ }
43
+ depth--
44
+ chain.push(current)
45
+ current = Object.getPrototypeOf(current)
46
+ }
47
+
48
+ return chain
49
+ }