How to use reduceToSingleString method in Cypress

Best JavaScript code snippet using cypress

Run Cypress automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

bxUtil.js

Source: bxUtil.js Github

copy
1angular.module('bxUtil', []).service('bxUtil', function() {
2  var arrayToHash, async, format, formatArray, formatError, formatPrimitive, formatProperty, formatRegExp, formatValue, inherits, inspect, isArray, isBoolean, isBuffer, isDate, isError, isFunction, isNull, isNullOrUndefined, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, log, months, objectToString, pad, random, reduceToSingleString, stylizeNoColor, stylizeWithColor, timestamp, _extend;
3  months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
4  formatRegExp = /%[sdj%]/g;
5  isArray = function(ar) {
6    return Array.isArray(ar);
7  };
8  isBoolean = function(arg) {
9    return typeof arg === "boolean";
10  };
11  isNull = function(arg) {
12    return arg === null;
13  };
14  isNullOrUndefined = function(arg) {
15    return arg == null;
16  };
17  isNumber = function(arg) {
18    return typeof arg === "number";
19  };
20  isString = function(arg) {
21    return typeof arg === "string";
22  };
23  isSymbol = function(arg) {
24    return typeof arg === "symbol";
25  };
26  isUndefined = function(arg) {
27    return arg === void 0;
28  };
29  isRegExp = function(re) {
30    return isObject(re) && objectToString(re) === "[object RegExp]";
31  };
32  isObject = function(arg) {
33    return typeof arg === "object" && arg;
34  };
35  isDate = function(d) {
36    return isObject(d) && objectToString(d) === "[object Date]";
37  };
38  isError = function(e) {
39    return isObject(e) && objectToString(e) === "[object Error]";
40  };
41  isFunction = function(arg) {
42    return typeof arg === "function";
43  };
44  isPrimitive = function(arg) {
45    return arg === null || typeof arg === "boolean" || typeof arg === "number" || typeof arg === "string" || typeof arg === "symbol" || typeof arg === "undefined";
46  };
47  isBuffer = function(arg) {
48    return arg && typeof arg === "object" && typeof arg.copy === "function" && typeof arg.fill === "function" && typeof arg.binarySlice === "function";
49  };
50  format = function(f) {
51    var args, i, len, objects, str, x;
52    if (!isString(f)) {
53      objects = [];
54      i = 0;
55      while (i < arguments.length) {
56        objects.push(inspect(arguments[i]));
57        i++;
58      }
59      return objects.join(" ");
60    }
61    i = 1;
62    args = arguments;
63    len = args.length;
64    str = String(f).replace(formatRegExp, function(x) {
65      var _;
66      if (x === "%%") {
67        return "%";
68      }
69      if (i >= len) {
70        return x;
71      }
72      switch (x) {
73        case "%s":
74          return String(args[i++]);
75        case "%d":
76          return Number(args[i++]);
77        case "%j":
78          try {
79            return JSON.stringify(args[i++]);
80          } catch (_error) {
81            _ = _error;
82            return "[Circular]";
83          }
84          break;
85        default:
86          return x;
87      }
88    });
89    x = args[i];
90    while (i < len) {
91      if (isNull(x) || !isObject(x)) {
92        str += " " + x;
93      } else {
94        str += " " + inspect(x);
95      }
96      x = args[++i];
97    }
98    return str;
99  };
100  formatValue = function(ctx, value, recurseTimes) {
101    var array, base, braces, keys, n, name, output, primitive, ret, visibleKeys;
102    if (ctx.customInspect && value && isFunction(value.inspect) && value.inspect !== inspect && !(value.constructor && value.constructor.prototype.is(value))) {
103      ret = value.inspect(recurseTimes);
104      if (!isString(ret)) {
105        ret = formatValue(ctx, ret, recurseTimes);
106      }
107      return ret;
108    }
109    primitive = formatPrimitive(ctx, value);
110    if (primitive) {
111      return primitive;
112    }
113    keys = shims.keys(value);
114    visibleKeys = arrayToHash(keys);
115    if (ctx.showHidden) {
116      keys = shims.getOwnPropertyNames(value);
117    }
118    if (keys.length === 0) {
119      if (isFunction(value)) {
120        name = (value.name ? ": " + value.name : "");
121        return ctx.stylize("[Function" + name + "]", "special");
122      }
123      if (isRegExp(value)) {
124        return ctx.stylize(RegExp.prototype.toString.call(value), "regexp");
125      }
126      if (isDate(value)) {
127        return ctx.stylize(Date.prototype.toString.call(value), "date");
128      }
129      if (isError(value)) {
130        return formatError(value);
131      }
132    }
133    base = "";
134    array = false;
135    braces = ["{", "}"];
136    if (isArray(value)) {
137      array = true;
138      braces = ["[", "]"];
139    }
140    if (isFunction(value)) {
141      n = (value.name ? ": " + value.name : "");
142      base = " [Function" + n + "]";
143    }
144    if (isRegExp(value)) {
145      base = " " + RegExp.prototype.toString.call(value);
146    }
147    if (isDate(value)) {
148      base = " " + Date.prototype.toUTCString.call(value);
149    }
150    if (isError(value)) {
151      base = " " + formatError(value);
152    }
153    if (keys.length === 0 && (!array || value.length === 0)) {
154      return braces[0] + base + braces[1];
155    }
156    if (recurseTimes < 0) {
157      if (isRegExp(value)) {
158        return ctx.stylize(RegExp.prototype.toString.call(value), "regexp");
159      } else {
160        return ctx.stylize("[Object]", "special");
161      }
162    }
163    ctx.seen.push(value);
164    output = void 0;
165    if (array) {
166      output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
167    } else {
168      output = keys.map(function(key) {
169        return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
170      });
171    }
172    ctx.seen.pop();
173    return reduceToSingleString(output, base, braces);
174  };
175  formatPrimitive = function(ctx, value) {
176    var simple;
177    if (isUndefined(value)) {
178      return ctx.stylize("undefined", "undefined");
179    }
180    if (isString(value)) {
181      simple = "'" + JSON.stringify(value).replace(/^"|"$/g, "").replace(/'/g, "\\'").replace(/\\"/g, "\"") + "'";
182      return ctx.stylize(simple, "string");
183    }
184    if (isNumber(value)) {
185      return ctx.stylize("" + value, "number");
186    }
187    if (isBoolean(value)) {
188      return ctx.stylize("" + value, "boolean");
189    }
190    if (isNull(value)) {
191      return ctx.stylize("null", "null");
192    }
193  };
194  formatError = function(value) {
195    return "[" + Error.prototype.toString.call(value) + "]";
196  };
197  formatArray = function(ctx, value, recurseTimes, visibleKeys, keys) {
198    var f, i, l, output;
199    output = [];
200    i = 0;
201    l = value.length;
202    while (i < l) {
203      if (hasOwnProperty(value, String(i))) {
204        f = formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), true);
205        output.push(f);
206      } else {
207        output.push("");
208      }
209      ++i;
210    }
211    keys.forEach(function(key) {
212      if (!key.match(/^\d+$/)) {
213        f = formatProperty(ctx, value, recurseTimes, visibleKeys, key, true);
214        return output.push(f);
215      }
216    });
217    return output;
218  };
219  formatProperty = function(ctx, value, recurseTimes, visibleKeys, key, array) {
220    var desc, name, str;
221    name = void 0;
222    str = void 0;
223    desc = void 0;
224    desc = Object.getOwnPropertyDescriptor(value, key) || {
225      value: value[key]
226    };
227    if (desc.get) {
228      if (desc.set) {
229        str = ctx.stylize("[Getter/Setter]", "special");
230      } else {
231        str = ctx.stylize("[Getter]", "special");
232      }
233    } else {
234      if (desc.set) {
235        str = ctx.stylize("[Setter]", "special");
236      }
237    }
238    if (!hasOwnProperty(visibleKeys, key)) {
239      name = "[" + key + "]";
240    }
241    if (!str) {
242      if (ctx.seen.indexOf(desc.value) < 0) {
243        if (isNull(recurseTimes)) {
244          str = formatValue(ctx, desc.value, null);
245        } else {
246          str = formatValue(ctx, desc.value, recurseTimes - 1);
247        }
248        if (str.indexOf("\n") > -1) {
249          if (array) {
250            str = str.split("\n").map(function(line) {
251              return "  " + line;
252            }).join("\n").substr(2);
253          } else {
254            str = "\n" + str.split("\n").map(function(line) {
255              return "   " + line;
256            }).join("\n");
257          }
258        }
259      } else {
260        str = ctx.stylize("[Circular]", "special");
261      }
262    }
263    if (isUndefined(name)) {
264      if (array && key.match(/^\d+$/)) {
265        return str;
266      }
267      name = JSON.stringify("" + key);
268      if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
269        name = name.substr(1, name.length - 2);
270        name = ctx.stylize(name, "name");
271      } else {
272        name = name.replace(/'/g, "\\'").replace(/\\"/g, "\"").replace(/(^"|"$)/g, "'");
273        name = ctx.stylize(name, "string");
274      }
275    }
276    return name + ": " + str;
277  };
278  reduceToSingleString = function(output, base, braces) {
279    var length, numLinesEst;
280    numLinesEst = 0;
281    length = output.reduce(function(prev, cur) {
282      numLinesEst++;
283      if (cur.indexOf("\n") >= 0) {
284        numLinesEst++;
285      }
286      return prev + cur.replace(/\u001b\[\d\d?m/g, "").length + 1;
287    }, 0);
288    if (length > 60) {
289      return braces[0] + (base === "" ? "" : base + "\n ") + " " + output.join(",\n  ") + " " + braces[1];
290    }
291    return braces[0] + base + " " + output.join(", ") + " " + braces[1];
292  };
293  pad = function(n) {
294    if (n < 10) {
295      return '0' + n.toString(10);
296    } else {
297      return n.toString(10);
298    }
299  };
300  objectToString = function(o) {
301    return Object.prototype.toString.call(o);
302  };
303  stylizeWithColor = function(str, styleType) {
304    var style;
305    style = inspect.styles[styleType];
306    if (style) {
307      return "\u001b[" + inspect.colors[style][0] + "m" + str + "\u001b[" + inspect.colors[style][1] + "m";
308    } else {
309      return str;
310    }
311  };
312  stylizeNoColor = function(str, styleType) {
313    return str;
314  };
315  inspect = function(obj, opts) {
316    var ctx;
317    ctx = {
318      seen: [],
319      stylize: stylizeNoColor
320    };
321    if (arguments.length >= 3) {
322      ctx.depth = arguments[2];
323    }
324    if (arguments.length >= 4) {
325      ctx.colors = arguments[3];
326    }
327    if (isBoolean(opts)) {
328      ctx.showHidden = opts;
329    } else {
330      if (opts) {
331        _extend(ctx, opts);
332      }
333    }
334    if (isUndefined(ctx.showHidden)) {
335      ctx.showHidden = false;
336    }
337    if (isUndefined(ctx.depth)) {
338      ctx.depth = 2;
339    }
340    if (isUndefined(ctx.colors)) {
341      ctx.colors = false;
342    }
343    if (isUndefined(ctx.customInspect)) {
344      ctx.customInspect = true;
345    }
346    if (ctx.colors) {
347      ctx.stylize = stylizeWithColor;
348    }
349    return formatValue(ctx, obj, ctx.depth);
350  };
351  inspect.colors = {
352    bold: [1, 22],
353    italic: [3, 23],
354    underline: [4, 24],
355    inverse: [7, 27],
356    white: [37, 39],
357    grey: [90, 39],
358    black: [30, 39],
359    blue: [34, 39],
360    cyan: [36, 39],
361    green: [32, 39],
362    magenta: [35, 39],
363    red: [31, 39],
364    yellow: [33, 39]
365  };
366  inspect.styles = {
367    special: "cyan",
368    number: "yellow",
369    boolean: "yellow",
370    undefined: "grey",
371    "null": "bold",
372    string: "green",
373    date: "magenta",
374    regexp: "red"
375  };
376  arrayToHash = function(array) {
377    var hash;
378    hash = {};
379    array.forEach(function(val, idx) {
380      return hash[val] = true;
381    });
382    return hash;
383  };
384  inherits = function(ctor, superCtor) {
385    ctor.super_ = superCtor;
386    return ctor.prototype = Object.create(superCtor.prototype, {
387      constructor: {
388        value: ctor,
389        enumerable: false,
390        writeable: true,
391        configurable: true
392      }
393    });
394  };
395  _extend = function(one, two) {
396    var k, keys, _i, _len;
397    if (!one) {
398      return {};
399    }
400    if (!two || typeof two !== 'object') {
401      return one;
402    }
403    keys = Object.keys(two);
404    for (_i = 0, _len = keys.length; _i < _len; _i++) {
405      k = keys[_i];
406      one[k] = two[k];
407    }
408    return one;
409  };
410  log = function() {
411    return console.log('%s - $s', timestamp(), format.apply(null, arguments));
412  };
413  random = function(length) {
414    var list, token;
415    token = '';
416    list = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm' + 'nopqrstuvwxyz0123456789';
417    while (token.length < length) {
418      token += list.charAt(Math.floor(Math.random() * list.length));
419    }
420    return token;
421  };
422  timestamp = function() {
423    var d, time;
424    d = new Date();
425    time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(":");
426    return [d.getDate(), months[d.getMonth()], time].join(" ");
427  };
428  async = function(fn) {
429    return setTimeout(function() {
430      return fn;
431    }, 0);
432  };
433  return {
434    isArray: isArray,
435    isBoolean: isBoolean,
436    isNull: isNull,
437    isNullOrUndefined: isNullOrUndefined,
438    isNumber: isNumber,
439    isString: isString,
440    isSymbol: isSymbol,
441    isUndefined: isUndefined,
442    isRegExp: isRegExp,
443    isObject: isObject,
444    isDate: isDate,
445    isError: isError,
446    isFunction: isFunction,
447    isPrimitive: isPrimitive,
448    isBuffer: isBuffer,
449    format: format,
450    formatValue: formatValue,
451    formatPrimitive: formatPrimitive,
452    formatError: formatError,
453    formatArray: formatArray,
454    formatProperty: formatProperty,
455    reduceToSingleString: reduceToSingleString,
456    pad: pad,
457    objectToString: objectToString,
458    stylizeWithColor: stylizeWithColor,
459    stylizeNoColor: stylizeNoColor,
460    inspect: inspect,
461    arrayToHash: arrayToHash,
462    inherits: inherits,
463    _extend: _extend,
464    log: log,
465    random: random,
466    timestamp: timestamp,
467    async: async
468  };
469});
470
Full Screen

noUtil.js

Source: noUtil.js Github

copy
1angular.module('noUtil', []).service('noUtil', function() {
2  var arrayToHash, async, format, formatArray, formatError, formatPrimitive, formatProperty, formatRegExp, formatValue, inherits, inspect, isArray, isBoolean, isBuffer, isDate, isError, isFunction, isNull, isNullOrUndefined, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, log, months, objectToString, pad, random, reduceToSingleString, safeApply, sluggify, stylizeNoColor, stylizeWithColor, timestamp, _extend;
3  months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
4  formatRegExp = /%[sdj%]/g;
5  sluggify = function(text) {
6    return text.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
7  };
8  safeApply = function(scope, fn) {
9    if (scope.$$phase || scope.$root.$$phase) {
10      return fn();
11    } else {
12      return scope.$apply(fn);
13    }
14  };
15  isArray = function(ar) {
16    return Array.isArray(ar);
17  };
18  isBoolean = function(arg) {
19    return typeof arg === "boolean";
20  };
21  isNull = function(arg) {
22    return arg === null;
23  };
24  isNullOrUndefined = function(arg) {
25    return arg == null;
26  };
27  isNumber = function(arg) {
28    return typeof arg === "number";
29  };
30  isString = function(arg) {
31    return typeof arg === "string";
32  };
33  isSymbol = function(arg) {
34    return typeof arg === "symbol";
35  };
36  isUndefined = function(arg) {
37    return arg === void 0;
38  };
39  isRegExp = function(re) {
40    return isObject(re) && objectToString(re) === "[object RegExp]";
41  };
42  isObject = function(arg) {
43    return typeof arg === "object" && arg;
44  };
45  isDate = function(d) {
46    return isObject(d) && objectToString(d) === "[object Date]";
47  };
48  isError = function(e) {
49    return isObject(e) && objectToString(e) === "[object Error]";
50  };
51  isFunction = function(arg) {
52    return typeof arg === "function";
53  };
54  isPrimitive = function(arg) {
55    return arg === null || typeof arg === "boolean" || typeof arg === "number" || typeof arg === "string" || typeof arg === "symbol" || typeof arg === "undefined";
56  };
57  isBuffer = function(arg) {
58    return arg && typeof arg === "object" && typeof arg.copy === "function" && typeof arg.fill === "function" && typeof arg.binarySlice === "function";
59  };
60  format = function(f) {
61    var args, i, len, objects, str, x;
62    if (!isString(f)) {
63      objects = [];
64      i = 0;
65      while (i < arguments.length) {
66        objects.push(inspect(arguments[i]));
67        i++;
68      }
69      return objects.join(" ");
70    }
71    i = 1;
72    args = arguments;
73    len = args.length;
74    str = String(f).replace(formatRegExp, function(x) {
75      var _;
76      if (x === "%%") {
77        return "%";
78      }
79      if (i >= len) {
80        return x;
81      }
82      switch (x) {
83        case "%s":
84          return String(args[i++]);
85        case "%d":
86          return Number(args[i++]);
87        case "%j":
88          try {
89            return JSON.stringify(args[i++]);
90          } catch (_error) {
91            _ = _error;
92            return "[Circular]";
93          }
94          break;
95        default:
96          return x;
97      }
98    });
99    x = args[i];
100    while (i < len) {
101      if (isNull(x) || !isObject(x)) {
102        str += " " + x;
103      } else {
104        str += " " + inspect(x);
105      }
106      x = args[++i];
107    }
108    return str;
109  };
110  formatValue = function(ctx, value, recurseTimes) {
111    var array, base, braces, keys, n, name, output, primitive, ret, visibleKeys;
112    if (ctx.customInspect && value && isFunction(value.inspect) && value.inspect !== inspect && !(value.constructor && value.constructor.prototype.is(value))) {
113      ret = value.inspect(recurseTimes);
114      if (!isString(ret)) {
115        ret = formatValue(ctx, ret, recurseTimes);
116      }
117      return ret;
118    }
119    primitive = formatPrimitive(ctx, value);
120    if (primitive) {
121      return primitive;
122    }
123    keys = shims.keys(value);
124    visibleKeys = arrayToHash(keys);
125    if (ctx.showHidden) {
126      keys = shims.getOwnPropertyNames(value);
127    }
128    if (keys.length === 0) {
129      if (isFunction(value)) {
130        name = (value.name ? ": " + value.name : "");
131        return ctx.stylize("[Function" + name + "]", "special");
132      }
133      if (isRegExp(value)) {
134        return ctx.stylize(RegExp.prototype.toString.call(value), "regexp");
135      }
136      if (isDate(value)) {
137        return ctx.stylize(Date.prototype.toString.call(value), "date");
138      }
139      if (isError(value)) {
140        return formatError(value);
141      }
142    }
143    base = "";
144    array = false;
145    braces = ["{", "}"];
146    if (isArray(value)) {
147      array = true;
148      braces = ["[", "]"];
149    }
150    if (isFunction(value)) {
151      n = (value.name ? ": " + value.name : "");
152      base = " [Function" + n + "]";
153    }
154    if (isRegExp(value)) {
155      base = " " + RegExp.prototype.toString.call(value);
156    }
157    if (isDate(value)) {
158      base = " " + Date.prototype.toUTCString.call(value);
159    }
160    if (isError(value)) {
161      base = " " + formatError(value);
162    }
163    if (keys.length === 0 && (!array || value.length === 0)) {
164      return braces[0] + base + braces[1];
165    }
166    if (recurseTimes < 0) {
167      if (isRegExp(value)) {
168        return ctx.stylize(RegExp.prototype.toString.call(value), "regexp");
169      } else {
170        return ctx.stylize("[Object]", "special");
171      }
172    }
173    ctx.seen.push(value);
174    output = void 0;
175    if (array) {
176      output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
177    } else {
178      output = keys.map(function(key) {
179        return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
180      });
181    }
182    ctx.seen.pop();
183    return reduceToSingleString(output, base, braces);
184  };
185  formatPrimitive = function(ctx, value) {
186    var simple;
187    if (isUndefined(value)) {
188      return ctx.stylize("undefined", "undefined");
189    }
190    if (isString(value)) {
191      simple = "'" + JSON.stringify(value).replace(/^"|"$/g, "").replace(/'/g, "\\'").replace(/\\"/g, "\"") + "'";
192      return ctx.stylize(simple, "string");
193    }
194    if (isNumber(value)) {
195      return ctx.stylize("" + value, "number");
196    }
197    if (isBoolean(value)) {
198      return ctx.stylize("" + value, "boolean");
199    }
200    if (isNull(value)) {
201      return ctx.stylize("null", "null");
202    }
203  };
204  formatError = function(value) {
205    return "[" + Error.prototype.toString.call(value) + "]";
206  };
207  formatArray = function(ctx, value, recurseTimes, visibleKeys, keys) {
208    var f, i, l, output;
209    output = [];
210    i = 0;
211    l = value.length;
212    while (i < l) {
213      if (hasOwnProperty(value, String(i))) {
214        f = formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), true);
215        output.push(f);
216      } else {
217        output.push("");
218      }
219      ++i;
220    }
221    keys.forEach(function(key) {
222      if (!key.match(/^\d+$/)) {
223        f = formatProperty(ctx, value, recurseTimes, visibleKeys, key, true);
224        return output.push(f);
225      }
226    });
227    return output;
228  };
229  formatProperty = function(ctx, value, recurseTimes, visibleKeys, key, array) {
230    var desc, name, str;
231    name = void 0;
232    str = void 0;
233    desc = void 0;
234    desc = Object.getOwnPropertyDescriptor(value, key) || {
235      value: value[key]
236    };
237    if (desc.get) {
238      if (desc.set) {
239        str = ctx.stylize("[Getter/Setter]", "special");
240      } else {
241        str = ctx.stylize("[Getter]", "special");
242      }
243    } else {
244      if (desc.set) {
245        str = ctx.stylize("[Setter]", "special");
246      }
247    }
248    if (!hasOwnProperty(visibleKeys, key)) {
249      name = "[" + key + "]";
250    }
251    if (!str) {
252      if (ctx.seen.indexOf(desc.value) < 0) {
253        if (isNull(recurseTimes)) {
254          str = formatValue(ctx, desc.value, null);
255        } else {
256          str = formatValue(ctx, desc.value, recurseTimes - 1);
257        }
258        if (str.indexOf("\n") > -1) {
259          if (array) {
260            str = str.split("\n").map(function(line) {
261              return "  " + line;
262            }).join("\n").substr(2);
263          } else {
264            str = "\n" + str.split("\n").map(function(line) {
265              return "   " + line;
266            }).join("\n");
267          }
268        }
269      } else {
270        str = ctx.stylize("[Circular]", "special");
271      }
272    }
273    if (isUndefined(name)) {
274      if (array && key.match(/^\d+$/)) {
275        return str;
276      }
277      name = JSON.stringify("" + key);
278      if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
279        name = name.substr(1, name.length - 2);
280        name = ctx.stylize(name, "name");
281      } else {
282        name = name.replace(/'/g, "\\'").replace(/\\"/g, "\"").replace(/(^"|"$)/g, "'");
283        name = ctx.stylize(name, "string");
284      }
285    }
286    return name + ": " + str;
287  };
288  reduceToSingleString = function(output, base, braces) {
289    var length, numLinesEst;
290    numLinesEst = 0;
291    length = output.reduce(function(prev, cur) {
292      numLinesEst++;
293      if (cur.indexOf("\n") >= 0) {
294        numLinesEst++;
295      }
296      return prev + cur.replace(/\u001b\[\d\d?m/g, "").length + 1;
297    }, 0);
298    if (length > 60) {
299      return braces[0] + (base === "" ? "" : base + "\n ") + " " + output.join(",\n  ") + " " + braces[1];
300    }
301    return braces[0] + base + " " + output.join(", ") + " " + braces[1];
302  };
303  pad = function(n) {
304    if (n < 10) {
305      return '0' + n.toString(10);
306    } else {
307      return n.toString(10);
308    }
309  };
310  objectToString = function(o) {
311    return Object.prototype.toString.call(o);
312  };
313  stylizeWithColor = function(str, styleType) {
314    var style;
315    style = inspect.styles[styleType];
316    if (style) {
317      return "\u001b[" + inspect.colors[style][0] + "m" + str + "\u001b[" + inspect.colors[style][1] + "m";
318    } else {
319      return str;
320    }
321  };
322  stylizeNoColor = function(str, styleType) {
323    return str;
324  };
325  inspect = function(obj, opts) {
326    var ctx;
327    ctx = {
328      seen: [],
329      stylize: stylizeNoColor
330    };
331    if (arguments.length >= 3) {
332      ctx.depth = arguments[2];
333    }
334    if (arguments.length >= 4) {
335      ctx.colors = arguments[3];
336    }
337    if (isBoolean(opts)) {
338      ctx.showHidden = opts;
339    } else {
340      if (opts) {
341        _extend(ctx, opts);
342      }
343    }
344    if (isUndefined(ctx.showHidden)) {
345      ctx.showHidden = false;
346    }
347    if (isUndefined(ctx.depth)) {
348      ctx.depth = 2;
349    }
350    if (isUndefined(ctx.colors)) {
351      ctx.colors = false;
352    }
353    if (isUndefined(ctx.customInspect)) {
354      ctx.customInspect = true;
355    }
356    if (ctx.colors) {
357      ctx.stylize = stylizeWithColor;
358    }
359    return formatValue(ctx, obj, ctx.depth);
360  };
361  inspect.colors = {
362    bold: [1, 22],
363    italic: [3, 23],
364    underline: [4, 24],
365    inverse: [7, 27],
366    white: [37, 39],
367    grey: [90, 39],
368    black: [30, 39],
369    blue: [34, 39],
370    cyan: [36, 39],
371    green: [32, 39],
372    magenta: [35, 39],
373    red: [31, 39],
374    yellow: [33, 39]
375  };
376  inspect.styles = {
377    special: "cyan",
378    number: "yellow",
379    boolean: "yellow",
380    undefined: "grey",
381    "null": "bold",
382    string: "green",
383    date: "magenta",
384    regexp: "red"
385  };
386  arrayToHash = function(array) {
387    var hash;
388    hash = {};
389    array.forEach(function(val, idx) {
390      return hash[val] = true;
391    });
392    return hash;
393  };
394  inherits = function(ctor, superCtor) {
395    ctor.super_ = superCtor;
396    return ctor.prototype = Object.create(superCtor.prototype, {
397      constructor: {
398        value: ctor,
399        enumerable: false,
400        writeable: true,
401        configurable: true
402      }
403    });
404  };
405  _extend = function(one, two) {
406    var k, keys, _i, _len;
407    if (!one) {
408      return {};
409    }
410    if (!two || typeof two !== 'object') {
411      return one;
412    }
413    keys = Object.keys(two);
414    for (_i = 0, _len = keys.length; _i < _len; _i++) {
415      k = keys[_i];
416      one[k] = two[k];
417    }
418    return one;
419  };
420  log = function() {
421    return console.log('%s - $s', timestamp(), format.apply(null, arguments));
422  };
423  random = function(length) {
424    var list, token;
425    token = '';
426    list = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm' + 'nopqrstuvwxyz0123456789';
427    while (token.length < length) {
428      token += list.charAt(Math.floor(Math.random() * list.length));
429    }
430    return token;
431  };
432  timestamp = function() {
433    var d, time;
434    d = new Date();
435    time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(":");
436    return [d.getDate(), months[d.getMonth()], time].join(" ");
437  };
438  async = function(fn) {
439    return setTimeout(function() {
440      return fn;
441    }, 0);
442  };
443  return {
444    sluggify: sluggify,
445    safeApply: safeApply,
446    isArray: isArray,
447    isBoolean: isBoolean,
448    isNull: isNull,
449    isNullOrUndefined: isNullOrUndefined,
450    isNumber: isNumber,
451    isString: isString,
452    isSymbol: isSymbol,
453    isUndefined: isUndefined,
454    isRegExp: isRegExp,
455    isObject: isObject,
456    isDate: isDate,
457    isError: isError,
458    isFunction: isFunction,
459    isPrimitive: isPrimitive,
460    isBuffer: isBuffer,
461    format: format,
462    formatValue: formatValue,
463    formatPrimitive: formatPrimitive,
464    formatError: formatError,
465    formatArray: formatArray,
466    formatProperty: formatProperty,
467    reduceToSingleString: reduceToSingleString,
468    pad: pad,
469    objectToString: objectToString,
470    stylizeWithColor: stylizeWithColor,
471    stylizeNoColor: stylizeNoColor,
472    inspect: inspect,
473    arrayToHash: arrayToHash,
474    inherits: inherits,
475    extend: _extend,
476    log: log,
477    random: random,
478    timestamp: timestamp,
479    async: async
480  };
481});
482
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Cypress on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)