Commit 9c6abccc authored by rockyl's avatar rockyl

改用ts

parent 8ef14521
/**
* Created by rockyl on 2020-01-27.
*/
const genericRegexp = /(\w+)(<(\w+)>)?/;
var genericRegexp = /(\w+)(<(\w+)>)?/;
function compute(props, options) {
let result = props || {};
for (let key in options) {
let sourceValue = getValue(result, options, key);
let value = sourceValue;
if (options) {
let option = options[key];
if (option && option.type) {
let {type, generic} = parseType(option.type);
switch (type) {
case 'vector2':
value = parseVector2(sourceValue);
break;
case 'array':
let seps = sourceValue.split(',');
seps = seps.map(sep => {
let item;
if (generic) {
switch (generic) {
case 'number':
item = parseFloat(sep);
break;
case 'boolean':
item = sep === 'true';
break;
default:
item = sep;
break;
}
} else {
item = sep;
}
return item;
});
value = seps;
break;
}
}
}
result[key] = value;
}
return result;
var result = props || {};
var _loop_1 = function (key) {
var sourceValue = getValue(result, options, key);
var value = sourceValue;
if (options) {
var option = options[key];
if (option && option.type) {
var _a = parseType(option.type), type = _a.type, generic_1 = _a.generic;
switch (type) {
case 'vector2':
value = parseVector2(sourceValue);
break;
case 'array':
var seps = sourceValue.split(',');
seps = seps.map(function (sep) {
var item;
if (generic_1) {
switch (generic_1) {
case 'number':
item = parseFloat(sep);
break;
case 'boolean':
item = sep === 'true';
break;
default:
item = sep;
break;
}
}
else {
item = sep;
}
return item;
});
value = seps;
break;
}
}
}
result[key] = value;
};
for (var key in options) {
_loop_1(key);
}
return result;
}
function parseType(typeStr) {
let type = typeStr, generic;
let regResult = typeStr.match(genericRegexp);
if (regResult) {
type = regResult[1];
generic = regResult[3];
}
return {
type, generic,
}
var type = typeStr, generic;
var regResult = typeStr.match(genericRegexp);
if (regResult) {
type = regResult[1];
generic = regResult[3];
}
return {
type: type, generic: generic,
};
}
function parseVector2(sourceValue) {
let value = sourceValue;
if (!sourceValue) {
value = {x: undefined, y: undefined};
}
if (typeof sourceValue === 'string') {
let arr = sourceValue.split(',');
value = {
x: arr[0] === '' ? undefined : parseFloat(arr[0]),
y: arr[1] === '' ? undefined : parseFloat(arr[1]),
};
} else if (Array.isArray(sourceValue)) {
value = {
x: sourceValue[0] === '' ? undefined : parseFloat(sourceValue[0]),
y: sourceValue[1] === '' ? undefined : parseFloat(sourceValue[1]),
};
}
return value;
var value = sourceValue;
if (!sourceValue) {
value = { x: undefined, y: undefined };
}
if (typeof sourceValue === 'string') {
var arr = sourceValue.split(',');
value = {
x: arr[0] === '' ? undefined : parseFloat(arr[0]),
y: arr[1] === '' ? undefined : parseFloat(arr[1]),
};
}
else if (Array.isArray(sourceValue)) {
value = {
x: sourceValue[0] === '' ? undefined : parseFloat(sourceValue[0]),
y: sourceValue[1] === '' ? undefined : parseFloat(sourceValue[1]),
};
}
return value;
}
function getValue(props, options, key) {
let value;
if (props.hasOwnProperty(key)) {
value = props[key];
} else if (options && options[key].hasOwnProperty('default')) {
value = options[key].default;
}
return value;
var value;
if (props.hasOwnProperty(key)) {
value = props[key];
}
else if (options && options[key].hasOwnProperty('default')) {
value = options[key].default;
}
return value;
}
export { compute, parseType, parseVector2 };
......
{"version":3,"file":"index.es.js","sources":["../src/index.js"],"sourcesContent":["/**\n * Created by rockyl on 2020-01-27.\n */\n\nconst genericRegexp = /(\\w+)(<(\\w+)>)?/;\n\nexport function compute(props, options) {\n\tlet result = props || {};\n\tfor (let key in options) {\n\t\tlet sourceValue = getValue(result, options, key);\n\t\tlet value = sourceValue;\n\t\tif (options) {\n\t\t\tlet option = options[key];\n\t\t\tif (option && option.type) {\n\t\t\t\tlet {type, generic} = parseType(option.type);\n\t\t\t\tswitch (type) {\n\t\t\t\t\tcase 'vector2':\n\t\t\t\t\t\tvalue = parseVector2(sourceValue);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'array':\n\t\t\t\t\t\tlet seps = sourceValue.split(',');\n\t\t\t\t\t\tseps = seps.map(sep => {\n\t\t\t\t\t\t\tlet item;\n\t\t\t\t\t\t\tif (generic) {\n\t\t\t\t\t\t\t\tswitch (generic) {\n\t\t\t\t\t\t\t\t\tcase 'number':\n\t\t\t\t\t\t\t\t\t\titem = parseFloat(sep);\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\tcase 'boolean':\n\t\t\t\t\t\t\t\t\t\titem = sep === 'true';\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn item;\n\t\t\t\t\t\t});\n\t\t\t\t\t\tvalue = seps;\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tresult[key] = value;\n\t}\n\treturn result;\n}\n\nexport function parseType(typeStr) {\n\tlet type = typeStr, generic;\n\tlet regResult = typeStr.match(genericRegexp);\n\tif (regResult) {\n\t\ttype = regResult[1];\n\t\tgeneric = regResult[3];\n\t}\n\n\treturn {\n\t\ttype, generic,\n\t}\n}\n\nexport function parseVector2(sourceValue) {\n\tlet value = sourceValue;\n\tif (!sourceValue) {\n\t\tvalue = {x: undefined, y: undefined};\n\t}\n\tif (typeof sourceValue === 'string') {\n\t\tlet arr = sourceValue.split(',');\n\t\tvalue = {\n\t\t\tx: arr[0] === '' ? undefined : parseFloat(arr[0]),\n\t\t\ty: arr[1] === '' ? undefined : parseFloat(arr[1]),\n\t\t};\n\t} else if (Array.isArray(sourceValue)) {\n\t\tvalue = {\n\t\t\tx: sourceValue[0] === '' ? undefined : parseFloat(sourceValue[0]),\n\t\t\ty: sourceValue[1] === '' ? undefined : parseFloat(sourceValue[1]),\n\t\t};\n\t}\n\treturn value;\n}\n\nfunction getValue(props, options, key) {\n\tlet value;\n\tif (props.hasOwnProperty(key)) {\n\t\tvalue = props[key];\n\t} else if (options && options[key].hasOwnProperty('default')) {\n\t\tvalue = options[key].default;\n\t}\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AC;GACjE,CAAC;EACF;CACD,OAAO,KAAK,CAAC;CACb;;AAED,SAAS,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE;CACtC,IAAI,KAAK,CAAC;CACV,IAAI,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;EAC9B,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;EACnB,MAAM,IAAI,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE;EAC7D,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;EAC7B;;CAED,OAAO,KAAK,CAAC;CACb;;;;"}
\ No newline at end of file
{"version":3,"file":"index.es.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * Created by rockyl on 2020-01-27.\n */\n\nconst genericRegexp = /(\\w+)(<(\\w+)>)?/;\n\nexport function compute(props, options) {\n\tlet result = props || {};\n\tfor (let key in options) {\n\t\tlet sourceValue = getValue(result, options, key);\n\t\tlet value = sourceValue;\n\t\tif (options) {\n\t\t\tlet option = options[key];\n\t\t\tif (option && option.type) {\n\t\t\t\tlet {type, generic} = parseType(option.type);\n\t\t\t\tswitch (type) {\n\t\t\t\t\tcase 'vector2':\n\t\t\t\t\t\tvalue = parseVector2(sourceValue);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'array':\n\t\t\t\t\t\tlet seps = sourceValue.split(',');\n\t\t\t\t\t\tseps = seps.map(sep => {\n\t\t\t\t\t\t\tlet item;\n\t\t\t\t\t\t\tif (generic) {\n\t\t\t\t\t\t\t\tswitch (generic) {\n\t\t\t\t\t\t\t\t\tcase 'number':\n\t\t\t\t\t\t\t\t\t\titem = parseFloat(sep);\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\tcase 'boolean':\n\t\t\t\t\t\t\t\t\t\titem = sep === 'true';\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn item;\n\t\t\t\t\t\t});\n\t\t\t\t\t\tvalue = seps;\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tresult[key] = value;\n\t}\n\treturn result;\n}\n\nexport function parseType(typeStr) {\n\tlet type = typeStr, generic;\n\tlet regResult = typeStr.match(genericRegexp);\n\tif (regResult) {\n\t\ttype = regResult[1];\n\t\tgeneric = regResult[3];\n\t}\n\n\treturn {\n\t\ttype, generic,\n\t}\n}\n\nexport function parseVector2(sourceValue) {\n\tlet value = sourceValue;\n\tif (!sourceValue) {\n\t\tvalue = {x: undefined, y: undefined};\n\t}\n\tif (typeof sourceValue === 'string') {\n\t\tlet arr = sourceValue.split(',');\n\t\tvalue = {\n\t\t\tx: arr[0] === '' ? undefined : parseFloat(arr[0]),\n\t\t\ty: arr[1] === '' ? undefined : parseFloat(arr[1]),\n\t\t};\n\t} else if (Array.isArray(sourceValue)) {\n\t\tvalue = {\n\t\t\tx: sourceValue[0] === '' ? undefined : parseFloat(sourceValue[0]),\n\t\t\ty: sourceValue[1] === '' ? undefined : parseFloat(sourceValue[1]),\n\t\t};\n\t}\n\treturn value;\n}\n\nfunction getValue(props, options, key) {\n\tlet value;\n\tif (props.hasOwnProperty(key)) {\n\t\tvalue = props[key];\n\t} else if (options && options[key].hasOwnProperty('default')) {\n\t\tvalue = options[key].default;\n\t}\n\n\treturn value;\n}\n"],"names":[],"mappings":"AAAA;;;AAIA,IAAM,aAAa,GAAG,iBAAiB,CAAC;AAExC,SAAgB,OAAO,CAAC,KAAK,EAAE,OAAO;IACrC,IAAI,MAAM,GAAG,KAAK,IAAI,EAAE,CAAC;4BAChB,GAAG;QACX,IAA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,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;KACnB;SAAM,IAAI,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE;QAC7D,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;KAC7B;IAED,OAAO,KAAK,CAAC;CACb;;;;"}
\ No newline at end of file
......@@ -5,95 +5,94 @@ Object.defineProperty(exports, '__esModule', { value: true });
/**
* Created by rockyl on 2020-01-27.
*/
const genericRegexp = /(\w+)(<(\w+)>)?/;
var genericRegexp = /(\w+)(<(\w+)>)?/;
function compute(props, options) {
let result = props || {};
for (let key in options) {
let sourceValue = getValue(result, options, key);
let value = sourceValue;
if (options) {
let option = options[key];
if (option && option.type) {
let {type, generic} = parseType(option.type);
switch (type) {
case 'vector2':
value = parseVector2(sourceValue);
break;
case 'array':
let seps = sourceValue.split(',');
seps = seps.map(sep => {
let item;
if (generic) {
switch (generic) {
case 'number':
item = parseFloat(sep);
break;
case 'boolean':
item = sep === 'true';
break;
default:
item = sep;
break;
}
} else {
item = sep;
}
return item;
});
value = seps;
break;
}
}
}
result[key] = value;
}
return result;
var result = props || {};
var _loop_1 = function (key) {
var sourceValue = getValue(result, options, key);
var value = sourceValue;
if (options) {
var option = options[key];
if (option && option.type) {
var _a = parseType(option.type), type = _a.type, generic_1 = _a.generic;
switch (type) {
case 'vector2':
value = parseVector2(sourceValue);
break;
case 'array':
var seps = sourceValue.split(',');
seps = seps.map(function (sep) {
var item;
if (generic_1) {
switch (generic_1) {
case 'number':
item = parseFloat(sep);
break;
case 'boolean':
item = sep === 'true';
break;
default:
item = sep;
break;
}
}
else {
item = sep;
}
return item;
});
value = seps;
break;
}
}
}
result[key] = value;
};
for (var key in options) {
_loop_1(key);
}
return result;
}
function parseType(typeStr) {
let type = typeStr, generic;
let regResult = typeStr.match(genericRegexp);
if (regResult) {
type = regResult[1];
generic = regResult[3];
}
return {
type, generic,
}
var type = typeStr, generic;
var regResult = typeStr.match(genericRegexp);
if (regResult) {
type = regResult[1];
generic = regResult[3];
}
return {
type: type, generic: generic,
};
}
function parseVector2(sourceValue) {
let value = sourceValue;
if (!sourceValue) {
value = {x: undefined, y: undefined};
}
if (typeof sourceValue === 'string') {
let arr = sourceValue.split(',');
value = {
x: arr[0] === '' ? undefined : parseFloat(arr[0]),
y: arr[1] === '' ? undefined : parseFloat(arr[1]),
};
} else if (Array.isArray(sourceValue)) {
value = {
x: sourceValue[0] === '' ? undefined : parseFloat(sourceValue[0]),
y: sourceValue[1] === '' ? undefined : parseFloat(sourceValue[1]),
};
}
return value;
var value = sourceValue;
if (!sourceValue) {
value = { x: undefined, y: undefined };
}
if (typeof sourceValue === 'string') {
var arr = sourceValue.split(',');
value = {
x: arr[0] === '' ? undefined : parseFloat(arr[0]),
y: arr[1] === '' ? undefined : parseFloat(arr[1]),
};
}
else if (Array.isArray(sourceValue)) {
value = {
x: sourceValue[0] === '' ? undefined : parseFloat(sourceValue[0]),
y: sourceValue[1] === '' ? undefined : parseFloat(sourceValue[1]),
};
}
return value;
}
function getValue(props, options, key) {
let value;
if (props.hasOwnProperty(key)) {
value = props[key];
} else if (options && options[key].hasOwnProperty('default')) {
value = options[key].default;
}
return value;
var value;
if (props.hasOwnProperty(key)) {
value = props[key];
}
else if (options && options[key].hasOwnProperty('default')) {
value = options[key].default;
}
return value;
}
exports.compute = compute;
......
{"version":3,"file":"index.js","sources":["../src/index.js"],"sourcesContent":["/**\n * Created by rockyl on 2020-01-27.\n */\n\nconst genericRegexp = /(\\w+)(<(\\w+)>)?/;\n\nexport function compute(props, options) {\n\tlet result = props || {};\n\tfor (let key in options) {\n\t\tlet sourceValue = getValue(result, options, key);\n\t\tlet value = sourceValue;\n\t\tif (options) {\n\t\t\tlet option = options[key];\n\t\t\tif (option && option.type) {\n\t\t\t\tlet {type, generic} = parseType(option.type);\n\t\t\t\tswitch (type) {\n\t\t\t\t\tcase 'vector2':\n\t\t\t\t\t\tvalue = parseVector2(sourceValue);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'array':\n\t\t\t\t\t\tlet seps = sourceValue.split(',');\n\t\t\t\t\t\tseps = seps.map(sep => {\n\t\t\t\t\t\t\tlet item;\n\t\t\t\t\t\t\tif (generic) {\n\t\t\t\t\t\t\t\tswitch (generic) {\n\t\t\t\t\t\t\t\t\tcase 'number':\n\t\t\t\t\t\t\t\t\t\titem = parseFloat(sep);\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\tcase 'boolean':\n\t\t\t\t\t\t\t\t\t\titem = sep === 'true';\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn item;\n\t\t\t\t\t\t});\n\t\t\t\t\t\tvalue = seps;\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tresult[key] = value;\n\t}\n\treturn result;\n}\n\nexport function parseType(typeStr) {\n\tlet type = typeStr, generic;\n\tlet regResult = typeStr.match(genericRegexp);\n\tif (regResult) {\n\t\ttype = regResult[1];\n\t\tgeneric = regResult[3];\n\t}\n\n\treturn {\n\t\ttype, generic,\n\t}\n}\n\nexport function parseVector2(sourceValue) {\n\tlet value = sourceValue;\n\tif (!sourceValue) {\n\t\tvalue = {x: undefined, y: undefined};\n\t}\n\tif (typeof sourceValue === 'string') {\n\t\tlet arr = sourceValue.split(',');\n\t\tvalue = {\n\t\t\tx: arr[0] === '' ? undefined : parseFloat(arr[0]),\n\t\t\ty: arr[1] === '' ? undefined : parseFloat(arr[1]),\n\t\t};\n\t} else if (Array.isArray(sourceValue)) {\n\t\tvalue = {\n\t\t\tx: sourceValue[0] === '' ? undefined : parseFloat(sourceValue[0]),\n\t\t\ty: sourceValue[1] === '' ? undefined : parseFloat(sourceValue[1]),\n\t\t};\n\t}\n\treturn value;\n}\n\nfunction getValue(props, options, key) {\n\tlet value;\n\tif (props.hasOwnProperty(key)) {\n\t\tvalue = props[key];\n\t} else if (options && options[key].hasOwnProperty('default')) {\n\t\tvalue = options[key].default;\n\t}\n\n\treturn value;\n}\n"],"names":[],"mappings":";;;;AAAA;;;;AAIA,MAAM,aAAa,GAAG,iBAAiB,CAAC;;AAExC,AAAO,SAAS,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE;CACvC,IAAI,MAAM,GAAG,KAAK,IAAI,EAAE,CAAC;CACzB,KAAK,IAAI,GAAG,IAAI,OAAO,EAAE;EACxB,IAAI,WAAW,GAAG,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;EACjD,IAAI,KAAK,GAAG,WAAW,CAAC;EACxB,IAAI,OAAO,EAAE;GACZ,IAAI,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;GAC1B,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE;IAC1B,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC7C,QAAQ,IAAI;KACX,KAAK,SAAS;MACb,KAAK,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;MAClC,MAAM;KACP,KAAK,OAAO;MACX,IAAI,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;MAClC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI;OACtB,IAAI,IAAI,CAAC;OACT,IAAI,OAAO,EAAE;QACZ,QAAQ,OAAO;SACd,KAAK,QAAQ;UACZ,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;UACvB,MAAM;SACP,KAAK,SAAS;UACb,IAAI,GAAG,GAAG,KAAK,MAAM,CAAC;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,KAAK,GAAG;GACP,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,EAAE,GAAG,SAAS,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;GACjE,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,EAAE,GAAG,SAAS,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;GACjE,CAAC;EACF;CACD,OAAO,KAAK,CAAC;CACb;;AAED,SAAS,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE;CACtC,IAAI,KAAK,CAAC;CACV,IAAI,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;EAC9B,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;EACnB,MAAM,IAAI,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE;EAC7D,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;EAC7B;;CAED,OAAO,KAAK,CAAC;CACb;;;;;;"}
\ No newline at end of file
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * Created by rockyl on 2020-01-27.\n */\n\nconst genericRegexp = /(\\w+)(<(\\w+)>)?/;\n\nexport function compute(props, options) {\n\tlet result = props || {};\n\tfor (let key in options) {\n\t\tlet sourceValue = getValue(result, options, key);\n\t\tlet value = sourceValue;\n\t\tif (options) {\n\t\t\tlet option = options[key];\n\t\t\tif (option && option.type) {\n\t\t\t\tlet {type, generic} = parseType(option.type);\n\t\t\t\tswitch (type) {\n\t\t\t\t\tcase 'vector2':\n\t\t\t\t\t\tvalue = parseVector2(sourceValue);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'array':\n\t\t\t\t\t\tlet seps = sourceValue.split(',');\n\t\t\t\t\t\tseps = seps.map(sep => {\n\t\t\t\t\t\t\tlet item;\n\t\t\t\t\t\t\tif (generic) {\n\t\t\t\t\t\t\t\tswitch (generic) {\n\t\t\t\t\t\t\t\t\tcase 'number':\n\t\t\t\t\t\t\t\t\t\titem = parseFloat(sep);\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\tcase 'boolean':\n\t\t\t\t\t\t\t\t\t\titem = sep === 'true';\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn item;\n\t\t\t\t\t\t});\n\t\t\t\t\t\tvalue = seps;\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tresult[key] = value;\n\t}\n\treturn result;\n}\n\nexport function parseType(typeStr) {\n\tlet type = typeStr, generic;\n\tlet regResult = typeStr.match(genericRegexp);\n\tif (regResult) {\n\t\ttype = regResult[1];\n\t\tgeneric = regResult[3];\n\t}\n\n\treturn {\n\t\ttype, generic,\n\t}\n}\n\nexport function parseVector2(sourceValue) {\n\tlet value = sourceValue;\n\tif (!sourceValue) {\n\t\tvalue = {x: undefined, y: undefined};\n\t}\n\tif (typeof sourceValue === 'string') {\n\t\tlet arr = sourceValue.split(',');\n\t\tvalue = {\n\t\t\tx: arr[0] === '' ? undefined : parseFloat(arr[0]),\n\t\t\ty: arr[1] === '' ? undefined : parseFloat(arr[1]),\n\t\t};\n\t} else if (Array.isArray(sourceValue)) {\n\t\tvalue = {\n\t\t\tx: sourceValue[0] === '' ? undefined : parseFloat(sourceValue[0]),\n\t\t\ty: sourceValue[1] === '' ? undefined : parseFloat(sourceValue[1]),\n\t\t};\n\t}\n\treturn value;\n}\n\nfunction getValue(props, options, key) {\n\tlet value;\n\tif (props.hasOwnProperty(key)) {\n\t\tvalue = props[key];\n\t} else if (options && options[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AAS,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;SACjE,CAAC;KACF;IACD,OAAO,KAAK,CAAC;CACb;AAED,SAAS,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG;IACpC,IAAI,KAAK,CAAC;IACV,IAAI,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;QAC9B,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;KACnB;SAAM,IAAI,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE;QAC7D,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;KAC7B;IAED,OAAO,KAAK,CAAC;CACb;;;;;;"}
\ No newline at end of file
......@@ -7,95 +7,94 @@
/**
* Created by rockyl on 2020-01-27.
*/
const genericRegexp = /(\w+)(<(\w+)>)?/;
var genericRegexp = /(\w+)(<(\w+)>)?/;
function compute(props, options) {
let result = props || {};
for (let key in options) {
let sourceValue = getValue(result, options, key);
let value = sourceValue;
if (options) {
let option = options[key];
if (option && option.type) {
let {type, generic} = parseType(option.type);
switch (type) {
case 'vector2':
value = parseVector2(sourceValue);
break;
case 'array':
let seps = sourceValue.split(',');
seps = seps.map(sep => {
let item;
if (generic) {
switch (generic) {
case 'number':
item = parseFloat(sep);
break;
case 'boolean':
item = sep === 'true';
break;
default:
item = sep;
break;
}
} else {
item = sep;
}
return item;
});
value = seps;
break;
}
}
}
result[key] = value;
}
return result;
var result = props || {};
var _loop_1 = function (key) {
var sourceValue = getValue(result, options, key);
var value = sourceValue;
if (options) {
var option = options[key];
if (option && option.type) {
var _a = parseType(option.type), type = _a.type, generic_1 = _a.generic;
switch (type) {
case 'vector2':
value = parseVector2(sourceValue);
break;
case 'array':
var seps = sourceValue.split(',');
seps = seps.map(function (sep) {
var item;
if (generic_1) {
switch (generic_1) {
case 'number':
item = parseFloat(sep);
break;
case 'boolean':
item = sep === 'true';
break;
default:
item = sep;
break;
}
}
else {
item = sep;
}
return item;
});
value = seps;
break;
}
}
}
result[key] = value;
};
for (var key in options) {
_loop_1(key);
}
return result;
}
function parseType(typeStr) {
let type = typeStr, generic;
let regResult = typeStr.match(genericRegexp);
if (regResult) {
type = regResult[1];
generic = regResult[3];
}
return {
type, generic,
}
var type = typeStr, generic;
var regResult = typeStr.match(genericRegexp);
if (regResult) {
type = regResult[1];
generic = regResult[3];
}
return {
type: type, generic: generic,
};
}
function parseVector2(sourceValue) {
let value = sourceValue;
if (!sourceValue) {
value = {x: undefined, y: undefined};
}
if (typeof sourceValue === 'string') {
let arr = sourceValue.split(',');
value = {
x: arr[0] === '' ? undefined : parseFloat(arr[0]),
y: arr[1] === '' ? undefined : parseFloat(arr[1]),
};
} else if (Array.isArray(sourceValue)) {
value = {
x: sourceValue[0] === '' ? undefined : parseFloat(sourceValue[0]),
y: sourceValue[1] === '' ? undefined : parseFloat(sourceValue[1]),
};
}
return value;
var value = sourceValue;
if (!sourceValue) {
value = { x: undefined, y: undefined };
}
if (typeof sourceValue === 'string') {
var arr = sourceValue.split(',');
value = {
x: arr[0] === '' ? undefined : parseFloat(arr[0]),
y: arr[1] === '' ? undefined : parseFloat(arr[1]),
};
}
else if (Array.isArray(sourceValue)) {
value = {
x: sourceValue[0] === '' ? undefined : parseFloat(sourceValue[0]),
y: sourceValue[1] === '' ? undefined : parseFloat(sourceValue[1]),
};
}
return value;
}
function getValue(props, options, key) {
let value;
if (props.hasOwnProperty(key)) {
value = props[key];
} else if (options && options[key].hasOwnProperty('default')) {
value = options[key].default;
}
return value;
var value;
if (props.hasOwnProperty(key)) {
value = props[key];
}
else if (options && options[key].hasOwnProperty('default')) {
value = options[key].default;
}
return value;
}
exports.compute = compute;
......
{"version":3,"file":"index.umd.js","sources":["../src/index.js"],"sourcesContent":["/**\n * Created by rockyl on 2020-01-27.\n */\n\nconst genericRegexp = /(\\w+)(<(\\w+)>)?/;\n\nexport function compute(props, options) {\n\tlet result = props || {};\n\tfor (let key in options) {\n\t\tlet sourceValue = getValue(result, options, key);\n\t\tlet value = sourceValue;\n\t\tif (options) {\n\t\t\tlet option = options[key];\n\t\t\tif (option && option.type) {\n\t\t\t\tlet {type, generic} = parseType(option.type);\n\t\t\t\tswitch (type) {\n\t\t\t\t\tcase 'vector2':\n\t\t\t\t\t\tvalue = parseVector2(sourceValue);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'array':\n\t\t\t\t\t\tlet seps = sourceValue.split(',');\n\t\t\t\t\t\tseps = seps.map(sep => {\n\t\t\t\t\t\t\tlet item;\n\t\t\t\t\t\t\tif (generic) {\n\t\t\t\t\t\t\t\tswitch (generic) {\n\t\t\t\t\t\t\t\t\tcase 'number':\n\t\t\t\t\t\t\t\t\t\titem = parseFloat(sep);\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\tcase 'boolean':\n\t\t\t\t\t\t\t\t\t\titem = sep === 'true';\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn item;\n\t\t\t\t\t\t});\n\t\t\t\t\t\tvalue = seps;\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tresult[key] = value;\n\t}\n\treturn result;\n}\n\nexport function parseType(typeStr) {\n\tlet type = typeStr, generic;\n\tlet regResult = typeStr.match(genericRegexp);\n\tif (regResult) {\n\t\ttype = regResult[1];\n\t\tgeneric = regResult[3];\n\t}\n\n\treturn {\n\t\ttype, generic,\n\t}\n}\n\nexport function parseVector2(sourceValue) {\n\tlet value = sourceValue;\n\tif (!sourceValue) {\n\t\tvalue = {x: undefined, y: undefined};\n\t}\n\tif (typeof sourceValue === 'string') {\n\t\tlet arr = sourceValue.split(',');\n\t\tvalue = {\n\t\t\tx: arr[0] === '' ? undefined : parseFloat(arr[0]),\n\t\t\ty: arr[1] === '' ? undefined : parseFloat(arr[1]),\n\t\t};\n\t} else if (Array.isArray(sourceValue)) {\n\t\tvalue = {\n\t\t\tx: sourceValue[0] === '' ? undefined : parseFloat(sourceValue[0]),\n\t\t\ty: sourceValue[1] === '' ? undefined : parseFloat(sourceValue[1]),\n\t\t};\n\t}\n\treturn value;\n}\n\nfunction getValue(props, options, key) {\n\tlet value;\n\tif (props.hasOwnProperty(key)) {\n\t\tvalue = props[key];\n\t} else if (options && options[key].hasOwnProperty('default')) {\n\t\tvalue = options[key].default;\n\t}\n\n\treturn value;\n}\n"],"names":[],"mappings":";;;;;;CAAA;CACA;CACA;;CAEA,MAAM,aAAa,GAAG,iBAAiB,CAAC;;AAExC,CAAO,SAAS,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE;CACxC,CAAC,IAAI,MAAM,GAAG,KAAK,IAAI,EAAE,CAAC;CAC1B,CAAC,KAAK,IAAI,GAAG,IAAI,OAAO,EAAE;CAC1B,EAAE,IAAI,WAAW,GAAG,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;CACnD,EAAE,IAAI,KAAK,GAAG,WAAW,CAAC;CAC1B,EAAE,IAAI,OAAO,EAAE;CACf,GAAG,IAAI,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;CAC7B,GAAG,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE;CAC9B,IAAI,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;CACjD,IAAI,QAAQ,IAAI;CAChB,KAAK,KAAK,SAAS;CACnB,MAAM,KAAK,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;CACxC,MAAM,MAAM;CACZ,KAAK,KAAK,OAAO;CACjB,MAAM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AC,cAAc,CAAC,SAAS,CAAC,EAAE;CAC/D,EAAE,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;CAC/B,EAAE;;CAEF,CAAC,OAAO,KAAK,CAAC;CACd,CAAC;;;;;;;;;;;;;;"}
\ No newline at end of file
{"version":3,"file":"index.umd.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * Created by rockyl on 2020-01-27.\n */\n\nconst genericRegexp = /(\\w+)(<(\\w+)>)?/;\n\nexport function compute(props, options) {\n\tlet result = props || {};\n\tfor (let key in options) {\n\t\tlet sourceValue = getValue(result, options, key);\n\t\tlet value = sourceValue;\n\t\tif (options) {\n\t\t\tlet option = options[key];\n\t\t\tif (option && option.type) {\n\t\t\t\tlet {type, generic} = parseType(option.type);\n\t\t\t\tswitch (type) {\n\t\t\t\t\tcase 'vector2':\n\t\t\t\t\t\tvalue = parseVector2(sourceValue);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'array':\n\t\t\t\t\t\tlet seps = sourceValue.split(',');\n\t\t\t\t\t\tseps = seps.map(sep => {\n\t\t\t\t\t\t\tlet item;\n\t\t\t\t\t\t\tif (generic) {\n\t\t\t\t\t\t\t\tswitch (generic) {\n\t\t\t\t\t\t\t\t\tcase 'number':\n\t\t\t\t\t\t\t\t\t\titem = parseFloat(sep);\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\tcase 'boolean':\n\t\t\t\t\t\t\t\t\t\titem = sep === 'true';\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn item;\n\t\t\t\t\t\t});\n\t\t\t\t\t\tvalue = seps;\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tresult[key] = value;\n\t}\n\treturn result;\n}\n\nexport function parseType(typeStr) {\n\tlet type = typeStr, generic;\n\tlet regResult = typeStr.match(genericRegexp);\n\tif (regResult) {\n\t\ttype = regResult[1];\n\t\tgeneric = regResult[3];\n\t}\n\n\treturn {\n\t\ttype, generic,\n\t}\n}\n\nexport function parseVector2(sourceValue) {\n\tlet value = sourceValue;\n\tif (!sourceValue) {\n\t\tvalue = {x: undefined, y: undefined};\n\t}\n\tif (typeof sourceValue === 'string') {\n\t\tlet arr = sourceValue.split(',');\n\t\tvalue = {\n\t\t\tx: arr[0] === '' ? undefined : parseFloat(arr[0]),\n\t\t\ty: arr[1] === '' ? undefined : parseFloat(arr[1]),\n\t\t};\n\t} else if (Array.isArray(sourceValue)) {\n\t\tvalue = {\n\t\t\tx: sourceValue[0] === '' ? undefined : parseFloat(sourceValue[0]),\n\t\t\ty: sourceValue[1] === '' ? undefined : parseFloat(sourceValue[1]),\n\t\t};\n\t}\n\treturn value;\n}\n\nfunction getValue(props, options, key) {\n\tlet value;\n\tif (props.hasOwnProperty(key)) {\n\t\tvalue = props[key];\n\t} else if (options && options[key].hasOwnProperty('default')) {\n\t\tvalue = options[key].default;\n\t}\n\n\treturn value;\n}\n"],"names":[],"mappings":";;;;;;CAAA;;;CAIA,IAAM,aAAa,GAAG,iBAAiB,CAAC;AAExC,UAAgB,OAAO,CAAC,KAAK,EAAE,OAAO;KACrC,IAAI,MAAM,GAAG,KAAK,IAAI,EAAE,CAAC;6BAChB,GAAG;SACX,IAAI,WAAW,GAAG,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;SACjD,IAAI,KAAK,GAAG,WAAW,CAAC;SACxB,IAAI,OAAO,EAAE;aACZ,IAAI,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;aAC1B,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE;iBACtB,IAAA,2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;;;;;;;;;;;;;"}
\ No newline at end of file
......@@ -5,6 +5,12 @@
"module": "dist/index.es.js",
"license": "MIT",
"scripts": {
"dev": "rollup -c -w",
"build": "rollup -c"
},
"devDependencies": {
"rollup-plugin-typescript": "^1.0.1",
"tslib": "^1.11.1",
"typescript": "^3.8.3"
}
}
......@@ -3,28 +3,39 @@
*/
const name = 'props-compute';
const typescript = require('rollup-plugin-typescript');
export default {
input: 'src/index.js',
input: 'src/index.ts',
output: [
{
file: `dist/index.js`,
format: 'cjs',
sourcemap: true,
globals: {
tslib: 'tslib'
},
},
{
file: `dist/index.es.js`,
format: 'es',
sourcemap: true,
globals: {
tslib: 'tslib'
},
},
{
file: `dist/index.umd.js`,
format: 'umd',
sourcemap: true,
name,
globals: {
tslib: 'tslib'
},
}
],
plugins: [
]
typescript(),
],
external: ['tslib'],
};
......@@ -2,3 +2,44 @@
# yarn lockfile v1
estree-walker@^0.6.1:
version "0.6.1"
resolved "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz#53049143f40c6eb918b23671d1fe3219f3a1b362"
integrity sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==
path-parse@^1.0.6:
version "1.0.6"
resolved "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c"
integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==
resolve@^1.10.0:
version "1.15.1"
resolved "https://registry.npmjs.org/resolve/-/resolve-1.15.1.tgz#27bdcdeffeaf2d6244b95bb0f9f4b4653451f3e8"
integrity sha512-84oo6ZTtoTUpjgNEr5SJyzQhzL72gaRodsSfyxC/AXRvwu0Yse9H8eF9IpGo7b8YetZhlI6v7ZQ6bKBFV/6S7w==
dependencies:
path-parse "^1.0.6"
rollup-plugin-typescript@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/rollup-plugin-typescript/-/rollup-plugin-typescript-1.0.1.tgz#86565033b714c3d1f3aba510aad3dc519f7091e9"
integrity sha512-rwJDNn9jv/NsKZuyBb/h0jsclP4CJ58qbvZt2Q9zDIGILF2LtdtvCqMOL+Gq9IVq5MTrTlHZNrn8h7VjQgd8tw==
dependencies:
resolve "^1.10.0"
rollup-pluginutils "^2.5.0"
rollup-pluginutils@^2.5.0:
version "2.8.2"
resolved "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz#72f2af0748b592364dbd3389e600e5a9444a351e"
integrity sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==
dependencies:
estree-walker "^0.6.1"
tslib@^1.11.1:
version "1.11.1"
resolved "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz#eb15d128827fbee2841549e171f45ed338ac7e35"
integrity sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA==
typescript@^3.8.3:
version "3.8.3"
resolved "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"
integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment