2 Copyright (C) 2008 Alina Friedrichsen <x-alina@gmx.net>
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
7 1. Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 2. Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
13 THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 VarType.isNull = function(obj) {
30 if(typeof obj == "undefined") return true;
31 if(typeof obj == "object" && (!obj)) return true;
35 VarType.toFloat = function(value) {
36 value = Number(value);
40 VarType.toDecimal = function(value) {
41 value = Number(value);
42 if(!isFinite(value)) value = 0.0;
46 VarType.toInt = function(value) {
47 value = Number(value);
48 if(!isFinite(value)) value = 0.0;
49 value = Math.floor(value);
53 VarType.toUInt = function(value) {
54 value = Number(value);
55 if(!isFinite(value)) value = 0.0;
56 else if(value < 0.0) value = 0.0;
57 value = Math.floor(value);
61 VarType.toStr = function(value) {
62 if(VarType.isNull(value)) value = "";
63 value = String(value);
67 VarType.toBool = function(value) {
68 value = Boolean(value);
72 VarType.needObject = function(obj) {
73 if(typeof obj != "object" || (!obj)) throw new TypeError();
76 VarType.needInstanceOf = function(obj, type) {
77 if(!(obj instanceof type)) throw new TypeError();
80 VarType.needFunction = function(obj) {
81 if(typeof obj != "function") throw new TypeError();
84 VarType.needNode = function(obj, type) {
85 VarType.needObject(obj);
86 if(VarType.isNull(obj.nodeType)) throw new TypeError();
87 if(!VarType.isNull(type)) {
88 type = VarType.toInt(type);
89 if(obj.nodeType != type) throw new TypeError();
93 Copyright (C) 2008 Alina Friedrichsen <x-alina@gmx.net>
95 Redistribution and use in source and binary forms, with or without
96 modification, are permitted provided that the following conditions
98 1. Redistributions of source code must retain the above copyright
99 notice, this list of conditions and the following disclaimer.
100 2. Redistributions in binary form must reproduce the above copyright
101 notice, this list of conditions and the following disclaimer in the
102 documentation and/or other materials provided with the distribution.
104 THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
105 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
106 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
107 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
108 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
109 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
110 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
111 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
112 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
113 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
120 VarType.isNull = function(obj) {
121 if(typeof obj == "undefined") return true;
122 if(typeof obj == "object" && (!obj)) return true;
126 VarType.toFloat = function(value) {
127 value = Number(value);
131 VarType.toDecimal = function(value) {
132 value = Number(value);
133 if(!isFinite(value)) value = 0.0;
137 VarType.toInt = function(value) {
138 value = Number(value);
139 if(!isFinite(value)) value = 0.0;
140 value = Math.floor(value);
144 VarType.toUInt = function(value) {
145 value = Number(value);
146 if(!isFinite(value)) value = 0.0;
147 else if(value < 0.0) value = 0.0;
148 value = Math.floor(value);
152 VarType.toStr = function(value) {
153 if(VarType.isNull(value)) value = "";
154 value = String(value);
158 VarType.toBool = function(value) {
159 value = Boolean(value);
163 VarType.needObject = function(obj) {
164 if(typeof obj != "object" || (!obj)) throw new TypeError();
167 VarType.needInstanceOf = function(obj, type) {
168 if(!(obj instanceof type)) throw new TypeError();
171 VarType.needFunction = function(obj) {
172 if(typeof obj != "function") throw new TypeError();
175 VarType.needNode = function(obj, type) {
176 VarType.needObject(obj);
177 if(VarType.isNull(obj.nodeType)) throw new TypeError();
178 if(!VarType.isNull(type)) {
179 type = VarType.toInt(type);
180 if(obj.nodeType != type) throw new TypeError();