typescript-dotnet-core
Version:
A the core classes and utilities of a JavaScript-Friendly .NET Based TypeScript Library.
7 lines (6 loc) • 3.43 kB
JavaScript
"use strict";
/*!
* @author electricessence / https://github.com/electricessence/
* Licensing: MIT https://github.com/electricessence/TypeScript.NET-Core/blob/master/LICENSE.md
*/Object.defineProperty(exports,"__esModule",{value:!0});var VOID0=void 0,_BOOLEAN=typeof!0,_NUMBER="number",_STRING="string",_SYMBOL="symbol",_OBJECT=typeof{},_UNDEFINED=typeof VOID0,_FUNCTION="function",LENGTH="length",typeInfoRegistry={},TypeInfo=function(){function n(i,t){switch(this.isBoolean=!1,this.isNumber=!1,this.isFinite=!1,this.isValidNumber=!1,this.isString=!1,this.isTrueNaN=!1,this.isObject=!1,this.isFunction=!1,this.isUndefined=!1,this.isNull=!1,this.isPrimitive=!1,this.isSymbol=!1,this.isArray=!1,this.isNullOrUndefined=!1,this.type=typeof i){case _BOOLEAN:this.isBoolean=!0,this.isPrimitive=!0;break;case _NUMBER:this.isNumber=!0,this.isTrueNaN=isNaN(i),this.isFinite=isFinite(i),this.isValidNumber=!this.isTrueNaN,this.isPrimitive=!0;break;case _STRING:this.isString=!0,this.isPrimitive=!0;break;case _SYMBOL:this.isSymbol=!0;break;case _OBJECT:null===(this.target=i)?(this.isNull=!0,this.isNullOrUndefined=!0,this.isPrimitive=!0):(this.isArray=i instanceof Array,this.isObject=!0);break;case _FUNCTION:this.target=i,this.isFunction=!0;break;case _UNDEFINED:this.isUndefined=!0,this.isNullOrUndefined=!0,this.isPrimitive=!0;break;default:throw"Fatal type failure. Unknown type: "+this.type}t&&t(this),Object.freeze(this)}return n.prototype.member=function(i){var t=this.target;return n.getFor(t&&i in t?t[i]:VOID0)},n.getFor=function(i){var t=typeof i;switch(t){case _OBJECT:case _FUNCTION:return new n(i)}var e=typeInfoRegistry[t];return e||(typeInfoRegistry[t]=e=new n(i)),e},n.prototype.is=function(i){return this.target instanceof i},n.prototype.as=function(i){return this.target instanceof i?this.target:null},n}();function Type(i){return new TypeInfo(i)}exports.TypeInfo=TypeInfo,function(t){function n(i,t){switch(void 0===t&&(t=!1),typeof i){case _BOOLEAN:case _STRING:case _NUMBER:return!0;case _UNDEFINED:return t;case _OBJECT:return null===i}return!1}function s(i,t,e){return void 0===e&&(e=!0),i&&!n(i)&&t in i&&(e||i[t]!==VOID0)}function e(i,t,e){return s(i,t)&&typeof i[t]===e}t.BOOLEAN=_BOOLEAN,t.NUMBER=_NUMBER,t.STRING=_STRING,t.OBJECT=_OBJECT,t.SYMBOL=_SYMBOL,t.UNDEFINED=_UNDEFINED,t.FUNCTION=_FUNCTION,t.is=function(i,t){return i instanceof t},t.as=function(i,t){return i instanceof t?i:null},t.isNullOrUndefined=function(i){return null==i},t.isBoolean=function(i){return typeof i===_BOOLEAN},t.isNumber=function(i,t){return void 0===t&&(t=!1),!(typeof i!==_NUMBER||t&&isNaN(i))},t.isTrueNaN=function(i){return typeof i===_NUMBER&&isNaN(i)},t.isString=function(i){return typeof i===_STRING},t.isPrimitive=n,t.isPrimitiveOrSymbol=function(i,t){return void 0===t&&(t=!1),typeof i===_SYMBOL||n(i,t)},t.isPropertyKey=function(i){switch(typeof i){case _STRING:case _NUMBER:case _SYMBOL:return!0}return!1},t.isFunction=function(i){return typeof i===_FUNCTION},t.isObject=function(i,t){return void 0===t&&(t=!1),typeof i===_OBJECT&&(t||null!==i)},t.numberOrNaN=function(i){return isNaN(i)?NaN:i},t.of=function(i){return TypeInfo.getFor(i)},t.hasMember=s,t.hasMemberOfType=e,t.hasMethod=function(i,t){return e(i,t,_FUNCTION)},t.isArrayLike=function(i){return i instanceof Array||t.isString(i)||!t.isFunction(i)&&s(i,LENGTH)}}(Type=Type||{}),Object.freeze(Type),exports.default=Type;
//# sourceMappingURL=Types.js.map