Commit c676e9e1 authored by rockyl's avatar rockyl

更新

parents
Pipeline #203273 failed with stages
in 0 seconds
# Created by .ignore support plugin (hsz.mobi)
### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
/**
* Created by rockyl on 2020-01-27.
*/
const 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 = option.type;
let generic;
let regResult = type.match(genericRegexp);
if (regResult) {
type = regResult[1];
generic = regResult[3];
}
switch (type) {
case 'vector2':
if (typeof sourceValue === 'string') {
let arr = sourceValue.split(',');
value = {
x: arr[0] === '' ? 0 : parseFloat(arr[0]),
y: arr[1] === '' ? 0 : parseFloat(arr[1]),
};
} else if (Array.isArray(sourceValue)) {
value = {
x: sourceValue[0] === '' ? 0 : parseFloat(sourceValue[0]),
y: sourceValue[1] === '' ? 0 : parseFloat(sourceValue[1]),
};
}
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;
}
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;
}
export { compute };
//# sourceMappingURL=index.es.js.map
{"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 = option.type;\n\t\t\t\tlet generic;\n\t\t\t\tlet regResult = type.match(genericRegexp);\n\t\t\t\tif (regResult) {\n\t\t\t\t\ttype = regResult[1];\n\t\t\t\t\tgeneric = regResult[3];\n\t\t\t\t}\n\t\t\t\tswitch (type) {\n\t\t\t\t\tcase 'vector2':\n\t\t\t\t\t\tif (typeof sourceValue === 'string') {\n\t\t\t\t\t\t\tlet arr = sourceValue.split(',');\n\t\t\t\t\t\t\tvalue = {\n\t\t\t\t\t\t\t\tx: arr[0] === '' ? 0 : parseFloat(arr[0]),\n\t\t\t\t\t\t\t\ty: arr[1] === '' ? 0 : parseFloat(arr[1]),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else if (Array.isArray(sourceValue)) {\n\t\t\t\t\t\t\tvalue = {\n\t\t\t\t\t\t\t\tx: sourceValue[0] === '' ? 0 : parseFloat(sourceValue[0]),\n\t\t\t\t\t\t\t\ty: sourceValue[1] === '' ? 0 : parseFloat(sourceValue[1]),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\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\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,MA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AI,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;UACtB,MAAM;SACP;UACC,IAAI,GAAG,GAAG,CAAC;UACX,MAAM;SACP;QACD,MAAM;QACN,IAAI,GAAG,GAAG,CAAC;QACX;OACD,OAAO,IAAI,CAAC;OACZ,CAAC,CAAC;MACH,KAAK,GAAG,IAAI,CAAC;MACb,MAAM;KACP;IACD;GACD;EACD,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;EACpB;CACD,OAAO,MAAM,CAAC;CACd;;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
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Created by rockyl on 2020-01-27.
*/
const 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 = option.type;
let generic;
let regResult = type.match(genericRegexp);
if (regResult) {
type = regResult[1];
generic = regResult[3];
}
switch (type) {
case 'vector2':
if (typeof sourceValue === 'string') {
let arr = sourceValue.split(',');
value = {
x: arr[0] === '' ? 0 : parseFloat(arr[0]),
y: arr[1] === '' ? 0 : parseFloat(arr[1]),
};
} else if (Array.isArray(sourceValue)) {
value = {
x: sourceValue[0] === '' ? 0 : parseFloat(sourceValue[0]),
y: sourceValue[1] === '' ? 0 : parseFloat(sourceValue[1]),
};
}
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;
}
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;
}
exports.compute = compute;
//# sourceMappingURL=index.js.map
{"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 = option.type;\n\t\t\t\tlet generic;\n\t\t\t\tlet regResult = type.match(genericRegexp);\n\t\t\t\tif (regResult) {\n\t\t\t\t\ttype = regResult[1];\n\t\t\t\t\tgeneric = regResult[3];\n\t\t\t\t}\n\t\t\t\tswitch (type) {\n\t\t\t\t\tcase 'vector2':\n\t\t\t\t\t\tif (typeof sourceValue === 'string') {\n\t\t\t\t\t\t\tlet arr = sourceValue.split(',');\n\t\t\t\t\t\t\tvalue = {\n\t\t\t\t\t\t\t\tx: arr[0] === '' ? 0 : parseFloat(arr[0]),\n\t\t\t\t\t\t\t\ty: arr[1] === '' ? 0 : parseFloat(arr[1]),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else if (Array.isArray(sourceValue)) {\n\t\t\t\t\t\t\tvalue = {\n\t\t\t\t\t\t\t\tx: sourceValue[0] === '' ? 0 : parseFloat(sourceValue[0]),\n\t\t\t\t\t\t\t\ty: sourceValue[1] === '' ? 0 : parseFloat(sourceValue[1]),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\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\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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C,CAAC,CAAC,CAAC;QACzD,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QACzD,CAAC;OACF;MACD,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;UACtB,MAAM;SACP;UACC,IAAI,GAAG,GAAG,CAAC;UACX,MAAM;SACP;QACD,MAAM;QACN,IAAI,GAAG,GAAG,CAAC;QACX;OACD,OAAO,IAAI,CAAC;OACZ,CAAC,CAAC;MACH,KAAK,GAAG,IAAI,CAAC;MACb,MAAM;KACP;IACD;GACD;EACD,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;EACpB;CACD,OAAO,MAAM,CAAC;CACd;;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
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory(global['props-compute'] = {}));
}(this, function (exports) { 'use strict';
/**
* Created by rockyl on 2020-01-27.
*/
const 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 = option.type;
let generic;
let regResult = type.match(genericRegexp);
if (regResult) {
type = regResult[1];
generic = regResult[3];
}
switch (type) {
case 'vector2':
if (typeof sourceValue === 'string') {
let arr = sourceValue.split(',');
value = {
x: arr[0] === '' ? 0 : parseFloat(arr[0]),
y: arr[1] === '' ? 0 : parseFloat(arr[1]),
};
} else if (Array.isArray(sourceValue)) {
value = {
x: sourceValue[0] === '' ? 0 : parseFloat(sourceValue[0]),
y: sourceValue[1] === '' ? 0 : parseFloat(sourceValue[1]),
};
}
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;
}
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;
}
exports.compute = compute;
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=index.umd.js.map
{"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 = option.type;\n\t\t\t\tlet generic;\n\t\t\t\tlet regResult = type.match(genericRegexp);\n\t\t\t\tif (regResult) {\n\t\t\t\t\ttype = regResult[1];\n\t\t\t\t\tgeneric = regResult[3];\n\t\t\t\t}\n\t\t\t\tswitch (type) {\n\t\t\t\t\tcase 'vector2':\n\t\t\t\t\t\tif (typeof sourceValue === 'string') {\n\t\t\t\t\t\t\tlet arr = sourceValue.split(',');\n\t\t\t\t\t\t\tvalue = {\n\t\t\t\t\t\t\t\tx: arr[0] === '' ? 0 : parseFloat(arr[0]),\n\t\t\t\t\t\t\t\ty: arr[1] === '' ? 0 : parseFloat(arr[1]),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else if (Array.isArray(sourceValue)) {\n\t\t\t\t\t\t\tvalue = {\n\t\t\t\t\t\t\t\tx: sourceValue[0] === '' ? 0 : parseFloat(sourceValue[0]),\n\t\t\t\t\t\t\t\ty: sourceValue[1] === '' ? 0 : parseFloat(sourceValue[1]),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\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\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,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;CAC3B,IAAI,IAAI,OAAO,CAAC;CAChB,IAAI,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;CAC9C,IAAI,IAAI,SAAS,EAAE;CACnB,KAAK,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;CACzB,KAAK,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;CAC5B,KAAK;CACL,IAAI,QAAQ,IAAI;CAChB,KAAK,KAAK,SAAS;CACnB,MAAM,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;CAC3C,OAAO,IAAI,GAAG,GAAG,WAAW,CAAC,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,IAAI,GAAG,GAAG,CAAC;CACnB,QAAQ;CACR,OAAO,OAAO,IAAI,CAAC;CACnB,OAAO,CAAC,CAAC;CACT,MAAM,KAAK,GAAG,IAAI,CAAC;CACnB,MAAM,MAAM;CACZ,KAAK;CACL,IAAI;CACJ,GAAG;CACH,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;CACtB,EAAE;CACF,CAAC,OAAO,MAAM,CAAC;CACf,CAAC;;CAED,SAAS,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE;CACvC,CAAC,IAAI,KAAK,CAAC;CACX,CAAC,IAAI,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;CAChC,EAAE,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;CACrB,EAAE,MAAM,IAAI,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,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
{
"name": "props-compute",
"version": "1.0.0",
"main": "dist/index.js",
"module": "dist/index.es.js",
"license": "MIT",
"scripts": {
"build": "rollup -c"
}
}
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/dist" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
/**
* Created by rockyl on 2018/11/16.
*/
const name = 'props-compute';
export default {
input: 'src/index.js',
output: [
{
file: `dist/index.js`,
format: 'cjs',
sourcemap: true,
},
{
file: `dist/index.es.js`,
format: 'es',
sourcemap: true,
},
{
file: `dist/index.umd.js`,
format: 'umd',
sourcemap: true,
name,
}
],
plugins: [
]
};
/**
* Created by rockyl on 2020-01-27.
*/
const genericRegexp = /(\w+)(<(\w+)>)?/;
export 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 = option.type;
let generic;
let regResult = type.match(genericRegexp);
if (regResult) {
type = regResult[1];
generic = regResult[3];
}
switch (type) {
case 'vector2':
if (typeof sourceValue === 'string') {
let arr = sourceValue.split(',');
value = {
x: arr[0] === '' ? 0 : parseFloat(arr[0]),
y: arr[1] === '' ? 0 : parseFloat(arr[1]),
};
} else if (Array.isArray(sourceValue)) {
value = {
x: sourceValue[0] === '' ? 0 : parseFloat(sourceValue[0]),
y: sourceValue[1] === '' ? 0 : parseFloat(sourceValue[1]),
};
}
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;
}
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;
}
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