summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules/js/htdocs/util.js
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-12-06 07:19:24 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-12-06 07:19:24 +0000
commit5b6af381171f4500c7cfc5c9ce179edef9e0fd78 (patch)
tree438e7d673c060c967b24acf9b261e2176d0dccd6 /sca-cpp/trunk/modules/js/htdocs/util.js
parent5bc169ce65762b5165c08e82386152ae83d58564 (diff)
Create a js module for client side javascripts. Move client component script to that module and add a few utility scripts.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1042535 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--sca-cpp/trunk/modules/js/htdocs/util.js85
1 files changed, 85 insertions, 0 deletions
diff --git a/sca-cpp/trunk/modules/js/htdocs/util.js b/sca-cpp/trunk/modules/js/htdocs/util.js
new file mode 100644
index 0000000000..96a84af6d6
--- /dev/null
+++ b/sca-cpp/trunk/modules/js/htdocs/util.js
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Utility functions.
+ */
+
+/**
+ * Simple scheme-like lists.
+ */
+function cons(car, cdr) {
+ return new Array(car).concat(cdr);
+}
+
+function car(l) {
+ return l[0];
+}
+
+function cdr(l) {
+ return l.slice(1);
+}
+
+function mklist() {
+ var a = new Array();
+ for (i = 0; i < arguments.length; i++)
+ a[i] = arguments[i];
+ return a;
+}
+
+function isList(v) {
+ return toString.call(v) === '[object Array]';
+}
+
+function isNil(v) {
+ return v == 'undefined' || v == null;
+}
+
+function isEmpty(l) {
+ return l.length == 0;
+}
+
+/**
+ * convert an array or object to a non-sparse array.
+ */
+function array(obj) {
+ if (isNil(obj.length)) {
+ var a = new Array();
+ a[0] = obj;
+ return a;
+ } else {
+ var a = new Array();
+ var n = 0;
+ for (var i in obj)
+ a[n++] = obj[i];
+ return a;
+ }
+}
+
+/**
+ * Dump an object to the console.
+ */
+function dump(o) {
+ for (f in o) {
+ try {
+ console.log(f + '=' + o[f]);
+ } catch (e) {}
+ }
+}
+