Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
props-compute
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
劳工
props-compute
Commits
f56a8b12
Commit
f56a8b12
authored
Feb 12, 2020
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
方法分离
parent
c676e9e1
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
148 additions
and
80 deletions
+148
-80
index.es.js
dist/index.es.js
+36
-20
index.es.js.map
dist/index.es.js.map
+1
-1
index.js
dist/index.js
+37
-19
index.js.map
dist/index.js.map
+1
-1
index.umd.js
dist/index.umd.js
+37
-19
index.umd.js.map
dist/index.umd.js.map
+1
-1
index.js
src/index.js
+35
-19
No files found.
dist/index.es.js
View file @
f56a8b12
...
...
@@ -12,27 +12,10 @@ function compute(props, options) {
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
];
}
let
{
type
,
generic
}
=
parseType
(
option
.
type
);
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
]),
};
}
value
=
parseVector2
(
sourceValue
);
break
;
case
'array'
:
let
seps
=
sourceValue
.
split
(
','
);
...
...
@@ -65,6 +48,39 @@ function compute(props, options) {
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
,
}
}
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
;
}
function
getValue
(
props
,
options
,
key
)
{
let
value
;
if
(
props
.
hasOwnProperty
(
key
))
{
...
...
@@ -76,5 +92,5 @@ function getValue(props, options, key) {
return
value
;
}
export
{
compute
};
export
{
compute
,
parseType
,
parseVector2
};
//# sourceMappingURL=index.es.js.map
dist/index.es.js.map
View file @
f56a8b12
{"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,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,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;IACvB,IAAI,OAAO,CAAC;IACZ,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAC1C,IAAI,SAAS,EAAE;KACd,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;KACpB,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;KACvB;IACD,QAAQ,IAAI;KACX,KAAK,SAAS;MACb,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;OACpC,IAAI,GAAG,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;OACjC,KAAK,GAAG;QACP,CAA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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.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,GAA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AAC,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
dist/index.js
View file @
f56a8b12
...
...
@@ -16,27 +16,10 @@ function compute(props, options) {
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
];
}
let
{
type
,
generic
}
=
parseType
(
option
.
type
);
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
]),
};
}
value
=
parseVector2
(
sourceValue
);
break
;
case
'array'
:
let
seps
=
sourceValue
.
split
(
','
);
...
...
@@ -69,6 +52,39 @@ function compute(props, options) {
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
,
}
}
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
;
}
function
getValue
(
props
,
options
,
key
)
{
let
value
;
if
(
props
.
hasOwnProperty
(
key
))
{
...
...
@@ -81,4 +97,6 @@ function getValue(props, options, key) {
}
exports
.
compute
=
compute
;
exports
.
parseType
=
parseType
;
exports
.
parseVector2
=
parseVector2
;
//# sourceMappingURL=index.js.map
dist/index.js.map
View file @
f56a8b12
{"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,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,I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M;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
{"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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K,EAAE,GAAG,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;GACjD,CAAC;EACF,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;EACtC,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
dist/index.umd.js
View file @
f56a8b12
...
...
@@ -18,27 +18,10 @@
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
];
}
let
{
type
,
generic
}
=
parseType
(
option
.
type
);
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
]),
};
}
value
=
parseVector2
(
sourceValue
);
break
;
case
'array'
:
let
seps
=
sourceValue
.
split
(
','
);
...
...
@@ -71,6 +54,39 @@
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
,
}
}
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
;
}
function
getValue
(
props
,
options
,
key
)
{
let
value
;
if
(
props
.
hasOwnProperty
(
key
))
{
...
...
@@ -83,6 +99,8 @@
}
exports
.
compute
=
compute
;
exports
.
parseType
=
parseType
;
exports
.
parseVector2
=
parseVector2
;
Object
.
defineProperty
(
exports
,
'__esModule'
,
{
value
:
true
});
...
...
dist/index.umd.js.map
View file @
f56a8b12
{"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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,KAAK,SAAS;CACvB,UAAU,IAAI,GAAG,GAAG,KAAK,MAAM,CAAC;CAChC,UAAU,MAAM;CAChB,SAAS;CACT,UAAU,IAAI,GAAG,GAAG,CAAC;CACrB,UAAU,MAAM;CAChB,SAAS;CACT,QAAQ,MAAM;CACd,QAAQ,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
{"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,IAAI,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;CACxC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI;CAC7B,OAAO,IAAI,IAAI,CAAC;CAChB,OAAO,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;;;;;;"}
\ No newline at end of file
src/index.js
View file @
f56a8b12
...
...
@@ -12,27 +12,10 @@ export function compute(props, options) {
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
];
}
let
{
type
,
generic
}
=
parseType
(
option
.
type
);
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
]),
};
}
value
=
parseVector2
(
sourceValue
);
break
;
case
'array'
:
let
seps
=
sourceValue
.
split
(
','
);
...
...
@@ -65,6 +48,39 @@ export function compute(props, options) {
return
result
;
}
export
function
parseType
(
typeStr
)
{
let
type
=
typeStr
,
generic
;
let
regResult
=
typeStr
.
match
(
genericRegexp
);
if
(
regResult
)
{
type
=
regResult
[
1
];
generic
=
regResult
[
3
];
}
return
{
type
,
generic
,
}
}
export
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
;
}
function
getValue
(
props
,
options
,
key
)
{
let
value
;
if
(
props
.
hasOwnProperty
(
key
))
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment