1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- /* eslint-disable */
- var FastJson = {
- isArray: function (a) {
- return typeof a === 'object' && Object.prototype.toString.call(a).toLowerCase() === '[object array]'
- },
- isObject: function (a) {
- return typeof a == 'object' && Object.prototype.toString.call(a).toLowerCase() == '[object object]'
- },
- format: function (a) {
- if (a == null) { return null }
- typeof a == 'string' && (a = eval('(' + a + ')'))
- return this._format(a, a, null, null, null)
- },
- _randomId: function () {
- return 'randomId_' + parseInt(1E9 * Math.random())
- },
- _getJsonValue: function (a, c) {
- var d = this._randomId()
- var b
- b = '' + ('function' + d + '(root){') + ('return root.' + c + ';')
- b += '}'
- b += ''
- var e = document.createElement('script')
- e.id = d
- e.text = b
- document.body.appendChild(e)
- d = window[d](a)
- e.parentNode.removeChild(e)
- return d
- },
- _format: function (a, c, d, b, e) {
- d || (d = '')
- if (this.isObject(c)) {
- if (c.$ref) {
- var g = c.$ref
- g.indexOf('$.') == 0 &&
- (b[e] = this._getJsonValue(a, g.substring(2)))
- return
- }
- for (var f in c) {
- b = d, b != '' && (b += '.'), g = c[f], b += f, this
- ._format(a, g, b, c, f)
- }
- } else if (this.isArray(c)) {
- for (f in c) {
- b = d, g = c[f], b = b + '[' + f + ']', this._format(a, g,
- b, c, f)
- }
- }
- return a
- }
- }
- module.exports = {
- FastJson
- }
|