1 /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 function isNull(arg) {
22 function isUndefined(arg) {
23 return arg === undefined;
27 function isNullOrUndefined(arg) {
28 return isNull(arg) || isUndefined(arg);
32 function isNumber(arg) {
33 return typeof arg === 'number';
36 function isFinite(arg) {
37 return (arg == 0) || (arg != arg / 2);
40 function isBoolean(arg) {
41 return typeof arg === 'boolean';
45 function isString(arg) {
46 return typeof arg === 'string';
50 function isObject(arg) {
51 return typeof arg === 'object' && arg != null;
55 function isFunction(arg) {
56 return typeof arg === 'function';
60 function isBuffer(arg) {
61 return arg instanceof Buffer;
65 function inherits(ctor, superCtor) {
66 ctor.prototype = Object.create(superCtor.prototype, {
80 for (var i = 0; i < arguments.length; ++i) {
81 arrs.push(formatValue(arguments[i]));
83 return arrs.join(' ');
88 var str = String(s).replace(/%[sdj%]/g, function(m) {
92 if (i >= args.length) {
96 case '%s': return String(args[i++]);
97 case '%d': return Number(args[i++]);
98 case '%j': return '[JSON object]';
103 while (i < args.length) {
104 str += ' ' + args[i++].toString();
110 function formatValue(v) {
111 if (isUndefined(v)) {
113 } else if (isNull(v)) {
121 function errnoException(err, syscall, original) {
122 var errname = "error"; // uv.errname(err);
123 var message = syscall + ' ' + errname;
126 message += ' ' + original;
128 var e = new Error(message);
137 function exceptionWithHostPort(err, syscall, address, port, additional) {
139 if (port && port > 0) {
140 details = address + ':' + port;
146 details += ' - Local (' + additional + ')';
149 var ex = exports.errnoException(err, syscall, details);
150 ex.address = address;
159 exports.isNull = isNull;
160 exports.isUndefined = isUndefined;
161 exports.isNullOrUndefined = isNullOrUndefined;
162 exports.isNumber = isNumber;
163 exports.isBoolean = isBoolean;
164 exports.isString = isString;
165 exports.isObject = isObject;
166 exports.isFinite = isFinite;
167 exports.isFunction = isFunction;
168 exports.isBuffer = isBuffer;
169 exports.isArray = Array.isArray;
170 exports.exceptionWithHostPort = exceptionWithHostPort;
171 exports.errnoException = errnoException;
173 exports.inherits = inherits;
175 exports.format = format;