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
f2121e72
Commit
f2121e72
authored
Sep 23, 2020
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支持range类型
parent
ba414655
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
98 additions
and
4 deletions
+98
-4
index.es.js
dist/index.es.js
+24
-1
index.es.js.map
dist/index.es.js.map
+1
-1
index.js
dist/index.js
+24
-0
index.js.map
dist/index.js.map
+1
-1
index.umd.js
dist/index.umd.js
+24
-0
index.umd.js.map
dist/index.umd.js.map
+1
-1
index.ts
src/index.ts
+23
-0
No files found.
dist/index.es.js
View file @
f2121e72
...
@@ -25,6 +25,9 @@ function compute(props, options) {
...
@@ -25,6 +25,9 @@ function compute(props, options) {
case
'vector2'
:
case
'vector2'
:
value
=
parseVector2
(
sourceValue
);
value
=
parseVector2
(
sourceValue
);
break
;
break
;
case
'range'
:
value
=
parseRange
(
sourceValue
);
break
;
case
'array'
:
case
'array'
:
var
seps
=
sourceValue
.
split
(
','
);
var
seps
=
sourceValue
.
split
(
','
);
seps
=
seps
.
map
(
function
(
sep
)
{
seps
=
seps
.
map
(
function
(
sep
)
{
...
@@ -85,6 +88,26 @@ function parseVector2(sourceValue) {
...
@@ -85,6 +88,26 @@ function parseVector2(sourceValue) {
}
}
return
value
;
return
value
;
}
}
function
parseRange
(
sourceValue
)
{
var
value
=
sourceValue
;
if
(
!
sourceValue
)
{
value
=
{
x
:
undefined
,
y
:
undefined
};
}
if
(
typeof
sourceValue
===
'string'
)
{
var
arr
=
sourceValue
.
split
(
','
);
value
=
{
min
:
arr
[
0
]
===
''
?
undefined
:
parseFloat
(
arr
[
0
]),
max
:
arr
[
1
]
===
''
?
undefined
:
parseFloat
(
arr
[
1
]),
};
}
else
if
(
Array
.
isArray
(
sourceValue
))
{
value
=
{
min
:
sourceValue
[
0
]
===
''
?
undefined
:
parseFloat
(
sourceValue
[
0
]),
max
:
sourceValue
[
1
]
===
''
?
undefined
:
parseFloat
(
sourceValue
[
1
]),
};
}
return
value
;
}
function
getValue
(
props
,
option
,
key
)
{
function
getValue
(
props
,
option
,
key
)
{
var
value
;
var
value
;
if
(
props
.
hasOwnProperty
(
key
))
{
if
(
props
.
hasOwnProperty
(
key
))
{
...
@@ -96,5 +119,5 @@ function getValue(props, option, key) {
...
@@ -96,5 +119,5 @@ function getValue(props, option, key) {
return
value
;
return
value
;
}
}
export
{
compute
,
parseType
,
parseVector2
};
export
{
compute
,
parse
Range
,
parse
Type
,
parseVector2
};
//# sourceMappingURL=index.es.js.map
//# sourceMappingURL=index.es.js.map
dist/index.es.js.map
View file @
f2121e72
{"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: Object | Array<any>) {\n\tlet result = props || {};\n\tif (Array.isArray(options)) {\n\t\tfor (let option of options) {\n\t\t\tlet key = option.name;\n\t\t\tlet value = getValue(result, option, key);\n\n\t\t\tresult[key] = transform(key, value, option);\n\t\t}\n\t} else {\n\t\tfor (let key in options) {\n\t\t\tlet option = options[key];\n\t\t\tlet value = getValue(result, option, key);\n\n\t\t\tresult[key] = transform(key, value, option);\n\t\t}\n\t}\n\treturn result;\n\n\tfunction transform(key, value, option) {\n\t\tlet sourceValue = value;\n\t\tif (option && option.type) {\n\t\t\tlet {type, generic} = parseType(option.type);\n\t\t\tswitch (type) {\n\t\t\t\tcase 'vector2':\n\t\t\t\t\tvalue = parseVector2(sourceValue);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'array':\n\t\t\t\t\tlet seps = sourceValue.split(',');\n\t\t\t\t\tseps = seps.map(sep => {\n\t\t\t\t\t\tlet item;\n\t\t\t\t\t\tif (generic) {\n\t\t\t\t\t\t\tswitch (generic) {\n\t\t\t\t\t\t\t\tcase 'number':\n\t\t\t\t\t\t\t\t\titem = parseFloat(sep);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 'boolean':\n\t\t\t\t\t\t\t\t\titem = sep === 'true';\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn item;\n\t\t\t\t\t});\n\t\t\t\t\tvalue = seps;\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn value;\n\t}\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, option, key) {\n\tlet value;\n\tif (props.hasOwnProperty(key)) {\n\t\tvalue = props[key];\n\t} else if (option && option.hasOwnProperty('default')) {\n\t\tvalue = option.default;\n\t}\n\n\treturn value;\n}\n"],"names":[],"mappings":"AAIA,IAAM,aAAa,GAAG,iBAAiB,CAAC;SAExB,OAAO,CAAC,KAAK,EAAE,OAA4B;IAC1D,IAAI,MAAM,GAAG,KAAK,IAAI,EAAE,CAAC;IACzB,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAC3B,KAAmB,UAAO,EAAP,mBAAO,EAAP,qBAAO,EAAP,IAAO,EAAE;YAAvB,IAAI,MAAM,gBAAA;YACd,IAAI,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC;YACtB,IAAI,KAAK,GAAG,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;YAE1C,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;SAC5C;KACD;SAAM;QACN,KAAK,IAAI,GAAG,IAAI,OAAO,EAAE;YACxB,IAAI,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;YAC1B,IAAI,KAAK,GAAG,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;YAE1C,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;SAC5C;KACD;IACD,OAAO,MAAM,CAAC;IAEd,SAAS,SAAS,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM;QACpC,IAAI,WAAW,GAAG,KAAK,CAAC;QACxB,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE;YACtB,IAAA,KAAkB,SAAS,CAAC,MAAM,CAAC,IAAI,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AE,SAAS,EAAC,CAAC;KACrC;IACD,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;QACpC,IAAI,GAAG,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACjC,KAAK,GAAG;YACP,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,GAAG,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACjD,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,GAAG,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;SACjD,CAAC;KACF;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;QACtC,KAAK,GAAG;YACP,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,EAAE,GAAG,SAAS,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;YACjE,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,EAAE,GAAG,SAAS,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;SACjE,CAAC;KACF;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,SAAS,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG;IACnC,IAAI,KAAK,CAAC;IACV,IAAI,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;QAC9B,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;KACnB;SAAM,IAAI,MAAM,IAAI,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE;QACtD,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC;KACvB;IAED,OAAO,KAAK,CAAC;AACd;;;;"}
{"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: Object | Array<any>) {\n\tlet result = props || {};\n\tif (Array.isArray(options)) {\n\t\tfor (let option of options) {\n\t\t\tlet key = option.name;\n\t\t\tlet value = getValue(result, option, key);\n\n\t\t\tresult[key] = transform(key, value, option);\n\t\t}\n\t} else {\n\t\tfor (let key in options) {\n\t\t\tlet option = options[key];\n\t\t\tlet value = getValue(result, option, key);\n\n\t\t\tresult[key] = transform(key, value, option);\n\t\t}\n\t}\n\treturn result;\n\n\tfunction transform(key, value, option) {\n\t\tlet sourceValue = value;\n\t\tif (option && option.type) {\n\t\t\tlet {type, generic} = parseType(option.type);\n\t\t\tswitch (type) {\n\t\t\t\tcase 'vector2':\n\t\t\t\t\tvalue = parseVector2(sourceValue);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'range':\n\t\t\t\t\tvalue = parseRange(sourceValue);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'array':\n\t\t\t\t\tlet seps = sourceValue.split(',');\n\t\t\t\t\tseps = seps.map(sep => {\n\t\t\t\t\t\tlet item;\n\t\t\t\t\t\tif (generic) {\n\t\t\t\t\t\t\tswitch (generic) {\n\t\t\t\t\t\t\t\tcase 'number':\n\t\t\t\t\t\t\t\t\titem = parseFloat(sep);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 'boolean':\n\t\t\t\t\t\t\t\t\titem = sep === 'true';\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn item;\n\t\t\t\t\t});\n\t\t\t\t\tvalue = seps;\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn value;\n\t}\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\nexport function parseRange(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\tmin: arr[0] === '' ? undefined : parseFloat(arr[0]),\n\t\t\tmax: arr[1] === '' ? undefined : parseFloat(arr[1]),\n\t\t};\n\t} else if (Array.isArray(sourceValue)) {\n\t\tvalue = {\n\t\t\tmin: sourceValue[0] === '' ? undefined : parseFloat(sourceValue[0]),\n\t\t\tmax: sourceValue[1] === '' ? undefined : parseFloat(sourceValue[1]),\n\t\t};\n\t}\n\treturn value;\n}\n\nfunction getValue(props, option, key) {\n\tlet value;\n\tif (props.hasOwnProperty(key)) {\n\t\tvalue = props[key];\n\t} else if (option && option.hasOwnProperty('default')) {\n\t\tvalue = option.default;\n\t}\n\n\treturn value;\n}\n"],"names":[],"mappings":"AAIA,IAAM,aAAa,GAAG,iBAAiB,CAAC;SAExB,OAAO,CAAC,KAAK,EAAE,OAA4B;IAC1D,IAAI,MAAM,GAAG,KAAK,IAAI,EAAE,CAAC;IACzB,IAAI,KAAK,CAAC,OAAO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S,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;SACnE,CAAC;KACF;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,SAAS,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG;IACnC,IAAI,KAAK,CAAC;IACV,IAAI,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;QAC9B,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;KACnB;SAAM,IAAI,MAAM,IAAI,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE;QACtD,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC;KACvB;IAED,OAAO,KAAK,CAAC;AACd;;;;"}
\ No newline at end of file
\ No newline at end of file
dist/index.js
View file @
f2121e72
...
@@ -29,6 +29,9 @@ function compute(props, options) {
...
@@ -29,6 +29,9 @@ function compute(props, options) {
case
'vector2'
:
case
'vector2'
:
value
=
parseVector2
(
sourceValue
);
value
=
parseVector2
(
sourceValue
);
break
;
break
;
case
'range'
:
value
=
parseRange
(
sourceValue
);
break
;
case
'array'
:
case
'array'
:
var
seps
=
sourceValue
.
split
(
','
);
var
seps
=
sourceValue
.
split
(
','
);
seps
=
seps
.
map
(
function
(
sep
)
{
seps
=
seps
.
map
(
function
(
sep
)
{
...
@@ -89,6 +92,26 @@ function parseVector2(sourceValue) {
...
@@ -89,6 +92,26 @@ function parseVector2(sourceValue) {
}
}
return
value
;
return
value
;
}
}
function
parseRange
(
sourceValue
)
{
var
value
=
sourceValue
;
if
(
!
sourceValue
)
{
value
=
{
x
:
undefined
,
y
:
undefined
};
}
if
(
typeof
sourceValue
===
'string'
)
{
var
arr
=
sourceValue
.
split
(
','
);
value
=
{
min
:
arr
[
0
]
===
''
?
undefined
:
parseFloat
(
arr
[
0
]),
max
:
arr
[
1
]
===
''
?
undefined
:
parseFloat
(
arr
[
1
]),
};
}
else
if
(
Array
.
isArray
(
sourceValue
))
{
value
=
{
min
:
sourceValue
[
0
]
===
''
?
undefined
:
parseFloat
(
sourceValue
[
0
]),
max
:
sourceValue
[
1
]
===
''
?
undefined
:
parseFloat
(
sourceValue
[
1
]),
};
}
return
value
;
}
function
getValue
(
props
,
option
,
key
)
{
function
getValue
(
props
,
option
,
key
)
{
var
value
;
var
value
;
if
(
props
.
hasOwnProperty
(
key
))
{
if
(
props
.
hasOwnProperty
(
key
))
{
...
@@ -101,6 +124,7 @@ function getValue(props, option, key) {
...
@@ -101,6 +124,7 @@ function getValue(props, option, key) {
}
}
exports
.
compute
=
compute
;
exports
.
compute
=
compute
;
exports
.
parseRange
=
parseRange
;
exports
.
parseType
=
parseType
;
exports
.
parseType
=
parseType
;
exports
.
parseVector2
=
parseVector2
;
exports
.
parseVector2
=
parseVector2
;
//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map
dist/index.js.map
View file @
f2121e72
{"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: Object | Array<any>) {\n\tlet result = props || {};\n\tif (Array.isArray(options)) {\n\t\tfor (let option of options) {\n\t\t\tlet key = option.name;\n\t\t\tlet value = getValue(result, option, key);\n\n\t\t\tresult[key] = transform(key, value, option);\n\t\t}\n\t} else {\n\t\tfor (let key in options) {\n\t\t\tlet option = options[key];\n\t\t\tlet value = getValue(result, option, key);\n\n\t\t\tresult[key] = transform(key, value, option);\n\t\t}\n\t}\n\treturn result;\n\n\tfunction transform(key, value, option) {\n\t\tlet sourceValue = value;\n\t\tif (option && option.type) {\n\t\t\tlet {type, generic} = parseType(option.type);\n\t\t\tswitch (type) {\n\t\t\t\tcase 'vector2':\n\t\t\t\t\tvalue = parseVector2(sourceValue);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'array':\n\t\t\t\t\tlet seps = sourceValue.split(',');\n\t\t\t\t\tseps = seps.map(sep => {\n\t\t\t\t\t\tlet item;\n\t\t\t\t\t\tif (generic) {\n\t\t\t\t\t\t\tswitch (generic) {\n\t\t\t\t\t\t\t\tcase 'number':\n\t\t\t\t\t\t\t\t\titem = parseFloat(sep);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 'boolean':\n\t\t\t\t\t\t\t\t\titem = sep === 'true';\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn item;\n\t\t\t\t\t});\n\t\t\t\t\tvalue = seps;\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn value;\n\t}\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, option, key) {\n\tlet value;\n\tif (props.hasOwnProperty(key)) {\n\t\tvalue = props[key];\n\t} else if (option && option.hasOwnProperty('default')) {\n\t\tvalue = option.default;\n\t}\n\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AAE,GAAG,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACjD,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,GAAG,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;SACjD,CAAC;KACF;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;QACtC,KAAK,GAAG;YACP,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,EAAE,GAAG,SAAS,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;YACjE,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,EAAE,GAAG,SAAS,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;SACjE,CAAC;KACF;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,SAAS,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG;IACnC,IAAI,KAAK,CAAC;IACV,IAAI,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;QAC9B,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;KACnB;SAAM,IAAI,MAAM,IAAI,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE;QACtD,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC;KACvB;IAED,OAAO,KAAK,CAAC;AACd;;;;;;"}
{"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: Object | Array<any>) {\n\tlet result = props || {};\n\tif (Array.isArray(options)) {\n\t\tfor (let option of options) {\n\t\t\tlet key = option.name;\n\t\t\tlet value = getValue(result, option, key);\n\n\t\t\tresult[key] = transform(key, value, option);\n\t\t}\n\t} else {\n\t\tfor (let key in options) {\n\t\t\tlet option = options[key];\n\t\t\tlet value = getValue(result, option, key);\n\n\t\t\tresult[key] = transform(key, value, option);\n\t\t}\n\t}\n\treturn result;\n\n\tfunction transform(key, value, option) {\n\t\tlet sourceValue = value;\n\t\tif (option && option.type) {\n\t\t\tlet {type, generic} = parseType(option.type);\n\t\t\tswitch (type) {\n\t\t\t\tcase 'vector2':\n\t\t\t\t\tvalue = parseVector2(sourceValue);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'range':\n\t\t\t\t\tvalue = parseRange(sourceValue);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'array':\n\t\t\t\t\tlet seps = sourceValue.split(',');\n\t\t\t\t\tseps = seps.map(sep => {\n\t\t\t\t\t\tlet item;\n\t\t\t\t\t\tif (generic) {\n\t\t\t\t\t\t\tswitch (generic) {\n\t\t\t\t\t\t\t\tcase 'number':\n\t\t\t\t\t\t\t\t\titem = parseFloat(sep);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 'boolean':\n\t\t\t\t\t\t\t\t\titem = sep === 'true';\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn item;\n\t\t\t\t\t});\n\t\t\t\t\tvalue = seps;\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn value;\n\t}\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\nexport function parseRange(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\tmin: arr[0] === '' ? undefined : parseFloat(arr[0]),\n\t\t\tmax: arr[1] === '' ? undefined : parseFloat(arr[1]),\n\t\t};\n\t} else if (Array.isArray(sourceValue)) {\n\t\tvalue = {\n\t\t\tmin: sourceValue[0] === '' ? undefined : parseFloat(sourceValue[0]),\n\t\t\tmax: sourceValue[1] === '' ? undefined : parseFloat(sourceValue[1]),\n\t\t};\n\t}\n\treturn value;\n}\n\nfunction getValue(props, option, key) {\n\tlet value;\n\tif (props.hasOwnProperty(key)) {\n\t\tvalue = props[key];\n\t} else if (option && option.hasOwnProperty('default')) {\n\t\tvalue = option.default;\n\t}\n\n\treturn value;\n}\n"],"names":[],"mappings":";;;;AAIA,IAAM,aAAa,GAAG,iBAAiB,CAAC;SAExB,OAAO,CAAC,KAAK,EAAE,OAA4B;IAC1D,IAAI,MAAM,GAAG,KAAK,IAAI,EAAE,CAAC;IACzB,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAC3B,KAAmB,UAAO,EAAP,mBAAO,EAAP,qBAAO,EAAP,IAAO,EAAE;YAAvB,IAAI,MAAM,gBAAA;YACd,IAAI,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC;YACtB,IAAI,KAAK,GAAG,QAAQ,CAA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AC,cAAc,CAAC,GAAG,CAAC,EAAE;QAC9B,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;KACnB;SAAM,IAAI,MAAM,IAAI,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE;QACtD,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC;KACvB;IAED,OAAO,KAAK,CAAC;AACd;;;;;;;"}
\ No newline at end of file
\ No newline at end of file
dist/index.umd.js
View file @
f2121e72
...
@@ -31,6 +31,9 @@
...
@@ -31,6 +31,9 @@
case
'vector2'
:
case
'vector2'
:
value
=
parseVector2
(
sourceValue
);
value
=
parseVector2
(
sourceValue
);
break
;
break
;
case
'range'
:
value
=
parseRange
(
sourceValue
);
break
;
case
'array'
:
case
'array'
:
var
seps
=
sourceValue
.
split
(
','
);
var
seps
=
sourceValue
.
split
(
','
);
seps
=
seps
.
map
(
function
(
sep
)
{
seps
=
seps
.
map
(
function
(
sep
)
{
...
@@ -91,6 +94,26 @@
...
@@ -91,6 +94,26 @@
}
}
return
value
;
return
value
;
}
}
function
parseRange
(
sourceValue
)
{
var
value
=
sourceValue
;
if
(
!
sourceValue
)
{
value
=
{
x
:
undefined
,
y
:
undefined
};
}
if
(
typeof
sourceValue
===
'string'
)
{
var
arr
=
sourceValue
.
split
(
','
);
value
=
{
min
:
arr
[
0
]
===
''
?
undefined
:
parseFloat
(
arr
[
0
]),
max
:
arr
[
1
]
===
''
?
undefined
:
parseFloat
(
arr
[
1
]),
};
}
else
if
(
Array
.
isArray
(
sourceValue
))
{
value
=
{
min
:
sourceValue
[
0
]
===
''
?
undefined
:
parseFloat
(
sourceValue
[
0
]),
max
:
sourceValue
[
1
]
===
''
?
undefined
:
parseFloat
(
sourceValue
[
1
]),
};
}
return
value
;
}
function
getValue
(
props
,
option
,
key
)
{
function
getValue
(
props
,
option
,
key
)
{
var
value
;
var
value
;
if
(
props
.
hasOwnProperty
(
key
))
{
if
(
props
.
hasOwnProperty
(
key
))
{
...
@@ -103,6 +126,7 @@
...
@@ -103,6 +126,7 @@
}
}
exports
.
compute
=
compute
;
exports
.
compute
=
compute
;
exports
.
parseRange
=
parseRange
;
exports
.
parseType
=
parseType
;
exports
.
parseType
=
parseType
;
exports
.
parseVector2
=
parseVector2
;
exports
.
parseVector2
=
parseVector2
;
...
...
dist/index.umd.js.map
View file @
f2121e72
{"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: Object | Array<any>) {\n\tlet result = props || {};\n\tif (Array.isArray(options)) {\n\t\tfor (let option of options) {\n\t\t\tlet key = option.name;\n\t\t\tlet value = getValue(result, option, key);\n\n\t\t\tresult[key] = transform(key, value, option);\n\t\t}\n\t} else {\n\t\tfor (let key in options) {\n\t\t\tlet option = options[key];\n\t\t\tlet value = getValue(result, option, key);\n\n\t\t\tresult[key] = transform(key, value, option);\n\t\t}\n\t}\n\treturn result;\n\n\tfunction transform(key, value, option) {\n\t\tlet sourceValue = value;\n\t\tif (option && option.type) {\n\t\t\tlet {type, generic} = parseType(option.type);\n\t\t\tswitch (type) {\n\t\t\t\tcase 'vector2':\n\t\t\t\t\tvalue = parseVector2(sourceValue);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'array':\n\t\t\t\t\tlet seps = sourceValue.split(',');\n\t\t\t\t\tseps = seps.map(sep => {\n\t\t\t\t\t\tlet item;\n\t\t\t\t\t\tif (generic) {\n\t\t\t\t\t\t\tswitch (generic) {\n\t\t\t\t\t\t\t\tcase 'number':\n\t\t\t\t\t\t\t\t\titem = parseFloat(sep);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 'boolean':\n\t\t\t\t\t\t\t\t\titem = sep === 'true';\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn item;\n\t\t\t\t\t});\n\t\t\t\t\tvalue = seps;\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn value;\n\t}\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, option, key) {\n\tlet value;\n\tif (props.hasOwnProperty(key)) {\n\t\tvalue = props[key];\n\t} else if (option && option.hasOwnProperty('default')) {\n\t\tvalue = option.default;\n\t}\n\n\treturn value;\n}\n"],"names":[],"mappings":";;;;;;CAIA,IAAM,aAAa,GAAG,iBAAiB,CAAC;UAExB,OAAO,CAAC,KAAK,EAAE,OAA4B;KAC1D,IAAI,MAAM,GAAG,KAAK,IAAI,EAAE,CAAC;KACzB,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;SAC3B,KAAmB,UAAO,EAAP,mBAAO,EAAP,qBAAO,EAAP,IAAO,EAAE;aAAvB,IAAI,MAAM,gBAAA;aACd,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KAAK,EAAE,GAAG,SAAS,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;aACjE,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,EAAE,GAAG,SAAS,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;UACjE,CAAC;MACF;KACD,OAAO,KAAK,CAAC;CACd,CAAC;CAED,SAAS,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG;KACnC,IAAI,KAAK,CAAC;KACV,IAAI,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;SAC9B,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;MACnB;UAAM,IAAI,MAAM,IAAI,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE;SACtD,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC;MACvB;KAED,OAAO,KAAK,CAAC;CACd;;;;;;;;;;;;;;"}
{"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: Object | Array<any>) {\n\tlet result = props || {};\n\tif (Array.isArray(options)) {\n\t\tfor (let option of options) {\n\t\t\tlet key = option.name;\n\t\t\tlet value = getValue(result, option, key);\n\n\t\t\tresult[key] = transform(key, value, option);\n\t\t}\n\t} else {\n\t\tfor (let key in options) {\n\t\t\tlet option = options[key];\n\t\t\tlet value = getValue(result, option, key);\n\n\t\t\tresult[key] = transform(key, value, option);\n\t\t}\n\t}\n\treturn result;\n\n\tfunction transform(key, value, option) {\n\t\tlet sourceValue = value;\n\t\tif (option && option.type) {\n\t\t\tlet {type, generic} = parseType(option.type);\n\t\t\tswitch (type) {\n\t\t\t\tcase 'vector2':\n\t\t\t\t\tvalue = parseVector2(sourceValue);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'range':\n\t\t\t\t\tvalue = parseRange(sourceValue);\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'array':\n\t\t\t\t\tlet seps = sourceValue.split(',');\n\t\t\t\t\tseps = seps.map(sep => {\n\t\t\t\t\t\tlet item;\n\t\t\t\t\t\tif (generic) {\n\t\t\t\t\t\t\tswitch (generic) {\n\t\t\t\t\t\t\t\tcase 'number':\n\t\t\t\t\t\t\t\t\titem = parseFloat(sep);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tcase 'boolean':\n\t\t\t\t\t\t\t\t\titem = sep === 'true';\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\titem = sep;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn item;\n\t\t\t\t\t});\n\t\t\t\t\tvalue = seps;\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn value;\n\t}\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\nexport function parseRange(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\tmin: arr[0] === '' ? undefined : parseFloat(arr[0]),\n\t\t\tmax: arr[1] === '' ? undefined : parseFloat(arr[1]),\n\t\t};\n\t} else if (Array.isArray(sourceValue)) {\n\t\tvalue = {\n\t\t\tmin: sourceValue[0] === '' ? undefined : parseFloat(sourceValue[0]),\n\t\t\tmax: sourceValue[1] === '' ? undefined : parseFloat(sourceValue[1]),\n\t\t};\n\t}\n\treturn value;\n}\n\nfunction getValue(props, option, key) {\n\tlet value;\n\tif (props.hasOwnProperty(key)) {\n\t\tvalue = props[key];\n\t} else if (option && option.hasOwnProperty('default')) {\n\t\tvalue = option.default;\n\t}\n\n\treturn value;\n}\n"],"names":[],"mappings":";;;;;;CAIA,IAAM,aAAa,GAAG,iBAAiB,CAAC;UAExB,OAAO,CAAC,KAAK,EAAE,OAA4B;KAC1D,IAAI,MAAM,GAAG,KAAK,IAAI,EAAE,CAAC;KACzB,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;SAC3B,KAAmB,UAAO,EAAP,mBAAO,EAAP,qBAAO,EAAP,IAAO,EAAE;aAAvB,IAAI,MAAM,gBAAA;aACd,IAAI,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC;aACtB,IAAI,KAAK,GAAG,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;aAE1C,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;UAC5C;MACD;UAAM;SACN,KAAK,IAAI,GAAG,IAAI,OAAO,EAAE;aACxB,IAAI,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;aAC1B,IAAI,KAAK,GAAG,QAAQ,CAAC,MAAM,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72
...
@@ -31,6 +31,9 @@ export function compute(props, options: Object | Array<any>) {
...
@@ -31,6 +31,9 @@ export function compute(props, options: Object | Array<any>) {
case
'vector2'
:
case
'vector2'
:
value
=
parseVector2
(
sourceValue
);
value
=
parseVector2
(
sourceValue
);
break
;
break
;
case
'range'
:
value
=
parseRange
(
sourceValue
);
break
;
case
'array'
:
case
'array'
:
let
seps
=
sourceValue
.
split
(
','
);
let
seps
=
sourceValue
.
split
(
','
);
seps
=
seps
.
map
(
sep
=>
{
seps
=
seps
.
map
(
sep
=>
{
...
@@ -93,6 +96,26 @@ export function parseVector2(sourceValue) {
...
@@ -93,6 +96,26 @@ export function parseVector2(sourceValue) {
return
value
;
return
value
;
}
}
export
function
parseRange
(
sourceValue
)
{
let
value
=
sourceValue
;
if
(
!
sourceValue
)
{
value
=
{
x
:
undefined
,
y
:
undefined
};
}
if
(
typeof
sourceValue
===
'string'
)
{
let
arr
=
sourceValue
.
split
(
','
);
value
=
{
min
:
arr
[
0
]
===
''
?
undefined
:
parseFloat
(
arr
[
0
]),
max
:
arr
[
1
]
===
''
?
undefined
:
parseFloat
(
arr
[
1
]),
};
}
else
if
(
Array
.
isArray
(
sourceValue
))
{
value
=
{
min
:
sourceValue
[
0
]
===
''
?
undefined
:
parseFloat
(
sourceValue
[
0
]),
max
:
sourceValue
[
1
]
===
''
?
undefined
:
parseFloat
(
sourceValue
[
1
]),
};
}
return
value
;
}
function
getValue
(
props
,
option
,
key
)
{
function
getValue
(
props
,
option
,
key
)
{
let
value
;
let
value
;
if
(
props
.
hasOwnProperty
(
key
))
{
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