json-treeify
Version:
json-treeify: Get tree string(├└│─) via json, support browser|node, browser none dependencies!
362 lines (311 loc) • 10.3 kB
JavaScript
/*!
* Froguard(figure_wf@163.com)
* https://github.com/Froguard/json-toy
* license MIT
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["typeOf"] = factory();
else
root["typeOf"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "./lib/type-of.js");
/******/ })
/************************************************************************/
/******/ ({
/***/ "./lib/type-of.js":
/*!************************!*\
!*** ./lib/type-of.js ***!
\************************/
/*! no static exports found */
/***/ (function(module, exports) {
function _typeString(obj) {
return Object.prototype.toString.call(obj);
}
function _getType(obj) {
if (obj === null || obj === undefined) {
return obj === undefined ? 'undefined' : 'null';
}
var typeName = _typeString(obj).slice(8, -1).toLowerCase();
var tpOf = typeof obj;
if (typeName !== 'arguments' && (tpOf === 'object' || tpOf === 'function')) {
typeName = obj.constructor && obj.constructor.name ? obj.constructor.name.toLowerCase() : typeName;
}
return typeName;
}
function _isTypeOf(type) {
type = (typeof type === 'string' || type instanceof String ? type : '').toLowerCase();
return function (obj) {
return type === _getType(obj);
};
}
var _Type_ = {};
['arguments', 'array', 'date', 'error', 'syntaxError', 'typeError', 'rangeError', 'regExp', 'symbol', 'set', 'weakSet', 'map', 'weakMap'].forEach(function (t) {
_Type_["is" + t[0].toUpperCase() + t.substr(1)] = _isTypeOf(t);
});
var isArguments = _Type_.isArguments;
var isSymbol = _Type_.isSymbol;
var isSet = _Type_.isSet;
var isWeakSet = _Type_.isWeakSet;
var isMap = _Type_.isMap;
var isWeakMap = _Type_.isWeakMap;
function isArray(obj) {
return _Type_.isArray(obj) || typeof Array.isArray !== 'undefined' && Array.isArray(obj);
}
function isDate(obj) {
return obj instanceof Date || _Type_.isDate(obj);
}
function isRegExp(obj) {
return obj instanceof RegExp || _Type_.isRegExp(obj);
}
function isError(obj) {
return _Type_.isError(obj) || obj instanceof Error;
}
function isSyntaxError(obj) {
return _Type_.isSyntaxError(obj) || obj instanceof SyntaxError;
}
function isTypeError(obj) {
return _Type_.isTypeError(obj) || obj instanceof TypeError;
}
function isRangeError(obj) {
return _Type_.isRangeError(obj) || obj instanceof RangeError;
}
function isObject(obj) {
return (typeof obj === 'object' || obj instanceof Object) && obj !== null;
}
function isFunction(obj) {
return typeof obj === 'function' || obj instanceof Function;
}
function isNull(obj) {
return obj === null;
}
function isUndefined(obj) {
return obj === undefined;
}
function isNill(obj) {
return obj === null || obj === undefined;
}
function isBoolean(obj) {
return obj === true || obj === false || obj instanceof Boolean;
}
function isString(obj) {
return typeof obj === 'string' || obj instanceof String;
}
function isChar(obj) {
return isString(obj) && obj.length === 1;
}
function isNumber(obj, warn) {
warn = warn === undefined ? true : !!warn;
if (warn && obj !== obj) {
console.warn('obj is NaN. Using \'isRealNumber(obj)\' instead of \'isNumber(obj)\'\nOr using \'isNumber(obj,false)\' to stop warning out\n');
}
return typeof obj === 'number' || obj instanceof Number;
}
function isNaN(obj) {
return obj !== obj;
}
function isRealNumber(obj) {
return !isNaN(obj) && isNumber(obj);
}
function isPrimitive(obj) {
return !isObject(obj) && !isFunction(obj);
}
function isSpreadable(obj) {
if (isArray(obj)) {
return !!obj.length;
} else if (isObject(obj) || isFunction(obj)) {
for (var j in obj) {
if (obj.hasOwnProperty(j)) {
return true;
}
}
}
return false;
}
function _isJSON(value, visited) {
(visited || (visited = [])).push(value);
return isPrimitive(value) || isArray(value) && value.every(function (element) {
return _isJSON(element, visited);
}) || isObject.isFlat(value) && Object.keys(value).every(function (key) {
var $ = Object.getOwnPropertyDescriptor(value, key);
return (!isObject($.value) || !~visited.indexOf($.value)) && !('get' in $) && !('set' in $) && _isJSON($.value, visited);
});
}
function isJSON(obj) {
return _isJSON(obj);
}
isObject.isEmpty = function (obj, ownCheck) {
if (!isObject(obj) && !isArray(obj)) {
return false;
}
ownCheck = ownCheck || false;
for (var k in obj) {
if (ownCheck) {
if (obj.hasOwnProperty(k)) {
return false;
}
} else {
return false;
}
}
return true;
};
isObject.isEmptyOwn = function (obj) {
return isObject.isEmpty(obj, true);
};
isObject.isFlat = function (obj) {
if (isNull(obj)) {
return true;
} else if (isObject(obj)) {
return null === Object.getPrototypeOf(obj) || null === Object.getPrototypeOf(Object.getPrototypeOf(obj));
}
return false;
};
isNumber.decimal = function (obj) {
return !isNaN(obj) && isNumber(obj) && obj % 1 !== 0;
};
isNumber.integer = function (obj) {
return !isNaN(obj) && isNumber(obj) && obj % 1 === 0;
};
isNumber.odd = function (obj) {
return !isNaN(obj) && isNumber(obj) && obj % 2 !== 0;
};
isNumber.even = function (obj) {
return !isNaN(obj) && isNumber(obj) && obj % 2 === 0;
};
function _instOf(value, type) {
var isInstanceOf = value instanceof type;
var isConstructorNameSame, isConstructorSourceSame;
if (!isInstanceOf && undefined !== value && null !== value) {
isConstructorNameSame = value.constructor && value.constructor.name === type.name;
isConstructorSourceSame = value.constructor && String(value.constructor) == String(type);
isInstanceOf = isConstructorNameSame && isConstructorSourceSame;
isInstanceOf = isInstanceOf || _instOf(Object.getPrototypeOf(value), type);
}
return isInstanceOf;
}
module.exports = {
typeStr: _typeString,
getTypeOf: _getType,
isTypeOf: _isTypeOf,
isInstanceOf: _instOf,
isArguments: isArguments,
isSymbol: isSymbol,
isSet: isSet,
isWeakSet: isWeakSet,
isMap: isMap,
isWeakMap: isWeakMap,
isArray: isArray,
isDate: isDate,
isRegExp: isRegExp,
isError: isError,
isSyntaxError: isSyntaxError,
isTypeError: isTypeError,
isRangeError: isRangeError,
isObject: isObject,
isFunction: isFunction,
isNull: isNull,
isUndefined: isUndefined,
isNill: isNill,
isNullOrUndefined: isNill,
isUndefinedOrNull: isNill,
isBoolean: isBoolean,
isString: isString,
isChar: isChar,
isNumber: isNumber,
isNaN: isNaN,
isRealNumber: isRealNumber,
isPrimitive: isPrimitive,
isSpreadable: isSpreadable,
isJSON: isJSON
};
/***/ })
/******/ });
});