UNPKG

rollun-ts-rql

Version:

RQL query object and serializer written in TypeScript

1 lines 2 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.IntegerTypeCaster=void 0;var _Token=require("../Token");function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor}var IntegerTypeCaster=function(){function IntegerTypeCaster(){_classCallCheck(this,IntegerTypeCaster)}_createClass(IntegerTypeCaster,[{key:"typeCast",value:function typeCast(token){if(token.test(_Token.TokenTypeNameMap.T_NULL)){return 0}if(token.test(_Token.TokenTypeNameMap.T_TRUE)){return 1}if(token.test(_Token.TokenTypeNameMap.T_FALSE)){return 0}if(token.test(_Token.TokenTypeNameMap.T_EMPTY)){return 0}if(token.test(_Token.TokenTypeNameMap.T_DATE)){var date=new Date(token.value);var dateMonth=String(date.getMonth()).length===2?1+date.getMonth():"0"+(1+date.getMonth());var dateDay=String(date.getDate()).length===2?date.getDate():"0"+date.getDate();var dateHours=String(date.getUTCHours()).length===2?date.getUTCHours():"0"+date.getUTCHours();var dateMinutes=String(date.getMinutes()).length===2?date.getMinutes():"0"+date.getMinutes();var dateSeconds=String(date.getSeconds()).length===2?date.getSeconds():"0"+date.getSeconds();return parseInt("".concat(date.getFullYear()).concat(dateMonth).concat(dateDay).concat(dateHours).concat(dateMinutes).concat(dateSeconds),10)}else{var parsedValue=parseInt(token.value,10);return isNaN(parsedValue)?0:parsedValue}}}]);return IntegerTypeCaster}();exports.IntegerTypeCaster=IntegerTypeCaster;