@x-oasis/is-class 0.1.38

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 ADDED
@@ -0,0 +1,19 @@
1
+ # @x-oasis/is-class
2
+
3
+ ## Installation
4
+
5
+ ```bash
6
+ $ npm i @x-oasis/is-class
7
+ ```
8
+
9
+ ## How to use
10
+
11
+ ```typescript
12
+ import isClass from '@x-oasis/is-class'
13
+ ```
14
+
15
+ ## How to run test
16
+
17
+ ```bash
18
+ $ pnpm test
19
+ ```
@@ -0,0 +1,2 @@
1
+ export declare type Ctor<T = object> = new (...args: any[]) => T;
2
+ export declare function isClass(thing: any): thing is Ctor;
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict'
3
+
4
+ if (process.env.NODE_ENV === 'production') {
5
+ module.exports = require('./is-class.cjs.production.min.js')
6
+ } else {
7
+ module.exports = require('./is-class.cjs.development.js')
8
+ }
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function isClass(thing) {
6
+ var isCtorClass = thing.constructor && thing.constructor.toString().substring(0, 5) === 'class';
7
+ if (thing.prototype === undefined) return isCtorClass;
8
+ var isPrototypeCtorClass = thing.prototype.constructor && thing.prototype.constructor.toString && thing.prototype.constructor.toString().substring(0, 5) === 'class';
9
+ return isCtorClass || isPrototypeCtorClass;
10
+ }
11
+
12
+ exports.isClass = isClass;
13
+ //# sourceMappingURL=is-class.cjs.development.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-class.cjs.development.js","sources":["../src/index.ts"],"sourcesContent":["export type Ctor<T = object> = new (...args: any[]) => T;\n\n// https://stackoverflow.com/a/43197340\nexport function isClass(thing: any): thing is Ctor {\n const isCtorClass =\n thing.constructor &&\n thing.constructor.toString().substring(0, 5) === 'class';\n if (thing.prototype === undefined) return isCtorClass;\n const isPrototypeCtorClass =\n thing.prototype.constructor &&\n thing.prototype.constructor.toString &&\n thing.prototype.constructor.toString().substring(0, 5) === 'class';\n return isCtorClass || isPrototypeCtorClass;\n}\n"],"names":["isClass","thing","isCtorClass","constructor","toString","substring","prototype","undefined","isPrototypeCtorClass"],"mappings":";;;;SAGgBA,OAAOA,CAACC,KAAU;EAChC,IAAMC,WAAW,GACfD,KAAK,CAACE,WAAW,IACjBF,KAAK,CAACE,WAAW,CAACC,QAAQ,EAAE,CAACC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,OAAO;EAC1D,IAAIJ,KAAK,CAACK,SAAS,KAAKC,SAAS,EAAE,OAAOL,WAAW;EACrD,IAAMM,oBAAoB,GACxBP,KAAK,CAACK,SAAS,CAACH,WAAW,IAC3BF,KAAK,CAACK,SAAS,CAACH,WAAW,CAACC,QAAQ,IACpCH,KAAK,CAACK,SAAS,CAACH,WAAW,CAACC,QAAQ,EAAE,CAACC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,OAAO;EACpE,OAAOH,WAAW,IAAIM,oBAAoB;AAC5C;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isClass=function(t){var r=t.constructor&&"class"===t.constructor.toString().substring(0,5);if(void 0===t.prototype)return r;var o=t.prototype.constructor&&t.prototype.constructor.toString&&"class"===t.prototype.constructor.toString().substring(0,5);return r||o};
2
+ //# sourceMappingURL=is-class.cjs.production.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-class.cjs.production.min.js","sources":["../src/index.ts"],"sourcesContent":["export type Ctor<T = object> = new (...args: any[]) => T;\n\n// https://stackoverflow.com/a/43197340\nexport function isClass(thing: any): thing is Ctor {\n const isCtorClass =\n thing.constructor &&\n thing.constructor.toString().substring(0, 5) === 'class';\n if (thing.prototype === undefined) return isCtorClass;\n const isPrototypeCtorClass =\n thing.prototype.constructor &&\n thing.prototype.constructor.toString &&\n thing.prototype.constructor.toString().substring(0, 5) === 'class';\n return isCtorClass || isPrototypeCtorClass;\n}\n"],"names":["thing","isCtorClass","constructor","toString","substring","undefined","prototype","isPrototypeCtorClass"],"mappings":"6FAGwBA,GACtB,IAAMC,EACJD,EAAME,aAC2C,UAAjDF,EAAME,YAAYC,WAAWC,UAAU,EAAG,GAC5C,QAAwBC,IAApBL,EAAMM,UAAyB,OAAOL,EAC1C,IAAMM,EACJP,EAAMM,UAAUJ,aAChBF,EAAMM,UAAUJ,YAAYC,UAC+B,UAA3DH,EAAMM,UAAUJ,YAAYC,WAAWC,UAAU,EAAG,GACtD,OAAOH,GAAeM"}
@@ -0,0 +1,9 @@
1
+ function isClass(thing) {
2
+ var isCtorClass = thing.constructor && thing.constructor.toString().substring(0, 5) === 'class';
3
+ if (thing.prototype === undefined) return isCtorClass;
4
+ var isPrototypeCtorClass = thing.prototype.constructor && thing.prototype.constructor.toString && thing.prototype.constructor.toString().substring(0, 5) === 'class';
5
+ return isCtorClass || isPrototypeCtorClass;
6
+ }
7
+
8
+ export { isClass };
9
+ //# sourceMappingURL=is-class.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-class.esm.js","sources":["../src/index.ts"],"sourcesContent":["export type Ctor<T = object> = new (...args: any[]) => T;\n\n// https://stackoverflow.com/a/43197340\nexport function isClass(thing: any): thing is Ctor {\n const isCtorClass =\n thing.constructor &&\n thing.constructor.toString().substring(0, 5) === 'class';\n if (thing.prototype === undefined) return isCtorClass;\n const isPrototypeCtorClass =\n thing.prototype.constructor &&\n thing.prototype.constructor.toString &&\n thing.prototype.constructor.toString().substring(0, 5) === 'class';\n return isCtorClass || isPrototypeCtorClass;\n}\n"],"names":["isClass","thing","isCtorClass","constructor","toString","substring","prototype","undefined","isPrototypeCtorClass"],"mappings":"SAGgBA,OAAOA,CAACC,KAAU;EAChC,IAAMC,WAAW,GACfD,KAAK,CAACE,WAAW,IACjBF,KAAK,CAACE,WAAW,CAACC,QAAQ,EAAE,CAACC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,OAAO;EAC1D,IAAIJ,KAAK,CAACK,SAAS,KAAKC,SAAS,EAAE,OAAOL,WAAW;EACrD,IAAMM,oBAAoB,GACxBP,KAAK,CAACK,SAAS,CAACH,WAAW,IAC3BF,KAAK,CAACK,SAAS,CAACH,WAAW,CAACC,QAAQ,IACpCH,KAAK,CAACK,SAAS,CAACH,WAAW,CAACC,QAAQ,EAAE,CAACC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,OAAO;EACpE,OAAOH,WAAW,IAAIM,oBAAoB;AAC5C;;;;"}
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@x-oasis/is-class",
3
+ "version": "0.1.38",
4
+ "description": "is-class function",
5
+ "main": "dist/index.js",
6
+ "typings": "dist/index.d.ts",
7
+ "module": "dist/is-class.esm.js",
8
+ "files": [
9
+ "dist",
10
+ "index.ts",
11
+ "src"
12
+ ],
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "author": "",
17
+ "license": "ISC",
18
+ "devDependencies": {
19
+ "tsdx": "^0.14.1"
20
+ },
21
+ "scripts": {
22
+ "build": "tsdx build --tsconfig tsconfig.build.json",
23
+ "clean": "rimraf ./dist",
24
+ "test": "vitest",
25
+ "compile": "tsc -p tsconfig.build.json"
26
+ }
27
+ }
package/src/index.ts ADDED
@@ -0,0 +1,14 @@
1
+ export type Ctor<T = object> = new (...args: any[]) => T;
2
+
3
+ // https://stackoverflow.com/a/43197340
4
+ export function isClass(thing: any): thing is Ctor {
5
+ const isCtorClass =
6
+ thing.constructor &&
7
+ thing.constructor.toString().substring(0, 5) === 'class';
8
+ if (thing.prototype === undefined) return isCtorClass;
9
+ const isPrototypeCtorClass =
10
+ thing.prototype.constructor &&
11
+ thing.prototype.constructor.toString &&
12
+ thing.prototype.constructor.toString().substring(0, 5) === 'class';
13
+ return isCtorClass || isPrototypeCtorClass;
14
+ }