@form-create/utils
Advanced tools
Comparing version 2.5.7 to 2.5.9
import deepExtend from './deepextend'; | ||
import {err} from './console'; | ||
import is from './type'; | ||
@@ -7,3 +8,6 @@ const PREFIX = '[[FORM-CREATE-PREFIX-'; | ||
export function toJson(obj) { | ||
const $T = '$FN:'; | ||
const FUNCTION = 'function'; | ||
export function toJson(obj, space) { | ||
return JSON.stringify(deepExtend([], obj, true), function (key, val) { | ||
@@ -13,6 +17,9 @@ if (val && val._isVue === true) | ||
if (typeof val !== 'function') { | ||
if (typeof val !== FUNCTION) { | ||
return val; | ||
} | ||
if (val.__inject) | ||
if (val.__json) { | ||
return val.__json; | ||
} | ||
if (val.__origin) | ||
val = val.__origin; | ||
@@ -22,26 +29,41 @@ | ||
return undefined; | ||
return PREFIX + val + SUFFIX; | ||
}); | ||
}, space); | ||
} | ||
function makeFn(fn) { | ||
return eval('(function(){return ' + fn + ' })()') | ||
return eval('(' + FUNCTION + '(){return ' + fn + ' })()') | ||
} | ||
export function parseJson(json, mode) { | ||
return JSON.parse(json, function (k, v) { | ||
if (!v || !v.indexOf) return v; | ||
export function parseFn(fn, mode) { | ||
if (fn && is.String(fn)) { | ||
let v = fn.trim(); | ||
let flag = false; | ||
if (v.indexOf(SUFFIX) > 0 && v.indexOf(PREFIX) === 0) { | ||
v = v.replace(SUFFIX, '').replace(PREFIX, ''); | ||
flag = true; | ||
} else if (v.indexOf($T) === 0) { | ||
v = v.replace($T, ''); | ||
flag = true; | ||
} else if (!mode && v.indexOf(FUNCTION) === 0 && v !== FUNCTION) { | ||
flag = true; | ||
} | ||
if (!flag) return fn; | ||
try { | ||
if (v.indexOf(SUFFIX) > 0 && v.indexOf(PREFIX) === 0) { | ||
v = v.replace(SUFFIX, '').replace(PREFIX, ''); | ||
return makeFn(v.indexOf('function') === -1 && v.indexOf('(') !== 0 ? 'function ' + v : v); | ||
} else if (!mode && v.indexOf('function') > -1) | ||
return makeFn(v) | ||
const val = makeFn(v.indexOf(FUNCTION) === -1 && v.indexOf('(') !== 0 ? (FUNCTION + ' ' + v) : v); | ||
val.__json = fn; | ||
return val; | ||
} catch (e) { | ||
err(`json 解析失败:${v}`); | ||
err(`解析失败:${v}`); | ||
return undefined; | ||
} | ||
return v; | ||
} | ||
return fn; | ||
} | ||
export function parseJson(json, mode) { | ||
return JSON.parse(json, function (k, v) { | ||
if (is.Undef(v) || !v.indexOf) return v; | ||
return parseFn(v, mode); | ||
}); | ||
} |
{ | ||
"name": "@form-create/utils", | ||
"version": "2.5.7", | ||
"version": "2.5.9", | ||
"description": "", | ||
@@ -31,3 +31,3 @@ "main": "./lib/index.js", | ||
}, | ||
"gitHead": "0cb3f47570480db294d6356ac7ab356768673bd2" | ||
"gitHead": "b4e39524136df76ad16c92a3697fdfe94ac296a7" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13406
296