mirror of https://gitee.com/bigwinds/arangodb
95 lines
2.5 KiB
JavaScript
95 lines
2.5 KiB
JavaScript
/**
|
|
* @depend util/core.js
|
|
*/
|
|
/**
|
|
* Format functions
|
|
*
|
|
* @author Christian Johansen (christian@cjohansen.no)
|
|
* @license BSD
|
|
*
|
|
* Copyright (c) 2010-2014 Christian Johansen
|
|
*/
|
|
(function (sinonGlobal, formatio) {
|
|
"use strict";
|
|
|
|
function makeApi(sinon) {
|
|
function valueFormatter(value) {
|
|
return "" + value;
|
|
}
|
|
|
|
function getFormatioFormatter() {
|
|
var formatter = formatio.configure({
|
|
quoteStrings: false,
|
|
limitChildrenCount: 250
|
|
});
|
|
|
|
function format() {
|
|
return formatter.ascii.apply(formatter, arguments);
|
|
}
|
|
|
|
return format;
|
|
}
|
|
|
|
function getNodeFormatter() {
|
|
try {
|
|
var util = require("util");
|
|
} catch (e) {
|
|
/* Node, but no util module - would be very old, but better safe than sorry */
|
|
}
|
|
|
|
function format(v) {
|
|
var isObjectWithNativeToString = typeof v === "object" && v.toString === Object.prototype.toString;
|
|
return isObjectWithNativeToString ? util.inspect(v) : v;
|
|
}
|
|
|
|
return util ? format : valueFormatter;
|
|
}
|
|
|
|
var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
|
|
var formatter;
|
|
|
|
if (isNode) {
|
|
try {
|
|
formatio = require("formatio");
|
|
}
|
|
catch (e) {} // eslint-disable-line no-empty
|
|
}
|
|
|
|
if (formatio) {
|
|
formatter = getFormatioFormatter();
|
|
} else if (isNode) {
|
|
formatter = getNodeFormatter();
|
|
} else {
|
|
formatter = valueFormatter;
|
|
}
|
|
|
|
sinon.format = formatter;
|
|
return sinon.format;
|
|
}
|
|
|
|
function loadDependencies(require, exports, module) {
|
|
var sinon = require("./util/core");
|
|
module.exports = makeApi(sinon);
|
|
}
|
|
|
|
var isNode = typeof module !== "undefined" && module.exports && typeof require === "function";
|
|
var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
|
|
|
|
if (isAMD) {
|
|
define(loadDependencies);
|
|
return;
|
|
}
|
|
|
|
if (isNode) {
|
|
loadDependencies(require, module.exports, module);
|
|
return;
|
|
}
|
|
|
|
if (sinonGlobal) {
|
|
makeApi(sinonGlobal);
|
|
}
|
|
}(
|
|
typeof sinon === "object" && sinon, // eslint-disable-line no-undef
|
|
typeof formatio === "object" && formatio // eslint-disable-line no-undef
|
|
));
|