extension-props
Advanced tools
Comparing version 0.9.0 to 0.9.1
declare function forInstance(v: any): boolean; | ||
declare function defineFunction(name: string, _prototype?: Function): Function | undefined; | ||
declare function isNormalFunction(f: Function): boolean; | ||
declare function isAsyncFunction(f: Function): boolean; | ||
declare function isSyncFunction(f: Function): boolean; | ||
declare function isArrowFunction(f: Function): boolean; | ||
declare function isNonArrowFunction(f: Function): boolean; | ||
interface FunctionType { | ||
@@ -12,2 +17,7 @@ clone(): Function; | ||
defineFunction: typeof defineFunction; | ||
isNormalFunction: typeof isNormalFunction; | ||
isAsyncFunction: typeof isAsyncFunction; | ||
isSyncFunction: typeof isSyncFunction; | ||
isArrowFunction: typeof isArrowFunction; | ||
isNonArrowFunction: typeof isNonArrowFunction; | ||
valueOf: typeof valueOf; | ||
@@ -14,0 +24,0 @@ }; |
@@ -44,2 +44,51 @@ "use strict"; | ||
} | ||
function isNormalFunction(f) { | ||
return f instanceof Function && f.prototype !== undefined; | ||
} | ||
function isAsyncFunction(f) { | ||
if (f instanceof Function && f.prototype === undefined) { | ||
try { | ||
return f[Symbol.toStringTag] === 'AsyncFunction'; | ||
} | ||
catch (e) { | ||
return /^\s*async/.test(f.toString()); | ||
} | ||
} | ||
else | ||
return false; | ||
} | ||
function isSyncFunction(f) { | ||
if (f instanceof Function) { | ||
try { | ||
return f[Symbol.toStringTag] !== 'AsyncFunction'; | ||
} | ||
catch (e) { | ||
return !/^\s*async/.test(f.toString()); | ||
} | ||
} | ||
else | ||
return false; | ||
} | ||
function isArrowFunction(f) { | ||
if (f instanceof Function && f.prototype === undefined) { | ||
var fstr = f.toString(); | ||
if (/^\s*function/.test(fstr) || /^\s*async\s*function/.test(fstr)) | ||
return false; | ||
return /^[a-zA-Z0-9_]+\s*=>/.test(fstr) || /^\s*async\s*[a-zA-Z0-9_]+\s*=>/.test(fstr) || | ||
/^\([^]*\)\s*=>/.test(fstr) || /^\s*async\s*\([^]*\)\s*=>/.test(fstr); | ||
} | ||
else | ||
return false; | ||
} | ||
function isNonArrowFunction(f) { | ||
if (f instanceof Function) { | ||
var fstr = f.toString(); | ||
if (f.prototype !== undefined || /^\s*function/.test(fstr) || /^\s*async\s*function/.test(fstr)) | ||
return true; | ||
return !/^[a-zA-Z0-9_]+\s*=>/.test(fstr) && !/^\s*async\s*[a-zA-Z0-9_]+\s*=>/.test(fstr) && | ||
!/^\([^]*\)\s*=>/.test(fstr) && !/^\s*async\s*\([^]*\)\s*=>/.test(fstr); | ||
} | ||
else | ||
return false; | ||
} | ||
function valueOf(v) { | ||
@@ -57,2 +106,7 @@ if (!forInstance(v) || v.prototype === undefined) | ||
defineFunction: defineFunction, | ||
isNormalFunction: isNormalFunction, | ||
isAsyncFunction: isAsyncFunction, | ||
isSyncFunction: isSyncFunction, | ||
isArrowFunction: isArrowFunction, | ||
isNonArrowFunction: isNonArrowFunction, | ||
valueOf: valueOf | ||
@@ -62,2 +116,7 @@ }; | ||
Function.defineFunction = defineFunction; | ||
Function.isNormalFunction = isNormalFunction; | ||
Function.isAsyncFunction = isAsyncFunction; | ||
Function.isSyncFunction = isSyncFunction; | ||
Function.isArrowFunction = isArrowFunction; | ||
Function.isNonArrowFunction = isNonArrowFunction; | ||
Function.prototype.clone = clone; | ||
@@ -64,0 +123,0 @@ Function.prototype.defineFunction = dynamicDefineFunction; |
@@ -43,2 +43,46 @@ import {type as typeClass} from './ClassType'; | ||
function isNormalFunction(f: Function): boolean { | ||
return f instanceof Function && f.prototype !== undefined; | ||
} | ||
function isAsyncFunction(f: Function): boolean { | ||
if (f instanceof Function && f.prototype === undefined) { | ||
try { | ||
return f[Symbol.toStringTag] === 'AsyncFunction'; | ||
} catch (e) { | ||
return /^\s*async/.test(f.toString()); | ||
} | ||
} else return false; | ||
} | ||
function isSyncFunction(f: Function): boolean { | ||
if (f instanceof Function) { | ||
try { | ||
return f[Symbol.toStringTag] !== 'AsyncFunction'; | ||
} catch (e) { | ||
return !/^\s*async/.test(f.toString()); | ||
} | ||
} else return false; | ||
} | ||
function isArrowFunction(f: Function): boolean { | ||
if (f instanceof Function && f.prototype === undefined) { | ||
const fstr = f.toString(); | ||
if (/^\s*function/.test(fstr) || /^\s*async\s*function/.test(fstr)) | ||
return false; | ||
return /^[a-zA-Z0-9_]+\s*=>/.test(fstr) || /^\s*async\s*[a-zA-Z0-9_]+\s*=>/.test(fstr) || | ||
/^\([^]*\)\s*=>/.test(fstr) || /^\s*async\s*\([^]*\)\s*=>/.test(fstr); | ||
} else return false; | ||
} | ||
function isNonArrowFunction(f: Function): boolean { | ||
if (f instanceof Function) { | ||
const fstr = f.toString(); | ||
if (f.prototype !== undefined || /^\s*function/.test(fstr) || /^\s*async\s*function/.test(fstr)) | ||
return true; | ||
return !/^[a-zA-Z0-9_]+\s*=>/.test(fstr) && !/^\s*async\s*[a-zA-Z0-9_]+\s*=>/.test(fstr) && | ||
!/^\([^]*\)\s*=>/.test(fstr) && !/^\s*async\s*\([^]*\)\s*=>/.test(fstr); | ||
} else return false; | ||
} | ||
interface FunctionType { | ||
@@ -64,2 +108,7 @@ clone(): Function; | ||
defineFunction, | ||
isNormalFunction, | ||
isAsyncFunction, | ||
isSyncFunction, | ||
isArrowFunction, | ||
isNonArrowFunction, | ||
valueOf | ||
@@ -70,2 +119,7 @@ }; | ||
Function.defineFunction = defineFunction; | ||
Function.isNormalFunction = isNormalFunction; | ||
Function.isAsyncFunction = isAsyncFunction; | ||
Function.isSyncFunction = isSyncFunction; | ||
Function.isArrowFunction = isArrowFunction; | ||
Function.isNonArrowFunction = isNonArrowFunction; | ||
@@ -72,0 +126,0 @@ Function.prototype.clone = clone; |
@@ -48,2 +48,7 @@ interface String { | ||
getAllPropertyNames(obj: any): string[]; | ||
isNormalFunction(f: Function): boolean; | ||
isAsyncFunction(f: Function): boolean; | ||
isSyncFunction(f: Function): boolean; | ||
isArrowFunction(f: Function): boolean; | ||
isNonArrowFunction(f: Function): boolean; | ||
} | ||
@@ -50,0 +55,0 @@ |
{ | ||
"name": "extension-props", | ||
"version": "0.9.0", | ||
"version": "0.9.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44957
1292